## OpenAPI
### 概述
`OpenAPI` 集成了各类第三方的 SDK。
### 安装
```
pip3 install openapipy
```
### 使用
#### 支付宝
> https://opendocs.alipay.com/open/270/105898
```python3
from openapi.providers.alipay import Client, Result
client = Client(
app_id='2016081500252288',
app_private_key_path='./resources/app_private_test2',
app_cert_public_key_path='./resources/appCertPublicKey_2016081500252288_test.crt',
alipay_root_cert_path='./resources/alipayRootCert_test.crt',
alipay_cert_public_key_path='./resources/alipayCertPublicKey_RSA2_test.crt',
is_sandbox=True
)
pc_pay_params = client.build_query_params(client.build_params(
'alipay.trade.page.pay',
{
'subject': 'popmart-molly',
'out_trade_no': 'pc123456',
'total_amount': '999.99',
'product_code': 'FAST_INSTANT_TRADE_PAY'
},
notify_url='http://47.94.172.250:9527/api/v1/pay/alipay/',
return_url='http://47.94.172.250:9527/api/v1/pay/alipay/'
))
pc_pay_url = f'{client.API_BASE_URL}?{pc_pay_params}'
print(pc_pay_url)
result: Result = client.request(
'get', 'alipay.trade.query',
params={
'out_trade_no': 'pc123456',
# 'trade_no': ''
}
)
print(result)
```
#### 微信
```python3
import json
from openapi.providers.wechat.pay import Client
wxpay_api = Client(
app_id='app_id',
mch_id='mch_id',
api_key_path='api_key_path',
is_sandbox=False
)
# 查询订单
result = wxpay_api.request(
'post', '/pay/orderquery',
data={
# 'out_trade_no': '9wfafGR31rCytY68wSFcXCII',
'transaction_id': '4200001591202211145504991626'
}
)
print(result)
data = {
'body': '米诺地尔町',
'out_trade_no': '1232112359910',
'total_fee': 1,
'spbill_create_ip': '127.0.0.1',
'notify_url': 'htt',
'trade_type': 'NATIVE',
'attach': json.dumps({'x': 1})
}
# 创建订单 -> pc
result = wxpay_api.request('post', '/pay/unifiedorder', data=data)
print(result)
# 创建订单 -> h5
data.update(trade_type='MWEB', out_trade_no='1231asd1222')
result = wxpay_api.request('post', '/pay/unifiedorder', data=data)
print(result)
# 创建订单 -> jsapi, 微信内
data.update(trade_type='JSAPI', out_trade_no='21321asd12311313', openid='ofwIAuEgpTZZwdPc1aort93xO')
result = wxpay_api.request('post', '/pay/unifiedorder', data=data)
print(result)
if result.result_code == wxpay_api.codes.SUCCESS:
jsapi_data = wxpay_api.get_jsapi_data(result.data['prepay_id'])
print(jsapi_data)
```
#### 抖店
> https://op.jinritemai.com/docs/api-docs/13/54
```python3
from openapi.providers.doudian import Client as DouDianClient, Result
client = DouDianClient('your_appid', 'your_secret', 'your_shop_id')
# 获取商品列表
result: Result = client.request('post', '/product/listV2', data={'page': 1, 'size': 10})
print(result)
```
#### 小鹅通
> https://api-doc.xiaoe-tech.com/?s=/2&page_id=420
```python3
from openapi.providers.xiaoetong import Client as XiaoetongClient, Result
client = XiaoetongClient('your_appid', 'your_secret', 'your_client_id')
# 获取分销人列表
result: Result = client.request('post', '/xe.distributor.list.get/1.0.0', data={})
print(result)
```
### 支持
```
2022 By ZhichaoLiu.
```
Raw data
{
"_id": null,
"home_page": "https://github.com/luffy-genius/openapi",
"name": "openapipy",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "openapi,openapi-python,python-openapi,openapipy,pyopenapi",
"author": "ZhiChaoLiu",
"author_email": "liuzhichao9527@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/35/6c/13d6ba06d232bc5240ea285b7326ad55b513ff141e6bb8ef4d6038eb8ab1/openapipy-0.10.0.tar.gz",
"platform": null,
"description": "## OpenAPI\n\n### \u6982\u8ff0\n\n`OpenAPI` \u96c6\u6210\u4e86\u5404\u7c7b\u7b2c\u4e09\u65b9\u7684 SDK\u3002\n\n### \u5b89\u88c5\n\n```\npip3 install openapipy\n```\n\n### \u4f7f\u7528\n\n#### \u652f\u4ed8\u5b9d\n\n> https://opendocs.alipay.com/open/270/105898\n\n```python3\nfrom openapi.providers.alipay import Client, Result\nclient = Client(\n app_id='2016081500252288',\n app_private_key_path='./resources/app_private_test2',\n app_cert_public_key_path='./resources/appCertPublicKey_2016081500252288_test.crt',\n alipay_root_cert_path='./resources/alipayRootCert_test.crt',\n alipay_cert_public_key_path='./resources/alipayCertPublicKey_RSA2_test.crt',\n is_sandbox=True\n)\n\npc_pay_params = client.build_query_params(client.build_params(\n 'alipay.trade.page.pay',\n {\n 'subject': 'popmart-molly',\n 'out_trade_no': 'pc123456',\n 'total_amount': '999.99',\n 'product_code': 'FAST_INSTANT_TRADE_PAY'\n },\n notify_url='http://47.94.172.250:9527/api/v1/pay/alipay/',\n return_url='http://47.94.172.250:9527/api/v1/pay/alipay/'\n))\npc_pay_url = f'{client.API_BASE_URL}?{pc_pay_params}'\nprint(pc_pay_url)\n\nresult: Result = client.request(\n 'get', 'alipay.trade.query',\n params={\n 'out_trade_no': 'pc123456',\n # 'trade_no': ''\n }\n)\nprint(result)\n```\n\n#### \u5fae\u4fe1\n\n```python3\nimport json\n\nfrom openapi.providers.wechat.pay import Client\n\nwxpay_api = Client(\n app_id='app_id',\n mch_id='mch_id',\n api_key_path='api_key_path',\n is_sandbox=False\n)\n\n# \u67e5\u8be2\u8ba2\u5355\nresult = wxpay_api.request(\n 'post', '/pay/orderquery',\n data={\n # 'out_trade_no': '9wfafGR31rCytY68wSFcXCII',\n 'transaction_id': '4200001591202211145504991626'\n }\n)\nprint(result)\n\ndata = {\n 'body': '\u7c73\u8bfa\u5730\u5c14\u753a',\n 'out_trade_no': '1232112359910',\n 'total_fee': 1,\n 'spbill_create_ip': '127.0.0.1',\n 'notify_url': 'htt',\n 'trade_type': 'NATIVE',\n 'attach': json.dumps({'x': 1})\n}\n\n# \u521b\u5efa\u8ba2\u5355 -> pc\nresult = wxpay_api.request('post', '/pay/unifiedorder', data=data)\nprint(result)\n\n# \u521b\u5efa\u8ba2\u5355 -> h5\ndata.update(trade_type='MWEB', out_trade_no='1231asd1222')\nresult = wxpay_api.request('post', '/pay/unifiedorder', data=data)\nprint(result)\n\n# \u521b\u5efa\u8ba2\u5355 -> jsapi, \u5fae\u4fe1\u5185\ndata.update(trade_type='JSAPI', out_trade_no='21321asd12311313', openid='ofwIAuEgpTZZwdPc1aort93xO')\nresult = wxpay_api.request('post', '/pay/unifiedorder', data=data)\nprint(result)\nif result.result_code == wxpay_api.codes.SUCCESS:\n jsapi_data = wxpay_api.get_jsapi_data(result.data['prepay_id'])\n print(jsapi_data)\n```\n\n#### \u6296\u5e97\n\n> https://op.jinritemai.com/docs/api-docs/13/54\n\n```python3\nfrom openapi.providers.doudian import Client as DouDianClient, Result\n\nclient = DouDianClient('your_appid', 'your_secret', 'your_shop_id')\n# \u83b7\u53d6\u5546\u54c1\u5217\u8868\nresult: Result = client.request('post', '/product/listV2', data={'page': 1, 'size': 10})\nprint(result)\n```\n\n#### \u5c0f\u9e45\u901a\n\n> https://api-doc.xiaoe-tech.com/?s=/2&page_id=420\n\n```python3\nfrom openapi.providers.xiaoetong import Client as XiaoetongClient, Result\n\nclient = XiaoetongClient('your_appid', 'your_secret', 'your_client_id')\n# \u83b7\u53d6\u5206\u9500\u4eba\u5217\u8868\nresult: Result = client.request('post', '/xe.distributor.list.get/1.0.0', data={})\nprint(result)\n```\n\n### \u652f\u6301\n\n```\n2022 By ZhichaoLiu.\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "openapi tools",
"version": "0.10.0",
"project_urls": {
"Homepage": "https://github.com/luffy-genius/openapi"
},
"split_keywords": [
"openapi",
"openapi-python",
"python-openapi",
"openapipy",
"pyopenapi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "356c13d6ba06d232bc5240ea285b7326ad55b513ff141e6bb8ef4d6038eb8ab1",
"md5": "1e10c1c120ae54c36b6a7d131a7ca714",
"sha256": "db2fe6410632e495555f94a9f5607c6b6297f62e6e496043aa35ac42469f13e3"
},
"downloads": -1,
"filename": "openapipy-0.10.0.tar.gz",
"has_sig": false,
"md5_digest": "1e10c1c120ae54c36b6a7d131a7ca714",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 30993,
"upload_time": "2023-12-24T04:32:38",
"upload_time_iso_8601": "2023-12-24T04:32:38.640288Z",
"url": "https://files.pythonhosted.org/packages/35/6c/13d6ba06d232bc5240ea285b7326ad55b513ff141e6bb8ef4d6038eb8ab1/openapipy-0.10.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-24 04:32:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "luffy-genius",
"github_project": "openapi",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "openapipy"
}