【官方限制】
在公众平台网站上,为订阅号提供了每天一条的群发权限,为服务号提供每月(自然月)4条的群发权限。而对于某些具备开发能力的公众号运营者,可以通过高级群发接口,实现更灵活的群发能力。
本接口中所有使用到media_id的地方,现在都可以使用素材管理中的永久素材media_id了。请但注意,使用同一个素材群发出去的链接是一样的,这意味着,删除某一次群发,会导致整个链接失效。本文仅以文本回复为例!
- 预览接口【订阅号与服务号认证后均可用】
$token = $this->accesstokenAction();
$url = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token='.$token;
$data = array(
'touser' => 'oopkWtzJEGb9t6JU65t2eEkwxV8s',
'text' => array(
'content' => urlencode('测试群发咯')
),
'msgtype' => 'text'
);
$configData = urldecode(json_encode($data));
$data = $this->curl_http($url, 'post', 'json', $configData);
//返回 msg_id
dump($data);die;
- 根据标签进行群发【订阅号与服务号认证后均可用】
$url = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.$token;
$data = array(
'filter' => array(
'is_to_all' => true,
'tag_id' => 1
),
'text' => array(
'content' => urlencode('根据标签群发12345')
),
'msgtype' => 'text'
);
$configData = urldecode(json_encode($data));
$data = $this->curl_http($url, 'post', 'json', $configData);
//返回 msg_id
dump($data);die;
- 根据OpenID列表群发【订阅号不可用,服务号认证后可用】
$url = 'https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token='.$token;
$data = array(
'touser' => array(
0 => 'oopkWtzJEGb9t6JU65t2eEkwxV8s',
1 => 'oopkWty95bC168gaaG_lLSqfcdac'
),
'text' => array(
'content' => urlencode('哼根据openID列表群发')
),
'msgtype' => 'text'
);
$configData = urldecode(json_encode($data));
$data = $this->curl_http($url, 'post', 'json', $configData);
//返回 msg_id
dump($data);die;
上传素材的方法:
//上传临时图片资源(三天后过期)
public function uploadImage(){
//字符集设置为utf8
header('content-type:text/html;charset=utf8');
//1.获取全局access_token
$access_token = $this->getWxAccessToken();
$url="https://api.weixin.qq.com/cgi-bin/media/upload?access_token=".$access_token."&type=image";
// $file=dirname(dirname(dirname(dirname(__FILE__)))).'\Public\Images\1.jpg';
$file=$_SERVER['DOCUMENT_ROOT'].'\bd\Public\Images\1.jpg';
$postArr = array('media' => "@".$file);
//3.将array转换成json
// $postJson= json_encode($array);
//4.调用curl
$res=$this->http_curl($url,'post','json',$postArr);
// var_dump($res['media_id']);
return $res['media_id'];
}