总返回: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;
}
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;
}
解决方案