通过学习借鉴朋友的实现方法进行整理,实现了PHP版的微信公共平台消息主动推送,分享给大家供大家参考,具体内容如下 此方法是通过模拟登录微信公共平台的方法来实现的。 代码如下:
一、登录接口部分代码
二、信息发送部分代码
三、群发信息代码
//共发送<a href="/tag/yonghu/" target="_blank" class="keywords">用户</a>数
$count = count($this->userFakeid);
//发送失败<a href="/tag/yonghu/" target="_blank" class="keywords">用户</a>数
$errCount = count($errUser);
//发送成功<a href="/tag/yonghu/" target="_blank" class="keywords">用户</a>数
$succeCount = $count-$errCount;
$data = array(
'status'=>0,'count'=>$count,'succeCount'=>$succeCount,'errCount'=>$errCount,'errUser'=>$errUser
);
return json_encode($data);
}
四、获取所有用户信息代码片段
return $info;
}
//获取用户信息
public function getUserInfo($groupId,$fakeId){
$url = "https://mp.weixin.qq.com/cgi-bin/getcontactinfo?t=ajax-getcontactinfo&lang=zh_CN&fakeid={$fakeId}";
$this->getHeader = 0;
$this->referer = 'https://mp.weixin.qq.com/cgi-bin/contactmanagepage?token='.$this->token.'&t=wxm-friend&lang=zh_CN&pagesize='.$this->pageSize.'&pageidx=0&type=0&groupid='.$groupId;
$this->send_data = array(
'token'=>$this->token,'ajax'=>1
);
$message_opt = $this->curlPost($url);
return $message_opt;
}
//获取所有用户fakeid
private function getUserFakeid(){
ini_set('max_execution_time',600);
$pageSize = 1000000;
$this->referer = "https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token={$_SESSION['token']}";
$url = "https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize={$pageSize}&pageidx=0&type=0&groupid=0&token={$this->token}&lang=zh_CN";
$user = $this->vget($url);
$preg = "/\"id\":(\d+),\"name\"/";
preg_match_all($preg,$user,$b);
$i = 0;
foreach($b[1] as $v){
$url = 'https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize='.$pageSize.'&pageidx=0&type=0&groupid='.$v.'&token='.$this->token.'&lang=zh_CN';
$user = $this->vget($url);
$preg = "/\"id\":(\d+),\"nick_name\"/";
preg_match_all($preg,$a);
foreach($a[1] as $vv){
$arr[$i]['fakeid'] = $vv;
$arr[$i]['groupid'] = $v;
$i++;
}
}
return $arr;
}
希望本文所述对大家学习PHP程序设计有所帮助。