.NET Framework 版本:2.0.50727.8937
Foxtable 版本:2017.12.18.1
错误所在事件:自定义函数GetAccessToken
详细错误信息:
调用的目标发生了异常。
索引超出了数组界限。
自定义函数GetAccessToken 代码
Static CreateTime As Date '记录最近一次生成access_token的时间
Static AccessTocken As String '记录最近一次生成的access_token
Dim AppId As String = Vars("DeveloperID") '开发者ID
Dim AppSecret As String = Vars("DeveloperSecret") '开发者密匙
Dim tp As TimeSpan = Date.Now - CreateTime
Dim e As RequestEventArgs = args(0)
Dim url As String = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"
If tp.TotalSeconds > 3600 Then
Dim hc As New HttpClient(CExp(url,AppId,AppSecret))
Dim ret As String = hc.GetData()
If ret = "" Then '如果失败,再尝试一次
hc.GetData()
End If
CreateTime = Date.Now()
Dim jo As JObject = JObject.Parse(ret)
If jo("errcode") Is Nothing Then
AccessTocken = jo("access_token")
Else
MessageBox.show("获取access_token失败,原因:" & vbcrlf & jo("errmsg").ToString)
End If
End If
Return AccessTocken