<?php
@header('Content-type: text/plain;charset=UTF-8');
require_once("../Utils.php");
$data = '{
"filter":{
"is_to_all":false,
"tag_id":100
},
"mpnews":{
"media_id":"FrsRJ3g3BHR-pIkuFLARnMOwMvwukEiXaYvy1xmpoX0"
},
"msgtype":"mpnews",
"send_ignore_reprint":0
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?"
."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
返回:
<?php
@header('Content-type: text/plain;charset=UTF-8');
require_once("../Utils.php");
$data = '{
"touser":"o4WmZ0h-4huBUVQUczx2ezaxIL9c",
"mpnews":{
"media_id":"FrsRJ3g3BHR-pIkuFLARnMOwMvwukEiXaYvy1xmpoX0"
},
"msgtype":"mpnews"
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?"
."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
发送图片
<?php
@header('Content-type: text/plain;charset=UTF-8');
require_once("../Utils.php");
$data = '{
"filter":{
"is_to_all":false,
"tag_id":100
},
"image":{
"media_id":"FrsRJ3g3BHR-pIkuFLARnGMeH3WkYJCu0ZPZ_OqQOB8"
},
"msgtype":"image"
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?"
."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
发送视频:
此处视频的media_id需经过POST请求到下述接口特别地获得:https://api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token=ACCESS_TOKEN POST获得,
uploadvideo.php
<?php
@header('Content-type: text/plain;charset=UTF-8');
require_once("../Utils.php");
$data = '{
"media_id": "aTL-93EXcL4F9g4SzTdBuokPQgS_qXisgswHO02iCrqbVpU_gL_tanb9LXZ2Lc2r",
"title": "群发视频",
"description": "你好吗?"
}';
$url = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo?"
."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
返回结果:
{
"type": "video",
"media_id": "4KExkgRWTofVOgQZRkCtpTEyFhuYk1Xwr1y-biXNS93U7hICK1rtHgXs8uzntW60",
"created_at": 1505400804
}
sendall_video.php
<?php
@header('Content-type: text/plain;charset=UTF-8');
require_once("../Utils.php");
$data = '{
"filter":{
"is_to_all":false,
"tag_id":100
},
"mpvideo":{
"media_id":"4KExkgRWTofVOgQZRkCtpTEyFhuYk1Xwr1y-biXNS93U7hICK1rtHgXs8uzntW60"
},
"msgtype":"mpvideo"
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?"
."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
二、根据OpenID列表群发【订阅号不可用,服务号认证后可用】
接口:https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN
消息格式相似:
{
"touser":[
"OPENID1",
"OPENID2"
],
"mpnews":{
"media_id":"123dsdajkasd231jhksad"
},
"msgtype":"mpnews",
"send_ignore_reprint":0
}
这里再也不列出代码。
三、删除群发消息【订阅号与服务号认证后都可用】
接口:https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token=ACCESS_TOKEN
post数据:
{
"msg_id":30124,
"article_idx":2
}
返回:
{
"errcode":0,
"errmsg":"ok"
}
说明:
一、只有已经发送成功的消息才能删除
二、删除消息是将消息的图文详情页失效,已经收到的用户,仍是能在其本地看到消息卡片。
三、删除群发消息只能删除图文消息和视频消息,其余类型的消息一经发送,没法删除。
四、若是屡次群发发送的是一个图文消息,那么删除其中一次群发,就会删除掉这个图文消息也,致使全部群发都失效
四、查询群发消息发送状态【订阅号与服务号认证后都可用】
接口:https://api.weixin.qq.com/cgi-bin/message/mass/get?access_token=ACCESS_TOKEN
post数据:
{
"msg_id": "201053012"
}
返回:
{
"msg_id":201053012,
"msg_status":"SEND_SUCCESS"
}