Through learning to learn from the realization of friends to organize, the implementation of the PHP version of the micro-letter public platform to push the message, to share with you for your reference, the specific content as follows
This method is to simulate the use of the micro-trust of the public platform to achieve the method. The
code is as follows:
First, login interface part code
Login Private Function Login () {$url = ' https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN ';
$this->send_data = Array (' username ' => $this->_account, ' pwd ' => MD5 ($this->_password),
' F ' => ' json ');
$this->referer = "https://mp.weixin.qq.com/";
$this->getheader = 1;
$result = explode ("\ n", $this->curlpost ($url));
foreach ($result as $key => $value) {$value = Trim ($value);
if (Preg_match ('/"Errcode": (. *)/I ', $value, $match)) {//Get token switch ($match [1]) {case-1:
Die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => "system error")));
Case-2: Die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => ' Account or password Error "))); Case-3: Die (UrlDecode json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' =>urlencode ("password Error")))
); Case-4: Die (Json_encode array (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => ' does not exist in the account '));
Case-5: Die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => "Access restricted"));
Case-6: Die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => "need to enter the verification Code")));
Case-7: Die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => "This account has been bundled with private micro-signals, not available for public platform logon"));
Case-8: Die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => ' mailbox already exists '));
Case-32:die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => ' validation code input error '));
Case-200:die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => ' because of the frequent submission of false information, the account is refused to log in ")));
Case-94:die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => "Please use Mailbox login '));
Case 10:die (Json_encode (' status ' =>1, ' Errcode ' => $match [1], ' msg ' => "The public meeting number has expired and cannot be logged in for use")); Case 0: $this->userfakeid = $this->getuserfakeid ();
Break } if (Preg_match ('/^set-cookie:[\s]+) = ([^=]+) = ([^;] +/I ', $value, $match)) {//Get cookie $this->cookie. = $match [1]. ' = '. $match [2]. ';
'; } if (Preg_match ('/"errmsg"/I ', $value, $match)) {//Get token $this->token = RTrim (substr ($value, Strrpos ($valu
E, ' = ') +1, ' ", '); }
}
}
Second, the information sent part of the code
Single message
private function Send ($fakeid, $content) {
$url = ' https://mp.weixin.qq.com/cgi-bin/singlesend?t= AJAX-RESPONSE&LANG=ZH_CN ';
$this->send_data = Array (
' type ' => 1,
' content ' => $content,
' error ' => ' false ',
' Tofakeid ' => $fakeid,
' token ' => $this->token,
' Ajax ' => 1,
);
$this->referer = ' https://mp.weixin.qq.com/cgi-bin/singlemsgpage?token= '. $this->token. ' &fromfakeid= '. $fakeid. ' &MSGID=&SOURCE=&COUNT=20&T=WXM-SINGLECHAT&LANG=ZH_CN ';
return $this->curlpost ($url);
}
Third, mass information code
Mass message public
function SendMessage ($content = ', $userId = ') {
if (Is_array ($userId) &&!empty ($userId ) {
foreach ($userId as $v) {
$json = Json_decode ($this->send ($v, $content));
if ($json->ret!=0) {
$errUser [] = $v;
}
}
} else{
foreach ($this->userfakeid as $v) {
$json = Json_decode ($this->send ($v [' Fakeid '], $content));
if ($json->ret!=0) {
$errUser [] = $v [' Fakeid '];
}} Total number of users sent
$count = count ($this->userfakeid);
Number of failed users sent
$errCount = count ($errUser);
Number of successful users sent
$succeCount = $count-$errCount;
$data = Array (
' status ' =>0,
' count ' => $count,
' Succecount ' => $succeCount,
' errcount ' = > $errCount,
' Erruser ' => $errUser
);
Return Json_encode ($data);
Four, get all the user information code fragment
Get all user information public function Getalluserinfo () {foreach ($this->userfakeid as $v) {$info [] = $this->getus
Erinfo ($v [' GroupID '], $v [' Fakeid ']);
return $info; //Get user Information public function getuserinfo ($groupId, $fakeId) {$url = "Https://mp.weixin.qq.com/cgi-bin/getcon
tactinfo?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;
//Get all Users 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, $user, $a);
foreach ($a [1] as $VV) {$arr [$i] [' fakeid '] = $VV;
$arr [$i] [' groupid '] = $v;
$i + +;
} return $arr; }
Hopefully this article will help you learn about PHP programming.