<?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"
}