日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

微信公众账户模拟登陆后的一系列操作

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 微信公众账户模拟登陆后的一系列操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<?php header("content-type:text/html;charset=utf-8");/*** wx_mass* * 完成微信公眾賬戶模擬登陸后的一系列操作* mass($content) 調用微信群發接口,群發文本信息* getUserList($page,$pagesize,$group) 獲取用戶信息* * 群發demo* * $user=array('account'=>'公眾賬戶名稱','password'=>'密碼');* $obj=new wx_mass($user);* $obj->mass('感謝您關注優樂購物,這條消息是由測試程序發出,給你帶來不便,敬請諒解!');* * @package wxdl* @author 我好笨* @copyright 2014* @version $Id$* @access public*/ class wx_mass {private $_cookiefile;private $_cookieexpired = 3600;private $_account;private $_password;private $_token;public function __construct($options){$this->_account = isset($options['account'])?$options['account']:'';$this->_password = isset($options['password'])?$options['password']:'';//必須使用絕對路徑$this->_cookiefile=dirname(__FILE__).'/temp/'.md5($this->_account);//此處需要創建一個文件夾裝cookie文件$this->getCookie();}/*** wx_mass::mass()* * 微信群發功能* * @param mixed $content 群發內容* @return 成功返回ture,失敗返回fasle*/public function mass($content){$refer="https://mp.weixin.qq.com/cgi-bin/masssendpage?t=mass/send&token=".$this->_token."&lang=zh_CN";$submit="https://mp.weixin.qq.com/cgi-bin/masssend";$post['ajax']=1;$post['city']='';$post['content']=$content;$post['country']='';$post['f']='json';$post['groupid']=-1;$post['imgcode']='';$post['lang']='zh_CN';$post['province']='';$post['random']=$this->randomFloat(0,1);$post['sex']=0;$post['synctxnews']=0;$post['synctxweibo']=0;$post['t']='ajax-response';$post['token']=$this->_token;$post['type']=1;$tmpInfo=$this->curl($submit,$refer,false,true,$post);$result = json_decode($tmpInfo,true);if (!isset($result['base_resp']) || $result['base_resp']['ret'] != 0){return false;}return true;}/*** wx_mass::getUserList()* * 根據分組ID獲取用戶列表* * @param integer $page* @param integer $pagesize* @param integer $groupid* @return*/public function getUserList($page=0,$pagesize=10,$groupid=100){$t = time().strval(mt_rand(100,999));$referer = "https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize=".$pagesize."&pageidx=".$page."&type=0&groupid=0&lang=zh_CN&token=".$this->_token;$submit = "https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize=".$pagesize."&pageidx=".$page."&type=0&groupid=$groupid&lang=zh_CN&f=json&token=".$this->_token;$result=$this->curl($submit,$referer);$json = json_decode($result,true);if(isset($json['contact_list'])){$json = json_decode($json['contact_list'],true);if(isset($json['contacts'])){return $json['contacts'];}}return false;}/*** wx_mass::login()* * 模擬登陸* * @return void*/private function login(){$submit = "https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";$refer = "https://mp.weixin.qq.com/";$post["username"] = $this->_account;$post["pwd"] = md5($this->_password);$post["f"] = "json";$post["imgcode"] = "";$tmpInfo=$this->curl($submit,$refer,true,true,$post);$result = json_decode($tmpInfo,true);if (!isset($result['base_resp']) || $result['base_resp']['ret'] != 0){return false;}preg_match("/token=(\d+)/i",$result['redirect_url'],$matches);if($matches){$this->_token = $matches[1];}}/*** wx_mass::curl()* * @param mixed $submit curl訪問目標URL* @param mixed $refer 偽造的refer* @param bool $write_cookie 讀寫cookie,true為保存,false為讀取* @param bool $is_post 是否post提交數據,true為提交數據,提交數據時,$post為提交的值* @param mixed $post is_post為真時,提交的數據* @return 返回curl執行結果*/private function curl($submit,$refer,$write_cookie=false,$is_post=false,$post=array()){$ch = curl_init(); // 啟動一個CURL會話curl_setopt($ch, CURLOPT_URL, $submit); // 要訪問的地址curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 對認證證書來源的檢查curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 從證書中檢查SSL加密算法是否存在curl_setopt($ch, CURLOPT_SSLVERSION, 3);curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模擬用戶使用的瀏覽器curl_setopt($ch, CURLOPT_REFERER, $refer);if($is_post){curl_setopt($ch, CURLOPT_POST, 1); // 發送一個常規的Post請求curl_setopt($ch, CURLOPT_POSTFIELDS, $post); // Post提交的數據包}curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 設置超時限制防止死循環if($write_cookie && file_exists($this->_cookiefile)){@unlink($this->_cookiefile);}if($write_cookie){curl_setopt($ch,CURLOPT_COOKIEJAR,$this->_cookiefile);}else{curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_cookiefile);}curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$tmpInfo = curl_exec($ch); // 執行操作var_dump($tmpInfo);if(curl_errno($ch)){$tmpInfo='Errno'.curl_error($ch);//捕抓異常}curl_close($ch); // 關閉CURL會話return $tmpInfo;}/*** wx_mass::getCookie()* * 獲取cookie,檢測cookie有效性* * @return void*/private function getCookie(){//登錄獲取cookie及token$this->login();}private function randomFloat($min = 0, $max = 1){return $min + mt_rand() / mt_getrandmax() * ($max - $min);} } $arr = array("account"=>"公眾賬戶名稱","password"=>"密碼"); $aar = new wx_mass($arr);$abc = $aar -> getUserList();var_dump($abc); ?>

  

轉載于:https://www.cnblogs.com/xingli-php/p/3970558.html

總結

以上是生活随笔為你收集整理的微信公众账户模拟登陆后的一系列操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。