如何通curl登录淘宝这样的SSL站呢?我看了PHP大的视频,试着写了一个登录淘宝SSL的,想去网上把自己的确认收货数据显示在自己的页面上,可是就是没有办法成功,有熟悉的能帮我看下么?我是不是思路有问题……代码里已经加入了SSL解析的参数了
- $cookie_file = tempnam('./', "cookie");
- //我的用户名是joyzone123,密码是taobao123
- $post_fields = "action=Authenticator&callback=&CtrlVersion=1,0,0,7&event_submit_do_login=anything&fc=2&from=tbTop&from_encoding&isIgnore&llnick&loginType=4&longLogin=-1&minipara&minititle&need_sign&need_user_id¬_duplite_str&popid&poy=XOR_1_000000000000000000000000000000_625A424A45137C6F7A7F0B786D08&pstrong&sign&style=default&support=000001&tid=XOR_1_000000000000000000000000000000_63504554470A7C717F750278&TPL_password=3DES_2_000000000000000000000000000000_A1B707D2820DE4DE14BBA1EA9365B529&TPL_redirect_url=http:www.taobao.com&TPL_username=joyzone123";
- //第一次打开登录页面,获取登录页面上的随机token
- $ch = curl_init('https://login.taobao.com/member/login.jhtml');
- curl_setopt($ch, CURLOPT_USERAGENT,
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; QQWubi 133; Embedded Web Browser from: http://bsalsa.com/; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Tablet PC 2.0; .NET4.0C; .NET4.0E; InfoPath.3; Media Center PC 6.0)");
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- $data = curl_exec($ch);
- curl_close($ch);
- preg_match("/_tb_token_.*value='(.*)'>/", $data, $arr);
- //重组POST内容加入随机token
- $post_fields = "_tb_token_=" . $arr[1] . "&" . $post_fields;
- //第二次POST内容到登录目标,并记录COOKIE
- $ch = curl_init('https://login.taobao.com/member/login.jhtml');
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_USERAGENT,
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; QQWubi 133; Embedded Web Browser from: http://bsalsa.com/; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Tablet PC 2.0; .NET4.0C; .NET4.0E; InfoPath.3; Media Center PC 6.0)");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
- $data = curl_exec($ch);
- curl_close($ch);
- //第三次,读取COOKIE并跳转到主页
- $ch = curl_init('http://www.taobao.com');
- curl_setopt($ch, CURLOPT_USERAGENT,
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; QQWubi 133; Embedded Web Browser from: http://bsalsa.com/; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Tablet PC 2.0; .NET4.0C; .NET4.0E; InfoPath.3; Media Center PC 6.0)");
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
- curl_exec($ch);
- curl_close($ch);
------------------------------
试了,不适用淘宝, 貌似有特殊的安全设定
------------------------------
解决了,说一下思路吧, 前三步就是这样, 第四部要用到内部跳转, 之后都要保持COOKIE的可写入,现在收货已经可以无需密码自动确认了
------------------------------
解决了,说一下思路吧, 前三步就是这样, 第四部要用到内部跳转, 之后都要保持COOKIE的可写入,现在收货已经可以无需密码自动确认了
相关热门文章
给主人留下些什么吧!~~
评论热议