Static CreateTime As Date '记录最近一次生成access_token的时间
Static AccessTocken As String '记录最近一次生成的access_token
Dim CorpID As String= "wXXXXXXXXX" '企业号的CorpID
Dim Secret As String = "hynxRXXXXXXXXXXXX" '管理组的Secret
Dim tp As TimeSpan = Date.Now - CreateTime
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
CreateTime = Date.Now()
Dim jo As JObject = JObject.Parse(ret)
If jo("access_token") IsNot Nothing Then
AccessTocken = jo("access_token")
Else
MessageBox.show("获取access_token失败,原因:" & vbcrlf & jo.ToString)
End If
End If
Return AccessTocken
click代码
Dim ur As String = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}"
Dim hcfg As new HttpClient(Cexp(ur,Functions.Execute("GetQYAccessToken")))
Dim jofg As New JObject '投诉回复后,推送该投诉的通知信息给分管领导
jofg("toparty") = "12" '群发该部门所有人.2fen
jofg("msgtype") = "text"
jofg("agentid") = 1000011
jofg("text") = New JObject
jofg("text")("content") = cstr("[投诉回复通知]:" & e.Form.Controls("车号").value & "来自" & e.Form.Controls("投诉渠道").value & "渠道的投诉已回复,请查阅." & " [一分公司 " & Date.NOW & "]" )
hcfg.Content = jofg.ToString
jofg = JObject.Parse(hcfg.GetData)
If jofg("errcode") = "0" Then
MessageBox.show("回复已发送成功!")
Else
MessageBox.show(jofg.ToString)
End If
执行后WIN7一切正常。 XP提示出现2个错误弹出
1: .NET Framework 版本:2.0.50727.3053
Foxtable 版本:2019.4.12.1
错误所在事件:
详细错误信息:
The underlying connection was closed: An unexpected error occurred on a send.
Received an unexpected EOF or 0 bytes from the transport stream.
2:.NET Framework 版本:2.0.50727.3053
Foxtable 版本:2019.4.12.1
错误所在事件:窗口,投诉回复,保存2,Click
详细错误信息:
Error reading JObject from JsonReader. Path '', line 0, position 0.