# VFP开发公众号领取优惠券,用户注册后跳转各种目标页,一套标准流程送给您

最近在给福建某知名超市设计成优惠券系统中,遇到了这样一个需求。超市系统中会员注册是依据手机号注册的,那公众号中发放优惠券系统就需要实现微信ID和手机号的绑定,然后再跳转到优惠券领取页面。 这里还有一个流程,原来登录是跳转到会员中心的,现在是要求直接跳转到领取优惠券页面。 流程如下: 流程

要实现这个流程在祺佑三层框架(猫框)中也很简单。 会员中心入口网址 ctl_user.fsp?proc=usercenterhtml

Procedure usercenterhtml
	Local cOpenid,lcCode,url,cTitle
	*cOpenid=This.ReGetOpenId() &&如果要调用OPENID 的地方,就要执行这个获取openid
	cWorkhtml=getwwwRootPath("")+"tmpl\usercenter.html"
	cReghtml=getwwwRootPath("")+"tmpl\reg.html"
	cOpenid=HttpQueryParams("openid")
	If Empty(cOpenid)
		This.ReGetOpenId()
	Else
		*写入cookie
		httpSetcookie("openid",cOpenid,Datetime()+2*3600)
		This.openid=cOpenid
	Endif
	*--验证用户openid数据表是否存在,如若存在即是已绑定
	If !Empty(This.openid)
		oDBSQLhelper=Newobject("MSSQLHelper","MSSQLHelper.prg")
		TEXT TO lcSQLCmd NOSHOW TEXTMERGE
		   SELECT COUNT(*) FROM wxuser_ck WHERE wxid=?this.openid
		ENDTEXT		
		nRow=oDBSQLhelper.GetSingle(lcSQLCmd)
		If Isnull(nRow) And !Empty(oDBSQLhelper.errmsg)
			Error oDBSQLhelper.errmsg
		Endif
		Do Case
			Case nRow==0  &&没有记录,跳转到登录面				
				Private lcmyurl				
				lcmyurl="ctl_user.fsp?proc=usercenterhtml&appuser=bluesky"
				cHtml=FWS_MergeFile(cReghtml)	&&需要注册
			Case nRow==1
				cHtml=Filetostr(cWorkhtml)  &&已注册,用户中心页
			Otherwise
				Error "用户重复注册"
		Endcase
	Endif
	
	Return cHtml
Endproc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

这里面有一句值得关注lcmyurl,存放了登录完成之后的跳转URL 登录页HTML代码

<form id="form">
    <div class="weui_cells weui_cells_form">       
        <div class="weui_cell weui_vcode">
            <div class="weui_cell_hd"><label class="weui_label"><i class="icon icon-90 f20 query-color"></i> 手机号</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input id="txtphone" class="weui_input" type="tel" required pattern="[0-9]{11}" maxlength="11"placeholder="请输入手机号" tips="请输入手机号" notMatchTips="请输入正确的手机号">
            </div>
            <div class="weui_cell_ft">
                <i class="weui_icon_warn"></i>
                <a id="btnyzm" href="javascript:;" class="weui-vcode-btn query-color">获取验证码</a>
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"><i class="icon icon-71 f20 query-color"></i> 验证码</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input id="txtyzm" class="weui_input" type="number" required placeholder="请输入验证码" emptyTips="请输入验证码">
            </div>
            <div class="weui_cell_ft">
                <i class="weui_icon_warn"></i>
            </div>
        </div>
    </div>
    <div class="weui_btn_area">
        <a id="formSubmitBtn" href="javascript:" class="weui_btn query-bg-color">注 册</a>
    </div>

</form>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

登录按钮绑定click事件

$("#formSubmitBtn").on("click",function(){
         	var cphone=$("#txtphone").val();
           	var yzm=$("#txtyzm").val();
         	$.post("ctl_user.fsp?proc=userbind&appuser=bluesky",{
           	 	phone:cphone,
           	 	code:yzm
           	 },function(data){
           	 	console.log(data);
           	 	var odata=JSON.parse(data);
           	 	if(odata.errno!=0){
           	 		$.alert(odata.errmsg);
           	 		return;
           	 	}           	 	
           	    $.alert("绑定成功,开始跳转");
           	    setTimeout(function(){					
           	    	window.location.href="<%=u(lcmyurl)%>"
           	    },3000)
           	    
           	 })
           	 
         })
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

这样就可以实现任意的URL,先跳转登录页,再跳转目标页的功能了。