{"id":32948,"date":"2024-11-25T14:27:00","date_gmt":"2024-11-25T06:27:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32948\/"},"modified":"2024-11-25T14:27:00","modified_gmt":"2024-11-25T06:27:00","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e9%94%99%e8%af%af%e7%a0%8147001%e6%98%af%e4%bb%80%e4%b9%88%e5%8e%9f%e5%9b%a0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32948\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u9519\u8bef\u780147001\u662f\u4ec0\u4e48\u539f\u56e0"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/039\/5e7c5919223fe128.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u9519\u8bef\u780147001\u662f\u4ec0\u4e48\u539f\u56e0\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u9519\u8bef\u780147001\u662f\u4ec0\u4e48\u539f\u56e0\u63d2\u56fe\" \/><\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u51fa\u73b047001\u9519\u8bef\u662f\u56e0\u4e3a\u683c\u5f0f\u4e0d\u5bf9\u5bfc\u81f4\u7684\u3002<\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u51fa\u73b047001 data format error\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<p>\u770b\u4e0b\u9519\u8bef\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/236\/449\/777\/1585207293476707.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u9519\u8bef\u780147001\u662f\u4ec0\u4e48\u539f\u56e0\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u9519\u8bef\u780147001\u662f\u4ec0\u4e48\u539f\u56e0\u63d2\u56fe1\" \/><\/p>\n<p>\u4e3b\u8981\u539f\u56e0\u662f\u8bf7\u6c42\u7684\u6570\u636e\u4e0d\u662fjson\u683c\u5f0f\u5f15\u8d77\u7684\u3002<\/p>\n<p>\u5206\u4eab\u4e0b\u6211\u7528\u7684\u4ee3\u7801\u548c\u51fd\u6570\uff1a<\/p>\n<p>&nbsp;\u53d1\u9001\u6a21\u677f\u6d88\u606f<\/p>\n<pre>public&nbsp;function&nbsp;sendmessage(){\n$data=$_POST=json_decode(file_get_contents('php:\/\/input'),&nbsp;TRUE);\n$access_token=$this-&amp;gt;getAccessToken();\n$request_url='https:\/\/api.weixin.qq.com\/cgi-bin\/message\/wxopen\/template\/send?access_token='.$access_token;\n$request_data=array(\n&nbsp;'touser'=&amp;gt;$data['touser'],\/\/\u63a5\u6536\u8005\uff08\u7528\u6237\uff09\u7684&nbsp;openid\n&nbsp;'template_id'=&amp;gt;$data['template_id'],\/\/\u6240\u9700\u4e0b\u53d1\u7684\u6a21\u677f\u6d88\u606f\u7684id\n&nbsp;'page'=&amp;gt;$data['page'],\/\/\u70b9\u51fb\u6a21\u677f\u5361\u7247\u540e\u7684\u8df3\u8f6c\u9875\u9762\n&nbsp;'form_id'=&amp;gt;$data['form_id'],\/\/\u8868\u5355\u63d0\u4ea4\u573a\u666f\u4e0b\uff0c\u4e3a&nbsp;submit&nbsp;\u4e8b\u4ef6\u5e26\u4e0a\u7684&nbsp;formId\uff1b\u652f\u4ed8\u573a\u666f\u4e0b\uff0c\u4e3a\u672c\u6b21\u652f\u4ed8\u7684&nbsp;prepay_id\n&nbsp;'data'=&amp;gt;$data['data'],\/\/\"keyword1\":&nbsp;{\"value\":&nbsp;\"339208499\",&nbsp;\"color\":&nbsp;\"#173177\"}\n&nbsp;'emphasis_keyword'=&amp;gt;$data['emphasis_keyword']\/\/\u6a21\u677f\u9700\u8981\u653e\u5927\u7684\u5173\u952e\u8bcd\uff0c\u4e0d\u586b\u5219\u9ed8\u8ba4\u65e0\u653e\u5927\n);\n$return=json_decode(https_request($request_url,$request_data,'json'),true);\n$this-&amp;gt;response($return,'json');\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53d1\u9001\u8bf7\u6c42<\/p>\n<pre>function&nbsp;https_request($url,$data,$type){\n&nbsp;if($type=='json'){\/\/json&nbsp;$_POST=json_decode(file_get_contents('php:\/\/input'),&nbsp;TRUE);\n&nbsp;$headers&nbsp;=&nbsp;array(\"Content-type:&nbsp;application\/json;charset=UTF-8\",\"Accept:&nbsp;application\/json\",\"Cache-Control:&nbsp;no-cache\",&nbsp;\"Pragma:&nbsp;no-cache\");\n&nbsp;$data=json_encode($data);\n&nbsp;}\n&nbsp;$curl&nbsp;=&nbsp;curl_init();\n&nbsp;curl_setopt($curl,&nbsp;CURLOPT_URL,&nbsp;$url);\n&nbsp;curl_setopt($curl,&nbsp;CURLOPT_SSL_VERIFYPEER,&nbsp;FALSE);\n&nbsp;curl_setopt($curl,&nbsp;CURLOPT_SSL_VERIFYHOST,&nbsp;FALSE);\n&nbsp;if&nbsp;(!empty($data)){\n&nbsp;curl_setopt($curl,&nbsp;CURLOPT_POST,&nbsp;1);\n&nbsp;curl_setopt($curl,&nbsp;CURLOPT_POSTFIELDS,$data);\n&nbsp;}\n&nbsp;curl_setopt($curl,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1);\n&nbsp;curl_setopt(&nbsp;$ch,&nbsp;CURLOPT_HTTPHEADER,&nbsp;$headers&nbsp;);&nbsp;\n&nbsp;$output&nbsp;=&nbsp;curl_exec($curl);\n&nbsp;curl_close($curl);\n&nbsp;return&nbsp;$output;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u63a8\u8350\uff1a\u300a\u300b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u9519\u8bef\u780147001\u662f\u4ec0\u4e48\u539f\u56e0\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>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u51fa\u73b047001\u9519\u8bef\u662f\u56e0\u4e3a\u683c\u5f0f\u4e0d\u5bf9\u5bfc\u81f4\u7684\u3002 \u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u51fa\u73b047001 data format error\u89e3\u51b3\u529e\u6cd5\uff1a \u770b\u4e0b\u9519\u8bef\uff1a \u4e3b\u8981\u539f\u56e0\u662f\u8bf7\u6c42\u7684\u6570\u636e\u4e0d\u662fjson\u683c\u5f0f\u5f15\u8d77\u7684\u3002 \u5206\u4eab\u4e0b\u6211\u7528\u7684\u4ee3\u7801\u548c\u51fd\u6570\uff1a &nbsp;\u53d1\u9001\u6a21\u677f\u6d88\u606f public&nbsp;function&nbsp;sendmessage(){ $data=$_POST=json_decode(file_get_contents(&#8216;php:\/\/input&#8217;),&nbsp;TRUE); $access_token=$this-&amp;gt;getAccessToken(); $request_url=&#8217;https:\/\/api.weixin.qq.com\/cgi-bin\/message\/wxopen\/template\/send?access_token=&#8217;.$access_token; $request_data=array( &nbsp;&#8216;touser&#8217;=&amp;gt;$data[&#8216;touser&#8217;],\/\/\u63a5\u6536\u8005\uff08\u7528\u6237\uff09\u7684&nbsp;openid &nbsp;&#8216;template_id&#8217;=&amp;gt;$data[&#8216;template_id&#8217;],\/\/\u6240\u9700\u4e0b\u53d1\u7684\u6a21\u677f\u6d88\u606f\u7684id &nbsp;&#8216;page&#8217;=&amp;gt;$data[&#8216;page&#8217;],\/\/\u70b9\u51fb\u6a21\u677f\u5361\u7247\u540e\u7684\u8df3\u8f6c\u9875\u9762 &nbsp;&#8216;form_id&#8217;=&amp;gt;$data[&#8216;form_id&#8217;],\/\/\u8868\u5355\u63d0\u4ea4\u573a\u666f\u4e0b\uff0c\u4e3a&nbsp;submit&nbsp;\u4e8b\u4ef6\u5e26\u4e0a\u7684&nbsp;formId\uff1b\u652f\u4ed8\u573a\u666f\u4e0b\uff0c\u4e3a\u672c\u6b21\u652f\u4ed8\u7684&nbsp;prepay_id &nbsp;&#8216;data&#8217;=&amp;gt;$data[&#8216;data&#8217;],\/\/&#8221;keyword1&#8243;:&nbsp;{&#8220;value&#8221;:&nbsp;&#8220;339208499&#8221;,&nbsp;&#8220;color&#8221;:&nbsp;&#8220;#173177&#8221;} &nbsp;&#8217;emphasis_keyword&#8217;=&amp;gt;$data[&#8217;emphasis_keyword&#8217;]\/\/\u6a21\u677f\u9700\u8981\u653e\u5927\u7684\u5173\u952e\u8bcd\uff0c\u4e0d\u586b\u5219\u9ed8\u8ba4\u65e0\u653e\u5927 ); $return=json_decode(https_request($request_url,$request_data,&#8217;json&#8217;),true); $this-&amp;gt;response($return,&#8217;json&#8217;); } \u767b\u5f55\u540e\u590d\u5236 \u53d1\u9001\u8bf7\u6c42 function&nbsp;https_request($url,$data,$type){ &nbsp;if($type==&#8217;json&#8217;){\/\/json&nbsp;$_POST=json_decode(file_get_contents(&#8216;php:\/\/input&#8217;),&nbsp;TRUE); &nbsp;$headers&nbsp;=&nbsp;array(&#8220;Content-type:&nbsp;application\/json;charset=UTF-8&#8243;,&#8221;Accept:&nbsp;application\/json&#8221;,&#8221;Cache-Control:&nbsp;no-cache&#8221;,&nbsp;&#8220;Pragma:&nbsp;no-cache&#8221;); &nbsp;$data=json_encode($data); &nbsp;} &nbsp;$curl&nbsp;=&nbsp;curl_init(); &nbsp;curl_setopt($curl,&nbsp;CURLOPT_URL,&nbsp;$url); &nbsp;curl_setopt($curl,&nbsp;CURLOPT_SSL_VERIFYPEER,&nbsp;FALSE); &nbsp;curl_setopt($curl,&nbsp;CURLOPT_SSL_VERIFYHOST,&nbsp;FALSE); &nbsp;if&nbsp;(!empty($data)){ &nbsp;curl_setopt($curl,&nbsp;CURLOPT_POST,&nbsp;1); &nbsp;curl_setopt($curl,&nbsp;CURLOPT_POSTFIELDS,$data); &nbsp;} &nbsp;curl_setopt($curl,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1); &nbsp;curl_setopt(&nbsp;$ch,&nbsp;CURLOPT_HTTPHEADER,&nbsp;$headers&nbsp;);&nbsp; &nbsp;$output&nbsp;=&nbsp;curl_exec($curl); &nbsp;curl_close($curl); &nbsp;return&nbsp;$output; } \u767b\u5f55\u540e\u590d\u5236 \u63a8\u8350\uff1a\u300a\u300b \u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u9519\u8bef\u780147001\u662f\u4ec0\u4e48\u539f\u56e0\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-32948","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32948","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=32948"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32948\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}