{"id":110,"date":"2020-01-01T22:58:17","date_gmt":"2020-01-01T14:58:17","guid":{"rendered":"http:\/\/blog.yuekegu.com\/?p=110"},"modified":"2020-01-01T22:58:17","modified_gmt":"2020-01-01T14:58:17","slug":"curl%e4%b9%8b%e9%87%87%e9%9b%86qq%e7%a9%ba%e9%97%b4%e7%95%99%e8%a8%80","status":"publish","type":"post","link":"https:\/\/book.yuekegu.com\/index.php\/2020\/01\/01\/curl%e4%b9%8b%e9%87%87%e9%9b%86qq%e7%a9%ba%e9%97%b4%e7%95%99%e8%a8%80\/","title":{"rendered":"curl\u4e4b\u91c7\u96c6QQ\u7a7a\u95f4\u7559\u8a00"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"\u4e3b\u8981\u6d41\u7a0b\u89e3\u6790\">\u4e3b\u8981\u6d41\u7a0b\u89e3\u6790<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9996\u5148\uff0c\u6253\u5f00\u6d4f\u89c8\u5668\u767b\u5f55QQ\u7a7a\u95f4\u5e76\u8bbf\u95ee\u7559\u8a00\u5217\u8868<br>\n<\/li><li>\u7531\u4e8eQQ\u7a7a\u95f4\u7684\u94fe\u63a5\u662fhttps\uff0ccurl\u65b9\u5f0f\u8bf7\u6c42https\u94fe\u63a5\u9700\u8981\u7a81\u7834https\u8ba4\u8bc1\uff0c\u8fd9\u5c31\u9700\u8981\u4e0b\u8f7d<a href=\"https:\/\/curl.haxx.se\/ca\/cacert.pem\">cacert.pem<\/a>\uff0c\u4e0b\u9762\u8bf7\u770bcacert.pem\u7684\u90e8\u7f72\u6b65\u9aa4<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001\u5c06\u4e0b\u8f7d\u7684`cacert.pem`\u6587\u4ef6\u653e\u81f3php\u5b89\u88c5\u76ee\u5f55\u4e0b\uff0c\u6bd4\u5982\uff1a\"D:\\wamp\\bin\\php\\php5.5.12\";\n2\u3001\u5728php.ini\u6587\u4ef6\u672b\u5c3e\u8ffd\u52a0\u4ee5\u4e0b\u914d\u7f6e\n\ncurl.cainfo=\"D:\/wamp\/bin\/php\/php5.5.12\/cacert.pem\"\nopenssl.cafile=\"D:\/wamp\/bin\/php\/php5.5.12\/cacert.pem\"\n3\u3001\u91cd\u542fwamp\u670d\u52a1\u5668\n4\u3001\u4e0a\u9762\u6b65\u9aa4\u64cd\u4f5c\u5b8c\u6bd5\uff0c\u5373\u53ef\u7528curl\u65b9\u5f0f\u8bbf\u95eeQQ\u7a7a\u95f4\u6570\u636e\u4e86<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6ce8\u610f\u4e8b\u9879\">\u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>1\u3001\u4e00\u5b9a\u8981\u8bbe\u7f6e\u65f6\u533a\u4e3a\u4e2d\u56fd\u65f6\u533a\uff08\u907f\u514dcookie\u4e0d\u540c\u65f6\u533a\u800c\u81ea\u52a8\u8fc7\u671f\uff09<\/li><li>2\u3001\u5728PHP \u7684\u547d\u4ee4\u884c\u6a21\u5f0f\u4e0b\u6267\u884c\uff08\u907f\u514d\u8d85\u65f6\u95ee\u9898\uff09<br>\n<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6269\u5c55\">\u6269\u5c55<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u901a\u8fc7QQ\u7a7a\u95f4\u7559\u8a00\u7684\u91c7\u96c6\uff0c\u53ef\u4ee5\u6269\u5c55\u4e0b\uff0c\u6bd4\u5982\u91c7\u96c6\u7a7a\u95f4\u65e5\u5fd7\u3001\u8bf4\u8bf4\u3001\u56fe\u7247\uff0c\u518d\u6bd4\u5982\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5237\u7559\u8a00\uff08\u6700\u597d\u5b9a\u65f6\u6267\u884c\u5237\u7559\u8a00\uff09\u3002<\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b\">\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\ndate_default_timezone_set('PRC');\n\/\/\u5185\u5b58\u65e0\u9650\u5236\nini_set('limit_memory', -1);\n\/\/\u4ee3\u7801\u6267\u884c\u4e0d\u8d85\u65f6\nset_time_limit(0);\n\n\/\/\u722c\u53d6QQ\u7a7a\u95f4\u7559\u8a00url\n$baseUrl = \"https:\/\/user.qzone.qq.com\/proxy\/domain\/m.qzone.qq.com\/cgi-bin\/new\/get_msgb?\";\n\n\/\/\/\/\u67e5\u627e\u7559\u8a00\u4e0b\u4e00\u9875\u89c4\u5f8b\n\/\/\u7b2c\u4e00\u9875\n\/\/uin=928692509&amp;hostUin=928692509&amp;start=0&amp;s=0.4852990803750179&amp;format=jsonp&amp;num=10&amp;inCharset=utf-8&amp;outCharset=utf-8&amp;g_tk=1467544760&amp;qzonetoken=e1fa4e2c8b873a4bf33b86e6f4838942ed7a538c10b5b8cb52e2bf4a959d253f90691c5ed8b045ada7&amp;g_tk=1467544760\n\/\/\u7b2c\u4e8c\u9875\n\/\/uin=928692509&amp;hostUin=928692509&amp;start=10&amp;s=0.4852990803750179&amp;format=jsonp&amp;num=10&amp;inCharset=utf-8&amp;outCharset=utf-8&amp;g_tk=1467544760&amp;qzonetoken=e1fa4e2c8b873a4bf33b86e6f4838942ed7a538c10b5b8cb52e2bf4a959d253f90691c5ed8b045ada7&amp;g_tk=1467544760\n\n\/\/\u722c\u53d6QQ\u7a7a\u95f4\u7559\u8a00\uff08\u81ea\u5df1\u6216QQ\u597d\u53cb\uff09\n$hostUinArr = [\n        '1270612806'=>'\u98de\u5f97\u66f4\u9ad8', '928692509'=>'Burning', '2075425089'=>'\u6012\u653e\u7684\u751f\u547d'\n    ];\n\n\/\/\u904d\u5386\u91c7\u96c6QQ\u597d\u53cb\u7a7a\u95f4\u7559\u8a00\nforeach($hostUinArr as $hostUin=>$qqName) {\n    downloadHostUinMessage($baseUrl, $hostUin, $qqName);\n}\n\n\/\/\u4ee5\u597d\u53cb\u540d\u79f0\u4e3a\u76ee\u5f55\uff0c\u5c06\u4e0b\u8f7d\u4e0b\u6765\u7684\u7559\u8a00\u5355\u72ec\u5b58\u653e\nfunction downloadHostUinMessage($baseUrl, $hostUin, $qqName){\n    $qqName = iconv('UTF-8', 'GBK', $qqName);\n    $dir = '.\/qqMessage\/'.$qqName;\n    \n    if(!is_dir($dir)) {\n        mkdir($dir, 0777, true);\n    }\n    \n    $totalPages = 1;\n    \n    for($i=0; $i&lt;$totalPages; $i++){\n        $start = $i*10;\n        $params = \"uin=928692509&amp;hostUin={$hostUin}&amp;start={$start}&amp;s=0.4852990803750179&amp;format=jsonp&amp;num=10&amp;inCharset=utf-8&amp;outCharset=utf-8&amp;g_tk=1467544760&amp;qzonetoken=e1fa4e2c8b873a4bf33b86e6f4838942ed7a538c10b5b8cb52e2bf4a959d253f90691c5ed8b045ada7&amp;g_tk=1467544760\";\n        \n        $url = $baseUrl . $params;\n        $iContent = qqCommentCurl($url);\n        \n        $iContent = str_replace('_Callback(', '', $iContent);\n        $iContent = trim(substr($iContent, 0, -2));\n        \/\/\u8ba1\u7b97\u603b\u9875\u6570\uff0c\u4fdd\u8bc1\u7559\u8a00\u91c7\u96c6\u5b8c\n        if($totalPages == 1) {\n            $iContentObj = json_decode($iContent);\n            if(isset($iContentObj->code) &amp;&amp; $iContentObj->code == 0) {\n                $dataObj = $iContentObj->data;\n                $totalPages = ceil($dataObj->total\/10);\n            } else {\n                \/\/\u7ed3\u675f\n                return false;\n            }\n        }\n        \n        file_put_contents($dir.'\/'.$hostUin.'_'.$i.'.txt', $iContent);\n    }\n}\n\n\/**\n * @author RenZhicai\n * QQ\u7a7a\u95f4\u7559\u8a00\u8bf7\u6c42curl\n * @param type $url\n * @return type\n *\/\nfunction qqCommentCurl($url='')\n{\n    $ch = curl_init();\n    \/\/\u9700\u8981\u83b7\u53d6\u7684 URL \u5730\u5740\uff0c\u4e5f\u53ef\u4ee5\u5728curl_init() \u521d\u59cb\u5316\u4f1a\u8bdd\u7684\u65f6\u5019\u3002\n    curl_setopt($ch, CURLOPT_URL, $url);\n    \/\/TRUE \u5c06curl_exec()\u83b7\u53d6\u7684\u4fe1\u606f\u4ee5\u5b57\u7b26\u4e32\u8fd4\u56de\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u8f93\u51fa\u3002\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n    if(preg_match('\/http:\\\/\\\/\/', $url)) {\n        \/\/FALSE \u7981\u6b62 cURL \u9a8c\u8bc1\u5bf9\u7b49\u8bc1\u4e66\uff08peer's certificate\uff09\u3002\u8981\u9a8c\u8bc1\u7684\u4ea4\u6362\u8bc1\u4e66\u53ef\u4ee5\u5728 CURLOPT_CAINFO \u9009\u9879\u4e2d\u8bbe\u7f6e\uff0c\u6216\u5728 CURLOPT_CAPATH\u4e2d\u8bbe\u7f6e\u8bc1\u4e66\u76ee\u5f55\u3002\n        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); \/\/\u8fd9\u4e2a\u662f\u91cd\u70b9\u3002\n    }\n    \n    \/\/\u542f\u7528\u65f6\u4f1a\u5c06\u5934\u6587\u4ef6\u7684\u4fe1\u606f\u4f5c\u4e3a\u6570\u636e\u6d41\u8f93\u51fa\u3002\n    curl_setopt($ch, CURLOPT_HEADER, 0); \n    \/\/TRUE \u65f6\u5c06\u4f1a\u6839\u636e\u670d\u52a1\u5668\u8fd4\u56de HTTP \u5934\u4e2d\u7684 \"Location: \" \u91cd\u5b9a\u5411\u3002\uff08\u6ce8\u610f\uff1a\u8fd9\u662f\u9012\u5f52\u7684\uff0c\"Location: \" \u53d1\u9001\u51e0\u6b21\u5c31\u91cd\u5b9a\u5411\u51e0\u6b21\uff0c\u9664\u975e\u8bbe\u7f6e\u4e86 CURLOPT_MAXREDIRS\uff0c\u9650\u5236\u6700\u5927\u91cd\u5b9a\u5411\u6b21\u6570\u3002\uff09\u3002\n    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); \/\/ \u8fd9\u6837\u80fd\u591f\u8ba9cURL\u652f\u6301\u9875\u9762\u94fe\u63a5\u8df3\u8f6c\n\n    \/\/header\u5934\u4fe1\u606f\n    $headerArr = [\n        \"accept-language: zh-CN,zh;q=0.8\",\n        \"user-agent: Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/61.0.3163.100 Safari\/537.36\"\n    ];\n    \/\/\u8bbe\u7f6e HTTP \u5934\u5b57\u6bb5\u7684\u6570\u7ec4\u3002\u683c\u5f0f\uff1a array('Content-type: text\/plain', 'Content-length: 100')\n    curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);\n    \n    curl_setopt($ch, CURLOPT_AUTOREFERER, true);\n    \n    \/\/\u8bbe\u7f6e\u65b0\u7684cookie\uff0c\u5ffd\u7565\u4e4b\u524d\u4f1a\u8bdd\u65f6\u5b58\u7684cookie\n    curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);\n    \/\/\u5305\u542b cookie \u6570\u636e\u7684\u6587\u4ef6\u540d\n    curl_setopt($ch, CURLOPT_COOKIEFILE, 'daoyancookiefile');\n    \/\/\u8fde\u63a5\u7ed3\u675f\u540e\uff0c\u6bd4\u5982\uff0c\u8c03\u7528 curl_close \u540e\uff0c\u4fdd\u5b58 cookie \u4fe1\u606f\u7684\u6587\u4ef6\u3002\n    curl_setopt($ch, CURLOPT_COOKIEJAR, 'daoyancookiefile');\n\n    \/\/\u767b\u5f55\u540e\u7684cookie\u4fe1\u606f  \n    $cookieStr = \"cookie: pgv_pvi=9803880448; tvfe_boss_uuid=7aa8e6046d68c6a2; RK=qBcndcbOTD; eas_sid=K1s5q0V8H8N5B4c1j9e2L0D8W3; pgv_pvid=8596381360; o_cookie=928692509; __Q_w_s_hat_seed=1; __Q_w_s__QZN_TodoMsgCnt=1; ptcz=dab5485d33e04f8612e84673ce0609bdcae13f792156f92dccf5a9784988a16a; uin=o0928692509; skey=@CgmH4oeQ8; pt2gguin=o0928692509; p_uin=o0928692509; pt4_token=Lub2nMWbTLfbx0TYxH*uyDBOU4tEBXvKvv0JNQRQuGo_; p_skey=MxE5cMJA2xHQ8BXgpbVqSL3hgeoEfcq-quN1kvcUrcQ_; pgv_info=ssid=s7150557986; Loading=Yes; qz_screen=1366x768; qqmusic_uin=; qqmusic_key=; qqmusic_fromtag=; qzmusicplayer=qzone_player_928692509_1509368391144; QZ_FE_WEBP_SUPPORT=1; cpu_performance_v8=6\";\n    \/\/\u8bbe\u5b9a HTTP \u8bf7\u6c42\u4e2d\"Cookie: \"\u90e8\u5206\u7684\u5185\u5bb9\u3002\u591a\u4e2a cookie \u7528\u5206\u53f7\u5206\u9694\uff0c\u5206\u53f7\u540e\u5e26\u4e00\u4e2a\u7a7a\u683c(\u4f8b\u5982\uff0c \"fruit=apple; colour=red\")\u3002\n    curl_setopt($ch, CURLOPT_COOKIE, $cookieStr);\n\n    $output = curl_exec($ch);\n    if($output === false){\n                \/\/\u8bb0\u5f55curl\u8bf7\u6c42\u5931\u8d25\u7684\u8be6\u60c5\n        $errorInfo = \"cURL Error: \".curl_error($ch);\n        file_put_contents('curl_error_'.date('YmdHis').'.txt', $errorInfo);\n    }\n    \n    curl_close($ch);\n\n    return $output;\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u91c7\u96c6\u6548\u679c\u4e00\u89c8\">\u91c7\u96c6\u6548\u679c\u4e00\u89c8<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images2017.cnblogs.com\/blog\/640833\/201710\/640833-20171030234206980-56313920.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images2017.cnblogs.com\/blog\/640833\/201710\/640833-20171030234245355-1540308951.png\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3b\u8981\u6d41\u7a0b\u89e3\u6790 \u9996\u5148\uff0c\u6253\u5f00\u6d4f\u89c8\u5668\u767b\u5f55QQ\u7a7a\u95f4\u5e76\u8bbf\u95ee\u7559\u8a00\u5217\u8868 \u7531\u4e8eQQ\u7a7a\u95f4\u7684\u94fe\u63a5\u662fhttps\uff0ccurl\u65b9\u5f0f\u8bf7\u6c42https\u94fe\u63a5\u9700\u8981\u7a81\u7834https\u8ba4\u8bc1\uff0c\u8fd9\u5c31\u9700\u8981\u4e0b\u8f7dcacert.pem\uff0c\u4e0b\u9762\u8bf7\u770bcacert.pem\u7684\u90e8\u7f72\u6b65\u9aa4 \u6ce8\u610f\u4e8b\u9879 1\u3001\u4e00\u5b9a\u8981\u8bbe\u7f6e\u65f6\u533a\u4e3a\u4e2d\u56fd\u65f6\u533a\uff08\u907f\u514dcookie\u4e0d\u540c\u65f6\u533a\u800c\u81ea\u52a8\u8fc7\u671f\uff09 2\u3001\u5728PHP \u7684\u547d\u4ee4\u884c\u6a21\u5f0f\u4e0b\u6267\u884c\uff08\u907f\u514d\u8d85\u65f6\u95ee\u9898\uff09 \u6269\u5c55 \u901a\u8fc7QQ\u7a7a\u95f4\u7559\u8a00\u7684\u91c7\u96c6\uff0c\u53ef\u4ee5\u6269\u5c55\u4e0b\uff0c\u6bd4\u5982\u91c7\u96c6\u7a7a\u95f4\u65e5\u5fd7\u3001\u8bf4\u8bf4\u3001\u56fe\u7247\uff0c\u518d\u6bd4\u5982\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5237\u7559\u8a00\uff08\u6700\u597d\u5b9a\u65f6\u6267\u884c\u5237\u7559\u8a00\uff09\u3002 \u5b8c\u6574\u4ee3\u7801\u793a\u4f8b \u91c7\u96c6\u6548\u679c\u4e00\u89c8<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-110","post","type-post","status-publish","format-standard","hentry","category-27"],"_links":{"self":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":0,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"wp:attachment":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}