{"id":32286,"date":"2024-11-25T14:53:56","date_gmt":"2024-11-25T06:53:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32286\/"},"modified":"2024-11-25T14:53:56","modified_gmt":"2024-11-25T06:53:56","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b8%adrequest%e8%af%b7%e6%b1%82%e5%b0%81%e8%a3%85%e7%9a%84%e4%bb%a3%e7%a0%81%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32286\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2drequest\u8bf7\u6c42\u5c01\u88c5\u7684\u4ee3\u7801\u5206\u6790"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u5185\u5bb9\u662f\u5173\u4e8e\u5c0f\u7a0b\u5e8f\u4e2drequest\u8bf7\u6c42\u5c01\u88c5\u7684\u4ee3\u7801\u5206\u6790\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p><strong>request<\/strong><\/p>\n<p>\u53ea\u7528POST\uff0c\u53ea\u5c01\u88c5\u4e86POST\uff0c\u7b49\u6709\u7528\u5230GET\u518d\u91cd\u5199\uff0c\u63a5\u53e3\u7528\u7684ThinkPHP5.0<\/p>\n<p><strong>\u4e3b\u8981\u4ee3\u7801<\/strong><\/p>\n<pre>var apiurl = \"xxxxx\";\nfunction http_post(controller,data,cb){\n  wx.request({\n    url:apiurl+controller,\n    data:data,\n    method:'post',\n    header:{'Content-Type':'application\/x-www-form-urlencoded'},\n    success:function(res){\n      return typeof cb == \"function\" &amp;&amp; cb(res.data)\n    },\n    fail:function(res){\n      return typeof cb == \"function\" &amp;&amp; cb(false)\n    }\n  })\n}\nmodule.exports = {\n  http_post:http_post,\/\/post\u8bf7\u6c42\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u524d\u7aefjs\u4f7f\u7528<\/strong><\/p>\n<pre>var wxq = require('..\/..\/utils\/wxrequest.js');\nvar openid = wx.getStorageSync('openid');\/\/\u83b7\u53d6\u7f13\u5b58\u91cc\u9762\u7684openid\n\nwxq.http_post('\u8fd9\u91cc\u662f\u63a7\u5236\u5668\/\u65b9\u6cd5',{'openid':openid},function(res){\n    console.info('\u56de\u8c03',res)\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u4e2drequest\u8bf7\u6c42\u5c01\u88c5\u7684\u4ee3\u7801\u5206\u6790\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>\u8fd9\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u5185\u5bb9\u662f\u5173\u4e8e\u5c0f\u7a0b\u5e8f\u4e2drequest\u8bf7\u6c42\u5c01\u88c5\u7684\u4ee3\u7801\u5206\u6790\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002 request \u53ea\u7528POST\uff0c\u53ea\u5c01\u88c5\u4e86POST\uff0c\u7b49\u6709\u7528\u5230GET\u518d\u91cd\u5199\uff0c\u63a5\u53e3\u7528\u7684ThinkPHP5.0 \u4e3b\u8981\u4ee3\u7801 var apiurl = &#8220;xxxxx&#8221;; function http_post(controller,data,cb){ wx.request({ url:apiurl+controller, data:data, method:&#8217;post&#8217;, header:{&#8216;Content-Type&#8217;:&#8217;application\/x-www-form-urlencoded&#8217;}, success:function(res){ return typeof cb == &#8220;function&#8221; &amp;&amp; cb(res.data) }, fail:function(res){ return typeof cb == &#8220;function&#8221; &amp;&amp; cb(false) } }) } module.exports = { http_post:http_post,\/\/post\u8bf7\u6c42 } \u767b\u5f55\u540e\u590d\u5236 \u524d\u7aefjs\u4f7f\u7528 var wxq = require(&#8216;..\/..\/utils\/wxrequest.js&#8217;); var openid = wx.getStorageSync(&#8216;openid&#8217;);\/\/\u83b7\u53d6\u7f13\u5b58\u91cc\u9762\u7684openid wxq.http_post(&#8216;\u8fd9\u91cc\u662f\u63a7\u5236\u5668\/\u65b9\u6cd5&#8217;,{&#8216;openid&#8217;:openid},function(res){ console.info(&#8216;\u56de\u8c03&#8217;,res) }) \u767b\u5f55\u540e\u590d\u5236 \u76f8\u5173\u63a8\u8350\uff1a [&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-32286","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32286","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=32286"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32286\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}