发布于2019-09-05 17:42 阅读(464) 评论(0) 点赞(0) 收藏(2)
我想做个php实现贴吧,网盘自动签到。然后快盘之类的做好了2个,现在贴吧遇到一个问题,
在post用户名和密码会出现 curlerror :malformed errno:3 这个错误。麻烦谁给看看。
我觉得是 传入postdata数组 然后没有httpheader没有设置成 Content-Type: application/x-www-form-urlencoded的问题,无论是修改header 还是使用了http_build_query 都不能解决。
这里有一个帖子是分析贴吧登入过程的,我照着这个来做的。
http://hack0nair.me/?p=284
github 搜索BaiduTieba_AutoSign 有对应的python源码
首先是mycurl
<?php
/**
* 签到服务基类
*/
class MyCurl
{
//cookie
public $cookieFile;
//CURL 选项
protected $curl_opts = array(
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_TIMEOUT => 100,
CURLOPT_HEADER => true,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.58 Safari/537.22'
);
function __construct() {
//$this->cookieFile = tempnam('./temp', 'cookie');
$this->cookieFile = dirname(__FILE__)."/cookie.txt";
}
/**
* 发送 POST 请求
* @param string $url
* @param array $data POST 数据数组
* @param array $httpheader 构造 httpheader 内容的数组
* @param boolean $header 是否输出 header 信息
*/
public function post($url, $data = array(), $httpheader = array(), $header = false)
{
$options = $this->curl_opts;
$options[CURLOPT_URL] = $url;
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $data;//http_build_query($data) ;
$options[CURLOPT_FOLLOWLOCATION] = true;
$options[CURLOPT_COOKIEJAR] = $this->cookieFile;
$options[CURLOPT_COOKIEFILE] = $this->cookieFile;
if(!empty($httpheader))
$options[CURLOPT_HTTPHEADER] = $httpheader;
if($header)
$options[CURLOPT_HEADER] = true;
return $this->curl($options);
}
/**
* 发送 GET 请求
* @param string $url
* @param array httpheader 构造 httpheader 内容的数组
* @param boolean $header 是否输出 header 信息
*/
public function get($url, $httpheader = array(), $header = false)
{
$options = $this->curl_opts;
$options[CURLOPT_URL] = $url;
$options[CURLOPT_COOKIEJAR] = $this->cookieFile;
$options[CURLOPT_COOKIEFILE] = $this->cookieFile;
if(!empty($httpheader))
$options[CURLOPT_HTTPHEADER] = $httpheader;
if($header)
$options[CURLOPT_HEADER] = true;
return $this->curl($options);
}
/**
* curl 请求
* @param array $options curl 选项数组
* @return string curl 响应结果
*/
public function curl($options)
{
$ch = curl_init();
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HEADER_OUT);
if($result)
return $result;
else
{
var_dump(curl_error($ch));
}
curl_close($ch);
}
}
?>
<?php
/**
* 贴吧签到
*/
require_once "MyCurl.php";
class TieBa
{
protected $curl;
//用户名和密码
protected $username;
protected $password;
protected $token;
//登录 URL
private $logUrl = 'https://passport.baidu.com/passApi/html/_blank.html';
private $tokenUrl = 'https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=false';
private $loginurl = 'https://passport.baidu.com/v2/api/?login';
//空间信息
private $tiebainfo = 'http://tieba.baidu.com/f?kw=imba';
/**
* 初始化配置信息
* @param string $username
* @param string $password
* @return void
*/
public function init($username, $password)
{
$this->username = $username;
$this->password = $password;
$this->curl = new MyCurl();
}
/*
* 获取token
*/
public function get_token(){
$getcookie = $this->curl->get($this->logUrl);//get cookie
$value = $this->curl->get($this->tokenUrl);
preg_match('/login_token=\'(\w+)\'/',$value,$token);
$this->token = $token[1];
}
/**
* 登入
*/
public function login()
{
$this->get_token();
$data = array(
'username'=>$this->username,
'password'=>$this->password,
'mem_pass'=>'on',
'safeflg'=>'0',
'tpl'=>'mn',
'charset'=>'utf-8',
'index'=>'0',
'isPhone'=>'false',
'loginType'=>'1',
'token'=>$this->token
);
$loginResp = $this->curl->post($this->loginUrl, $data);
//$loginResp = $this->curl->post($this->loginUrl, $data,array('Content-Type: application/x-www-form-urlencoded'),true);
//$loginResp = json_decode($loginResp);
echo http_build_query($data);
var_dump($loginResp);
}
/**
* 签到方法
*/
public function sign()
{
$signResp = $this->curl->get($this->tiebainfo);
//$signResp = json_decode($signResp);
print_r($signResp);
}
}
?>
require_once 'tieba.php';
$test = new TieBa();
$test->init("贴吧用户名","密码");
$test->login();
//$test->sign();
作者:哇哇
链接:https://www.pythonheidong.com/blog/article/95783/1daddddb6cb15a40a817/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!