{"id":1062092,"date":"2024-12-31T15:48:45","date_gmt":"2024-12-31T07:48:45","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1062092.html"},"modified":"2024-12-31T15:48:47","modified_gmt":"2024-12-31T07:48:47","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e5%be%ae%e4%bf%a1%e6%94%af%e4%bb%98%e5%ae%9d","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1062092.html","title":{"rendered":"\u5982\u4f55\u7528python\u5fae\u4fe1\u652f\u4ed8\u5b9d"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/97e430cd-cb80-4596-9834-2ba3332e18a4.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u7528python\u5fae\u4fe1\u652f\u4ed8\u5b9d\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u4e0e\u5fae\u4fe1\u652f\u4ed8\u5b9d\u8fdb\u884c\u652f\u4ed8\uff1a\u9009\u62e9\u5408\u9002\u7684\u652f\u4ed8\u63a5\u53e3\u3001\u4f7f\u7528\u5bf9\u5e94\u7684SDK\u3001\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\u7684\u5b8c\u6574\u6d41\u7a0b\u3001\u5904\u7406\u652f\u4ed8\u56de\u8c03<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u73b0\u4ee3\u7535\u5b50\u5546\u52a1\u4e2d\uff0c\u96c6\u6210\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u652f\u4ed8\u529f\u80fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4f7f\u7528Python\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u5b9e\u73b0\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u652f\u4ed8\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u9009\u62e9\u5408\u9002\u7684\u652f\u4ed8\u63a5\u53e3<\/p>\n<\/p>\n<p><p>\u8981\u96c6\u6210\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u7684\u652f\u4ed8\u529f\u80fd\uff0c\u9996\u5148\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u652f\u4ed8\u63a5\u53e3\u3002\u5fae\u4fe1\u652f\u4ed8\u548c\u652f\u4ed8\u5b9d\u90fd\u63d0\u4f9b\u4e86\u591a\u79cd\u652f\u4ed8\u63a5\u53e3\uff0c\u5305\u62ec\u7f51\u9875\u7248\u652f\u4ed8\u3001\u626b\u7801\u652f\u4ed8\u3001App\u652f\u4ed8\u7b49\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u652f\u4ed8\u63a5\u53e3\u3002<\/p>\n<\/p>\n<p><h3>\u5fae\u4fe1\u652f\u4ed8<\/h3>\n<\/p>\n<p><p>\u5fae\u4fe1\u652f\u4ed8\u63d0\u4f9b\u4e86\u591a\u79cd\u652f\u4ed8\u65b9\u5f0f\uff0c\u5305\u62ecJSAPI\u652f\u4ed8\u3001Native\u652f\u4ed8\u3001App\u652f\u4ed8\u7b49\u3002JSAPI\u652f\u4ed8\u9002\u7528\u4e8e\u7f51\u9875\u7aef\uff0cNative\u652f\u4ed8\u9002\u7528\u4e8e\u626b\u7801\u652f\u4ed8\uff0cApp\u652f\u4ed8\u9002\u7528\u4e8e\u79fb\u52a8\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u652f\u4ed8\u5b9d\u652f\u4ed8<\/h3>\n<\/p>\n<p><p>\u652f\u4ed8\u5b9d\u652f\u4ed8\u540c\u6837\u63d0\u4f9b\u4e86\u591a\u79cd\u652f\u4ed8\u65b9\u5f0f\uff0c\u5305\u62ec\u7535\u8111\u7f51\u7ad9\u652f\u4ed8\u3001\u624b\u673a\u7f51\u7ad9\u652f\u4ed8\u3001App\u652f\u4ed8\u7b49\u3002\u6839\u636e\u4e1a\u52a1\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u652f\u4ed8\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5bf9\u5e94\u7684SDK<\/p>\n<\/p>\n<p><p>\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u5b98\u65b9\u5747\u63d0\u4f9b\u4e86\u5bf9\u5e94\u7684Python SDK\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u96c6\u6210\u652f\u4ed8\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u5fae\u4fe1\u652f\u4ed8SDK<\/h3>\n<\/p>\n<p><p>\u5fae\u4fe1\u652f\u4ed8\u63d0\u4f9b\u4e86\u5b98\u65b9\u7684Python SDK\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u5fae\u4fe1\u652f\u4ed8\u5b98\u65b9\u6587\u6863\u83b7\u53d6\u3002\u5b89\u88c5\u5fae\u4fe1\u652f\u4ed8SDK\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install wechatpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u652f\u4ed8\u5b9d\u652f\u4ed8SDK<\/h3>\n<\/p>\n<p><p>\u652f\u4ed8\u5b9d\u652f\u4ed8\u4e5f\u63d0\u4f9b\u4e86\u5b98\u65b9\u7684Python SDK\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u652f\u4ed8\u5b9d\u5f00\u53d1\u8005\u5e73\u53f0\u83b7\u53d6\u3002\u5b89\u88c5\u652f\u4ed8\u5b9d\u652f\u4ed8SDK\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install alipay-sdk-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\u7684\u5b8c\u6574\u6d41\u7a0b<\/p>\n<\/p>\n<p><h3>\u5fae\u4fe1\u652f\u4ed8<\/h3>\n<\/p>\n<ol>\n<li>\u914d\u7f6e\u5fae\u4fe1\u652f\u4ed8\u53c2\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from wechatpy import WeChatPay<\/p>\n<p>app_id = &#39;your_app_id&#39;<\/p>\n<p>mch_id = &#39;your_mch_id&#39;<\/p>\n<p>api_key = &#39;your_api_key&#39;<\/p>\n<p>pay = WeChatPay(app_id, mch_id, api_key)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u751f\u6210\u652f\u4ed8\u8ba2\u5355<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">order = {<\/p>\n<p>    &#39;body&#39;: &#39;Test Order&#39;,<\/p>\n<p>    &#39;out_trade_no&#39;: &#39;201803010001&#39;,<\/p>\n<p>    &#39;total_fee&#39;: 100,<\/p>\n<p>    &#39;spbill_create_ip&#39;: &#39;127.0.0.1&#39;,<\/p>\n<p>    &#39;notify_url&#39;: &#39;https:\/\/your_notify_url.com&#39;,<\/p>\n<p>    &#39;trade_type&#39;: &#39;JSAPI&#39;,<\/p>\n<p>    &#39;openid&#39;: &#39;user_openid&#39;,<\/p>\n<p>}<\/p>\n<p>result = pay.order.create(order)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u83b7\u53d6\u652f\u4ed8\u53c2\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">jsapi_params = pay.jsapi.get_jsapi_params(result[&#39;prepay_id&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u524d\u7aef\u4f7f\u7528\u83b7\u53d6\u7684\u652f\u4ed8\u53c2\u6570\u8c03\u7528\u5fae\u4fe1\u652f\u4ed8<\/li>\n<\/ol>\n<p><h3>\u652f\u4ed8\u5b9d\u652f\u4ed8<\/h3>\n<\/p>\n<ol>\n<li>\u914d\u7f6e\u652f\u4ed8\u5b9d\u652f\u4ed8\u53c2\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from alipay import AliPay<\/p>\n<p>app_id = &#39;your_app_id&#39;<\/p>\n<p>private_key_path = &#39;\/path\/to\/your\/private_key.pem&#39;<\/p>\n<p>alipay_public_key_path = &#39;\/path\/to\/alipay_public_key.pem&#39;<\/p>\n<p>alipay = AliPay(<\/p>\n<p>    appid=app_id,<\/p>\n<p>    app_private_key_path=private_key_path,<\/p>\n<p>    alipay_public_key_path=alipay_public_key_path,<\/p>\n<p>    sign_type=&#39;RSA2&#39;<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u751f\u6210\u652f\u4ed8\u8ba2\u5355<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">order_string = alipay.api_alipay_trade_page_pay(<\/p>\n<p>    out_trade_no=&#39;201803010001&#39;,<\/p>\n<p>    total_amount=100.00,<\/p>\n<p>    subject=&#39;Test Order&#39;,<\/p>\n<p>    return_url=&#39;https:\/\/your_return_url.com&#39;,<\/p>\n<p>    notify_url=&#39;https:\/\/your_notify_url.com&#39;<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u524d\u7aef\u8df3\u8f6c\u5230\u652f\u4ed8\u5b9d\u652f\u4ed8\u9875\u9762<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">pay_url = &#39;https:\/\/openapi.alipay.com\/gateway.do?&#39; + order_string<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u5904\u7406\u652f\u4ed8\u56de\u8c03<\/p>\n<\/p>\n<p><p>\u652f\u4ed8\u6210\u529f\u540e\uff0c\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u4f1a\u901a\u8fc7\u56de\u8c03\u63a5\u53e3\u901a\u77e5\u670d\u52a1\u5668\u652f\u4ed8\u7ed3\u679c\u3002\u5f00\u53d1\u8005\u9700\u8981\u5b9e\u73b0\u56de\u8c03\u63a5\u53e3\u6765\u5904\u7406\u652f\u4ed8\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u5fae\u4fe1\u652f\u4ed8\u56de\u8c03<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request<\/p>\n<p>from wechatpy.pay import WeChatPay<\/p>\n<p>from wechatpy.pay import WeChatPayException<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>pay = WeChatPay(app_id, mch_id, api_key)<\/p>\n<p>@app.route(&#39;\/wechat_notify&#39;, methods=[&#39;POST&#39;])<\/p>\n<p>def wechat_notify():<\/p>\n<p>    try:<\/p>\n<p>        data = pay.parse_payment_result(request.data)<\/p>\n<p>        if data[&#39;result_code&#39;] == &#39;SUCCESS&#39;:<\/p>\n<p>            # \u5904\u7406\u652f\u4ed8\u6210\u529f\u903b\u8f91<\/p>\n<p>            return &#39;success&#39;<\/p>\n<p>    except WeChatPayException as e:<\/p>\n<p>        # \u5904\u7406\u652f\u4ed8\u5931\u8d25\u903b\u8f91<\/p>\n<p>        return &#39;f<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>l&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u652f\u4ed8\u5b9d\u652f\u4ed8\u56de\u8c03<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request<\/p>\n<p>from alipay import AliPay<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>alipay = AliPay(<\/p>\n<p>    appid=app_id,<\/p>\n<p>    app_private_key_path=private_key_path,<\/p>\n<p>    alipay_public_key_path=alipay_public_key_path,<\/p>\n<p>    sign_type=&#39;RSA2&#39;<\/p>\n<p>)<\/p>\n<p>@app.route(&#39;\/alipay_notify&#39;, methods=[&#39;POST&#39;])<\/p>\n<p>def alipay_notify():<\/p>\n<p>    data = request.form.to_dict()<\/p>\n<p>    signature = data.pop(&#39;sign&#39;)<\/p>\n<p>    success = alipay.verify(data, signature)<\/p>\n<p>    if success:<\/p>\n<p>        # \u5904\u7406\u652f\u4ed8\u6210\u529f\u903b\u8f91<\/p>\n<p>        return &#39;success&#39;<\/p>\n<p>    else:<\/p>\n<p>        # \u5904\u7406\u652f\u4ed8\u5931\u8d25\u903b\u8f91<\/p>\n<p>        return &#39;fail&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528Python\u5b9e\u73b0\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u652f\u4ed8\u529f\u80fd\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u652f\u4ed8\u63a5\u53e3\uff0c\u4f7f\u7528\u5bf9\u5e94\u7684SDK\uff0c\u6309\u7167\u5b8c\u6574\u7684\u652f\u4ed8\u6d41\u7a0b\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\uff0c\u5e76\u5904\u7406\u652f\u4ed8\u56de\u8c03\u3002\u8fd9\u6837\u5373\u53ef\u5728\u5e94\u7528\u4e2d\u96c6\u6210\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u652f\u4ed8\u529f\u80fd\uff0c\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u548c\u652f\u4ed8\u4fbf\u6377\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\u7684\u5b89\u5168\u6027<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\u65f6\uff0c\u5b89\u5168\u6027\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5f00\u53d1\u8005\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u5168\u5b58\u50a8\u5bc6\u94a5\u548c\u8bc1\u4e66<\/strong>\uff1a\u652f\u4ed8\u63a5\u53e3\u7684\u5bc6\u94a5\u548c\u8bc1\u4e66\u9700\u8981\u5b89\u5168\u5b58\u50a8\uff0c\u907f\u514d\u6cc4\u9732\u3002<\/li>\n<li><strong>\u4f7f\u7528HTTPS<\/strong>\uff1a\u652f\u4ed8\u63a5\u53e3\u7684\u56de\u8c03\u5730\u5740\u548c\u6240\u6709\u6d89\u53ca\u5230\u652f\u4ed8\u7684\u8bf7\u6c42\u90fd\u5e94\u4f7f\u7528HTTPS\uff0c\u786e\u4fdd\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u6570\u636e\u7b7e\u540d\u9a8c\u8bc1<\/strong>\uff1a\u652f\u4ed8\u56de\u8c03\u65f6\uff0c\u9700\u8981\u9a8c\u8bc1\u6570\u636e\u7b7e\u540d\uff0c\u786e\u4fdd\u56de\u8c03\u6570\u636e\u7684\u771f\u5b9e\u6027\u548c\u5b8c\u6574\u6027\u3002<\/li>\n<li><strong>\u9632\u6b62\u91cd\u590d\u652f\u4ed8<\/strong>\uff1a\u5728\u751f\u6210\u652f\u4ed8\u8ba2\u5355\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u8ba2\u5355\u53f7\u7684\u552f\u4e00\u6027\uff0c\u9632\u6b62\u91cd\u590d\u652f\u4ed8\u3002<\/li>\n<li><strong>\u5f02\u5e38\u5904\u7406<\/strong>\uff1a\u5728\u5904\u7406\u652f\u4ed8\u56de\u8c03\u65f6\uff0c\u9700\u8981\u5bf9\u5404\u79cd\u5f02\u5e38\u60c5\u51b5\u8fdb\u884c\u5904\u7406\uff0c\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\u548c\u6ce8\u610f\u4e8b\u9879\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528Python\u5b89\u5168\u3001\u7a33\u5b9a\u5730\u5b9e\u73b0\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u652f\u4ed8\u529f\u80fd\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u4fbf\u6377\u7684\u652f\u4ed8\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u5904\u7406\u652f\u4ed8\u9000\u6b3e<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7528\u6237\u53ef\u80fd\u9700\u8981\u7533\u8bf7\u9000\u6b3e\u3002\u5f00\u53d1\u8005\u9700\u8981\u5b9e\u73b0\u652f\u4ed8\u9000\u6b3e\u529f\u80fd\uff0c\u4ee5\u4fbf\u5904\u7406\u7528\u6237\u7684\u9000\u6b3e\u8bf7\u6c42\u3002<\/p>\n<\/p>\n<p><h3>\u5fae\u4fe1\u652f\u4ed8\u9000\u6b3e<\/h3>\n<\/p>\n<ol>\n<li>\u914d\u7f6e\u5fae\u4fe1\u652f\u4ed8\u53c2\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from wechatpy import WeChatPay<\/p>\n<p>app_id = &#39;your_app_id&#39;<\/p>\n<p>mch_id = &#39;your_mch_id&#39;<\/p>\n<p>api_key = &#39;your_api_key&#39;<\/p>\n<p>mch_cert = &#39;\/path\/to\/your\/apiclient_cert.pem&#39;<\/p>\n<p>mch_key = &#39;\/path\/to\/your\/apiclient_key.pem&#39;<\/p>\n<p>pay = WeChatPay(app_id, mch_id, api_key, mch_cert=mch_cert, mch_key=mch_key)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u7533\u8bf7\u9000\u6b3e<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">refund = {<\/p>\n<p>    &#39;out_trade_no&#39;: &#39;201803010001&#39;,<\/p>\n<p>    &#39;out_refund_no&#39;: &#39;201803010001_refund&#39;,<\/p>\n<p>    &#39;total_fee&#39;: 100,<\/p>\n<p>    &#39;refund_fee&#39;: 100,<\/p>\n<p>    &#39;refund_desc&#39;: &#39;Test Refund&#39;,<\/p>\n<p>}<\/p>\n<p>result = pay.refund.apply(refund)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u652f\u4ed8\u5b9d\u652f\u4ed8\u9000\u6b3e<\/h3>\n<\/p>\n<ol>\n<li>\u914d\u7f6e\u652f\u4ed8\u5b9d\u652f\u4ed8\u53c2\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from alipay import AliPay<\/p>\n<p>app_id = &#39;your_app_id&#39;<\/p>\n<p>private_key_path = &#39;\/path\/to\/your\/private_key.pem&#39;<\/p>\n<p>alipay_public_key_path = &#39;\/path\/to\/alipay_public_key.pem&#39;<\/p>\n<p>alipay = AliPay(<\/p>\n<p>    appid=app_id,<\/p>\n<p>    app_private_key_path=private_key_path,<\/p>\n<p>    alipay_public_key_path=alipay_public_key_path,<\/p>\n<p>    sign_type=&#39;RSA2&#39;<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u7533\u8bf7\u9000\u6b3e<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">refund = alipay.api_alipay_trade_refund(<\/p>\n<p>    out_trade_no=&#39;201803010001&#39;,<\/p>\n<p>    refund_amount=100.00,<\/p>\n<p>    refund_reason=&#39;Test Refund&#39;<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5b9e\u73b0\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u7684\u9000\u6b3e\u529f\u80fd\uff0c\u5904\u7406\u7528\u6237\u7684\u9000\u6b3e\u8bf7\u6c42\uff0c\u63d0\u5347\u7528\u6237\u6ee1\u610f\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u5904\u7406\u652f\u4ed8\u5bf9\u8d26<\/p>\n<\/p>\n<p><p>\u652f\u4ed8\u5bf9\u8d26\u662f\u4fdd\u969c\u652f\u4ed8\u7cfb\u7edf\u7a33\u5b9a\u8fd0\u884c\u7684\u91cd\u8981\u73af\u8282\uff0c\u5f00\u53d1\u8005\u9700\u8981\u5b9a\u671f\u8fdb\u884c\u652f\u4ed8\u5bf9\u8d26\uff0c\u786e\u4fdd\u652f\u4ed8\u6570\u636e\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u5fae\u4fe1\u652f\u4ed8\u5bf9\u8d26<\/h3>\n<\/p>\n<ol>\n<li>\u914d\u7f6e\u5fae\u4fe1\u652f\u4ed8\u53c2\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from wechatpy import WeChatPay<\/p>\n<p>app_id = &#39;your_app_id&#39;<\/p>\n<p>mch_id = &#39;your_mch_id&#39;<\/p>\n<p>api_key = &#39;your_api_key&#39;<\/p>\n<p>pay = WeChatPay(app_id, mch_id, api_key)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4e0b\u8f7d\u5bf9\u8d26\u5355<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">bill_date = &#39;20180301&#39;<\/p>\n<p>bill_type = &#39;ALL&#39;<\/p>\n<p>bill = pay.bill.download(bill_date, bill_type)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u652f\u4ed8\u5b9d\u652f\u4ed8\u5bf9\u8d26<\/h3>\n<\/p>\n<ol>\n<li>\u914d\u7f6e\u652f\u4ed8\u5b9d\u652f\u4ed8\u53c2\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from alipay import AliPay<\/p>\n<p>app_id = &#39;your_app_id&#39;<\/p>\n<p>private_key_path = &#39;\/path\/to\/your\/private_key.pem&#39;<\/p>\n<p>alipay_public_key_path = &#39;\/path\/to\/alipay_public_key.pem&#39;<\/p>\n<p>alipay = AliPay(<\/p>\n<p>    appid=app_id,<\/p>\n<p>    app_private_key_path=private_key_path,<\/p>\n<p>    alipay_public_key_path=alipay_public_key_path,<\/p>\n<p>    sign_type=&#39;RSA2&#39;<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4e0b\u8f7d\u5bf9\u8d26\u5355<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">bill_date = &#39;20180301&#39;<\/p>\n<p>bill_type = &#39;trade&#39;<\/p>\n<p>bill = alipay.api_alipay_data_dataservice_bill_downloadurl_query(<\/p>\n<p>    bill_date=bill_date,<\/p>\n<p>    bill_type=bill_type<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5b9e\u73b0\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u7684\u652f\u4ed8\u5bf9\u8d26\u529f\u80fd\uff0c\u786e\u4fdd\u652f\u4ed8\u6570\u636e\u7684\u51c6\u786e\u6027\u548c\u5b8c\u6574\u6027\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528Python\u5b9e\u73b0\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u652f\u4ed8\u529f\u80fd\uff0c\u5e76\u5904\u7406\u652f\u4ed8\u56de\u8c03\u3001\u9000\u6b3e\u548c\u5bf9\u8d26\u7b49\u64cd\u4f5c\u3002\u96c6\u6210\u652f\u4ed8\u529f\u80fd\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5b89\u5168\u6027\uff0c\u786e\u4fdd\u652f\u4ed8\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002\u901a\u8fc7\u5408\u7406\u7684\u5b9e\u73b0\u548c\u4f18\u5316\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u4fbf\u6377\u3001\u5b89\u5168\u7684\u652f\u4ed8\u4f53\u9a8c\uff0c\u63d0\u5347\u7528\u6237\u6ee1\u610f\u5ea6\u548c\u4e1a\u52a1\u7ade\u4e89\u529b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u4e0e\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u8fdb\u884c\u652f\u4ed8\u96c6\u6210\uff1f<\/strong><br \/>\u8981\u5b9e\u73b0\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u7684\u652f\u4ed8\u96c6\u6210\uff0c\u60a8\u9700\u8981\u4e86\u89e3\u5404\u81ea\u7684API\u63a5\u53e3\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0a\u6ce8\u518c\u5f00\u53d1\u8005\u8d26\u53f7\u5e76\u7533\u8bf7\u76f8\u5e94\u7684API\u5bc6\u94a5\u3002\u63a5\u7740\uff0c\u4f7f\u7528Python\u7684requests\u5e93\u6216\u5176\u4ed6HTTP\u5ba2\u6237\u7aef\u5e93\uff0c\u8c03\u7528\u8fd9\u4e9bAPI\u63a5\u53e3\uff0c\u4f20\u9012\u5fc5\u8981\u7684\u53c2\u6570\uff0c\u4f8b\u5982\u8ba2\u5355\u53f7\u3001\u91d1\u989d\u7b49\u3002\u786e\u4fdd\u5904\u7406\u597d\u56de\u8c03\u5730\u5740\uff0c\u4ee5\u4fbf\u5728\u652f\u4ed8\u5b8c\u6210\u540e\u63a5\u6536\u72b6\u6001\u901a\u77e5\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u7684\u652f\u4ed8\u56de\u8c03\uff1f<\/strong><br \/>\u63a5\u6536\u652f\u4ed8\u56de\u8c03\u7684\u5173\u952e\u5728\u4e8e\u8bbe\u7f6e\u4e00\u4e2a\u80fd\u591f\u5904\u7406HTTP\u8bf7\u6c42\u7684\u670d\u52a1\u7aef\u63a5\u53e3\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528Flask\u6216Django\u7b49\u6846\u67b6\u6765\u521b\u5efa\u8fd9\u4e2a\u63a5\u53e3\u3002\u5728\u6536\u5230\u56de\u8c03\u540e\uff0c\u60a8\u9700\u8981\u9a8c\u8bc1\u8bf7\u6c42\u7684\u5408\u6cd5\u6027\uff0c\u4f8b\u5982\u68c0\u67e5\u7b7e\u540d\u662f\u5426\u6b63\u786e\u3002\u5b8c\u6210\u9a8c\u8bc1\u540e\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u652f\u4ed8\u7ed3\u679c\u66f4\u65b0\u8ba2\u5355\u72b6\u6001\uff0c\u5e76\u8fd4\u56de\u76f8\u5e94\u7684HTTP\u54cd\u5e94\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528Python\u8fdb\u884c\u5fae\u4fe1\u548c\u652f\u4ed8\u5b9d\u652f\u4ed8\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u5b89\u5168\u6027\u95ee\u9898\uff1f<\/strong><br \/>\u5b89\u5168\u6027\u662f\u652f\u4ed8\u7cfb\u7edf\u4e2d\u6700\u91cd\u8981\u7684\u4e00\u73af\u3002\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u5728\u670d\u52a1\u5668\u4e0a\u4f7f\u7528HTTPS\u534f\u8bae\u6765\u52a0\u5bc6\u6570\u636e\u4f20\u8f93\u3002\u5176\u6b21\uff0c\u52a1\u5fc5\u5bf9\u6240\u6709\u8f93\u5165\u8fdb\u884c\u4e25\u683c\u7684\u9a8c\u8bc1\uff0c\u4ee5\u9632\u6b62SQL\u6ce8\u5165\u6216XSS\u653b\u51fb\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u66f4\u65b0\u60a8\u7684API\u5bc6\u94a5\uff0c\u76d1\u63a7\u652f\u4ed8\u8bb0\u5f55\uff0c\u4ee5\u53ca\u65f6\u53d1\u73b0\u5e76\u5904\u7406\u4efb\u4f55\u5f02\u5e38\u60c5\u51b5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u4e0e\u5fae\u4fe1\u652f\u4ed8\u5b9d\u8fdb\u884c\u652f\u4ed8\uff1a\u9009\u62e9\u5408\u9002\u7684\u652f\u4ed8\u63a5\u53e3\u3001\u4f7f\u7528\u5bf9\u5e94\u7684SDK\u3001\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\u7684\u5b8c\u6574\u6d41\u7a0b\u3001\u5904\u7406\u652f\u4ed8\u56de [&hellip;]","protected":false},"author":3,"featured_media":1062099,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1062092"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1062092"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1062092\/revisions"}],"predecessor-version":[{"id":1062103,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1062092\/revisions\/1062103"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1062099"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1062092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1062092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1062092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}