创建永久二维码
永久二维码,是无过期时间的,但数量较少(目前为最多10万个)。
创建永久二维码的代码参考:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,Functions.Execute("GetAccessToken")))
Dim
jo As
New
JObject
jo("action_name")
= "QR_LIMIT_SCENE"
'类型为永久二维码
jo("action_info")
= New
JObject
jo("action_info")("scene")
= New
JObject
jo("action_info")("scene")("scene_id")
= 112
'指定此二维码的场景ID
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
Is Nothing
Then
Dim dr
As DataRow
= DataTables("QRCode").AddNew()
dr("Ticket")
= jo("ticket")
dr("Descripttion")
= "永久二维码说明"
dr.Save()
Else
MessageBox.Show(jo("errcode"))
End
If
永久二维码的场景ID可以是字符串,生成带字符串场景ID的永久二维码的代码可以参考:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,Functions.Execute("GetAccessToken")))
Dim
jo As
New
JObject
jo("action_name")
= "QR_LIMIT_STR_SCENE"
'永久二维码,场景ID为字符串
jo("action_info")
= New
JObject
jo("action_info")("scene")
= New
JObject
jo("action_info")("scene")("scene_str")
= "字符串形式的场景ID"
'指定此二维码的场景场景ID
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
Is Nothing
Then
Dim dr
As DataRow
= DataTables("QRCode").AddNew()
dr("Ticket")
= jo("ticket")
dr("Descripttion")
= "永久二维码说明"
dr.Save()
Else
MessageBox.Show(jo("errcode"))
End
If
永久二维码的获取和下载,方法和临时二维码完全一致,例如下面的代码同时完成了二维码的生成和下载任务:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject
jo("action_name")
= "QR_LIMIT_SCENE"
'类型为永久二维码
jo("action_info")
= New JObject
jo("action_info")("scene")
= New JObject
jo("action_info")("scene")("scene_id")
= 112 '指定此二维码的场景ID
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
Is Nothing
Then
Dim dr
As DataRow =
DataTables("QRCode").AddNew()
dr("Ticket")
= jo("ticket")
dr("Descripttion")
= "永久二维码说明"
dr.Save()
'下载生成好的二维码
hc = New
HttpClient("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="
& dr("Ticket"))
hc.GetFile("c:\data\qrcode.jpg")
Else
MessageBox.Show(jo("errcode"))
End
If