You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.7 KiB
79 lines
3.7 KiB
<?php
|
|
namespace LaneWeChat\Core;
|
|
|
|
class AdvancedBroadcast{
|
|
public static function uploadNews($articles){
|
|
$queryUrl = 'https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token='.AccessToken::getAccessToken();
|
|
$queryAction = 'POST';
|
|
foreach($articles as &$article){
|
|
$article['author'] = urlencode($article['author']);
|
|
$article['title'] = urlencode($article['title']);
|
|
$article['content'] = urlencode($article['content']);
|
|
$article['digest'] = urlencode($article['digest']);
|
|
}
|
|
$template = array();
|
|
$template['articles'] = $articles;
|
|
$template = json_encode($template);
|
|
$template = urldecode($template);
|
|
$result = Curl::callWebServer($queryUrl, $template, $queryAction);
|
|
return empty($result['media_id']) ? false : $result['media_id'];
|
|
}
|
|
|
|
public static function sentNewsByGroup($groupId, $mediaId, $isToAll=false){
|
|
$queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken();
|
|
$queryAction = 'POST';
|
|
$template = array();
|
|
$template['filter']['group_id'] = $groupId;
|
|
$template['filter']['is_to_all'] = $isToAll;
|
|
$template['mpnews']['media_id'] = $mediaId;
|
|
$template['msgtype'] = 'mpnews';
|
|
$template = json_encode($template);
|
|
return Curl::callWebServer($queryUrl, $template, $queryAction);
|
|
}
|
|
|
|
public static function sentTextByGroup($groupId, $content, $isToAll=false){
|
|
$queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken();
|
|
$queryAction = 'POST';
|
|
$template = array();
|
|
$template['filter']['group_id'] = $groupId;
|
|
$template['filter']['is_to_all'] = $isToAll;
|
|
$template['text']['content'] = $content;
|
|
$template['msgtype'] = 'text';
|
|
$template = json_encode($template);
|
|
return Curl::callWebServer($queryUrl, $template, $queryAction);
|
|
}
|
|
|
|
public static function sentVoiceByGroup($groupId, $mediaId, $isToAll=false){
|
|
$queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken();
|
|
$queryAction = 'POST';
|
|
$template = array();
|
|
$template['filter']['group_id'] = $groupId;
|
|
$template['filter']['is_to_all'] = $isToAll;
|
|
$template['voice']['media_id'] = $mediaId;
|
|
$template['msgtype'] = 'voice';
|
|
$template = json_encode($template);
|
|
return Curl::callWebServer($queryUrl, $template, $queryAction);
|
|
}
|
|
|
|
public static function sentImageByGroup($groupId, $mediaId, $isToAll=false){
|
|
$queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken();
|
|
$queryAction = 'POST';
|
|
$template = array();
|
|
$template['filter']['group_id'] = $groupId;
|
|
$template['filter']['is_to_all'] = $isToAll;
|
|
$template['image']['media_id'] = $mediaId;
|
|
$template['msgtype'] = 'image';
|
|
$template = json_encode($template);
|
|
return Curl::callWebServer($queryUrl, $template, $queryAction);
|
|
}
|
|
|
|
public static function sentVideoByGroup($mediaId, $title, $description, $groupId, $isToAll=false){
|
|
$queryUrl = 'https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token='.AccessToken::getAccessToken();
|
|
$queryAction = 'POST';
|
|
$template = array();
|
|
$template['media_id'] = $mediaId;
|
|
$template['title'] = $title;
|
|
$template['description'] = $description;
|
|
$template = json_encode($template);
|
|
$result = Curl::callWebServer($queryUrl, $template, $queryAction);
|
|
if(empty($result['type']) || $result['type'] != 'video' || empty($result['media_id'])){ |