zoukankan      html  css  js  c++  java
  • 如何通curl登录淘宝这样的SSL站呢?

    http://bbs.php100.com/read.php?tid=51347

    如何通curl登录淘宝这样的SSL站呢?我看了PHP大的视频,试着写了一个登录淘宝SSL的,想去网上把自己的确认收货数据显示在自己的页面上,可是就是没有办法成功,有熟悉的能帮我看下么?我是不是思路有问题……代码里已经加入了SSL解析的参数了 
    1. $cookie_file = tempnam('./', "cookie");
    2. //我的用户名是joyzone123,密码是taobao123
    3. $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&not_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";

    4. //第一次打开登录页面,获取登录页面上的随机token
    5. $ch = curl_init('https://login.taobao.com/member/login.jhtml');
    6. curl_setopt($ch, CURLOPT_USERAGENT,
    7. "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)");
    8. curl_setopt($ch, CURLOPT_HEADER, 0);
    9. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    10. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    11. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    12. $data = curl_exec($ch);
    13. curl_close($ch);
    14. preg_match("/_tb_token_.*value='(.*)'>/", $data, $arr);

    15. //重组POST内容加入随机token
    16. $post_fields = "_tb_token_=" . $arr[1] . "&" . $post_fields;
    17. //第二次POST内容到登录目标,并记录COOKIE
    18. $ch = curl_init('https://login.taobao.com/member/login.jhtml');
    19. curl_setopt($ch, CURLOPT_HEADER, 0);
    20. curl_setopt($ch, CURLOPT_USERAGENT,
    21. "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)");
    22. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    23. curl_setopt($ch, CURLOPT_POST, 1);
    24. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
    25. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    26. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    27. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
    28. $data = curl_exec($ch);
    29. curl_close($ch);
    30. //第三次,读取COOKIE并跳转到主页
    31. $ch = curl_init('http://www.taobao.com');
    32. curl_setopt($ch, CURLOPT_USERAGENT,
    33. "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)");
    34. curl_setopt($ch, CURLOPT_HEADER, 0);
    35. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    36. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
    37. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
    38. curl_exec($ch);
    39. curl_close($ch);


    ------------------------------

    试了,不适用淘宝, 貌似有特殊的安全设定
    ------------------------------
    解决了,说一下思路吧, 前三步就是这样, 第四部要用到内部跳转, 之后都要保持COOKIE的可写入,现在收货已经可以无需密码自动确认了

    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
    阅读(155) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~
    评论热议
  • 相关阅读:
    打造自己的性能测试类
    网站配置之最佳实践
    C#控制台窗口居中显示(转)
    将PDM文件导出成CHM帮助文件
    分享使用NPOI导出Excel树状结构的数据,如部门用户菜单权限
    Oracle 给已创建的表增加自增长列
    托管调试助手“NonComVisibleBaseClass”检测到问题
    翻页效果
    Excel表格转Json数据结构
    关于2D渲染的一些小想法
  • 原文地址:https://www.cnblogs.com/ztguang/p/12648265.html
Copyright © 2011-2022 走看看