获取access_token
access_token是公众号的全局唯一接口调用凭据,公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。
接口调用请求说明
http请求方式: GET
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
这个是json结果文件
{"access_token":"7zVLyZ4h0YqFA5pMQ07WxpniDMt6nQVd5jEKRTKcP3WP2uZCKY0haP3gY1EPtCLBM1Kcw6b50U2lV0bqb-YSHr4iCHsANEsUDa0qd9qbVRWnvu859NGatrpdv9L1X7JgTPVeAIAWSY","expires_in":7200}
运行代码如下:
Dim XMLH As Object
XMLH = CreateObject("Microsoft.XMLHTTP")
Dim drs As List(Of DataRow) = DataTables("ACCESS_TOKEN").Select("AppID应用ID is not null")
For Each dr As DataRow In drs
XMLH.open("GET", "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" & dr("AppID应用ID") & "&secret=" & dr("AppSecret应用密钥") & "", True) '获得实时信息
XMLH.send(Nothing)
Do While XMLH.readyState <> 4
Application.DoEvents
Loop
'把数据json数据转化成对象
Dim json As String = XMLH.responseText
Dim ScriptControl As Object, data As Object, JscriptCode As String
JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
.Language = "Javascript"
.Timeout = -1
.AddCode(JscriptCode)
data = .Run("toObject", json)
End With
'MessageBox.Show(json)
dr("ACCESSTOKEN") = data.access_token
'MessageBox.Show(dr("ACCESSTOKEN"))
dr("expiresin") = data.expires_in
'MessageBox.Show(dr("expiresin"))
Next
可以对应把数据写入到对应表字段中
[此贴子已经被作者于2016/10/9 0:36:37编辑过]