{"id":28913,"date":"2024-11-25T09:26:59","date_gmt":"2024-11-25T01:26:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28913\/"},"modified":"2024-11-25T09:26:59","modified_gmt":"2024-11-25T01:26:59","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e7%bd%91%e7%bb%9c%e8%af%b7%e6%b1%82get%e8%af%b7%e6%b1%82%e8%af%a6%e7%bb%86%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28913\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(GET\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(get\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/p>\n<p><strong>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u7f51\u7edc\u8bf7\u6c42 GET<\/strong><\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e2d\u7f51\u7edc\u8bf7\u6c42\u5fc5\u4e0d\u53ef\u5c11,\u4eca\u5929\u8bf4\u8bf4\u6700\u7b80\u5355\u7684\u8bf7\u6c42.\u540e\u7eed\u4f1a\u5c1d\u8bd5\u4e0a\u4f20\u4e0b\u8f7d,Socket\u8fd9\u4e9b.<\/p>\n<p>1.\u4e00\u4e2a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0c\u540c\u65f6\u53ea\u80fd\u67095\u4e2a\u7f51\u7edc\u8bf7\u6c42\u8fde\u63a5\u3002<\/p>\n<p>\u8fd9\u4e2a\u89c4\u5b9a\u5e94\u8be5\u662f\u5fae\u4fe1\u4e3a\u4e86\u4fdd\u8bc1\u7528\u6237\u4f53\u9a8c\u5236\u5b9a\u7684,\u6bd5\u7adf\u662f\u5c0f\u7a0b\u5e8f.<\/p>\n<p>2.wx.request()&nbsp; \u53c2\u6570\u8bf4\u660e:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/013\/41df6507ac55810a92e6cc959719d613-0.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(GET\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(GET\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u652f\u6301GET,POST\u7b49\u8bf7\u6c42.\u7528method\u53ef\u4ee5\u8bbe\u7f6e.<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662fGET\u8bf7\u6c42\u7684\u4ee3\u7801:<\/p>\n<pre>&lt;span&gt;\/\/rate.js&nbsp;\r\n\/\/\u83b7\u53d6\u5e94\u7528\u5b9e\u4f8b&nbsp;\r\nvar&nbsp;app&nbsp;=&nbsp;getApp()&nbsp;\r\nPage(&nbsp;{&nbsp;\r\n&nbsp;data:&nbsp;{&nbsp;\r\n&nbsp;&nbsp;code:&nbsp;'USD',&nbsp;\r\n&nbsp;&nbsp;currencyF_Name:&nbsp;'',&nbsp;\r\n&nbsp;&nbsp;currencyT_Name:&nbsp;'',&nbsp;\r\n&nbsp;&nbsp;currencyF:&nbsp;'',&nbsp;\r\n&nbsp;&nbsp;currencyT:&nbsp;'',&nbsp;\r\n&nbsp;&nbsp;currencyFD:&nbsp;1,&nbsp;\r\n&nbsp;&nbsp;exchange:&nbsp;0,&nbsp;\r\n&nbsp;&nbsp;result:&nbsp;0,&nbsp;\r\n&nbsp;&nbsp;updateTime:&nbsp;'',&nbsp;\r\n&nbsp;},&nbsp;\r\n&nbsp;onLoad:&nbsp;function(&nbsp;options&nbsp;)&nbsp;{&nbsp;\r\n&nbsp;&nbsp;var&nbsp;that&nbsp;=&nbsp;this;&nbsp;\r\n&nbsp;&nbsp;&nbsp;\/\/\u83b7\u53d6\u6c47\u7387&nbsp;\r\n&nbsp;&nbsp;&nbsp;wx.request(&nbsp;{&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;url:&nbsp;\"http:\/\/op.juhe.cn\/onebox\/exchange\/currency?key=\u6211\u7684appkey&amp;amp;from=CNY&amp;amp;to=\"+code,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;success:&nbsp;function(&nbsp;res&nbsp;)&nbsp;{&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that.setData(&nbsp;{&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyF_Name:&nbsp;res.data.result[0].currencyF_Name,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyT_Name:&nbsp;res.data.result[0].currencyT_Name,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyF:&nbsp;res.data.result[0].currencyF,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyT:&nbsp;res.data.result[0].currencyT,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyFD:&nbsp;res.data.result[0].currencyFD,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exchange:&nbsp;res.data.result[0].exchange,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result:&nbsp;res.data.result[0].result,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateTime:&nbsp;res.data.result[0].updateTime,&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;\r\n&nbsp;&nbsp;&nbsp;})&nbsp;\r\n&nbsp;}&nbsp;\r\n})&lt;\/span&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e0a\u9762\u4ee3\u7801\u4e2d\u53ea\u9700\u8981\u7ed9\u51faURL\u5373\u53ef,onLoad\u5728\u9875\u9762\u521d\u59cb\u5316\u65f6\u542f\u52a8,<span style=\"color: #0000ff\">wx.request({})\u4e2dsuccess\u7684res.data<\/span>\u662f\u4ece\u540e\u53f0\u83b7\u53d6\u7684\u6570\u636e,\u8fd9\u4e00\u70b9\u9700\u8981\u6ce8\u610f.<\/p>\n<p>\u4ee5\u4e0b\u662f\u83b7\u53d6\u7684\u6570\u636e\u7684\u683c\u5f0f.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/013\/6681ee2e44789e8b74fa5a5c5623d9b2-1.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(GET\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(GET\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e\u63d2\u56fe1\" \/><\/p>\n<p>json\u7684\u89e3\u6790\u90fd\u4e0d\u9700\u8981\u81ea\u5df1\u505a\u4e86.\u6211\u505a\u7684\u65f6\u5019\u8fd8\u5f97\u7528gson\u6216\u8005\u662ffastjson\u6765\u89e3\u6790json.\u5fae\u4fe1\u4e3a\u6211\u4eec\u89e3\u51b3\u4e86\u5f88\u591a\u9ebb\u70e6.<\/p>\n<p>\u611f\u8c22\u9605\u8bfb\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u8c22\u8c22\u5927\u5bb6\u5bf9\u672c\u7ad9\u7684\u652f\u6301\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(GET\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e\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\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(get\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b \u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u7f51\u7edc\u8bf7\u6c42 GET \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e2d\u7f51\u7edc\u8bf7\u6c42\u5fc5\u4e0d\u53ef\u5c11,\u4eca\u5929\u8bf4\u8bf4\u6700\u7b80\u5355\u7684\u8bf7\u6c42.\u540e\u7eed\u4f1a\u5c1d\u8bd5\u4e0a\u4f20\u4e0b\u8f7d,Socket\u8fd9\u4e9b. 1.\u4e00\u4e2a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0c\u540c\u65f6\u53ea\u80fd\u67095\u4e2a\u7f51\u7edc\u8bf7\u6c42\u8fde\u63a5\u3002 \u8fd9\u4e2a\u89c4\u5b9a\u5e94\u8be5\u662f\u5fae\u4fe1\u4e3a\u4e86\u4fdd\u8bc1\u7528\u6237\u4f53\u9a8c\u5236\u5b9a\u7684,\u6bd5\u7adf\u662f\u5c0f\u7a0b\u5e8f. 2.wx.request()&nbsp; \u53c2\u6570\u8bf4\u660e: \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u652f\u6301GET,POST\u7b49\u8bf7\u6c42.\u7528method\u53ef\u4ee5\u8bbe\u7f6e. \u4ee5\u4e0b\u662fGET\u8bf7\u6c42\u7684\u4ee3\u7801: &lt;span&gt;\/\/rate.js&nbsp; \/\/\u83b7\u53d6\u5e94\u7528\u5b9e\u4f8b&nbsp; var&nbsp;app&nbsp;=&nbsp;getApp()&nbsp; Page(&nbsp;{&nbsp; &nbsp;data:&nbsp;{&nbsp; &nbsp;&nbsp;code:&nbsp;&#8216;USD&#8217;,&nbsp; &nbsp;&nbsp;currencyF_Name:&nbsp;&#8221;,&nbsp; &nbsp;&nbsp;currencyT_Name:&nbsp;&#8221;,&nbsp; &nbsp;&nbsp;currencyF:&nbsp;&#8221;,&nbsp; &nbsp;&nbsp;currencyT:&nbsp;&#8221;,&nbsp; &nbsp;&nbsp;currencyFD:&nbsp;1,&nbsp; &nbsp;&nbsp;exchange:&nbsp;0,&nbsp; &nbsp;&nbsp;result:&nbsp;0,&nbsp; &nbsp;&nbsp;updateTime:&nbsp;&#8221;,&nbsp; &nbsp;},&nbsp; &nbsp;onLoad:&nbsp;function(&nbsp;options&nbsp;)&nbsp;{&nbsp; &nbsp;&nbsp;var&nbsp;that&nbsp;=&nbsp;this;&nbsp; &nbsp;&nbsp;&nbsp;\/\/\u83b7\u53d6\u6c47\u7387&nbsp; &nbsp;&nbsp;&nbsp;wx.request(&nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;url:&nbsp;&#8220;http:\/\/op.juhe.cn\/onebox\/exchange\/currency?key=\u6211\u7684appkey&amp;amp;from=CNY&amp;amp;to=&#8221;+code,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;success:&nbsp;function(&nbsp;res&nbsp;)&nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that.setData(&nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyF_Name:&nbsp;res.data.result[0].currencyF_Name,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyT_Name:&nbsp;res.data.result[0].currencyT_Name,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyF:&nbsp;res.data.result[0].currencyF,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyT:&nbsp;res.data.result[0].currencyT,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyFD:&nbsp;res.data.result[0].currencyFD,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exchange:&nbsp;res.data.result[0].exchange,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result:&nbsp;res.data.result[0].result,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateTime:&nbsp;res.data.result[0].updateTime,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; &nbsp;&nbsp;&nbsp;})&nbsp; &nbsp;}&nbsp; })&lt;\/span&gt; \u767b\u5f55\u540e\u590d\u5236 \u4e0a\u9762\u4ee3\u7801\u4e2d\u53ea\u9700\u8981\u7ed9\u51faURL\u5373\u53ef,onLoad\u5728\u9875\u9762\u521d\u59cb\u5316\u65f6\u542f\u52a8,wx.request({})\u4e2dsuccess\u7684res.data\u662f\u4ece\u540e\u53f0\u83b7\u53d6\u7684\u6570\u636e,\u8fd9\u4e00\u70b9\u9700\u8981\u6ce8\u610f. \u4ee5\u4e0b\u662f\u83b7\u53d6\u7684\u6570\u636e\u7684\u683c\u5f0f. json\u7684\u89e3\u6790\u90fd\u4e0d\u9700\u8981\u81ea\u5df1\u505a\u4e86.\u6211\u505a\u7684\u65f6\u5019\u8fd8\u5f97\u7528gson\u6216\u8005\u662ffastjson\u6765\u89e3\u6790json.\u5fae\u4fe1\u4e3a\u6211\u4eec\u89e3\u51b3\u4e86\u5f88\u591a\u9ebb\u70e6. \u611f\u8c22\u9605\u8bfb\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u8c22\u8c22\u5927\u5bb6\u5bf9\u672c\u7ad9\u7684\u652f\u6301\uff01 \u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7f51\u7edc\u8bf7\u6c42(GET\u8bf7\u6c42)\u8be6\u7ec6\u8bf4\u660e\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-28913","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28913","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=28913"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28913\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}