{"id":2995,"date":"2024-04-25T13:09:31","date_gmt":"2024-04-25T05:09:31","guid":{"rendered":"https:\/\/iosmianqian.yimenapp.com\/webclip\/?p=2995"},"modified":"2024-04-25T13:09:31","modified_gmt":"2024-04-25T05:09:31","slug":"%e8%8b%b9%e6%9e%9c%e5%85%8d%e7%ad%bephp%e6%ba%90%e7%a0%81%e4%bd%9c%e7%94%a8%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/iosmianqian.yimenapp.com\/webclip\/2024\/04\/25\/2995\/","title":{"rendered":"\u82f9\u679c\u514d\u7b7ephp\u6e90\u7801\u4f5c\u7528\u4ecb\u7ecd"},"content":{"rendered":"<p>\u82f9\u679c\u514d\u7b7e\u652f\u4ed8\u662f\u4e00\u4e2a\u7ed5\u8fc7\u82f9\u679c\u5b98\u65b9\u652f\u4ed8\u7cfb\u7edf\uff0c\u4f7f\u7528\u4e2a\u4eba\u5f00\u53d1\u8005\u8d26\u53f7\u5b9e\u73b0\u7684\u4e00\u79cd\u652f\u4ed8\u6a21\u5f0f\u3002\u901a\u8fc7\u8fd9\u79cd\u6a21\u5f0f\uff0c\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u8d2d\u4e70\u865a\u62df\u5546\u54c1\u6216\u670d\u52a1,\u800c\u4e0d\u9700\u8981\u901a\u8fc7\u82f9\u679c\u7684\u652f\u4ed8\u7cfb\u7edf\uff0c\u4ece\u800c\u907f\u5f00\u82f9\u679c\u7684\u5ba1\u67e5\u548c\u62bd\u6210\u3002\u7136\u800c,\u8fd9\u79cd\u65b9\u5f0f\u8fdd\u53cd\u4e86\u82f9\u679c\u7684\u653f\u7b56\uff0c\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5b58\u5728\u4e00\u5b9a\u7684\u98ce\u9669\u3002<\/p>\n<p>\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5316\u7684\u82f9\u679c\u514d\u7b7e\u652f\u4ed8\u7684PHP\u5b9e\u73b0\u539f\u7406\u3002\u8bf7\u6ce8\u610f,\u4f7f\u7528\u8fd9\u4e9b\u4ee3\u7801\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4f60\u7684\u5e94\u7528\u88ab\u4e0b\u67b6\uff0c\u6211\u4eec\u4e0d\u63a8\u8350\u8fd9\u6837\u505a\u3002\u8fd9\u4e2a\u6559\u7a0b\u4ec5\u4f5c\u4e3a\u6280\u672f\u4ea4\u6d41\uff0c\u5e2e\u52a9\u60a8\u4e86\u89e3\u5176\u5de5\u4f5c\u539f\u7406\u3002<\/p>\n<p>1. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684PHP\u6587\u4ef6\uff0c\u547d\u540d\u4e3a &#8220;apple_pay.php&#8221;\u3002<\/p>\n<p>2. \u5728PHP\u6587\u4ef6\u4e2d,\u6211\u4eec\u9700\u8981\u9996\u5148\u8bbe\u7f6e\u4e00\u4e9b\u5e38\u91cf\u548c\u914d\u7f6e\u53d8\u91cf\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<p>&#8220;`php<\/p>\n<\/p>\n<p>\/\/ \u4f60\u7684RSA\u79c1\u94a5\u548c\u516c\u94a5<\/p>\n<p>define(&#8220;PRIVATE_KEY&#8221;, &#8220;Your private key&#8221;);<\/p>\n<p>define(&#8220;PUBLIC_KEY&#8221;, &#8220;Your public key&#8221;);<\/p>\n<p>\/\/ \u652f\u4ed8\u5b9d\u540c\u6b65\u901a\u77e5\u56de\u8c03\u94fe\u63a5<\/p>\n<p>define(&#8220;ALIPAY_NOT<a href=\"https:\/\/iosmianqian.yimenapp.com\/webclip-469.html\">\u82f9\u679cios\u6c38\u4e45\u514d\u7b7e\u540d<\/a>IFY_URL&#8221;, &#8220;https:\/\/example.com\/alipay_notify.php&#8221;);<\/p>\n<p>\/\/ \u5546\u54c1\u4fe1\u606f\u914d\u7f6e\uff0c\u5546\u54c1\u540d\u79f0\u4e0e\u4ef7\u683c<\/p>\n<p>$products = array(<\/p>\n<p>    &#8216;product_01&#8217; =&gt; array(&#8216;name&#8217; =&gt; &#8216;\u865a\u62df\u5546\u54c11&#8217;, &#8216;price&#8217; =&gt; 6.00),<\/p>\n<p>    &#8216;product_02&#8217; =&gt; array(&#8216;name&#8217; =&gt; &#8216;\u865a\u62df\u5546\u54c12&#8217;, &#8216;price&#8217; =&gt; 15.00),<\/p>\n<p>    \/\/ \u66f4\u591a\u5546\u54c1&#8230;<\/p>\n<p>);<\/p>\n<p>&#8220;`<\/p>\n<p>3. \u63a5\u4e0b\u6765,\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u52a0\u5bc6\u51fd\u6570\uff0c\u7528\u4e8e\u5c06\u8bf7\u6c42\u53c2\u6570\u8fdb\u884c\u7b7e\u540d\u3002<\/p>\n<p>&#8220;`php<\/p>\n<p>function sign($dataStr) {<\/p>\n<p>    $privateKeyId = openssl_get_privatekey(PRIVATE_KEY);<\/p>\n<p>    $result = openssl_sign($dataStr, $sign, $privateKeyId, OPENSSL_ALGO_SHA1);<\/p>\n<p>    openssl_free_key($privateKeyId);<\/p>\n<\/p>\n<p>    $sign = base64_encode($sign);<\/p>\n<p>    return $sign;<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>4. \u73b0\u5728\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u5904\u7406\u652f\u4ed8\u8bf7\u6c42\u7684\u6838\u5fc3\u51fd\u6570\u3002<\/p>\n<p>&#8220;`php<\/p>\n<p>function processPayment($orderNumber, $productID, $userID) {<\/p>\n<p>    global $products;<\/p>\n<p>    \/\/ \u83b7\u53d6\u5546\u54c1\u4fe1\u606f<\/p>\n<p>    $product = $products[$productID];<\/p>\n<\/p>\n<p>    \/\/ \u751f\u6210\u5f85\u7b7e\u540d\u5b57\u7b26\u4e32<\/p>\n<p>    $dataStr = &#8220;order_nu<a href=\"https:\/\/iosmianqian.yimenapp.com\/webclip-335.html\">\u514d\u7b7eios\u5c01\u88c5app<\/a>mber={$orderNumber}&amp;product_id={$produ<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/30\/12\/21676842626.jpg\" \/><\/figure>\n<\/p>\n<p>ctID}&amp;user_id={$userID}&#8221;;<\/p>\n<p>    \/\/ \u5bf9\u5f85\u7b7e\u540d\u5b57\u7b26\u4e32\u8fdb\u884c\u7b7e\u540d<\/p>\n<p>    $signedData = sign($dataStr);<\/p>\n<p>    \/\/ \u8bf7\u6c42\u652f\u4ed8\u5b9d\u652f\u4ed8\u63a5\u53e3<\/p>\n<p>    $alipayUrl = &#8220;https:\/\/openapi.alipay.com\/gateway.do?&#8221;.$dataStr.&#8221;&amp;sign=&#8221;.$signedData.&#8221;&amp;notify_url=&#8221;.urlencode(ALIPAY_NOTIFY_URL);<\/p>\n<p>    \/\/ \u91cd\u5b9a\u5411\u5230\u652f\u4ed8\u5b9d\u652f\u4ed8\u9875\u9762<\/p>\n<p>    header(&#8220;Location: &#8220;.$alipayUrl);<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>5. \u6700\u540e,\u6211\u4eec\u9700\u8981\u5904\u7406\u7528\u6237\u63d0\u4ea4\u7684\u652f\u4ed8\u8bf7\u6c42\u3002<\/p>\n<p>&#8220;`php<\/p>\n<p>if (isset($_POST[&#8216;product_id&#8217;]) &amp;&amp; isset($_POST[&#8216;user_id&#8217;])) {<\/p>\n<p>    \/\/ \u9a8c\u8bc1\u5546\u54c1ID\u548c\u7528\u6237ID<\/p>\n<p>    $productID = $_POST[&#8216;product_id&#8217;];<\/p>\n<p>    $userID = $_POST[&#8216;user_id&#8217;];<\/p>\n<p>    \/\/ \u5982\u679c\u5546\u54c1ID\u548c\u7528\u6237ID\u6709\u6548\uff0c\u8fdb\u884c\u652f\u4ed8\u6d41\u7a0b<\/p>\n<p>    if (isset($products[$productID]) &amp;&amp; !empty($userID)) {<\/p>\n<p>        \/\/ \u751f\u6210\u8ba2\u5355\u53f7<\/p>\n<p>        $orderNumber = time().&#8221;_&#8221;.rand(100000, 999999);<\/p>\n<p>        \/\/ \u5904\u7406\u652f\u4ed8<\/p>\n<p>        processPayment($orderNumber, $productID, $userID);<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u6574\u4e2a\u6e90\u7801\u4ec5\u4f5c\u4e3a\u6f14\u793a\u5982\u4f55\u5b9e\u73b0\u82f9\u679c\u514d\u7b7ePHP\u652f\u4ed8\u6d41\u7a0b\u3002\u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u6d89\u53ca\u652f\u4ed8\u6d41\u7a0b\u53ca\u4f9d\u8d56\u7b2c\u4e09\u65b9\u652f\u4ed8\u5e73\u53f0\uff0c\u8bf7\u4ed4\u7ec6\u5ba1\u67e5\u4ee3\u7801\uff0c\u5e76\u8c28\u614e\u4f7f\u7528\u3002\u6211\u4eec\u5efa\u8bae\u60a8\u91c7\u7528\u5408\u89c4\u7684\u652f\u4ed8\u65b9\u5f0f\uff0c\u9075\u5b88\u82f9\u679c\u5546\u5e97\u7684\u76f8\u5173\u653f\u7b56\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u82f9\u679c\u514d\u7b7e\u652f\u4ed8\u662f\u4e00\u4e2a\u7ed5\u8fc7\u82f9\u679c\u5b98\u65b9\u652f\u4ed8\u7cfb\u7edf\uff0c\u4f7f\u7528\u4e2a\u4eba\u5f00\u53d1\u8005\u8d26\u53f7\u5b9e\u73b0\u7684\u4e00\u79cd\u652f\u4ed8\u6a21\u5f0f\u3002\u901a\u8fc7\u8fd9\u79cd\u6a21\u5f0f\uff0c\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u8d2d\u4e70\u865a\u62df\u5546\u54c1\u6216\u670d\u52a1,\u800c\u4e0d\u9700\u8981\u901a\u8fc7\u82f9\u679c\u7684\u652f\u4ed8\u7cfb\u7edf\uff0c\u4ece\u800c\u907f\u5f00\u82f9\u679c\u7684\u5ba1\u67e5\u548c\u62bd\u6210\u3002\u7136\u800c,\u8fd9\u79cd\u65b9\u5f0f\u8fdd\u53cd\u4e86<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[3151,72,33,612,2991],"topic":[],"class_list":["post-2995","post","type-post","status-publish","format-standard","hentry","category-iosmianqian","tag-3151","tag-72","tag-33","tag-612","tag-2991"],"_links":{"self":[{"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/posts\/2995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/comments?post=2995"}],"version-history":[{"count":1,"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/posts\/2995\/revisions"}],"predecessor-version":[{"id":3030,"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/posts\/2995\/revisions\/3030"}],"wp:attachment":[{"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/media?parent=2995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/categories?post=2995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/tags?post=2995"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/iosmianqian.yimenapp.com\/webclip\/wp-json\/wp\/v2\/topic?post=2995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}