{"id":31415,"date":"2024-11-25T14:01:22","date_gmt":"2024-11-25T06:01:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31415\/"},"modified":"2024-11-25T14:01:22","modified_gmt":"2024-11-25T06:01:22","slug":"%e5%be%ae%e4%bf%a1%e7%bd%91%e9%a1%b5%e8%8e%b7%e5%8f%96%e7%94%a8%e6%88%b7%e5%9f%ba%e6%9c%ac%e4%bf%a1%e6%81%af%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31415\/","title":{"rendered":"\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u548c\u5927\u5bb6\u5206\u4eab\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5\uff0c\u4e4b\u524d\u5199\u8fc7\u6587\u7ae0<strong><span style=\"font-size:18px\">\u5fae\u4fe1\u7f51\u9875\u6388\u6743\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f<\/span><\/strong>\u8bb2\u7f51\u9875\u5f00\u53d1\u7684\u65f6\u5019\uff0c\u6709\u65f6\u5019\u9700\u8981\u83b7\u53d6\u7528\u6237\u7684\u6635\u79f0\u5934\u50cf\u7b49\u4e2a\u4eba\u57fa\u672c\u4fe1\u606f\uff0c\u83b7\u53d6\u7528\u6237\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f51\u9875\u6388\u6743\uff0c\u7528\u6237\u540c\u610f\u4e4b\u540e\uff0c\u83b7\u53d6\u5230\uff0c\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/6e90deedbb0f50cd9c0fd2b19acabe68-0.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5\u63d2\u56fe\" \/><\/p>\n<p>\u4f46\u662f\uff0c<strong><span style=\"color:#ff0000\">\u8fd9\u6837\u5c31\u591a\u4e86\u4e00\u4e2a\u6b65\u9aa4\uff0c\u6709\u7684\u7528\u6237\u53ef\u80fd\u770b\u5230\u591a\u4e00\u4e2a\u6b65\u9aa4\uff0c\u5c31\u968f\u624b\u70b9\u51fb\u56de\u9000<\/span><\/strong>\uff0c\u5c31\u8fd9\u4e48\u5931\u6389\u4e86\u4e00\u4e2a\u5b9d\u8d35\u7684\u7528\u6237\uff0c\u5f88\u662f\u9057\u61be\uff0c\u90a3\u4e48\u4eca\u5929\u6211\u4eec\u5c31\u4f7f\u7528\u53e6\u4e00\u79cd\u65b9\u5f0f\u6765\u83b7\u53d6\u7528\u6237\u4fe1\u606f\uff0c\u5c31\u662f\u901a\u8fc7OpenID\u6765\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u5c31\u7b80\u5355\u591a\u4e86\uff0c\u5728<strong><span style=\"color:#ff0000\">\u7528\u6237\u4e0d\u77e5\u4e0d\u89c9\u7684\u60c5\u51b5\u4e0b<\/span><\/strong>\uff0c\u6211\u4eec\u5c31\u62ff\u5230\u4e86\u4ed6\u7684\u4e2a\u4eba\u4fe1\u606f\uff0c\u800c\u4e14\u8fd9\u6837\u83b7\u53d6\u7684\u4fe1\u606f\u6bd4\u6388\u6743\u83b7\u53d6\u7684\u8fd8\u8981\u591a\uff0c\u6bd4\u5982\u8fd9\u6837\u8fd8<strong><span style=\"color:#ff0000\">\u53ef\u4ee5\u77e5\u9053\u8be5\u7528\u6237\u662f\u5426\u5173\u6ce8\u4ee5\u53ca\u5173\u6ce8\u65f6\u95f4<\/span><\/strong>\u3002<\/p>\n<p>\u524d\u671f\u51c6\u5907\uff1a<br \/><strong>\u83b7\u53d6\u5230\u7528\u6237\u7684openid<\/strong>\uff0c\u8fd9\u4e2a\u5728\u4e0a\u4e00\u7bc7\u6587\u7ae0\u8bb2\u8fc7\u4e86\uff0c\u8be6\u89c1\uff1a<strong><span style=\"font-size:18px\">\u5fae\u4fe1\u516c\u4f17\u53f7\u83b7\u53d6\u7528\u6237\u7684openid<\/span><\/strong><\/p>\n<p>\u8bdd\u4e0d\u591a\u8bf4\uff0c\u76f4\u63a5\u4e0a\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/\u83b7\u53d6\u4ee4\u724c\r\npublic&nbsp;function&nbsp;getAccessToken(){\r\n\t\r\n\t\/\/\u6307\u5b9a\u4fdd\u5b58\u6587\u4ef6\u4f4d\u7f6e\r\n\tif(!is_dir('.\/access_token\/')){\r\n\t\tmkdir(iconv(\"GBK\",\"UTF-8\",'.\/access_token\/'),0777,true);&nbsp;\r\n\t}\r\n\t$file&nbsp;=&nbsp;'.\/access_token\/token';\r\n\tif(file_exists($file)){\r\n\t\t$content&nbsp;=&nbsp;file_get_contents($file);\r\n\t\t$cont&nbsp;=&nbsp;json_decode($content);\r\n\t\tif(&nbsp;(time()-filemtime($file))&nbsp;expires_in){&nbsp;&nbsp;&nbsp;\/\/\u5f53\u524d\u65f6\u95f4-\u6587\u4ef6\u521b\u5efa\u65f6\u95f4&lt;token return&gt;access_token;\r\n\t\t}\r\n\t}\r\n\t\r\n\t$curl&nbsp;=&nbsp;'https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential&amp;amp;appid='.$this-&amp;gt;appid.'&amp;amp;secret='.$this-&amp;gt;appsecret;\r\n\t$content&nbsp;=&nbsp;$this-&amp;gt;_request($curl);\r\n\tfile_put_contents($file,$content);\r\n\t$cont&nbsp;=&nbsp;json_decode($content);\r\n\treturn&nbsp;$cont-&amp;gt;access_token;\r\n\r\n}\r\n\r\n\/**\r\n&nbsp;*&nbsp;\u901a\u8fc7openid\u62c9\u53d6\u7528\u6237\u4fe1\u606f\r\n&nbsp;*&nbsp;@param&nbsp;&nbsp;string&nbsp;$openid&nbsp;[description]\r\n&nbsp;*&nbsp;@return&nbsp;[type]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[description]\r\n&nbsp;*\/\r\npublic&nbsp;function&nbsp;getUserInfo($openid=''){\r\n\tif(!$openid)&nbsp;return&nbsp;false;\r\n\t$access_token&nbsp;=&nbsp;$this-&amp;gt;getAccessToken();\r\n\t$urlStr&nbsp;=&nbsp;'https:\/\/api.weixin.qq.com\/cgi-bin\/user\/info?access_token=%s&amp;amp;openid=%s&amp;amp;lang=zh_CN';\r\n\t$url&nbsp;=&nbsp;sprintf($urlStr,$access_token,$openid);\r\n\t$result&nbsp;=&nbsp;json_decode($this-&amp;gt;_request($url),true);\r\n\treturn&nbsp;$result;\r\n}&lt;\/token&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c31\u53ef\u4ee5\u5728\u7528\u6237\u4e0d\u77e5\u4e0d\u89c9\u7684\u65f6\u5019,\u62ff\u5230\u5982\u4e0b\u4fe1\u606f:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/6568de6d4bf0801ae95a707541263962-1.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5\u63d2\u56fe1\" \/><\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5\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>\u672c\u6587\u4e3b\u8981\u548c\u5927\u5bb6\u5206\u4eab\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5\uff0c\u4e4b\u524d\u5199\u8fc7\u6587\u7ae0\u5fae\u4fe1\u7f51\u9875\u6388\u6743\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u8bb2\u7f51\u9875\u5f00\u53d1\u7684\u65f6\u5019\uff0c\u6709\u65f6\u5019\u9700\u8981\u83b7\u53d6\u7528\u6237\u7684\u6635\u79f0\u5934\u50cf\u7b49\u4e2a\u4eba\u57fa\u672c\u4fe1\u606f\uff0c\u83b7\u53d6\u7528\u6237\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f51\u9875\u6388\u6743\uff0c\u7528\u6237\u540c\u610f\u4e4b\u540e\uff0c\u83b7\u53d6\u5230\uff0c\u5982\u56fe\u6240\u793a\uff1a \u4f46\u662f\uff0c\u8fd9\u6837\u5c31\u591a\u4e86\u4e00\u4e2a\u6b65\u9aa4\uff0c\u6709\u7684\u7528\u6237\u53ef\u80fd\u770b\u5230\u591a\u4e00\u4e2a\u6b65\u9aa4\uff0c\u5c31\u968f\u624b\u70b9\u51fb\u56de\u9000\uff0c\u5c31\u8fd9\u4e48\u5931\u6389\u4e86\u4e00\u4e2a\u5b9d\u8d35\u7684\u7528\u6237\uff0c\u5f88\u662f\u9057\u61be\uff0c\u90a3\u4e48\u4eca\u5929\u6211\u4eec\u5c31\u4f7f\u7528\u53e6\u4e00\u79cd\u65b9\u5f0f\u6765\u83b7\u53d6\u7528\u6237\u4fe1\u606f\uff0c\u5c31\u662f\u901a\u8fc7OpenID\u6765\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u5c31\u7b80\u5355\u591a\u4e86\uff0c\u5728\u7528\u6237\u4e0d\u77e5\u4e0d\u89c9\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5c31\u62ff\u5230\u4e86\u4ed6\u7684\u4e2a\u4eba\u4fe1\u606f\uff0c\u800c\u4e14\u8fd9\u6837\u83b7\u53d6\u7684\u4fe1\u606f\u6bd4\u6388\u6743\u83b7\u53d6\u7684\u8fd8\u8981\u591a\uff0c\u6bd4\u5982\u8fd9\u6837\u8fd8\u53ef\u4ee5\u77e5\u9053\u8be5\u7528\u6237\u662f\u5426\u5173\u6ce8\u4ee5\u53ca\u5173\u6ce8\u65f6\u95f4\u3002 \u524d\u671f\u51c6\u5907\uff1a\u83b7\u53d6\u5230\u7528\u6237\u7684openid\uff0c\u8fd9\u4e2a\u5728\u4e0a\u4e00\u7bc7\u6587\u7ae0\u8bb2\u8fc7\u4e86\uff0c\u8be6\u89c1\uff1a\u5fae\u4fe1\u516c\u4f17\u53f7\u83b7\u53d6\u7528\u6237\u7684openid \u8bdd\u4e0d\u591a\u8bf4\uff0c\u76f4\u63a5\u4e0a\u4ee3\u7801\uff1a \/\/\u83b7\u53d6\u4ee4\u724c public&nbsp;function&nbsp;getAccessToken(){ \/\/\u6307\u5b9a\u4fdd\u5b58\u6587\u4ef6\u4f4d\u7f6e if(!is_dir(&#8216;.\/access_token\/&#8217;)){ mkdir(iconv(&#8220;GBK&#8221;,&#8221;UTF-8&#8243;,&#8217;.\/access_token\/&#8217;),0777,true);&nbsp; } $file&nbsp;=&nbsp;&#8216;.\/access_token\/token&#8217;; if(file_exists($file)){ $content&nbsp;=&nbsp;file_get_contents($file); $cont&nbsp;=&nbsp;json_decode($content); if(&nbsp;(time()-filemtime($file))&nbsp;expires_in){&nbsp;&nbsp;&nbsp;\/\/\u5f53\u524d\u65f6\u95f4-\u6587\u4ef6\u521b\u5efa\u65f6\u95f4&lt;token return&gt;access_token; } } $curl&nbsp;=&nbsp;&#8216;https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential&amp;amp;appid=&#8217;.$this-&amp;gt;appid.&#8217;&amp;amp;secret=&#8217;.$this-&amp;gt;appsecret; $content&nbsp;=&nbsp;$this-&amp;gt;_request($curl); file_put_contents($file,$content); $cont&nbsp;=&nbsp;json_decode($content); return&nbsp;$cont-&amp;gt;access_token; } \/** &nbsp;*&nbsp;\u901a\u8fc7openid\u62c9\u53d6\u7528\u6237\u4fe1\u606f &nbsp;*&nbsp;@param&nbsp;&nbsp;string&nbsp;$openid&nbsp;[description] &nbsp;*&nbsp;@return&nbsp;[type]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[description] &nbsp;*\/ public&nbsp;function&nbsp;getUserInfo($openid=&#8221;){ if(!$openid)&nbsp;return&nbsp;false; $access_token&nbsp;=&nbsp;$this-&amp;gt;getAccessToken(); $urlStr&nbsp;=&nbsp;&#8216;https:\/\/api.weixin.qq.com\/cgi-bin\/user\/info?access_token=%s&amp;amp;openid=%s&amp;amp;lang=zh_CN&#8217;; $url&nbsp;=&nbsp;sprintf($urlStr,$access_token,$openid); $result&nbsp;=&nbsp;json_decode($this-&amp;gt;_request($url),true); return&nbsp;$result; }&lt;\/token&gt; \u767b\u5f55\u540e\u590d\u5236 \u5c31\u53ef\u4ee5\u5728\u7528\u6237\u4e0d\u77e5\u4e0d\u89c9\u7684\u65f6\u5019,\u62ff\u5230\u5982\u4e0b\u4fe1\u606f: \u76f8\u5173\u63a8\u8350\uff1a \u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u7f51\u9875\u83b7\u53d6\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684\u65b9\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-31415","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31415","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=31415"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31415\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}