{"id":2324,"date":"2023-08-08T18:39:18","date_gmt":"2023-08-08T10:39:18","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=2324"},"modified":"2023-08-08T18:39:18","modified_gmt":"2023-08-08T10:39:18","slug":"php%e7%82%b9%e9%a4%90%e7%b3%bb%e7%bb%9f%e6%ba%90%e7%a0%81%e7%94%9f%e6%88%90app%e4%bc%98%e5%8a%bf%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/2324\/","title":{"rendered":"php\u70b9\u9910\u7cfb\u7edf\u6e90\u7801\u751f\u6210app\u4f18\u52bf\uff1f"},"content":{"rendered":"

\u5982\u4f55\u5c06PHP\u70b9\u9910\u7cfb\u7edf\u6e90\u7801\u751f\u6210\u4e3a\u4e00\u4e2aAPP\u5e94\u7528<\/p>\n

\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u5c06PHP\u70b9\u9910\u7cfb\u7edf\u6e90\u7801\u8f6c\u6362\u4e3a\u4e00\u4e2aAPP\u5e94\u7528\u3002\u901a\u8fc7\u8fd9\u4e2a\u6559\u7a0b\uff0c\u60a8\u5c06\u4e86\u89e3\u5230\u6e90\u4ee3\u7801\u8f6c\u6362\u4e3aAPP\u7684\u539f\u7406\u4ee5\u53ca\u5c06\u60a8\u7684\u73b0\u6709PHP\u70b9\u9910\u7cfb\u7edf\u4ee3\u7801\u8f6c\u6362\u4e3a\u5b89\u5353\u548c\u82f9\u679c\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u8be6\u7ec6\u6b65\u9aa4\u3002\u8bf7\u6ce8\u610f\uff0c\u60a8\u9700\u8981\u62e5\u6709\u4e00\u5b9a\u7684PHP\u3001HTML\u3001CSS\u548cJavaScript\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u4ee5\u4fbf\u80fd\u591f\u8fdb\u884c\u4e0b\u8ff0\u6b65\u9aa4\u3002<\/p>\n

1. \u539f\u7406<\/p>\n

\u5c06PHP\u70b9\u9910\u7cfb\u7edf\u6e90\u7801\u751f\u6210\u4e00\u4e2aAPP\u5e94\u7528\u7684\u539f\u7406\u662f\u5c06\u539f\u59cb\u7684Web\u7f51\u9875\u5e94\u7528\u8f6c\u6362\u4e3a\u4e00\u4e2aWebView\u5e94\u7528\u3002WebView\u662f\u4e00\u79cd\u5d4c\u5165\u5230\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u6d4f\u89c8\u5668\u3002\u5b83\u4f7f\u60a8\u80fd\u591f\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u663e\u793a\u7f51\u9875\u5185\u5bb9\uff0c\u800c\u4e0d\u9700\u8981\u7528\u6237\u5355\u72ec\u6253\u5f00\u4e00\u4e2a\u6d4f\u89c8\u5668\u5e94\u7528\u3002\u56e0\u6b64\uff0c\u901a\u8fc7\u5c06\u60a8\u7684PHP\u70b9\u9910\u7cfb\u7edf\u4ee5WebView\u5f62\u5f0f\u5c01\u88c5\u5230\u4e00\u4e2a\u5b89\u5353\u6216\u82f9\u679c\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u60a8\u5c31\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u60a8\u7684\u7f51\u9875\u7cfb\u7edf\u8f6c\u6362\u4e3a\u79fb\u52a8APP\u5e94\u7528\u3002<\/p>\n

2. \u5b9e\u73b0\u6b65\u9aa4<\/p>\n

\u4ee5\u4e0b\u6b65\u9aa4\u5c06\u7b80\u8981\u6982\u8ff0\u5982\u4f55\u5c06\u60a8\u7684PHP\u70b9\u9910\u7cfb\u7edf\u4ee3\u7801\u8f6c\u6362\u4e3a\u4e00\u4e2aAPP\u5e94\u7528\uff1a<\/p>\n

a) \u51c6\u5907\u5de5\u4f5c<\/p>\n

1. \u5b89\u88c5\u73af\u5883\uff1a\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5\u4e86Node.js \u548cnpm\uff0c\u8fd9\u662fCordova\u6240\u9700\u7684\u3002<\/p>\n

2. \u5b89\u88c5Cordova\uff1aCordova \u662f\u4e00\u4e2a\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u672c\u5730APP\u7684\u5de5\u5177\u3002\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Cordova\uff1a<\/p>\n

“`<\/p>\n

npm install -g cordova<\/p>\n

“`<\/p>\n<\/p>\n

b) \u521b\u5efaCordova\u9879\u76ee<\/p>\n

\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Cordova\u9879\u76ee\uff0c\u5176\u4e2d\u201cmyApp\u201d\u662f\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u540d\u79f0\uff1a<\/p>\n

“`<\/p>\n

cordova crea<\/p>\n

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

te myApp<\/p>\n

\u600e\u4e48\u628aapp\u751f\u6210h5<\/a> “`<\/p>\n

