{"id":6656,"date":"2023-10-05T12:39:20","date_gmt":"2023-10-05T04:39:20","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=6656"},"modified":"2023-10-05T12:39:20","modified_gmt":"2023-10-05T04:39:20","slug":"php%e8%8b%b9%e6%9e%9c%e7%ad%be%e5%90%8d%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/10\/05\/php%e8%8b%b9%e6%9e%9c%e7%ad%be%e5%90%8d%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%9a%84%ef%bc%9f\/","title":{"rendered":"php\u82f9\u679c\u7b7e\u540d\u5982\u4f55\u5b9e\u73b0\u7684\uff1f"},"content":{"rendered":"

PHP\u82f9\u679c\u7b7e\u540d\u662f\u6307\u4f7f\u7528PHP\u7f16\u7a0b\u8bed\u8a00\u6765\u5b9e\u73b0\u5bf9\u82f9\u679c\u5e94\u7528\u8fdb\u884c\u7b7e\u540d\u7684\u64cd\u4f5c\u3002\u82f9\u679c\u7b7e\u540d\u662f\u4e00\u79cd\u5bf9\u5e94\u7528\u8fdb\u884c\u6570\u5b57\u7b7e\u540d\u7684\u65b9\u5f0f\uff0c\u7528\u4e8e\u9a8c\u8bc1\u5e94\u7528\u7684\u5b89\u5168\u6027\u548c\u5b8c\u6574\u6027\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecdPHP\u82f9\u679c\u7b7e\u540d\u7684\u539f\u7406\u548c\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n

1. \u82f9\u679c\u7b7e\u540d\u7684\u539f\u7406<\/p>\n

\u82f9\u679c\u7b7e\u540d\u662f\u901a\u8fc7\u4f7f\u7528Apple\u63d0\u4f9b\u7684\u5bc6\u94a5\u548c\u8bc1\u4e66\u6765\u5bf9\u5e94\u7528\u8fdb\u884c\u6570\u5b57\u7b7e\u540d\u3002\u6bcf\u4e2a\u5e94\u7528\u90fd\u6709\u4e00\u4e2a\u7279\u5b9a\u7684Bundle ID\uff0c\u4f7f\u7528\u79c1\u94a5\u5bf9\u5e94\u7528\u8fdb\u884c\u7b7e\u540d\u540e\uff0c\u751f\u6210\u4e00\u4e2aProvisioning Profile\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u4e2d\u5305\u542b\u4e86\u5e94\u7528\u7684\u7b7e\u540d\u4fe1\u606f\u548c\u8bc1\u4e66\u3002\u5f53\u7528\u6237\u8fdb\u884c\u5e94\u7528\u5b89\u88c5\u65f6\uff0c\u7cfb\u7edf\u4f1a\u9a8c\u8bc1\u5e94\u7528\u7684\u7b7e\u540d\u548c\u8bc1\u4e66\uff0c\u786e\u4fdd\u5e94\u5b89\u5353\u624b\u673a\u5b89\u88c5\u5305\u7b7e\u540d\u4e0d\u4e00\u81f4\u662f\u4ec0\u4e48\u610f\u601d<\/a>\u7528\u6765\u6e90\u53ef\u9760\u3002<\/p>\n

2. PHP\u82f9\u679c\u7b7e\u540d\u7684\u5b9e\u73b0\u65b9\u6cd5<\/p>\n

\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528PHP\u5b9e\u73b0\u82f9\u679c\u7b7e\u540d\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n

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

function signApp($appPath, $provisioningProfilePath, $certificatePath, $keyPath, $keyPassword) {<\/p>\n

\/\/ \u8bfb\u53d6\u5e94\u7528\u6587\u4ef6\u548c\u7b7e\u540d\u6587\u4ef6<\/p>\n

$appContent = file_get_contents($appPath);<\/p>\n

$provisioningProfileContent = file_get_contents($provisioningProfilePath);<\/p>\n<\/p>\n

\/\/ \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u76ee\u5f55<\/p>\n

$tempDir = tempnam(sys_get_temp_dir(), ‘sign’);<\/p>\n

unlink($tempDir);<\/p>\n

mkdir($tempDir);<\/p>\n<\/p>\n

\/\/ \u5c06\u5e94\u7528\u6587\u4ef6\u548c\u7b7e\u540d\u6587\u4ef6\u590d\u5236\u5230\u4e34\u65f6\u76ee\u5f55\u4e0b<\/p>\n

$appCopyPath = $tempDir . ‘\/app.ipa’;<\/p>\n

$provisioningProfileCopyPath = $tempDir . ‘\/provisioning.mobileprovision’;<\/p>\n

file_put_contents($appCopyPath, $appContent);<\/p>\n

file_put_contents($provisioningProfileCopyPath, $provisioningProfileContent);<\/p>\n<\/p>\n

\/\/ \u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177codesign\u5bf9\u5e94\u7528\u8fdb\u884c\u7b7e\u540d<\/p>\n

$command = “codesign -f -s \\”$certificatePath\\” –keychain \\”$keyPath\\” –keychain-password \\”$keyPassword\\” –entitlements \\”$provisioningProfileCopyPath\\” \\”$appCopyPath\\””;<\/p>\n

exec($command, $output, $result);<\/p>\n<\/p>\n

\/\/ \u5982\u679c\u7b7e\u540d\u6210\u529f\uff0c\u5219\u5c06\u7b7e\u540d\u540e\u7684\u5e94\u7528\u6587\u4ef6\u4fdd\u5b58\u5230\u6307\u5b9a\u8def\u5f84<\/p>\n

if ($result == 0) {<\/p>\n

$signedAppPath = $tempDir . apk\u600e\u4e48\u6539\u6587\u4ef6\u7b7e\u540d<\/a>‘\/signed.ipa’;<\/p>\n

rename($appCopyPath, $signedAppPath);<\/p>\n<\/p>\n

\/\/ \u5220\u9664\u4e34\u65f6\u76ee\u5f55<\/p>\n

exec(“rm -r \\”$tempDir\\””);<\/p>\n<\/p>\n

return $sign<\/p>\n

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

edAppPath;<\/p>\n

} else {<\/p>\n

return false;<\/p>\n

}<\/p>\n

}<\/p>\n

\/\/ \u793a\u4f8b\u7528\u6cd5<\/p>\n

$appPath = ‘\/path\/to\/your\/app.ipa’;<\/p>\n

$provisioningProfilePath = ‘\/path\/to\/your\/provisioning.mobileprovision’;<\/p>\n

$certificatePath = ‘\/path\/to\/your\/certificate.p12’;<\/p>\n

$keyPath = ‘\/path\/to\/your\/keychain.keychain’;<\/p>\n

$keyPassword = ‘your_key_password’;<\/p>\n

$signedAppPath = signApp($appPath, $provisioningProfilePath, $certificatePath, $keyPath, $keyPassword);<\/p>\n

if ($signedAppPath !== false) {<\/p>\n

\/\/ \u7b7e\u540d\u6210\u529f\uff0c\u53ef\u4ee5\u8fdb\u884c\u76f8\u5173\u64cd\u4f5c\uff0c\u6bd4\u5982\u4fdd\u5b58\u7b7e\u540d\u540e\u7684\u5e94\u7528\u6587\u4ef6\u6216\u8005\u53d1\u5e03\u5230App Store<\/p>\n

} else {<\/p>\n

\/\/ \u7b7e\u540d\u5931\u8d25\uff0c\u5904\u7406\u9519\u8bef\u903b\u8f91<\/p>\n

}<\/p>\n

?><\/p>\n

“`<\/p>\n

\u4ee5\u4e0a\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c$appPath\u8868\u793a\u5f85\u7b7e\u540d\u7684\u5e94\u7528\u6587\u4ef6\u8def\u5f84\uff0c$provisioningProfilePath\u8868\u793a\u7b7e\u540d\u6587\u4ef6\u8def\u5f84\uff0c$certificatePath\u8868\u793a\u8bc1\u4e66\u6587\u4ef6\u8def\u5f84\uff0c$keyPath\u8868\u793a\u5bc6\u94a5\u6587\u4ef6\u8def\u5f84\uff0c$keyPassword\u8868\u793a\u5bc6\u94a5\u5bc6\u7801\u3002<\/p>\n

\u4f7f\u7528codesign\u547d\u4ee4\u5bf9\u5e94\u7528\u8fdb\u884c\u7b7e\u540d\uff0c\u9700\u8981\u4f7f\u7528\u5bc6\u94a5\u548c\u76f8\u5e94\u7684\u8bc1\u4e66\u3002\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86exec\u51fd\u6570\u6765\u6267\u884c\u547d\u4ee4\u884c\u64cd\u4f5c\uff0c\u5e76\u83b7\u53d6\u7b7e\u540d\u7684\u7ed3\u679c\u3002<\/p>\n

\u7b7e\u540d\u6210\u529f\u540e\uff0c\u5c06\u7b7e\u540d\u540e\u7684\u5e94\u7528\u6587\u4ef6\u4fdd\u5b58\u5230\u6307\u5b9a\u8def\u5f84\uff0c\u53ef\u4ee5\u8fdb\u884c\u540e\u7eed\u64cd\u4f5c\uff0c\u6bd4\u5982\u4fdd\u5b58\u5230\u672c\u5730\u6216\u8005\u53d1\u5e03\u5230App Store\u3002<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u4ee3\u7801\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4f7f\u7528PHP\u5b9e\u73b0\u82f9\u679c\u7b7e\u540d\u5e76\u4e0d\u590d\u6742\uff0c\u53ea\u9700\u8981\u4e86\u89e3\u82f9\u679c\u7b7e\u540d\u7684\u539f\u7406\u548c\u5bf9\u5e94\u7684\u5de5\u5177\u547d\u4ee4\u5373\u53ef\u3002\u5f53\u7136\uff0c\u5177\u4f53\u7684\u7b7e\u540d\u6d41\u7a0b\u548c\u64cd\u4f5c\u6b65\u9aa4\u8fd8\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u5e94\u7528\u60c5\u51b5\u548c\u5b9e\u9645\u9700\u6c42\u8fdb\u884c\u8c03\u6574\u548c\u4f18\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

PHP\u82f9\u679c\u7b7e\u540d\u662f\u6307\u4f7f\u7528PHP\u7f16\u7a0b\u8bed\u8a00\u6765\u5b9e\u73b0\u5bf9\u82f9\u679c\u5e94\u7528\u8fdb\u884c\u7b7e\u540d\u7684\u64cd\u4f5c\u3002\u82f9\u679c\u7b7e\u540d\u662f\u4e00\u79cd\u5bf9\u5e94\u7528\u8fdb\u884c\u6570\u5b57\u7b7e\u540d\u7684\u65b9\u5f0f\uff0c\u7528\u4e8e\u9a8c\u8bc1\u5e94\u7528\u7684\u5b89\u5168\u6027\u548c\u5b8c\u6574\u6027\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecdPHP\u82f9\u679c\u7b7e\u540d\u7684\u539f\u7406\u548c\u5b9e\u73b0\u65b9\u6cd5\u30021. \u82f9\u679c\u7b7e\u540d<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[12001,12,205,12002,1034],"topic":[],"class_list":{"0":"post-6656","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-appzhengshu","7":"tag-p12","8":"tag-12","9":"tag-205","11":"tag-1034"},"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/6656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=6656"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/6656\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=6656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=6656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=6656"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=6656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}