
ASP微信服务号H5客户登陆,且获取客户授权的用户基本信息是需要客户授权,下面讲解详细步骤:
第一步:客户点击登录页,自动跳转到微信服务器端获取code
第二步:用第一步获取的code去获取客户的access_token、openid
第三步:用刚才获取到的access_token、openid去获取客户基本信息
上述三步设计的内容相对逻辑简单,但是写代码逻辑全部被封装到WeixinDLL,下面直接上代码。
登录页面:login.asp
1 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
2 <!DOCTYPE html>
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
7 <title>客户微信登陆</title>
8 </head>
9 <body>
10 <%
11 On Error Resume Next
12 Dim WxObj
13 Set WxObj = Server.CreateObject("WeixinDLL.WeixinClass")
14 WxObj.SetAppID = "微信服务号AppID"
15 Dim RedirectUrl,CallUrl
16 CallUrl = "https://www.domain.com/login/call.asp" ' 这个是跳转返回我们自己服务器接收客户数据信息的页面
17 RedirectUrl = WxObj.Get_RedirectUrl(CallUrl) '这个是将微信条状登录复杂页面封装到DLL内直接调用即可
18 Response.Redirect(RedirectUrl) '跳转登录认证
19 Set WxObj = Nothing
20 If Err Then Response.Write Err.Description
21 %>
22 </body>
23 </html>
接收客户信息的页面:call.asp
1 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
2 <!DOCTYPE html>
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
7 <title>客户授权微信个人信息</title>
8 </head>
9 <body>
10 <%
11 'On Error Resume Next
12 Dim WxObj
13 Set WxObj = Server.CreateObject("WeixinDLL.WeixinClass")
14 WxObj.SetAppID = "微信服务号AppID"
15 WxObj.SetAppSecret = "微信服务号AppSecret"
16
17 Dim Code,TOJson,UserJson,uJson,TokenOpenID
18 Code = Trim(Request("code"))
19 TOJson = WxObj.Get_Token_OpenID(code)
20 If TOJson="" Then Response.Write "获取access_token与openid失败":Response.End()
21
22 UserJson = WxObj.GetUserInfo(TOJson)
23 Set uJson = WxObj.parseJSON(UserJson)
24 Response.Write "openid=" & uJson.openid & "<br>"
25 Response.Write "nickname=" & uJson.nickname & "<br>"
26 Response.Write "headimgurl=" & uJson.headimgurl & "<br>"
27 Response.Write "country=" & uJson.country & "<br>"
28 Response.Write "province=" & uJson.province & "<br>"
29 Response.Write "city=" & uJson.city & "<br>"
30 'Response.Write "unionid=" & uJson.unionid & "<br>" ' 公众号绑定到微信开放平台帐号后,才会出现该字段
31
32 Set uJson = Nothing
33 Set WxObj = Nothing
34 'If Err Then Response.Write Err.Description
35 %>
36 </body>
37 </html>
注意上述客户授权微信服务号H5登录程序用到了 WeixinDLL 组件,如需要此组件者,可以联系我:z18670092211