以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]access_token写在什么位置  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=136449)

--  作者:2474842866
--  发布时间:2019/6/13 14:51:00
--  [求助]access_token写在什么位置
微信接口那里access_token的代码写在哪里啊?
Static CreateTime As Date \'记录最近一次生成access_token的时间
Static
AccessTocken As String \'记录最近一次生成的access_token
Dim
AppId As String= "wx8acdb7df5beb68fd" \'开发者ID
Dim
AppSecret As String = "a5a3b06a790d4200a151e6b13c3dc263" \'开发者密匙
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


--  作者:有点甜
--  发布时间:2019/6/13 16:25:00
--  

参考

 

http://www.foxtable.com/webhelp/scr/1486.htm