首页 > 作文

PHP实现的微信公众号扫码模拟登录功能示例

更新时间:2023-04-07 08:18:37 阅读: 评论:0

本文实例讲述了php实现的微信公众号扫码模拟登录功能。分享给大家供大家参考,具体如下:

php微信公众号扫码模拟登录功能

功能只是将:https://github.com/huanz/wechat-mp-hack 改成php实现罢了.
之前有个休闲豆每日晨报订阅号每天定时群发消息,去年微信突然要求一定要扫码授权才能登录,fk,然后就放弃了,前几天看到早有人使用程序扫码登录,获取token,cookie自动群发了,闲着也是闲着,就将js改成php实现了登录功能.

主要流程如下

1,先访问 ,模拟登录,进入二维码页面
2,带着返回的cookie下载二维码.程序后台一直while循环,等待扫描消息.
3,打开下载的二维码,微信扫码,登录成功,获取token和cookie,然后后面就可以自由发挥了.

供上代码.

class weindauto{  //--------------------------------------------------------login start  private $_apis = [    "host"     => "https://mp.weixin.qq.com",    "login"     => "/d/file/titlepic/bizlogin    "qrcode"    => "/d/file/titlepic/loginqrcode    "loginqrcode"  => "/d/file/titlepic/loginqrcode    "loginask"   => "/d/file/titlepic/loginqrcode    "loginauth"   => "/d/file/titlepic/loginauth    "bizlogin"   => "/d/file/titlepic/bizlogin"  ];  private $_redirect_url = "";  private $_key      = "";  private function _getcookiefile(){    return wei_upload_path."cookie_{$this->_key}.text";  }  private functio2013韩剧排行榜前十名n _getsavepath(){    return wei_upload_path.$this->_qrcodename();  }  private function _qrcodename(){    return "qrcode_{$this->_key}.png";  }  private function _log($msg){    log::record("[微信调度:".date("y-m-d h:i:s")."] ======: {$msg}");  }  public function gettoken(){    return utils::getcache("token_{$this->_key}");  }  public function ttoken($token){     utils::tcache("token_{$this->_key}",$token);  }  public function init($options){    if(!ist($options["key"])){      die("key is null!");    }    $this->_key   =  $options["key"];    if($this->gettoken()){      echo("has token !");      return;    }el{      //尼玛,先要获取首页!!!      $this->fetch("https://mp.weixin.qq.com/","","text");      $this->_log("start login!!");      $this->start_login($options);    }  }  private function start_login($options){    $_res    = $this->_login($options["account"],$options["password"]);    if(!$_res["status"]){      $this->_log($_res["info"]);      return;    }    //保存二维码    $this->_saveqrcode();    $_ask_api    =  $this->_apis["loginask"];    $_input["refer"] =  $this->_redirect_url;    $_index     =  1;    while(true){/*      if($_index>60){        break;      }*/      $_res    =  $this->fetch($_ask_api.$this->getwxrandomnum(),$_input);      $_status   =  $_res["status"];      if($_status==1){        if($_res["ur_category"]==1){          $_ask_api = $this->_apis["loginauth"];        }el{          $this->_log("login success");          break;        }      }el if($_status==4){        $this->_log("已经扫码");      }eljan是几月份 if($_status==2){        $this->_log("管理员拒绝");        break;      }el if($_status==3){        $this->_log("登录超时");        break;      }el{        if($_ask_api==$this->_apis["loginask"]){          $this->_log("请打开test.jpg,用微信扫码");        }el{          $this->_log("等待确认");        }      }      sleep(2);      $_index++;    }    /*if($_index>=60){      $this->_log("u亲,超时了");      return;    }*/    $this->_log("开始验证");    $_input["post"]   = ["lang"=>"zh_cn","f"=>"json","ajax"=>1,"random"=>$this->getwxrandomnum(),"token"=>""];    $_input["refer"]   = $this->_redirect_url;    $_res        = $this->fetch($this->_apis["bizlogin"],$_input);    $this->_log(print_r($_res,true));    if($_res["ba_resp"]["ret"]!=0){      $this->_log("error = ".$_res["ba_resp"]["err_msg"]);      return ;    }    $redirect_url    =  $_res["redirect_url"];//跳转路径    if(preg_match('/token=([\d]+)/i', $redirect_url,$match)){//获取cookie      $this->ttoken($match[1]);    }    $this->_log("验证成功,token: ".$this->gettoken());  }  //下载二维码  private function _saveqrcode(){    $_input["refer"] = $this->_redirect_url;    $_res    = $this->fetch($this->_apis["qrcode"],$_input,"text");    $fp     = fopen($this->_getsavepath(), "wb+") or die("open fails");    fwrite($fp,$_res) or die("fwrite fails");    fclo($fp);  }  private function _login($_urname,$_password){    $_input["post"] = array(      'urname'  => $_urname,      'pwd'    => md5($_password),      'f'     => 'json',      'imgcode'  => ""    );    $_input["refer"] = "https://mp.weixin.qq.com";    $_表达思念的句子res      = $this->fetch($this->_apis["login"],$_input);    if($_res["ba_resp"]["ret"]!==0){      return utils::error($_res["ba_resp"]["err_msg"]);    }    $this->_redirect_url  =  "https://mp.weixin.qq.com".$_res["redirect_url"];//跳转路径    return utils::success("ok");  }  function getwxrandomnum(){    return "0.".mt_rand(1000000000000000,9999999999999999);  }  /**   * @param $url   * @param null $_input   * @param string $data_type   * @return mixed   * $_input= ["post"=>[],"refer"=>"",cookiefile='']   */  function fetch( $url, $_input=null, $data_type='json') {    $ch = curl_init();    $uragent = ist($_input['uragent']) ? $_input['uragent'] : 'mozilla/5.0 (windows nt 6.1; wow64; rv:10.0.2) gecko/20100101 firefox/10.0.2';    //curl_topt( $ch, curlopt_httpheader, $this->_headers); //设置http头字段的数组    curl_topt( $ch, curlopt_url, $url );    curl_topt( $ch, curlopt_returntransfer, true );    curl_topt( $ch, curlopt_autoreferer, true );    curl_topt( $ch, curlopt_followlocation, true );    curl_topt( $ch, curlopt_post, ist($_input['post']) );    if( ist($_input['post']) )     curl_topt( $ch, curlopt_postfields, $_input['post'] );    if( ist($_input['refer']) )    curl_topt( $ch, curlopt_referer, $_input['refer'] );    curl_topt( $ch, curlopt_uragent, $uragent );    curl_topt( $ch, curlopt_connecttimeout, ( ist($_input['timeout']) ? $_input['timeout'] : 5 ) );    curl_topt( $ch, curlopt_cookiejar, ( ist($_input['cookiefile']) ? $_input['cookiefile'] : $this->_getcookiefile() ));    curl_topt( $ch, curlopt_cookiefile, ( ist($_input['cookiefile']) ? $_input['cookiefile'] : $this->_getcookiefile() ));    $result = curl_exec( $ch );    curl_clo( $ch );    if ($data_type == 'json') {      $result = json_decode($result,true);    }    return $result;  }  //--------------------------------------------------------login end}

怎么调用?上码

$arr = array(  'account'  => '***',  'password' => '****',  'key'    => "tmall",);$w       =  new weindauto();$w->init($arr);if(!$w->gettoken()){  die("not token!");}

更多关于php相关内容感兴趣的读者可查看本站专题:《php微信开发技巧汇总》、《php curl用法总结》、《php网络编程技巧总结》、《p机械效率教案hp字符串(string)用法总结》、《php中json格式数据操作技巧汇总》及《php针对xml文件操作技巧总结》

希望本文所述对大家php程序设计有所帮助。

本文发布于:2023-04-07 08:17:43,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/47294e36161676d6dfd20893b99da95a.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP实现的微信公众号扫码模拟登录功能示例.doc

本文 PDF 下载地址:PHP实现的微信公众号扫码模拟登录功能示例.pdf

标签:二维码   功能   尼玛   跳转
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图