以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 企业微信报错 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=142553) |
||
-- 作者:xietan417 -- 发布时间:2019/10/30 16:22:00 -- 企业微信报错 2019-10-30 16:03:40.0069 Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Foxtable.UserFunctions.Execute(String Name, Object[] Args) Error reading JObject from JsonReader. Path \'\', line 0, position 0. at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings) at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings) at UserCode.AvR2BnE2uqj4l9SDd(Object[] Args) 最近后台日记老是收到这样的报错,userid经常获取不到,有的人没问题,有的人就不行!奇怪了
[此贴子已经被作者于2019/10/30 16:23:51编辑过]
|
||
-- 作者:有点蓝 -- 发布时间:2019/10/30 16:26:00 -- JObject.Parse把字符串转换为json对象出错,一般情况下是没有接收到数据,也就是空字符串,或者是不是合法的json格式字符串,就会有这个错误 |
||
-- 作者:xietan417 -- 发布时间:2019/10/30 16:30:00 -- Dim e As RequestEventArgs = args(0) Dim UserId As String Dim UserName As String Dim sb As New StringBuilder If e.GetValues.ContainsKey("code") Then \'如果通过授权链接跳转而来,就根据传递过来的code参数调用接口,获取用户的UserId Dim ul As String = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={0}&code={1}" ul = CExp(ul,Functions.Execute("GetQYAccessToken"),e.GetValues("code")) Dim hc As new HttpClient(ul) Dim jo As JObject = JObject.Parse(hc.GetData) If jo("UserId") IsNot Nothing Then UserId = jo("UserId") End If Else UserId = e.Cookies("userid") \'否则从cookie中提取userid和username End If If UserId > "" then\'授权成功 e.AppendCookie("userid",UserId) \'将userid和username存储在Cookie中 Return UserId ElseIf e.GetValues.ContainsKey("code") = False Then \'如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接 Dim ul1 As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state={2}#wechat_redirect" Dim ul2 As String = UrlEncode("http://www.gain.com.cn") ul1 = CExp(ul1,"wxc47938dd3fd523334",ul2,"123") sb.Append("<meta http-equiv=\'Refresh\' c>") \'跳转到授权链接 e.WriteString(sb.ToString) Return "" End If 我这个代码都运行了1年多了,之前也没出现过问题啊~ |
||
-- 作者:有点蓝 -- 发布时间:2019/10/30 16:42:00 -- 没有完美的程序,程序运行的越久就越有可能出问题 Dim hc As new HttpClient(ul) dim ret as string = hc.GetData msgbox(ret) ‘或者使用日志记录一下 if ret > "" then Dim jo As JObject = JObject.Parse(ret) If jo("UserId") IsNot Nothing Then UserId = jo("UserId") End If
|
||
-- 作者:xietan417 -- 发布时间:2019/10/30 16:45:00 -- 好的,谢谢! |
||
-- 作者:xietan417 -- 发布时间:2019/10/30 17:24:00 --
报这个错的话,难道是我的GetQYAccessToken 函数出了问题?
|
||
-- 作者:有点蓝 -- 发布时间:2019/10/30 17:30:00 -- 应该是。可能是使用了A应用的secret来访问B应用 |
||
-- 作者:xietan417 -- 发布时间:2019/10/30 17:35:00 -- 现在新的企业微信已没有组的Secret了,全部都使用应用的Secret了,看来我要找一下腾讯客服了解一下怎么升级一下我的企业微信了! |
||
-- 作者:有点蓝 -- 发布时间:2019/10/31 8:29:00 -- 用法一样的,把应用的Secret当做是组的Secret一样用即可。应用的Secret只能用在这个应用上,不能用来访问其他应用 |