{"id":32590,"date":"2024-11-25T17:15:58","date_gmt":"2024-11-25T09:15:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32590\/"},"modified":"2024-11-25T17:15:58","modified_gmt":"2024-11-25T09:15:58","slug":"%e5%be%ae%e4%bf%a1%e5%85%ac%e4%bc%97%e5%8f%b7%e7%bd%91%e9%a1%b5%e6%8e%88%e6%9d%83%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32590\/","title":{"rendered":"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3"},"content":{"rendered":"<p>\u5728\u8fd9\u4e2a\u79fb\u52a8\u7aef\u7684\u65f6\u4ee3\uff0c\u516c\u4f17\u53f7\u4e5f\u9010\u6e10\u6210\u4e3a\u4eba\u4eec\u83b7\u53d6\u4fe1\u606f\u7684\u4e00\u79cd\u6e20\u9053\uff0c\u4e5f\u662f\u5546\u5bb6\u53d1\u5c55\u6f5c\u5728\u5ba2\u6237\u7684\u4e00\u79cd\u624b\u6bb5\uff0c\u56e0\u6b64\uff0c\u8bb8\u591a\u7a0b\u5e8f\u5458\u8f6c\u6218\u5fae\u4fe1\u5f00\u53d1\uff0c\u90a3\u4e48\u4eca\u5929\uff0c\u6211\u4eec\u5c31\u6765\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e0b\u5fae\u4fe1\u516c\u4f17\u53f7\u5f00\u53d1\u4e2d\u7684\u7f51\u9875\u6388\u6743\u5230\u5e95\u8981\u600e\u6837\u624d\u80fd\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u5728\u8fd9\u4e4b\u524d\u5148\u7ed9\u5927\u5bb6\u4e00\u4e2a\u6211\u81ea\u5b9a\u4e49\u7684\u8bf7\u6c42\u63a5\u53e3\u7684\u51fd\u6570\uff0c\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4ee3\u7801\u4e2d\u8bf7\u6c42\u63a5\u53e3\u7528\u7684\u90fd\u662f\u8fd9\u4e2a\u51fd\u6570<\/strong><\/p>\n<p><strong>\u8be5\u51fd\u6570\u7684\u4f5c\u7528\u662f\uff0c\u60f3\u63a5\u53e3\u53d1\u8d77\u8bf7\u6c42\uff0c\u4f20\u9012\u53c2\u6570\u5e76\u8fd4\u56de\u63a5\u53e3\u8fd4\u56de\u7684\u6570\u636e<\/strong><\/p>\n<p><strong>(\u8fd9\u4e2a\u91cc\u9762\u7684\u4ee3\u7801\u5c31\u4e0d\u505a\u591a\u89e3\u91ca\u4e86\uff0c\u5982\u679c\u5927\u5bb6\u60f3\u8981\u4e86\u89e3\u53ef\u4ee5\u53bb\u770b\u4e00\u4e0b)<\/strong><\/p>\n<pre>\/\/\u81ea\u5b9a\u4e49\u8bf7\u6c42\u63a5\u53e3\u51fd\u6570\uff0c$data\u4e3a\u7a7a\u65f6\u53d1\u8d77get\u8bf7\u6c42\uff0c$data\u6709\u503c\u65f6\u53d1\u60c5post\u8bf7\u6c42\nfunction&nbsp;http_url($url,$data=null){\n&nbsp;&nbsp;&nbsp;&nbsp;$ch&nbsp;=&nbsp;curl_init();\n&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_URL,$url);\n&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);\n&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);\n&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);\n&nbsp;&nbsp;&nbsp;&nbsp;if(!empty($data)){\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_POST,1);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_POSTFIELDS,$data);\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;$res&nbsp;=&nbsp;curl_exec($ch);\n&nbsp;&nbsp;&nbsp;&nbsp;if(curl_errno($ch)){\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;\"error:\".curl_error($ch);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;curl_close($ch);\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$res;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\uff08\u6587\u4e2d\u6240\u4f7f\u7528\u7684\u63a5\u53e3\u4e3a\u817e\u8baf\u5b98\u65b9\u63d0\u4f9b\uff0c\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u7684<\/strong><strong>\uff09<\/strong><\/p>\n<p><span style=\"font-size: 16px\"><strong>\u4e00\u3001\u9996\u5148\u6211\u4eec\u9700\u8981\u914d\u7f6e\u6211\u4eec\u7684\u516c\u4f17\u53f7<\/strong><\/span><\/p>\n<p>1\u3001\u5728\u5fae\u4fe1\u516c\u4f17\u53f7\u8bf7\u6c42\u7528\u6237\u7f51\u9875\u6388\u6743\u4e4b\u524d\uff0c\u5f00\u53d1\u8005\u9700\u8981\u5148\u5230\u516c\u4f17\u5e73\u53f0\u5b98\u7f51\u4e2d\u7684\u201c<strong>\u5f00\u53d1 &#8211; \u63a5\u53e3\u6743\u9650 &#8211; \u7f51\u9875\u670d\u52a1 &#8211; \u7f51\u9875\u5e10\u53f7 &#8211; \u7f51\u9875\u6388\u6743\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f<\/strong>\u201d\u7684\u914d\u7f6e\u9009\u9879\u4e2d\uff0c\u4fee\u6539\u6388\u6743\u56de\u8c03\u57df\u540d\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u586b\u5199\u7684\u662f\u57df\u540d\uff08\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff09\uff0c\u800c\u4e0d\u662fURL\uff0c\u56e0\u6b64<strong>\u8bf7\u52ff\u52a0 http:\/\/ \u7b49\u534f\u8bae\u5934<\/strong>\uff1b<\/p>\n<p>2\u3001\u6388\u6743\u56de\u8c03\u57df\u540d\u914d\u7f6e\u89c4\u8303\u4e3a\u5168\u57df\u540d\uff0c\u6bd4\u5982\u9700\u8981\u7f51\u9875\u6388\u6743\u7684\u57df\u540d\u4e3a\uff1awww.qq.com\uff0c\u914d\u7f6e\u4ee5\u540e\u6b64\u57df\u540d\u4e0b\u9762\u7684\u9875\u9762http:\/\/www.qq.com\/music.html&nbsp;\u3001&nbsp;http:\/\/www.qq.com\/login.html&nbsp;\u90fd\u53ef\u4ee5\u8fdb\u884cOAuth2.0\u9274\u6743\u3002\u4f46http:\/\/pay.qq.com&nbsp;\u3001&nbsp;http:\/\/music.qq.com&nbsp;\u3001&nbsp;http:\/\/qq.com\u65e0\u6cd5\u8fdb\u884cOAuth2.0\u9274\u6743<\/p>\n<p>3\u3001\u5982\u679c\u516c\u4f17\u53f7\u767b\u5f55\u6388\u6743\u7ed9\u4e86\u7b2c\u4e09\u65b9\u5f00\u53d1\u8005\u6765\u8fdb\u884c\u7ba1\u7406\uff0c\u5219\u4e0d\u5fc5\u505a\u4efb\u4f55\u8bbe\u7f6e\uff0c\u7531\u7b2c\u4e09\u65b9\u4ee3\u66ff\u516c\u4f17\u53f7\u5b9e\u73b0\u7f51\u9875\u6388\u6743\u5373\u53ef<\/p>\n<p><span style=\"font-size: 16px\"><strong>\u4e8c\u3001\u7528\u6237\u540c\u610f\u6388\u6743\uff0c\u83b7\u53d6code<\/strong><\/span><\/p>\n<p>\u63a5\u53e3\u5730\u5740\uff1a<\/p>\n<p>&nbsp; &nbsp;<img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/103\/914\/801\/1563255233734997.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe\" \/><\/p>\n<pre>function&nbsp;Get_Code()&nbsp;&nbsp;\/\/\u83b7\u53d6code\n{\n\/\/\u6784\u9020\u8bf7\u6c42\u5730\u5740\n$code_url&nbsp;=&nbsp;\"https:\/\/open.weixin.qq.com\/connect\/oauth2\/authorize?appid=\u5fae\u4fe1\u516c\u4f17\u53f7appid&amp;amp;redirect_uri=\u8bf7\u6c42\u529f\u540e\u56de\u8c03\u5730\u5740&amp;amp;response_type=code&amp;amp;scope=snsapi_userinfo&amp;amp;state=STATE&nbsp;#wechat_redirect\";\n\/\/\u8df3\u8f6c\u5230\u8bf7\u6c42\u5730\u5740\uff0c\u5e94\u4e3a\u672c\u7701\u8bbe\u7f6e\u4e86\u56de\u8c03\u5730\u5740\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u4f7f\u7528file_get_content()\u6765\u8bf7\u6c42\u63a5\u53e3\u3002\nheader(\"location:\"&nbsp;.&nbsp;$code_url);\nexit;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 16px\"><strong>\u4e09\u3001\u901a\u4e2a\u83b7\u53d6\u5230\u7684code\u6765\u6216\u7f3aaccess_token\u548copenid<\/strong><\/span><\/p>\n<p>\u63a5\u53e3\uff1ahttps:\/\/api.weixin.qq.com\/sns\/oauth2\/access_token?appid=APPID&amp;secret=SECRET&amp;code=CODE&amp;grant_type=authorization_code<br \/><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/461\/850\/617\/1563255724705416.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe1\" \/><\/p>\n<pre>\/**\n&nbsp;*&nbsp;&nbsp;\u901a\u8fc7\u83b7\u53d6\u5230\u7684code\u6765\u83b7\u53d6access_token\u548copenid&nbsp;\n&nbsp;*&nbsp;&nbsp;$code\u4e3a\u83b7\u53d6\u5230\u7684code\n&nbsp;*&nbsp;\u63a5\u53e3\u7684\u53c2\u6570\u6ce8\u610f\u6362\u6210\u81ea\u5df1\u7684\uff0c\u5982appid\u548csecret\n&nbsp;*\/\nfunction&nbsp;GetAccess_Token($code)\n{\n$get_access_token_url&nbsp;=&nbsp;\"https:\/\/api.weixin.qq.com\/sns\/oauth2\/access_token?appid=appid&amp;amp;secret=secret&amp;amp;code=$code&amp;amp;grant_type=authorization_code\";\n$res&nbsp;=&nbsp;http_url($get_access_token_url);\nreturn&nbsp;json_decode($res,&nbsp;true);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 16px\"><strong>\u56db\u3001\u5224\u65adaccess_token\u662f\u5426\u6709\u6548<\/strong><\/span><\/p>\n<p>\u63a5\u53e3\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/798\/918\/975\/1563256618632142.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe2\" alt=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe2\" \/><\/p>\n<pre>\/**\n&nbsp;*&nbsp;\u68c0\u67e5access_token\u662f\u5426\u6709\u6548\n&nbsp;*&nbsp;\n&nbsp;*\/\nfunction&nbsp;CkeckAccessToken($access_token,&nbsp;$openid)\n{\n&nbsp;&nbsp;&nbsp;&nbsp;$check_url&nbsp;=&nbsp;\"https:\/\/api.weixin.qq.com\/sns\/auth?access_token=$access_token&amp;amp;openid=$openid\";\n&nbsp;&nbsp;&nbsp;&nbsp;$res&nbsp;=&nbsp;http_url($check_url);\n&nbsp;&nbsp;&nbsp;&nbsp;$result&nbsp;=&nbsp;json_decode($res,&nbsp;true);\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(isset($result['errmsg'])&nbsp;&amp;amp;&amp;amp;&nbsp;$result['errmsg']&nbsp;==&nbsp;1)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/access_token\u6709\u6548&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/access_token\u65e0\u6548&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 16px\"><strong>\u4e94\u3001\u5982\u679c\u5931\u6548\uff0c\u5237\u65b0access_token<\/strong><\/span><\/p>\n<p>\u63a5\u53e3\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/645\/841\/768\/1563256823718809.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe3\" alt=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe3\" \/><\/p>\n<pre>\/**\n&nbsp;*&nbsp;\u5982\u679c\u83b7\u53d6\u5230\u7684access_token\u65e0\u6548\uff0c\u901a\u8fc7refresh_token\u6765\u5237\u65b0access_token\n&nbsp;*\u63a5\u53e3\u7684\u53c2\u6570\u6ce8\u610f\u6362\u6210\u81ea\u5df1\u7684\n&nbsp;*\/\nfunction&nbsp;GetRefresh_Token($refresh_token)\n{\n$get_refresh_token_url&nbsp;=&nbsp;\"https:\/\/api.weixin.qq.com\/sns\/oauth2\/refresh_token?appid=appid&amp;amp;grant_type=refresh_token&amp;amp;refresh_token=$refresh_token\";\n$res&nbsp;=&nbsp;http_url($get_refresh_token_url);\nreturn&nbsp;json_decode($res,&nbsp;true);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 16px\"><strong>\u516d\u3001\u83b7\u53d6\u7528\u6237\u4fe1\u606f<\/strong><\/span><\/p>\n<p>\u63a5\u53e3\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/159\/783\/369\/1563256996819674.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe4\" alt=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe4\" \/><\/p>\n<pre>\/**&nbsp;*&nbsp;\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f&nbsp;*&nbsp;&nbsp;*\/\nfunction&nbsp;Get_User_Info($access_token,&nbsp;$openid){&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$get_user_info&nbsp;=&nbsp;\"https:\/\/api.weixin.qq.com\/sns\/userinfo?access_token=$access_token&amp;amp;openid=$openid&amp;amp;lang=zh_CN\";&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$res&nbsp;=&nbsp;http_url($get_user_info);&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;json_decode($res,&nbsp;true);\n&nbsp;&nbsp;&nbsp;}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u83b7\u53d6\u5230\u7528\u6237\u4fe1\u606f\u6570\u636e\uff1a<\/p>\n<pre>{&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;\"openid\":\"&nbsp;OPENID\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"&nbsp;nickname\":&nbsp;NICKNAME,\n&nbsp;&nbsp;&nbsp;&nbsp;\"sex\":\"1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"province\":\"PROVINCE\"\n&nbsp;&nbsp;&nbsp;&nbsp;\"city\":\"CITY\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"country\":\"COUNTRY\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"headimgurl\":&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"http:\/\/thirdwx.qlogo.cn\/mmopen\/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe\/46\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"privilege\":[&nbsp;\"PRIVILEGE1\"&nbsp;\"PRIVILEGE2\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],\n&nbsp;&nbsp;&nbsp;&nbsp;\"unionid\":&nbsp;\"o6_bmasdasdsad6_2sgVt7hMZOPfL\"\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/526\/374\/145\/1563257148384144.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe5\" alt=\"\u5fae\u4fe1\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u63d2\u56fe5\" \/><span style=\"max-width:90%\"><strong>\u4e0b\u9762\u4e0a\u5b8c\u6574\u4ee3\u7801\uff1a<\/strong><\/span><\/p>\n<pre>&lt;?php     \/\/\u8df3\u8f6c\u7b2c\u4e09\u65b9\u9875\u9762\uff0c\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\n    \/\/ \u8fd9\u662f\u8bf7\u6c42\u9875\u9762\u4e5f\u662fcode\u7684\u56de\u8c03\u9875\u9762\n    session_start();                \/\/\u542f\u52a8session\n    if (isset($_GET[&#039;code&#039;])) {     \/\/\u5224\u65ad\u662f\u5426\u6709code\u4f20\u8fc7\u6765\uff0c\u5982\u679c\u6ca1\u6709\u8c03\u7528\u51fd\u6570\u8bf7\u6c42code\n          $res = GetAccess_Token($_GET[&#039;code&#039;]);     \/\/\u4f7f\u7528code\u83b7\u53d6access_token\u548copenid\n          if (CkeckAccessToken($res[&#039;access_token&#039;], $res[&#039;openid&#039;]) == 0) {     \/\/\u5224\u65adaccess_token\u662f\u5426\u6709\u6548\uff0c\u5982\u679c\u65e0\u6548\u83b7\u53d6\u65b0\u7684access_token\n                  $res = GetRefresh_Token($res[&#039;refresh_token&#039;]);                    \/\/\u6216\u7f3a\u65b0\u7684access_token\n            }\n           $userinfo = Get_User_Info($res[&#039;access_token&#039;], $res[&#039;openid&#039;]);        \/\/\u83b7\u53d6\u7528\u6237\u4fe1\u606f\n           $_SESSION[&#039;userinfo&#039;] = $userinfo;                                      \/\/\u5c06\u7528\u6237\u4fe1\u606f\u5b58\u5165session\u4e2d\n           $next_url = &#039;http:\/\/web\/index.php&#039;;                                     \/\/\u4e0b\u4e00\u4e2a\u9875\u9762\u5730\u5740\n           header(\"location:\" . $next_url);                                       \/\/\u83b7\u53d6\u5230\u4fe1\u606f\u540e\u8df3\u8f6c\u5230\u5176\u4ed6\u9875\u9762\n           exit;\n      } else { \n         \/\/\u83b7\u53d6code\n      Get_Code();\n      }\n    function Get_Code()  \/\/\u83b7\u53d6code{\n    $code_url = \"https:\/\/open.weixin.qq.com\/connect\/oauth2\/authorize?appid=appid&amp;redirect_uri=\u56de\u8c03\u5730\u5740&amp;response_type=code&amp;scope=snsapi_userinfo&amp;state=STATE #wechat_redirect\";\n    header(\"location:\" . $code_url);\n    exit;\n    }\n    \/**\n    *  \u901a\u8fc7\u83b7\u53d6\u5230\u7684code\u6765\u83b7\u53d6access_token\u548copenid\n    *\n    *\/\n    function GetAccess_Token($code){\n        $get_access_token_url = \"https:\/\/api.weixin.qq.com\/sns\/oauth2\/access_token?appid=appid&amp;secret=secret&amp;code=$code&amp;grant_type=authorization_code\";\n        $res = http_url($get_access_token_url);\n        return json_decode($res, true);\n        }\n    \/**\n     * \u68c0\u67e5access_token\u662f\u5426\u6709\u6548\n     *\n    *\/\n    function CkeckAccessToken($access_token, $openid){\n    $check_url = \"https:\/\/api.weixin.qq.com\/sns\/auth?access_token=$access_token&amp;openid=$openid\"; \n    $res = http_url($check_url);\n    $result = json_decode($res, true);\n    if (isset($result[&#039;errmsg&#039;]) &amp;&amp; $result[&#039;errmsg&#039;] == 1) {\n       return 1;       \/\/access_token\u6709\u6548 \n     } else { \n       return 0;       \/\/access_token\u65e0\u6548 \n     }\n    }\n\n    \/**\n     * \u5982\u679c\u83b7\u53d6\u5230\u7684access_token\u65e0\u6548\uff0c\u901a\u8fc7refresh_token\u6765\u5237\u65b0access_token \n     *\/\n    function GetRefresh_Token($refresh_token){\n        $get_refresh_token_url = \"https:\/\/api.weixin.qq.com\/sns\/oauth2\/refresh_token?appid=appid&amp;grant_type=refresh_token&amp;refresh_token=$refresh_token\";\n        $res = http_url($get_refresh_token_url);\n        return json_decode($res, true);\n     }\n    \/**\n     * \u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\n     *\n     *\/\n    function Get_User_Info($access_token, $openid){\n        $get_user_info = \"https:\/\/api.weixin.qq.com\/sns\/userinfo?access_token=$access_token&amp;openid=$openid&amp;lang=zh_CN\";\n        $res = http_url($get_user_info);\n        return json_decode($res, true);}\n    \/\/\u81ea\u5b9a\u4e49\u8bf7\u6c42\u63a5\u53e3\u51fd\u6570\uff0c$data\u4e3a\u7a7a\u65f6\u53d1\u8d77get\u8bf7\u6c42\uff0c$data\u6709\u503c\u65f6\u53d1\u8d77post\u8bf7\u6c42\n    function http_url($url,$data=null){\n       $ch = curl_init();\n        curl_setopt($ch,CURLOPT_URL,$url);\n        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);\n        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);\n        curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);\n        if(!empty($data)){    \n            curl_setopt($ch,CURLOPT_POST,1);\n            curl_setopt($ch,CURLOPT_POSTFIELDS,$data);\n         }\n         $res = curl_exec($ch);\n         if(curl_errno($ch)){\n           echo \"error:\".curl_error($ch);\n           exit;\n          }\n          curl_close($ch);\n          return $res;\n          }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p> &nbsp; &nbsp;<span style=\"font-size: 16px\"><\/span><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u516c\u4f17\u53f7\u7f51\u9875\u6388\u6743\u8be6\u89e3\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8fd9\u4e2a\u79fb\u52a8\u7aef\u7684\u65f6\u4ee3\uff0c\u516c\u4f17\u53f7\u4e5f\u9010\u6e10\u6210\u4e3a\u4eba\u4eec\u83b7\u53d6\u4fe1\u606f\u7684\u4e00\u79cd\u6e20\u9053\uff0c\u4e5f\u662f\u5546\u5bb6\u53d1\u5c55\u6f5c\u5728\u5ba2\u6237\u7684\u4e00\u79cd\u624b\u6bb5\uff0c\u56e0\u6b64\uff0c\u8bb8\u591a\u7a0b\u5e8f\u5458\u8f6c\u6218\u5fae\u4fe1\u5f00\u53d1\uff0c\u90a3\u4e48\u4eca\u5929\uff0c\u6211\u4eec\u5c31\u6765\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e0b\u5fae\u4fe1\u516c\u4f17\u53f7\u5f00\u53d1\u4e2d\u7684\u7f51\u9875\u6388\u6743\u5230\u5e95\u8981\u600e\u6837\u624d\u80fd\u5b9e\u73b0\u3002 \u5728\u8fd9\u4e4b\u524d\u5148\u7ed9\u5927\u5bb6\u4e00\u4e2a\u6211\u81ea\u5b9a\u4e49\u7684\u8bf7\u6c42\u63a5\u53e3\u7684\u51fd\u6570\uff0c\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4ee3\u7801\u4e2d\u8bf7\u6c42\u63a5\u53e3\u7528\u7684\u90fd\u662f\u8fd9\u4e2a\u51fd\u6570 \u8be5\u51fd\u6570\u7684\u4f5c\u7528\u662f\uff0c\u60f3\u63a5\u53e3\u53d1\u8d77\u8bf7\u6c42\uff0c\u4f20\u9012\u53c2\u6570\u5e76\u8fd4\u56de\u63a5\u53e3\u8fd4\u56de\u7684\u6570\u636e (\u8fd9\u4e2a\u91cc\u9762\u7684\u4ee3\u7801\u5c31\u4e0d\u505a\u591a\u89e3\u91ca\u4e86\uff0c\u5982\u679c\u5927\u5bb6\u60f3\u8981\u4e86\u89e3\u53ef\u4ee5\u53bb\u770b\u4e00\u4e0b) \/\/\u81ea\u5b9a\u4e49\u8bf7\u6c42\u63a5\u53e3\u51fd\u6570\uff0c$data\u4e3a\u7a7a\u65f6\u53d1\u8d77get\u8bf7\u6c42\uff0c$data\u6709\u503c\u65f6\u53d1\u60c5post\u8bf7\u6c42 function&nbsp;http_url($url,$data=null){ &nbsp;&nbsp;&nbsp;&nbsp;$ch&nbsp;=&nbsp;curl_init(); &nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_URL,$url); &nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE); &nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0); &nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); &nbsp;&nbsp;&nbsp;&nbsp;if(!empty($data)){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_POST,1); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch,CURLOPT_POSTFIELDS,$data); &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;$res&nbsp;=&nbsp;curl_exec($ch); &nbsp;&nbsp;&nbsp;&nbsp;if(curl_errno($ch)){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&#8220;error:&#8221;.curl_error($ch); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;curl_close($ch); &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$res; } \u767b\u5f55\u540e\u590d\u5236 \uff08\u6587\u4e2d\u6240\u4f7f\u7528\u7684\u63a5\u53e3\u4e3a\u817e\u8baf\u5b98\u65b9\u63d0\u4f9b\uff0c\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u7684\uff09 \u4e00\u3001\u9996\u5148\u6211\u4eec\u9700\u8981\u914d\u7f6e\u6211\u4eec\u7684\u516c\u4f17\u53f7 1\u3001\u5728\u5fae\u4fe1\u516c\u4f17\u53f7\u8bf7\u6c42\u7528\u6237\u7f51\u9875\u6388\u6743\u4e4b\u524d\uff0c\u5f00\u53d1\u8005\u9700\u8981\u5148\u5230\u516c\u4f17\u5e73\u53f0\u5b98\u7f51\u4e2d\u7684\u201c\u5f00\u53d1 &#8211; \u63a5\u53e3\u6743\u9650 &#8211; \u7f51\u9875\u670d\u52a1 &#8211; \u7f51\u9875\u5e10\u53f7 &#8211; \u7f51\u9875\u6388\u6743\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u201d\u7684\u914d\u7f6e\u9009\u9879\u4e2d\uff0c\u4fee\u6539\u6388\u6743\u56de\u8c03\u57df\u540d\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u586b\u5199\u7684\u662f\u57df\u540d\uff08\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff09\uff0c\u800c\u4e0d\u662fURL\uff0c\u56e0\u6b64\u8bf7\u52ff\u52a0 http:\/\/ \u7b49\u534f\u8bae\u5934\uff1b 2\u3001\u6388\u6743\u56de\u8c03\u57df\u540d\u914d\u7f6e\u89c4\u8303\u4e3a\u5168\u57df\u540d\uff0c\u6bd4\u5982\u9700\u8981\u7f51\u9875\u6388\u6743\u7684\u57df\u540d\u4e3a\uff1awww.qq.com\uff0c\u914d\u7f6e\u4ee5\u540e\u6b64\u57df\u540d\u4e0b\u9762\u7684\u9875\u9762http:\/\/www.qq.com\/music.html&nbsp;\u3001&nbsp;http:\/\/www.qq.com\/login.html&nbsp;\u90fd\u53ef\u4ee5\u8fdb\u884cOAuth2.0\u9274\u6743\u3002\u4f46http:\/\/pay.qq.com&nbsp;\u3001&nbsp;http:\/\/music.qq.com&nbsp;\u3001&nbsp;http:\/\/qq.com\u65e0\u6cd5\u8fdb\u884cOAuth2.0\u9274\u6743 3\u3001\u5982\u679c\u516c\u4f17\u53f7\u767b\u5f55\u6388\u6743\u7ed9\u4e86\u7b2c\u4e09\u65b9\u5f00\u53d1\u8005\u6765\u8fdb\u884c\u7ba1\u7406\uff0c\u5219\u4e0d\u5fc5\u505a\u4efb\u4f55\u8bbe\u7f6e\uff0c\u7531\u7b2c\u4e09\u65b9\u4ee3\u66ff\u516c\u4f17\u53f7\u5b9e\u73b0\u7f51\u9875\u6388\u6743\u5373\u53ef \u4e8c\u3001\u7528\u6237\u540c\u610f\u6388\u6743\uff0c\u83b7\u53d6code \u63a5\u53e3\u5730\u5740\uff1a &nbsp; &nbsp; function&nbsp;Get_Code()&nbsp;&nbsp;\/\/\u83b7\u53d6code { \/\/\u6784\u9020\u8bf7\u6c42\u5730\u5740 $code_url&nbsp;=&nbsp;&#8220;https:\/\/open.weixin.qq.com\/connect\/oauth2\/authorize?appid=\u5fae\u4fe1\u516c\u4f17\u53f7appid&amp;amp;redirect_uri=\u8bf7\u6c42\u529f\u540e\u56de\u8c03\u5730\u5740&amp;amp;response_type=code&amp;amp;scope=snsapi_userinfo&amp;amp;state=STATE&nbsp;#wechat_redirect&#8221;; \/\/\u8df3\u8f6c\u5230\u8bf7\u6c42\u5730\u5740\uff0c\u5e94\u4e3a\u672c\u7701\u8bbe\u7f6e\u4e86\u56de\u8c03\u5730\u5740\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u4f7f\u7528file_get_content()\u6765\u8bf7\u6c42\u63a5\u53e3\u3002 header(&#8220;location:&#8221;&nbsp;.&nbsp;$code_url); exit; } \u767b\u5f55\u540e\u590d\u5236 \u4e09\u3001\u901a\u4e2a\u83b7\u53d6\u5230\u7684code\u6765\u6216\u7f3aaccess_token\u548copenid \u63a5\u53e3\uff1ahttps:\/\/api.weixin.qq.com\/sns\/oauth2\/access_token?appid=APPID&amp;secret=SECRET&amp;code=CODE&amp;grant_type=authorization_code \/** [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-32590","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32590"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32590\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}