预览群发消息
群发的次数有限,所以最好先通过预览调整好消息内容再群发。
预览的次数是每天100次,所以也不要滥用。
预览各种类型的群发消息,代码基本是相同的。
预览文本消息
参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("touser")
= "ofjtFwBSZ5cNqTKLSKx2TNEAxfBI"
'接收预览信息的OpenID
jo("text")
= New
JObject
jo("text")("content")
= "需要群发的文本消息"
jo("msgtype")
= "text"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("已经发送预览消息,请注意查看")
Else
MessageBox.Show(jo.ToString)
End
If
预览图片消息
必须事先将要群发的图片上传到微信服务器,因为群发的只是图片素材的ID,参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("touser")
= "ofjtFwBSZ5cNqTKLSKx2TNEAxfBI"
'接收预览信息的OpenID
jo("image")
= New
JObject
jo("image")("media_id")
= "XuVl2KV07GQG2J0Gv6QLLzErZRJ3ug1l1PQtg4KUgJw"
'已经上传的永久图片素材ID
jo("msgtype")
= "image"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("已经发送预览消息,请注意查看")
Else
MessageBox.Show(jo.ToString)
End
If
预览图文消息
必须事先将要群发的图文消息上传到微信服务器,因为群发的只是图文消息的ID,参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("touser")
= "ofjtFwBSZ5cNqTKLSKx2TNEAxfBI"
'接收预览信息的OpenID
jo("mpnews")
= New
JObject
jo("mpnews")("media_id")
= "XuVl2KV07GQG2J0Gv6QLLzTT6WJPsP0yUDdwnoueJio"
'已经上传的永久图文素材ID
jo("msgtype")
= "mpnews"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("已经发送预览消息,请注意查看")
Else
MessageBox.Show(jo.ToString)
End
If
预览语音消息
必须事先将要群发的语音文件上传到微信服务器,因为群发的只是语音素材的ID,参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("touser")
= "ofjtFwBSZ5cNqTKLSKx2TNEAxfBI"
'接收预览信息的OpenID
jo("voice")
= New
JObject
jo("voice")("media_id")
= "XuVl2KV07GQG2J0Gv6QLL5Ciga6xkphUAbcNEk2UUrE"
'已经上传的永久语音素材ID
jo("msgtype")
= "voice"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("已经发送预览消息,请注意查看")
Else
MessageBox.Show(jo.ToString)
End
If
预览视频消息
必须事先将要群发的视频文件上传到微信服务器,因为群发的只是视频素材的ID,参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("touser")
= "ofjtFwBSZ5cNqTKLSKx2TNEAxfBI"
'接收预览信息的OpenID
jo("mpvideo")
= New
JObject
jo("mpvideo")("media_id")
= "XuVl2KV07GQG2J0Gv6QLL0Bi3oDe1o9RvMENqM-oZ8A"
'已经上传的永久视频素材ID
jo("msgtype")
= "mpvideo"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("已经发送预览消息,请注意查看")
Else
MessageBox.Show(jo.ToString)
End
If