php 模拟微信账号登录

  1. // 微信公众账号
  2.  define("Account", "100000000");
  3. // 微信公众号登陆密码  MD5加密
  4.  define("PassWord", "8743E01B6FAA881EDFCA08ADAE979BC1");
  5.  
  6. class __user_remote_opera{
  7. // 模拟登录
  8. public function login(){
  9. $snoopy = new Snoopy(); 
  10. $submit = "http://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";
  11. $post["username"] = Account;
  12. $post["pwd"] = PassWord;
  13. $post["f"] = "json";
  14. $snoopy->submit($submit,$post);
  15. $cookie = '';
  16. foreach ($snoopy->headers as $key => $value) {
  17. $value = trim($value);
  18. if(strpos($value,'Set-Cookie: ') || strpos($value,'Set-Cookie: ') === 0){
  19. $tmp = str_replace("Set-Cookie: ","",$value);
  20. $tmp = str_replace("Path=/","",$tmp);
  21. $cookie .= $tmp;
  22. }
  23. }
  24. if(!$cookie){
  25. $this->login();
  26. }else{
  27. $this->write("cookie.log",$cookie);
  28. return $cookie;
  29. }
  30. }
  31. // 主动推送信息
  32. public function sendTextMsg($fakeId,$content){
  33. $cookie = $this->read('cookie.log');
  34. $send_snoopy = new Snoopy(); 
  35. $send_snoopy->agent = "(Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0)"; //伪装浏览器  
  36. $send_snoopy->referer = "http://mp.weixin.qq.com/cgi-bin/singlemsgpage?fromfakeid=".$fakeId."&msgid=&source=&count=20&t=wxm-singlechat&lang=zh_CN"; //伪装来源页地址 http_referer  
  37. $send_snoopy->rawheaders['Cookie'] = $cookie;
  38. $send_snoopy->rawheaders["Pragma"] = "no-cache"; //cache 的http头信息  
  39. $send_snoopy->rawheaders["Host"] = "mp.weixin.qq.com"; 
  40. $post = array();
  41. $post['tofakeid'] = $fakeId;
  42. $post['type'] = 1;
  43. $post['content'] = $content;
  44. $post['ajax'] = 1;
  45. $submit = "http://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response";
  46. $send_snoopy->submit($submit,$post);
  47. $result = $send_snoopy->results;
  48. if($result['ret'] != 0){
  49. $cookie = $this->login();
  50. $this->sendTextMsg($fakeId,$content);
  51. }else{
  52. return $result;
  53. }
  54. }
  55. public function write($filename,$content){
  56. $__sae = new SaeStorage();
  57. $fp = $__sae->write("tempfile",$filename,$content);
  58. }
  59. // 读文件
  60. public function read($filename){
  61. $__sae = new SaeStorage();
  62. if($__sae->fileExists("tempfile",$filename)){
  63. $data = '';
  64. $data = $__sae->read("tempfile",$filename);
  65. if($data){
  66. $send_snoopy = new Snoopy(); 
  67. $send_snoopy->rawheaders['Cookie'] = $data;
  68. $submit = "http://mp.weixin.qq.com/cgi-bin/getcontactinfo?t=ajax-getcontactinfo&lang=zh_CN&fakeid=";
  69. $send_snoopy->submit($submit,array());
  70. $result = json_decode($send_snoopy->results,1);
  71. if(!$result){
  72. return $this->login();
  73. }else{
  74. return $data;
  75. }
  76. }else{
  77. return $this->login();
  78. }
  79. }else{
  80. return $this->login();
  81. }
  82. }
  83.  
  84. }
posted @ 2013-12-06 19:32  php点点滴滴  阅读(1674)  评论(0编辑  收藏  举报