根据标签进行群发
公众号的群发次数有限,所有必须慎重,用完了次数,你就只能等明天或者下个月了,^_^。
当你向某个用户群发消息的次数用完之后,继续向其群发消息,微信服务器并不会有任何提示,但对方肯定不会收到你群发的消息,因为微信服务器在群发的过程中自动将其排除在外了。
此外群发是是需要时间的,我们要做的只是通知微信服务器向全部或部分用户群发消息,什么时候完成得看腾讯的。
不过腾讯在群发完毕后,会推送一个事件到Foxtable端的Http服务,我们可以据此获取群发结果。
群发各种类型的消息,代码基本是相同的,需要注意的是,测试号只能群发文本消息。
群发文本消息
参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("filter")
= New
JObject
jo("filter")("is_to_all")
= False
jo("filter")("tag_id")
= 104
'向104(标签ID)标签下的所有用户群发
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("errmsg"))
End
If
群发图片消息
必须事先将要群发的图片上传到微信服务器,因为群发的只是图片素材的ID,参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("filter")
= New
JObject
jo("filter")("is_to_all")
= False
jo("filter")("tag_id")
= 100
'向100(标签ID)标签下的所有用户群发
jo("image")
= New
JObject
jo("image")("media_id")
= "AO9_Rt0R6isjlzuh9Mskm9VT57PP6mgf4HppbSur32Y"
'要群发的图片素材ID
jo("msgtype")
= "image"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("提交群发消息成功")
Else
MessageBox.Show(jo("errcode"))
End
If
群发图文消息
必须事先将要群发的图文消息上传到微信服务器,因为群发的只是图文素材的ID,参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("filter")
= New
JObject
jo("filter")("is_to_all")
= False
jo("filter")("tag_id")
= 100
'向100(标签ID)标签下的所有用户群发
jo("mpnews")
= New
JObject
jo("mpnews")("media_id")
= "AO9_Rt0R6isjlzuh9Mskm5tTjK69DAjI7xozcdwStdk"
'要群发的图文消息素材ID
jo("msgtype")
= "mpnews"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("提交群发消息成功")
Else
MessageBox.Show(jo("errcode"))
End
If
群发语音消息
必须事先将要群发的语音文件上传到微信服务器,因为群发的只是语音素材的ID,参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("filter")
= New
JObject
jo("filter")("is_to_all")
= False
jo("filter")("tag_id")
= 100
'向100(标签ID)标签下的所有用户群发
jo("voice")
= New
JObject
jo("voice")("media_id")
= "AO9_Rt0R6isjlzuh9Mskm1VSuKR3vHgKyJkG3kHyKwg"
'要群发的语音消息素材ID
jo("msgtype")
= "voice"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("提交群发消息成功")
Else
MessageBox.Show(jo("errcode"))
End
If
群发视频消息
必须事先将要群发的视频文件上传到微信服务器,因为群发的只是视频素材的ID,参考代码:
Dim
url As
String =
"https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}"
Dim
hc As
New HttpClient(CExp(url,
Functions.Execute("GetAccessToken")))
Dim
jo As
New JObject()
jo("filter")
= New
JObject
jo("filter")("is_to_all")
= False
jo("filter")("tag_id")
= 100
'向100(标签ID)标签下的所有用户群发
jo("mpvideo")
= New
JObject
jo("mpvideo")("media_id")
= "AO9_Rt0R6isjlzuh9MskmzglvCD-tb59QcXGNbdkE3E"
'要群发的
视频消息素材ID
jo("msgtype")
= "mpvideo"
hc.Content
= jo.ToString()
jo =
JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("提交群发消息成功")
Else
MessageBox.Show(jo("errcode"))
End
If