{"id":48000,"date":"2024-12-02T14:53:07","date_gmt":"2024-12-02T06:53:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48000\/"},"modified":"2024-12-02T14:53:07","modified_gmt":"2024-12-02T06:53:07","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-php-%e5%87%bd%e6%95%b0%e6%89%a9%e5%b1%95%e8%bf%9b%e8%a1%8c-api-%e9%9b%86%e6%88%90%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48000\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210\uff1f<\/h1>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210\uff1f\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p>PHP \u51fd\u6570\u6269\u5c55\u53ef\u96c6\u6210 API\uff0c\u65e0\u9700\u4fee\u6539 PHP \u6838\u5fc3\u3002\u521b\u5efa\u6269\u5c55\u6587\u4ef6\uff0c\u7f16\u8bd1\u5e76\u5b89\u88c5\u5b83\u3002\u5728 PHP \u811a\u672c\u4e2d\u52a0\u8f7d\u6269\u5c55\uff0c\u5373\u53ef\u4f7f\u7528\u5916\u90e8\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u96c6\u6210 Stripe API\uff1a\u5b89\u88c5 Composer \u5305\uff0c\u52a0\u8f7d\u6269\u5c55\uff0c\u521d\u59cb\u5316 Stripe \u5ba2\u6237\u673a\uff0c\u5373\u53ef\u4f7f\u7528 Stripe \u5e93\u4e0e API \u4ea4\u4e92\u3002\u51fd\u6570\u6269\u5c55\u4fbf\u4e8e API \u96c6\u6210\uff0c\u8282\u7701\u5f00\u53d1\u65f6\u95f4\u548c\u7cbe\u529b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729948396671ceaecd7047.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210<\/h2>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>PHP \u51fd\u6570\u6269\u5c55\u5141\u8bb8\u60a8\u5c06\u5916\u90e8\u5e93\u7684\u529f\u80fd\u5f15\u5165 PHP \u5e94\u7528\u7a0b\u5e8f\u3002\u901a\u8fc7\u4f7f\u7528\u51fd\u6570\u6269\u5c55\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u96c6\u6210\u7b2c\u4e09\u65b9 API\uff0c\u800c\u65e0\u9700\u4fee\u6539 PHP \u6838\u5fc3\u3002<\/p>\n<p><strong>\u521b\u5efa\u6269\u5c55<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\u7684\u6269\u5c55\u6587\u4ef6\uff08\u6269\u5c55\u540d\u4e3a <code>.so<\/code>\uff09\uff1a<\/p>\n<pre>&lt;?php\n\/\/ \u5b9a\u4e49\u6269\u5c55\u540d\nextension_name = \"my_extension\";\n\n\/\/ \u5b9a\u4e49\u5916\u90e8\u51fd\u6570\u7684\u58f0\u660e\nextern int my_function(int $a, int $b);<\/pre>\n<p><strong>\u7f16\u8bd1\u6269\u5c55<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u7f16\u8bd1\u6269\u5c55\uff1a<\/p>\n<pre>gcc -shared -fPIC -o my_extension.so my_extension.c<\/pre>\n<p><strong>\u5b89\u88c5\u6269\u5c55<\/strong><\/p>\n<p>\u5c06\u7f16\u8bd1\u540e\u7684\u6269\u5c55\u6587\u4ef6\u590d\u5236\u5230 <code>ext<\/code> \u76ee\u5f55\u4e2d\uff1a<\/p>\n<pre>sudo cp my_extension.so \/usr\/local\/lib\/php\/extensions\/<\/pre>\n<p><strong>\u52a0\u8f7d\u6269\u5c55<\/strong><\/p>\n<p>\u5728\u60a8\u7684 PHP \u811a\u672c\u4e2d\uff0c\u4f7f\u7528 <code>extension_load()<\/code> \u51fd\u6570\u52a0\u8f7d\u6269\u5c55\uff1a<\/p>\n<pre>extension_load('my_extension.so');<\/pre>\n<p><strong>\u4f7f\u7528\u5916\u90e8\u51fd\u6570<\/strong><\/p>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u50cf\u4f7f\u7528\u4efb\u4f55\u5176\u4ed6 PHP \u51fd\u6570\u4e00\u6837\u4f7f\u7528\u5916\u90e8\u51fd\u6570\uff1a<\/p>\n<pre>$result = my_function(1, 2);\necho $result;<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u96c6\u6210 Stripe API<\/strong><\/p>\n<p>\u8003\u8651\u4e00\u4e2a\u4f7f\u7528 Stripe API \u5904\u7406\u652f\u4ed8\u7684 PHP \u5e94\u7528\u7a0b\u5e8f\u3002\u8981\u96c6\u6210 Stripe API\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5 <code>stripe-php<\/code> Composer \u5305\uff1a<\/p>\n<pre>composer require stripe\/stripe-php<\/pre>\n<\/li>\n<li>\n<p>\u5728\u60a8\u7684 PHP \u811a\u672c\u4e2d\uff0c\u4f7f\u7528 <code>extension_load()<\/code> \u51fd\u6570\u52a0\u8f7d Stripe \u6269\u5c55\uff1a<\/p>\n<pre>extension_load('stripe.so');<\/pre>\n<\/li>\n<li>\n<p>\u5f15\u5165 <code>Stripe<\/code> \u547d\u540d\u7a7a\u95f4\u5e76\u521d\u59cb\u5316 Stripe \u5ba2\u6237\u673a\uff1a<\/p>\n<pre>use Stripe\\Stripe;\n\nStripe::setApiKey('YOUR_STRIPE_API_KEY');<\/pre>\n<\/li>\n<li>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Stripe \u5e93\u4e2d\u7684\u65b9\u6cd5\u4e0e Stripe API \u8fdb\u884c\u4ea4\u4e92\uff1a<\/p>\n<pre>$charge = Stripe\\Charge::create([\n \"amount\" =&gt; 1000,\n \"currency\" =&gt; \"usd\",\n \"source\" =&gt; \"tok_123456789\",\n \"description\" =&gt; \"Example charge\"\n]);<\/pre>\n<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u4f7f\u7528\u51fd\u6570\u6269\u5c55\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06 API \u96c6\u6210\u5230\u60a8\u7684 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4ece\u800c\u8282\u7701\u5f00\u53d1\u65f6\u95f4\u548c\u7cbe\u529b\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8ephp,API\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210\uff1f \u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300a\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210\uff1f\u300b\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 PHP \u51fd\u6570\u6269\u5c55\u53ef\u96c6\u6210 API\uff0c\u65e0\u9700\u4fee\u6539 PHP \u6838\u5fc3\u3002\u521b\u5efa\u6269\u5c55\u6587\u4ef6\uff0c\u7f16\u8bd1\u5e76\u5b89\u88c5\u5b83\u3002\u5728 PHP \u811a\u672c\u4e2d\u52a0\u8f7d\u6269\u5c55\uff0c\u5373\u53ef\u4f7f\u7528\u5916\u90e8\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u96c6\u6210 Stripe API\uff1a\u5b89\u88c5 Composer \u5305\uff0c\u52a0\u8f7d\u6269\u5c55\uff0c\u521d\u59cb\u5316 Stripe \u5ba2\u6237\u673a\uff0c\u5373\u53ef\u4f7f\u7528 Stripe \u5e93\u4e0e API \u4ea4\u4e92\u3002\u51fd\u6570\u6269\u5c55\u4fbf\u4e8e API \u96c6\u6210\uff0c\u8282\u7701\u5f00\u53d1\u65f6\u95f4\u548c\u7cbe\u529b\u3002 \u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c API \u96c6\u6210 \u7b80\u4ecb PHP \u51fd\u6570\u6269\u5c55\u5141\u8bb8\u60a8\u5c06\u5916\u90e8\u5e93\u7684\u529f\u80fd\u5f15\u5165 PHP \u5e94\u7528\u7a0b\u5e8f\u3002\u901a\u8fc7\u4f7f\u7528\u51fd\u6570\u6269\u5c55\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u96c6\u6210\u7b2c\u4e09\u65b9 API\uff0c\u800c\u65e0\u9700\u4fee\u6539 PHP \u6838\u5fc3\u3002 \u521b\u5efa\u6269\u5c55 \u9996\u5148\uff0c\u60a8\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\u7684\u6269\u5c55\u6587\u4ef6\uff08\u6269\u5c55\u540d\u4e3a .so\uff09\uff1a &lt;?php \/\/ \u5b9a\u4e49\u6269\u5c55\u540d extension_name = &#8220;my_extension&#8221;; \/\/ \u5b9a\u4e49\u5916\u90e8\u51fd\u6570\u7684\u58f0\u660e extern int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48000","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48000","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=48000"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48000\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}