甜老师,一个项目里多个公司微信公众号,设计中控服务器,怎么区分不同公司的 CreateTime 和 AccessTocken 呢。。
Static CreateTime As Date Static AccessTocken As String
此主题相关图片如下:微信截图_20180103102137.png
Dim AppId As String= Args(0)
Dim AppSecret As String = Args(1)
Dim gongsi As String = args(2)
Static CreateTime As Date '记录最近一次生成access_token的时间
Static AccessTocken As String '记录最近一次生成的access_token
Dim tp As TimeSpan = Date.Now - CreateTime
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
[此贴子已经被作者于2018/1/3 10:52:55编辑过]