{"id":13609851,"url":"https://github.com/lxneng/alipay","last_synced_at":"2025-04-12T22:31:59.669Z","repository":{"id":11761763,"uuid":"14295746","full_name":"lxneng/alipay","owner":"lxneng","description":"An Unofficial Alipay API for Python","archived":false,"fork":false,"pushed_at":"2017-11-22T10:18:39.000Z","size":69,"stargazers_count":326,"open_issues_count":0,"forks_count":94,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-03-20T01:04:14.404Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lxneng.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-11T08:51:07.000Z","updated_at":"2024-02-07T17:47:47.000Z","dependencies_parsed_at":"2022-09-26T18:01:51.370Z","dependency_job_id":null,"html_url":"https://github.com/lxneng/alipay","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxneng%2Falipay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxneng%2Falipay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxneng%2Falipay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxneng%2Falipay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lxneng","download_url":"https://codeload.github.com/lxneng/alipay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248640764,"owners_count":21138092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T19:01:38.673Z","updated_at":"2025-04-12T22:31:59.231Z","avatar_url":"https://github.com/lxneng.png","language":"Python","funding_links":[],"categories":["E-commerce","资源列表","Python","电子商务","E-commerce [🔝](#readme)","Awesome Python"],"sub_categories":["电子商务","E-commerce"],"readme":"An Unofficial Alipay API for Python\n=======================================\n\n.. image:: https://img.shields.io/travis/lxneng/alipay.svg\n    :target: https://travis-ci.org/lxneng/alipay\n\n.. image:: https://img.shields.io/pypi/v/alipay.svg\n    :target: https://pypi.python.org/pypi/alipay/\n\n.. image:: https://img.shields.io/pypi/dm/alipay.svg\n    :target: https://pypi.python.org/pypi/alipay/\n\nOverview\n---------------------------------------\n\nAn Unofficial Alipay API for Python, It Contain these API:\n\n- Generate direct payment url\n- Generate partner trade payment url\n- Generate standard mixed payment url\n- Generate batch trans pay url\n- Generate send goods confirm url\n- Generate forex trade url\n- Generate QR code url\n- Verify notify\n- Single Trade Query\n- Generate Refund With Pwd URL\n\nofficial document: https://b.alipay.com/order/techService.htm\n\nInstall\n---------------------------------------\n\n.. code-block:: bash\n\n    pip install alipay\n\nUsage\n---------------------------------------\n\nInitialization\n~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from alipay import Alipay\n    \u003e\u003e\u003e alipay = Alipay(pid='your_alipay_pid', key='your_alipay_key', seller_email='your_seller_mail')\n\nOr you can use `seller_id` instead of `seller_email`:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e alipay = Alipay(pid='your_alipay_pid', key='your_alipay_key', seller_id='your_seller_id')\n\n\nGenerate direct payment url\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n..\n\n    生成即时到账支付链接\n\nIntroduction: https://b.alipay.com/order/productDetail.htm?productId=2012111200373124\n\n.. code-block:: python\n\n\t\u003e\u003e\u003e alipay.create_direct_pay_by_user_url(out_trade_no='your_order_id', subject='your_order_subject', total_fee='100.0', return_url='your_order\n\t_return_url', notify_url='your_order_notify_url')\n\t'https://mapi.alipay.com/gateway.do?seller_email=.....'\n\nGenerate partner trade payment url\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n..\n\n    生成担保交易支付链接\n\nIntroduction: https://b.alipay.com/order/productDetail.htm?productId=2012111200373121\n\n.. code-block:: python\n\n\t\u003e\u003e\u003e params = {\n\t... 'out_trade_no': 'your_order_id',\n\t... 'subject': 'your_order_subject',\n\t... 'logistics_type': 'DIRECT',\n\t... 'logistics_fee': '0',\n\t... 'logistics_payment': 'SELLER_PAY',\n\t... 'price': '10.00',\n\t... 'quantity': '12',\n\t... 'return_url': 'your_order_return_url',\n\t... 'notify_url': 'your_order_notify_url'\n\t... }\n\t\u003e\u003e\u003e alipay.create_partner_trade_by_buyer_url(**params)\n\t'https://mapi.alipay.com/gateway.do?seller_email=.....'\n\nGenerate standard mixed payment url\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n..\n\n    生成标准双接口支付链接\n\nIntroduction: https://b.alipay.com/order/productDetail.htm?productId=2012111300373136\n\n.. code-block:: python\n\n    \u003e\u003e\u003e alipay.trade_create_by_buyer_url(**params)\n    'https://mapi.alipay.com/gateway.do?seller_email=.....'\n\nGenerate batch trans pay url\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n..\n\n    生成批量付款链接\n\nIntroduction: https://b.alipay.com/order/productDetail.htm?productId=2012111200373121\n\n.. code-block:: python\n\n\t\u003e\u003e\u003e params = {\n\t... 'batch_list': (), #批量付款用户列表\n\t... 'account_name': 'seller_account_name', #卖家支付宝名称\n\t... 'batch_no': 'batch_id', #转账流水号，须唯一\n\t... 'notify_url': 'your_batch_notify_url' #异步通知地址\n\t... }\n\t\u003e\u003e\u003e alipay.create_batch_trans_notify_url(**params)\n\t'https://mapi.alipay.com/gateway.do?seller_email=xxx\u0026detail_data=....'\n\nNote: batch_list 为批量付款用户列表，具体格式如下例子：(如涉及中文请使用unicode字符)\n\n.. code-block:: python\n\n\t\u003e\u003e\u003e batch_list = ({'account': 'test@xxx.com', #支付宝账号\n\t...                'name': u'测试', #支付宝用户姓名\n\t...                'fee': '100', #转账金额\n\t...                'note': 'test'},\n\t...               {'account': 'test@xxx.com', #支付宝账号\n\t...                'name': u'测试', #支付宝用户姓名\n\t...                'fee': '100', #转账金额\n\t...                'note': 'test'}) #转账原因\n\nGenerate send goods confirm url\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n..\n\n    生成确认发货链接\n\nIntroduction: https://cshall.alipay.com/support/help_detail.htm?help_id=491097\n\n.. code-block:: python\n\n    \u003e\u003e\u003e params = {\n    ... 'trade_no': 'your_alipay_trade_id',\n    ... 'logistics_name': 'your_logicstic_name',\n    ... 'transport_type': 'EXPRESS',\n    ... 'invocie_no': 'your_invocie_no'\n    ... }\n    \u003e\u003e\u003e alipay.send_goods_confirm_by_platform(**params)\n    'https://mapi.alipay.com/gateway.do?sign=.....\u0026trade_no=...'\n\nGenerate forex trade url\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n..\n\n    - Create website payment for foreigners (With QR code)\n    - Create mobile payment for foreigners\n\nIntroduction: http://global.alipay.com/ospay/home.htm\n\n.. code-block:: python\n\n    \u003e\u003e\u003e params = {\n    ... 'out_trade_no': 'your_order_id',\n    ... 'subject': 'your_order_subject',\n    ... 'logistics_type': 'DIRECT',\n    ... 'logistics_fee': '0',\n    ... 'logistics_payment': 'SELLER_PAY',\n    ... 'price': '10.00',\n    ... 'quantity': '12',\n    ... 'return_url': 'your_order_return_url',\n    ... 'notify_url': 'your_order_notify_url'\n    ... }\n    \u003e\u003e\u003e # Create website payment for foreigners\n    \u003e\u003e\u003e alipay.create_forex_trade_url(**params)\n    'https://mapi.alipay.com/gateway.do?service=create_forex_trade......'\n    \u003e\u003e\u003e # Create mobile payment for foreigners\n    \u003e\u003e\u003e alipay.create_forex_trade_wap_url(**params)\n    'https://mapi.alipay.com/gateway.do?service=create_forex_trade_wap......'\n\n\nGenerate QR code url\n~~~~~~~~~~~~~~~~~~~\n\n..\n\n    生成创建 QR 码链接\n\nIntroduction: https://b.alipay.com/order/productDetail.htm?productId=2012120700377303\n\n.. code-block:: python\n\n    \u003e\u003e\u003e alipay.add_alipay_qrcode_url(**params)\n    'https://mapi.alipay.com/gateway.do?seller_id=.......'\n\nNote: 如果你的 `biz_data` 中有 Unicode 字符，在 dumps 的时候需要把 `ensure_ascii` 设置为 `False`，即 :code:`json.dumps(d, ensure_ascii=False)` 否则会遇到错误\n\n\nVerify notify\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nverify notify from alipay server, example in Pyramid Application\n\n.. code-block:: python\n\n    def alipy_notify(request):\n        alipay = request.registry['alipay']\n        if alipay.verify_notify(**request.params):\n            # this is a valid notify, code business logic here\n        else:\n            # this is a invalid notify\n\n\nSingle Trade Query\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n..\n\n    单笔交易查询\n\n文档：http://wenku.baidu.com/link?url=WLjyz-H6AlfDLIU7kR4LcVNQgxSTMxX61fW0tDCE8yZbqXflCd0CVFsZaIKbRFDvVLaFlq0Q3wcJ935A7Kw-mRSs0iA4wQu8cLaCe5B8FIq\n\n.. code-block:: python\n\n\timport re\n\txml = alipay.single_trade_query(out_trade_no=\"10000005\")\n\tres = re.findall('\u003ctrade_status\u003e(\\S+)\u003c/trade_status\u003e', xml) # use RE to find trade_status, xml parsing is more useful, in fact.\n\tstatus = None if not res else res[0]\n\tprint status # will print out TRADE_SUCCESS when trade is success\n\nGenerate Refund With Pwd URL\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n..\n\n    生成即时到账有密退款链接\n\nIntroduction: https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.XRddqH\u0026treeId=62\u0026articleId=104744\u0026docType=1\n\n.. code-block:: python\n\n    \u003e\u003e\u003e params = {\n    ... 'batch_list': (), #批量退款数据集\n    ... 'batch_no': 'batch_id', #退款批次号，须唯一\n    ... 'notify_url': 'your_batch_notify_url' #异步通知地址\n    ... }\n    \u003e\u003e\u003e alipay.refund_fastpay_by_platform_pwd(**params)\n    'https://mapi.alipay.com/gateway.do?seller_email=xxx\u0026detail_data=....'\n\nNote: batch_list 为批量退款数据集，具体格式如下例子：(如涉及中文请使用unicode字符)\n\n.. code-block:: python\n\n    \u003e\u003e\u003e batch_list = ({'trade_no': 'xxxxxxxx', #原付款支付宝交易号\n    ...                'fee': '100', #退款总金额\n    ...                'note': 'test'}, #退款原因\n    ...               {'trade_no': 'xxxxxxxx', #原付款支付宝交易号\n    ...                'fee': '100', #退款总金额\n    ...                'note': 'test'}) #退款原因\n\nExample in Pyramid Application\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nInclude alipay either by setting your includes in your .ini, or by calling config.include('alipay').\n\n.. code-block:: python\n\n\tpyramid.includes = alipay\n\nnow in your View\n\n.. code-block:: python\n\n    def some_view(request):\n        alipay = request.registry['alipay']\n        url = alipay.create_direct_pay_by_user_url(...)\n\n\nReference\n---------------------------------------\n\n- `Ruby Alipay GEM \u003chttps://github.com/chloerei/alipay\u003e`_\n- `Official document \u003chttps://b.alipay.com/order/techService.htm\u003e`_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxneng%2Falipay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flxneng%2Falipay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxneng%2Falipay/lists"}