'--------------企业号GetQYAccessToken---------------------------
Static yyyCreateTime As Date '记录最近一次生成access_token的时间
Static yyyAccessTocken As String '记录最近一次生成的access_token
Dim CorpID As String = Tables("S_基础数据").rows(23)("内容") '企业号的CorpID
Dim Secret As String = Tables("S_基础数据").rows(27)("内容") '管理组的Secret27
Dim tp As TimeSpan = Date.Now - yyyCreateTime
If tp.TotalSeconds > 3600 Then
Dim url As String = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}"
Dim hc As New HttpClient(CExp(url, CorpID, Secret))
Dim ret As String = hc.GetData()
If ret = "" Then '如果失败,再尝试一次
hc.GetData()
End If
yyyCreateTime = Date.Now()
Dim jo As JObject = JObject.Parse(ret)
If jo("access_token") IsNot Nothing Then
yyyAccessTocken = jo("access_token")
MessageBox.show(yyyAccessTocken)
Else
MessageBox.show("获取access_token失败,原因:" & vbcrlf & jo.ToString)
End If
End If
Return yyyAccessTocken
上面代码能正常获取yyyAccessTocken
Dim st As New Date(1970,1,1,8,0,0)
Dim t1 As Integer = CInt((Date.Today.AddDays(-100) - st).TotalSeconds()) '时间戳开始时间
Dim t2 As Integer = CInt((Date.Now - st).TotalSeconds()) '时间戳结束时间
Dim ur As String = "https://qyapi.weixin.qq.com/cgi-bin/corp/getapprovaldata?access_token={0}"
Dim hc As New HttpClient(Cexp(ur, Functions.Execute("GetQYAccessToken4"))) '企业号应用
Dim jo As New JObject
jo("starttime") = t1
jo("endtime") = t2
hc.Content = jo.Tostring()
jo = JObject.Parse(hc.GetData)
Dim json As String = jo("data").ToString()
MessageBox.Show(json)
为啥这里是空值
[此贴子已经被作者于2024/4/4 11:00:16编辑过]