{"id":29617,"date":"2024-11-25T16:59:45","date_gmt":"2024-11-25T08:59:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29617\/"},"modified":"2024-11-25T16:59:45","modified_gmt":"2024-11-25T08:59:45","slug":"%e5%be%ae%e4%bf%a1%e5%bc%80%e5%8f%91%e4%b9%8b%e4%b8%8a%e4%bc%a0%e4%b8%b4%e6%97%b6%e7%b4%a0%e6%9d%90%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29617\/","title":{"rendered":"\u5fae\u4fe1\u5f00\u53d1\u4e4b\u4e0a\u4f20\u4e34\u65f6\u7d20\u6750\u4ecb\u7ecd"},"content":{"rendered":"<p>\u4e3b\u8981\u4e3a\u5927\u5bb6\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5f00\u53d1\u4e4b\u7b80\u5355\u5b9e\u73b0\u4e34\u65f6\u7d20\u6750\u7684\u76f8\u5173\u8d44\u6599\uff0c\u6709\u5177\u4f53\u7684\u4ee3\u7801\u5206\u6790\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u3002<\/p>\n<pre>public&nbsp;function&nbsp;uploadImg($imgUrl){\r\n&nbsp;\r\n&nbsp;&nbsp;$TOKEN=$this-&amp;gt;getAccessToken();\r\n&nbsp;&nbsp;$URL&nbsp;='http:\/\/file.api.weixin.qq.com\/cgi-bin\/media\/upload?access_token='.$TOKEN.'&amp;amp;type=image';\r\n&nbsp;&nbsp;$data&nbsp;=&nbsp;array('media'=&amp;gt;'@'.$imgUrl);\r\n&nbsp;&nbsp;$result&nbsp;=&nbsp;$this-&amp;gt;curl_post($URL,$data);\r\n&nbsp;&nbsp;$data&nbsp;=&nbsp;@json_decode($result,true);\r\n&nbsp;&nbsp;&nbsp;\r\n&nbsp;&nbsp;return&nbsp;$data['media_id'];\r\n&nbsp;}\r\n&nbsp;\r\n&nbsp;public&nbsp;function&nbsp;getAccessToken(){\r\n&nbsp;\r\n&nbsp;&nbsp;$url&nbsp;=&nbsp;'https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential&amp;amp;appid=wxe574b1bd35d7d4da&amp;amp;secret=d4624c36b6795d1d99dcf0547af5443d';\r\n&nbsp;&nbsp;&nbsp;\r\n&nbsp;&nbsp;$result&nbsp;=&nbsp;json_decode($this-&amp;gt;curlGet($url),true);\r\n&nbsp;\r\n&nbsp;&nbsp;return&nbsp;$result['access_token'];\r\n&nbsp;}\r\n&nbsp;\r\n&nbsp;function&nbsp;curl_post($url,&nbsp;$data&nbsp;=&nbsp;null)\r\n{\r\n&nbsp;\/\/\u521b\u5efa\u4e00\u4e2a\u65b0cURL\u8d44\u6e90\r\n&nbsp;$curl&nbsp;=&nbsp;curl_init();\r\n&nbsp;\/\/\u8bbe\u7f6eURL\u548c\u76f8\u5e94\u7684\u9009\u9879\r\n&nbsp;curl_setopt($curl,&nbsp;CURLOPT_URL,&nbsp;$url);\r\n&nbsp;if&nbsp;(!empty($data)){\r\n&nbsp;&nbsp;curl_setopt($curl,&nbsp;CURLOPT_POST,&nbsp;1);\r\n&nbsp;&nbsp;curl_setopt($curl,&nbsp;CURLOPT_POSTFIELDS,&nbsp;$data);\r\n&nbsp;}\r\n&nbsp;curl_setopt($curl,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1);\r\n&nbsp;\/\/\u6267\u884ccurl\uff0c\u6293\u53d6URL\u5e76\u628a\u5b83\u4f20\u9012\u7ed9\u6d4f\u89c8\u5668\r\n&nbsp;$output&nbsp;=&nbsp;curl_exec($curl);\r\n&nbsp;\/\/\u5173\u95edcURL\u8d44\u6e90\uff0c\u5e76\u4e14\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90\r\n&nbsp;curl_close($curl);\r\n&nbsp;return&nbsp;$output;\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8c03\u7528uploadImg($imgurl)&nbsp;\u4f20\u5730\u5740\u53c2\u6570<br \/>\u8fd4\u56de\u7ed3\u679c&nbsp;<\/p>\n<pre>array&nbsp;(\r\n&nbsp;'type'&nbsp;=&amp;gt;&nbsp;'image',\r\n&nbsp;'media_id'&nbsp;=&amp;gt;&nbsp;'W89mt3FEaxXOMOw0fLj2Cb6A8vfMjuXrj6XW59O3l9a7Tj_h2SjlBEr4dvp4Du2R',\r\n&nbsp;'created_at'&nbsp;=&amp;gt;&nbsp;1464140301,\r\n\uff09<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5f00\u53d1\u4e4b\u4e0a\u4f20\u4e34\u65f6\u7d20\u6750\u4ecb\u7ecd\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>\u4e3b\u8981\u4e3a\u5927\u5bb6\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5f00\u53d1\u4e4b\u7b80\u5355\u5b9e\u73b0\u4e34\u65f6\u7d20\u6750\u7684\u76f8\u5173\u8d44\u6599\uff0c\u6709\u5177\u4f53\u7684\u4ee3\u7801\u5206\u6790\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u3002 public&nbsp;function&nbsp;uploadImg($imgUrl){ &nbsp; &nbsp;&nbsp;$TOKEN=$this-&amp;gt;getAccessToken(); &nbsp;&nbsp;$URL&nbsp;=&#8217;http:\/\/file.api.weixin.qq.com\/cgi-bin\/media\/upload?access_token=&#8217;.$TOKEN.&#8217;&amp;amp;type=image&#8217;; &nbsp;&nbsp;$data&nbsp;=&nbsp;array(&#8216;media&#8217;=&amp;gt;&#8217;@&#8217;.$imgUrl); &nbsp;&nbsp;$result&nbsp;=&nbsp;$this-&amp;gt;curl_post($URL,$data); &nbsp;&nbsp;$data&nbsp;=&nbsp;@json_decode($result,true); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;return&nbsp;$data[&#8216;media_id&#8217;]; &nbsp;} &nbsp; &nbsp;public&nbsp;function&nbsp;getAccessToken(){ &nbsp; &nbsp;&nbsp;$url&nbsp;=&nbsp;&#8216;https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential&amp;amp;appid=wxe574b1bd35d7d4da&amp;amp;secret=d4624c36b6795d1d99dcf0547af5443d&#8217;; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;$result&nbsp;=&nbsp;json_decode($this-&amp;gt;curlGet($url),true); &nbsp; &nbsp;&nbsp;return&nbsp;$result[&#8216;access_token&#8217;]; &nbsp;} &nbsp; &nbsp;function&nbsp;curl_post($url,&nbsp;$data&nbsp;=&nbsp;null) { &nbsp;\/\/\u521b\u5efa\u4e00\u4e2a\u65b0cURL\u8d44\u6e90 &nbsp;$curl&nbsp;=&nbsp;curl_init(); &nbsp;\/\/\u8bbe\u7f6eURL\u548c\u76f8\u5e94\u7684\u9009\u9879 &nbsp;curl_setopt($curl,&nbsp;CURLOPT_URL,&nbsp;$url); &nbsp;if&nbsp;(!empty($data)){ &nbsp;&nbsp;curl_setopt($curl,&nbsp;CURLOPT_POST,&nbsp;1); &nbsp;&nbsp;curl_setopt($curl,&nbsp;CURLOPT_POSTFIELDS,&nbsp;$data); &nbsp;} &nbsp;curl_setopt($curl,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1); &nbsp;\/\/\u6267\u884ccurl\uff0c\u6293\u53d6URL\u5e76\u628a\u5b83\u4f20\u9012\u7ed9\u6d4f\u89c8\u5668 &nbsp;$output&nbsp;=&nbsp;curl_exec($curl); &nbsp;\/\/\u5173\u95edcURL\u8d44\u6e90\uff0c\u5e76\u4e14\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90 &nbsp;curl_close($curl); &nbsp;return&nbsp;$output; } \u767b\u5f55\u540e\u590d\u5236 \u8c03\u7528uploadImg($imgurl)&nbsp;\u4f20\u5730\u5740\u53c2\u6570\u8fd4\u56de\u7ed3\u679c&nbsp; array&nbsp;( &nbsp;&#8216;type&#8217;&nbsp;=&amp;gt;&nbsp;&#8216;image&#8217;, &nbsp;&#8216;media_id&#8217;&nbsp;=&amp;gt;&nbsp;&#8216;W89mt3FEaxXOMOw0fLj2Cb6A8vfMjuXrj6XW59O3l9a7Tj_h2SjlBEr4dvp4Du2R&#8217;, &nbsp;&#8216;created_at&#8217;&nbsp;=&amp;gt;&nbsp;1464140301, \uff09 \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5f00\u53d1\u4e4b\u4e0a\u4f20\u4e34\u65f6\u7d20\u6750\u4ecb\u7ecd\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-29617","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29617","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=29617"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29617\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}