{"id":2321,"date":"2023-08-08T18:39:20","date_gmt":"2023-08-08T10:39:20","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=2321"},"modified":"2023-08-08T18:39:20","modified_gmt":"2023-08-08T10:39:20","slug":"php%e7%bd%91%e7%ab%99%e6%89%93%e5%8c%85%e7%94%9f%e6%88%90app%e5%ae%9e%e7%8e%b0%e6%96%b9%e6%b3%95%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/2321\/","title":{"rendered":"php\u7f51\u7ad9\u6253\u5305\u751f\u6210app\u5b9e\u73b0\u65b9\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"

PHP\u7f51\u7ad9\u6253\u5305\u751f\u6210APP\u7684\u6559\u7a0b<\/p>\n

\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06\u73b0\u6709\u7684PHP\u7f51\u7ad9\u6253\u5305\u6210\u4e00\u4e2a\u79fb\u52a8APP\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u8bb8\u591a\u573a\u666f\u4e0b\u975e\u5e38\u6709\u7528\uff0c\u4f8b\u5982\uff0c\u60a8\u62e5\u6709\u4e00\u4e2a\u6d41\u884c\u7684\u7f51\u7ad9\uff0c\u5e76\u5e0c\u671b\u5c06\u5176\u6269\u5c55\u5230\u79fb\u52a8\u5e73\u53f0\uff0c\u6216\u8005\u60a8\u6b63\u5728\u5f00\u53d1\u4e00\u4e2a\u65b0\u9879\u76ee\uff0c\u9700\u8981\u540c\u65f6\u652f\u6301\u684c\u9762\u548c\u79fb\u52a8\u7528\u6237\u3002<\/p>\n

\u539f\u7406\uff1a\u6df7\u5408\u5e94\u7528\u6280\u672f\uff08Hybrid App\uff09<\/p>\n

\u5c06PHP\u7f51\u7ad9\u5c01\u88c5\u6210\u4e00\u4e2aAPP\u7684\u539f\u7406\u662f\uff0c\u5229\u7528\u6df7\u5408\u5e94\u7528\u6280\u672f\u521b\u5efa\u4e00\u4e2a\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u8be5\u7a0b\u5e8f\u5c06\u4f7f\u7528\u4e00\u4e2a\u5185\u7f6e\u7684WebView\u7ec4\u4ef6\u6765\u663e\u793a\u60a8\u7684\u7f51\u7ad9\u5185\u5bb9\u3002\u6df7\u5408\u5e94\u7528\u5141\u8bb8\u60a8\u5229\u7528HTML\uff0cCSS\u548cJavaScript\u7b49\u6280\u672f\uff0c\u5c06\u5176\u6253\u5305\u5230\u7269\u7406\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4ee5\u4fbf\u7528\u6237\u80fd\u591f\u4ece\u79fb\u52a8\u8bbe\u5907\u4e0a\u7684\u5e94\u7528\u5546\u5e97\u4e0b\u8f7d\u548c\u5b89\u88c5\u3002<\/p>\n

\u4ee5\u4e0b\u662f\u5728Android\u548ciOS\u5e73\u53f0\u4e0a\u5c06PHP\u7f51\u7ad9\u6253\u5305\u751f\u6210APP\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n

1. \u51c6\u5907\u5de5\u4f5c<\/p>\n

\u9996\u5148\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5\u4ee5\u4e0b\u5de5\u5177\uff1a<\/p>\n

– Node.js\uff08https:\/\/nodejs.org\/\uff09<\/p>\n

– Cordova\uff08\u901a\u8fc7\u547d\u4ee4\u884c\u5b89\u88c5\uff1a`npm install -g cordova`\uff09<\/p>\n

– Android Studio\uff08\u7528\u4e8e\u6784\u5efaAndroid\u5e94\u7528\uff1ahttps:\/\/developer.android.com\/studio\uff09<\/p>\n

– Xcode\uff08\u4ec5\u7528\u4e8e\u6784\u5efaiOS\u5e94\u7528\uff1ahttps:\/\/developer.apple.com\/xcode\/\uff09<\/p>\n

\u8bf7\u786e\u4fdd\u5c06\u8fd9\u4e9b\u5de5\u5177\u5b89\u88c5\u5728\u60a8\u7684\u7cfb\u7edf\u4e0a\uff0c\u5e76\u66f4\u65b0\u5230\u6700\u65b0<\/p>\n

<\/figure>\n<\/p>\n

\u7248\u672c\u3002<\/p>\n

2. \u521b\u5efaCordova\u9879\u76ee<\/p>\n

\u6253\u5f00\u547d\u4ee4\u884c\u7ec8\u7aef\uff0c\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Cordova\u9879\u76ee\uff1a<\/p>\n

“`<\/p>\n

cordova create MyApp com.example.myapp MyApp<\/p>\n

cd MyApp<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a”MyApp”\u7684\u65b0\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u57fa\u672c\u7684Cordova\u5e94\u7528\u7a0b\u5e8f\u7ed3\u6784\u3002<\/p>\n

3. \u6dfb\u52a0\u76ee\u6807\u5e73\u53f0<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u5c06Android\u548c\/\u6216iOS\u5e73\u53f0\u6dfb\u52a0\u5230\u9879\u76ee\u4e2d\uff1a<\/p>\n

“`<\/p>\n

cordova platform add android<\/p>\n

cordova platform add ios \/\/ \u4ec5\u5728macOS\u7cfb\u7edf\u4e0a\u53ef\u7528<\/p>\n

“`<\/p>\n

4. \u914d\u7f6eWebView<\/p>\n

\u5728\u8fd9\u4e00\u6b65\uff0c\u6211\u4eec\u5c06\u4f7f\u7528InAppBrowser\u63d2\u4ef6\u5c06\u60a8\u7684PHP\u7f51\u7ad9\u5d4c\u5165\u5230\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88c5\u4ee5\u4e0b\u63d2\u4ef6\uff1a<\/p>\n

“`<\/p>\n

cordova plugin add cordova-plugin-inappbrowser<\/p>\n

“`<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6253\u5f00`www\/js\/index.js`\u6587\u4ef6\uff0c\u5e76\u5728`onDeviceReady`\u51fd\u6570\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`javascript<\/p>\n

document.addEventListener(‘deviceready’, onDeviceReady, false);<\/p>\n

function onDeviceReady() {<\/p>\n

var u\u751f\u6210app\u5236\u4f5c\u7f51\u7ad9\u6e90\u7801<\/a>rl = ‘https:\/\/example.com’; \/\/ \u66f4\u6539\u4e3a\u60a8\u7684PHP\u7f51\u7ad9URL<\/p>\n

var target = ‘_blank’;<\/p>\n

var options = ‘location=no,hidden=yes’;<\/p>\n

var ref = cordova.InAppBrowser.open(url, target, options);<\/p>\n

ref.addEventListener(‘loadstop’, function () {<\/p>\n

ref.show();<\/p>\n

});<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e86`location=no`\u4ee5\u9690\u85cf\u5730\u5740\u680f\uff0c\u5e76\u5728\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u540e\u663e\u793aWebView\u3002<\/p>\n

5. \u6784\u5efa\u548c\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u73b0\u5728\u60a8\u5df2\u7ecf\u5b8c\u6210\u4e86\u4ee3\u7801\u7f16\u8f91\uff0c\u53ef\u4ee5\u6784\u5efa\u5e76\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6784\u5efa\u9879\u76ee\uff1a<\/p>\n

“`<\/p>\n

cordova build<\/p>\n

“`<\/p>\n

\u7136\u540e\uff0c\u60a8\u9700\u8981\u8fd0\u884c\u6a21\u62df\u5668\u6216\u8fde\u63a5\u5b9e\u9645\u8bbe\u5907\u8fdb\u884c\u6d4b\u8bd5\u3002\u6839\u636e\u76ee\u6807\u5e73\u53f0\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

\u624b\u673aapp\u53ef\u4ee5\u76f4\u63a5\u751f\u6210\u7f51\u9875<\/a>cordova run android<\/p>\n

cordova run ios<\/p>\n

“`<\/p>\n

\u81f3\u6b64\uff0c\u60a8\u5df2\u5c06PHP\u7f51\u7ad9\u6253\u5305\u6210\u4e86\u4e00\u4e2a\u53ef\u4ee5\u5728Android\u548ciOS\u8bbe\u5907\u4e0a\u8fd0\u884c\u7684\u79fb\u52a8APP\u3002\u8bf7\u6ce8\u610f\uff0cWebView\u7684\u6027\u80fd\u53ef\u80fd\u4e0d\u5982\u539f\u751f\u5e94\u7528\uff0c\u4f46\u5bf9\u4e8e\u8bb8\u591a\u7c7b\u578b\u7684\u9879\u76ee\uff0c\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u6709\u7528\uff0c\u5e76\u4e14\u6613\u4e8e\u5b9e\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

PHP\u7f51\u7ad9\u6253\u5305\u751f\u6210APP\u7684\u6559\u7a0b\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06\u73b0\u6709\u7684PHP\u7f51\u7ad9\u6253\u5305\u6210\u4e00\u4e2a\u79fb\u52a8APP\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u8bb8\u591a\u573a\u666f\u4e0b\u975e\u5e38\u6709\u7528\uff0c\u4f8b\u5982\uff0c\u60a8\u62e5\u6709\u4e00\u4e2a\u6d41\u884c\u7684\u7f51\u7ad9\uff0c\u5e76\u5e0c\u671b\u5c06\u5176\u6269\u5c55\u5230\u79fb\u52a8\u5e73\u53f0\uff0c\u6216\u8005\u60a8\u6b63\u5728\u5f00\u53d1\u4e00<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[4874,4756,12,247,23],"topic":[],"class_list":["post-2321","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-discuzapp","tag-h5-app","tag-12","tag-247","tag-23"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=2321"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2321\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=2321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=2321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=2321"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=2321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}