\u5207\u6362\u5230\u9879\u76ee\u76ee\u5f55\u5e76\u6dfb\u52a0\u60a8\u9700\u8981\u7684\u5e73\u53f0\uff08\u5982\uff1aandroid \u6216 ios\uff09\uff0c\u4f8b\u5982\uff1a<\/p>\n

“`<\/p>\n

cd myApp<\/p>\n

cordova platform add android<\/p>\n

“`<\/p>\n

c) \u5c01\u88c5\u60a8\u7684PHP\u70b9\u9910\u7cfb\u7edf<\/p>\n

\u5728\u6b64\u9636\u6bb5\uff0c\u60a8\u9700\u8981\u5c06\u5df2\u6709\u7f51\u7ad9\u6253\u5305app\u751f\u6210<\/a>\u7684PHP\u70b9\u9910\u7cfb\u7edf\u7684\u6240\u6709HTML\u3001CSS\u3001JavaScript\u548c\u56fe\u7247\u7b49\u8d44\u6e90\u653e\u5165\u65b0\u521b\u5efa\u7684Cordova\u9879\u76ee\u7684 www \u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n

\u5728 www\/ \u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a”index.html”\u7684\u6587\u4ef6\uff0c\u5e76\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230\u6587\u4ef6\u4e2d\uff1a<\/p>\n

“`html<\/p>\n<\/p>\n

\n

\n<\/p>\n

\n

\n

document.addEventListener(‘deviceready’, function() {<\/p>\n

var webView = document.createElement(‘iframe’);<\/p>\n

webView.style.width = ‘100%’;<\/p>\n

webView.style.height = ‘100%’;<\/p>\n

webView.style.border = ‘none’;<\/p>\n

webView.src = ‘[\u60a8\u7684PHP\u70b9\u9910\u7cfb\u7edf\u7f51\u5740]’;<\/p>\n

document.getElementById(‘app’).appendChild(webView);<\/p>\n

});<\/p>\n<\/p>\n<\/p>\n

“`<\/p>\n

\u6ce8\u610f\uff1a\u8bf7\u5c06 “[\u60a8\u7684PHP\u70b9\u9910\u7cfb\u7edf\u7f51\u5740]” \u66ff\u6362\u4e3a\u5b9e\u9645\u7684PHP\u70b9\u9910\u7cfb\u7edf\u8bbf\u95ee\u5730\u5740\u3002<\/p>\n

d) \u6784\u5efa\u548c\u8fd0\u884c\u5e94\u7528<\/p>\n

\u73b0\u5728\u60a8\u53ef\u4ee5\u5f00\u59cb\u6784\u5efa\u548c\u8fd0\u884c\u60a8\u7684\u5e94\u7528\u3002\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u8f6c\u5230\u60a8\u7684myApp\u76ee\u5f55\uff0c\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

cordova build android<\/p>\n

cordova run android<\/p>\n

“`<\/p>\n

\u4e0a\u9762\u7684\u547d\u4ee4\u5c06\u4f1a\u6784\u5efa\u5e76\u8fd0\u884c\u5b89\u5353\u5e94\u7528\u3002\u5bf9\u4e8eiOS\u5e73\u53f0\uff0c\u60a8\u53ea\u9700\u5c06`android`\u66ff\u6362\u4e3a`ios`\u5373\u53ef\uff0c\u4f46\u8bf7\u6ce8\u610f\u5728macOS\u4e0a\u6784\u5efaiOS\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u5df2\u7ecf\u6210\u529f\u5c06\u60a8\u7684PHP\u70b9\u9910\u7cfb\u7edf\u8f6c\u6362\u6210\u4e86\u4e00\u4e2aAPP\u5e94\u7528\u3002\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u5c06\u60a8\u7684APP\u5e94\u7528\u53d1\u5e03\u5230Google Play Store\u6216Apple App Store\uff0c\u8ba9\u60a8\u7684\u7528\u6237\u4eab\u53d7\u5230\u79fb\u52a8\u8bbe\u5907\u4e0a\u7684\u4fbf\u6377\u70b9\u9910\u4f53\u9a8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5982\u4f55\u5c06PHP\u70b9\u9910\u7cfb\u7edf\u6e90\u7801\u751f\u6210\u4e3a\u4e00\u4e2aAPP\u5e94\u7528\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u5c06PHP\u70b9\u9910\u7cfb\u7edf\u6e90\u7801\u8f6c\u6362\u4e3a\u4e00\u4e2aAPP\u5e94\u7528\u3002\u901a\u8fc7\u8fd9\u4e2a\u6559\u7a0b\uff0c\u60a8\u5c06\u4e86\u89e3\u5230\u6e90\u4ee3\u7801\u8f6c\u6362\u4e3aAPP\u7684\u539f\u7406\u4ee5\u53ca\u5c06\u60a8\u7684\u73b0\u6709PHP\u70b9\u9910\u7cfb\u7edf\u4ee3\u7801\u8f6c\u6362\u4e3a\u5b89\u5353\u548c\u82f9\u679c\u7684<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[4879,12,105,294,4880],"topic":[],"class_list":["post-2324","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-app","tag-12","tag-105","tag-294"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2324","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\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=2324"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2324\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=2324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=2324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=2324"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=2324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}