以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]无法获取openid (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=104036) |
-- 作者:kensou11111 -- 发布时间:2017/7/21 15:19:00 -- [求助]无法获取openid 为何我参照帮助写的代码无法获取用户的openid,是哪里写错了吗? 内部函数maintest的代码(手机主界面): Dim e As RequestEventArgs = args(0) Dim wb As New weui If e.PostValues.Count = 0 Then wb.AddPageTitle("","ph1","查询条件") wb.AddForm("","form1","viewtest.htm") With wb.AddButtonGroup("form1","btg1",True) .Add("btn1", "查询信息","submit") .Add("btn2", "新增信息","","addtest.htm?ordertype=weixin") End With e.WriteString(wb.Build) End If 内部函数addtest的代码(手机录入界面): Dim e As RequestEventArgs = args(0) Dim wb As New weui If e.PostValues.Count = 0 Then \'生成增加订单网页 wb.AddForm("","form1","addtest.htm") With wb.AddInputGroup("form1","ipg1","录入资料") .AddInput("姓名","姓名","text") .AddSelect("性别","性别","男|女") .AddInput("身份证号","身份证号","text") .AddInput("手机号","手机号","text") With .AddUploader("身份证照片","身份证照片",False) .TextPosition = 0 \'标题靠左 End With With .AddUploader("操作证照片","操作证照片",False) .TextPosition = 0 \'标题靠左 End With With .AddUploader("合同照片","合同照片",False) .TextPosition = 0 \'标题靠左 End With End With With wb.AddButtonGroup("form1","btg1",True) .Add("btn1", "提交", "submit") .Add("btn2", "返回", "","maintest.htm") End With Else \'保存新增的订单 Dim nms() As String = {"姓名","性别","身份证号","手机号"} For Each nm As String In nms If e.PostValues.ContainsKey(nm) = False Then \'生成错误提示页 With wb.AddMsgPage("","msgpage","增加失败", nm & "不能为空!") .icon = "Warn" \'改变图标 .AddButton("btn1","返回").Attribute = "" End With e.WriteString(wb.Build) Return Nothing \'必须返回 End If Next Dim nms2() As String = {"身份证照片","操作证照片","合同照片"} Dim dr As DataRow dr = DataTables("员工资料").AddNew() Dim orderType As String = e.Values("ordertype" ) Dim code As String = e.Values( "code" ) If orderType= "weixin" Then \'微信授权的网页才会有code参数 Dim wechatserv = WeChat.WeChatServer.Server ("wxe491a3cc46a558fe") Dim uinfo = wechatserv.UserController.GetOauth2UserInfo(code) \'获取微信用户信息 If uinfo.Success Then dr("openid") = uinfo.openid End If End If For Each nm As String In nms dr(nm) = e.PostValues(nm) Next For Each key As String In e.Files.Keys For Each fln As String In e.Files(key) e.SaveFile(key, fln, ProjectPath & "Attachments\\" & fln) Next If key = "身份证照片" Then dr.Lines("身份证照片") = e.Files(key) ElseIf key = "操作证照片" Then dr.Lines("操作证照片") = e.Files(key) ElseIf key = "合同照片" Then dr.Lines("合同照片") = e.Files(key) End If Next dr.Save() With wb.AddMsgPage("","msgpage","提交成功", "数据已上传到服务器") \'增加订单成功提示信息 .AddButton("btn1","确定","maintest.htm") End With End If e.WriteString(wb.Build) \'生成网页 [此贴子已经被作者于2017/7/21 15:19:40编辑过]
|
-- 作者:kensou11111 -- 发布时间:2017/7/21 15:23:00 -- 初始化微信服务,则在一个按钮中写了如下代码 Dim pinfo As New WeChat.WeChatPublicNoInfo() pinfo.DeveloperID = "wxe491a3cc46a558fe" \'公众号开发者ID pinfo.DeveloperSecret = "8ca98fcf1ffec41f1fb8761e218fd64a" \'公众号的开发者密钥 pinfo.Token = "MyToken" \'消息令牌 pinfo.EncodingAESKey = "H6ALCg8tM8akB9aUmZeFsoXOEzMAkleQRAw6WkQcQjh" \'消息加密密钥 pinfo.PublicNoType = 1 \'1=服务号 3=订阅号 pinfo.CryptMsgType = 1 \'明文消息 2=加密消息 WeChat.WeChatServer.Add(pinfo) \'添加服务号到服务\' msgbox("微信服务初始化成功") Dim url As String = "http://kensou11111.gnway.cc/addtest.htm" url = WeChat.WeChatOauth2Helper.GetOAuth2Uri("wxe491a3cc46a558fe", url,True , "123456789", "snsapi_base", "code") httprequest 代码: Dim fl As String = "e:\\web\\" & e.path If filesys.FileExists(fl) Dim idx As Integer = fl.LastIndexOf(".") Dim ext As String = fl.SubString(idx) Select Case ext Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar" e.WriteFile(fl) Return \'这里必须返回 End Select End If Select Case e.Path Case "addtest.htm" Functions.Execute("addtest",e) Case "viewtest.htm" Functions.Execute("viewtest",e) Case "maintest.htm" Functions.Execute("maintest",e) End Select 测试时其余资料和图片都可以正常保存,但用户的openid没有保存成功。
[此贴子已经被作者于2017/7/21 15:35:49编辑过]
|
-- 作者:有点甜 -- 发布时间:2017/7/21 16:02:00 -- 你没有弄授权
http://www.foxtable.com/mobilehelp/scr/0235.htm
http://www.foxtable.com/mobilehelp/scr/0236.htm
|
-- 作者:kensou11111 -- 发布时间:2017/7/21 16:22:00 -- 以下是引用有点甜在2017/7/21 16:02:00的发言:
你没有弄授权
http://www.foxtable.com/mobilehelp/scr/0235.htm
http://www.foxtable.com/mobilehelp/scr/0236.htm
我参考的是微新接口帮助中的这个例子 http://wechat.foxtable.com:9009/WebHelp/scr/we9011.htm 那么我是不是应该将主界面中跳转的录入界面的url换成授权验证的url? [此贴子已经被作者于2017/7/21 16:22:29编辑过]
|
-- 作者:有点甜 -- 发布时间:2017/7/21 16:42:00 -- 是的,进入你的网站的时候,就应该获取授权了,只需要授权一次。
跳转后,才能获取openid的。 |