php模拟登陆不成功,php 模拟登陆成功后,怎么样群发送消息?网上找的代码,总提示出错...

总返回:string(113) “{“base_resp”:{“ret”:0,”err_msg”:”ok”},”redirect_url”:”\/cgi-bin\/home?t=home\/index&lang=zh_CN&token=1465531654″}”

string(33) “{“ret”:”-1″, “msg”:”system fail”}”

理论上,登陆成功后是为了取得 token就行了吧

public function mass($content)

{

$refer=”https://mp.weixin.qq.com/cgi-bin/masssendpage?t=mass/send&token=”.$this->_token.”&lang=zh_CN”;

//var_dump($refer); 测试结果,这里可以得到 token=1465531654

$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;

}

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;

}

解决方案

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明php 模拟登陆成功后,怎么样群发送消息?网上找的代码,总提示出错!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值