微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ASP微信服务号H5客户登陆,且获取客户授权的用户基本信息

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

原文地址:https://www.cnblogs.com/ysk5/p/14728910.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