public function sendall(){
$all_openid=$this->tosendall();
foreach($all_openid as $value){
$this->set_msg($value);
}
}
public function tosendall(){
$access_token=$this->getAccesstoken();
$url="https://api.weixin.qq.com/cgi-bin/user/get?access_token={$access_token}&next_openid=";
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data=curl_exec($ch);
$data=json_decode($data,true);
return $data['data']['openid'];
}
public function set_msg($openid){
$access_token = $this->getAccesstoken();
$template = array(
"touser" => "$openid",//用户openid
"template_id" => "-dRb-6prGX6AO6Pt_uTirmH2fztkVHLFG7HHfISwjXg",//模板id
"url" => "",//跳转链接
"data" => array(
'first' => array('value' => urlencode("为更好的为您提供服务,原公众号功能升级,现已升级完毕并更名为惠三秦,特此通知。")),
'keyword1' => array('value' => urlencode("公众号功能")),
'keyword2' => array('value' => urlencode("全站业务")),
'keyword3' => array('value' => urlencode("2018年3月30日")),
'keyword4' => array('value' => urlencode("现已升级完毕")),
'remark' => array('value' => urlencode("点击这里,更多优惠!更多惊喜都在等你来发现。")),
)
);
$json_template = json_encode($template);
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
$json = $this->curl_post($url, urldecode($json_template));
$rs = json_decode($json, true);
if ($rs['errcode'] == 0) {echo 'ok';
} else {
echo "no";
print_r($rs);
}
}