Skip to content

Commit

Permalink
Fix some typos.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-binbin authored and fzlee committed May 24, 2021
1 parent 1b249e6 commit 1488fd4
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 164 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ ENV/
# Rope project settings
.ropeproject


# OSX stuff
.DS_Store


# local project folder
localtest/
.idea
.vscode
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![PyPI version](https://badge.fury.io/py/python-alipay-sdk.svg)](https://badge.fury.io/py/python-alipay-sdk) [![codecov](https://codecov.io/gh/fzlee/alipay/branch/master/graph/badge.svg)](https://codecov.io/gh/fzlee/alipay) ![travis-ci](https://travis-ci.org/fzlee/alipay.svg?branch=master)
## [中文文档](./README.zh-hans.md)

## Unofficial AliPay Python SDK
## Unofficial AliPay Python SDK

Taking a look at [this guide](https://ifconfiger.com/page/python-alipay-sdk) if you are interested at the details on signing your order requests.

Expand All @@ -12,20 +12,17 @@ Taking a look at [this guide](https://ifconfiger.com/page/python-alipay-sdk) if
* [API](./docs/apis.md)
* [Advanced API, introduced in 3.0](./docs/apis_new.md)


## What's new in 3.0 and how to migrate to 3.0
3.0 introduced two new functions: `client_api` and `server_appi` as a replacement of old-styled function based api .


3.0 keeps backward compability with 2.*, The only thing you should keep in mind is `Alipay.verify` won't pop `sign` from `data` automatically, you should handle it by yourself.

3.0 keeps backward compatibility with 2.*, The only thing you should keep in mind is `Alipay.verify` won't pop `sign` from `data` automatically, you should handle it by yourself.

## Test
```
```bash
python -m unittest discover
```

Or you may do test manually in this way, `debug=True` will direct your request to sandbox environment:
```
```python
alipay = AliPay(..., debug=True)
```
17 changes: 9 additions & 8 deletions README.zh-hans.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
## python-alipay-sdk
[![PyPI version](https://badge.fury.io/py/python-alipay-sdk.svg)](https://badge.fury.io/py/python-alipay-sdk) [![codecov](https://codecov.io/gh/fzlee/alipay/branch/master/graph/badge.svg)](https://codecov.io/gh/fzlee/alipay) ![travis-ci](https://travis-ci.org/fzlee/alipay.svg?branch=master)
## [English document](./README.md)

## 非官方支付宝 Python SDK
## 非官方支付宝 Python SDK

关于签名的详细实现细节参看[这篇教程](https://ifconfiger.com/page/python-alipay-sdk). 如果你不希望深入了解技术实现的细节,你可以直接阅读下面的使用教程。
关于签名的详细实现细节参看[这篇教程](https://ifconfiger.com/page/python-alipay-sdk)如果你不希望深入了解技术实现的细节,你可以直接阅读下面的使用教程。

## 使用教程
* [准备](./docs/preparation.zh-hans.md)
* [初始化](./docs/init.zh-hans.md)
* [接口](./docs/apis.zh-hans.md)
* [3.0新版接口](./docs/apis_new.zh-hans.md)
* [3.0 新版接口](./docs/apis_new.zh-hans.md)

## 3.0的特性以及如何升级
3.0 提供了两个函数`client_api``server_api`, 他们可以处理大部分支付宝的接口.
## 3.0 的特性以及如何升级
3.0 提供了两个函数 `client_api``server_api`他们可以处理大部分支付宝的接口

3.0 保持向前的兼容性, 唯一需要注意的是`Alipay.verify`函数不会将sign从data里面pop出来, 你需要自己处理.
3.0 保持向前的兼容性唯一需要注意的是 `Alipay.verify` 函数不会将 `sign``data` 里面 `pop` 出来,你需要自己处理。

## 测试
```
```bash
python -m unittest discover
```

或者你可以传入debug=True, 进行手动测试
或者你可以传入 `debug=True`进行手动测试
```python
alipay = AliPay(..., debug=True)
```
1 change: 0 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
"""
__inti__.py
~~~~~~~~~~
"""
152 changes: 74 additions & 78 deletions alipay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
__init__.py
~~~~~~~~~~
"""
import json
from datetime import datetime
Expand Down Expand Up @@ -66,9 +65,9 @@ def __init__(
"""
初始化:
alipay = AliPay(
appid="",
app_notify_url="http://example.com",
sign_type="RSA2"
appid="",
app_notify_url="http://example.com",
sign_type="RSA2"
)
"""
self._appid = str(appid)
Expand Down Expand Up @@ -108,17 +107,16 @@ def _sign(self, unsigned_string):
方法1
key = rsa.PrivateKey.load_pkcs1(open(self._app_private_key_string).read())
sign = rsa.sign(unsigned_string.encode(), key, "SHA-1")
# base64 编码,转换为unicode表示并移除回车
# base64 编码,转换为 unicode 表示并移除回车
sign = base64.encodebytes(sign).decode().replace("\n", "")
方法2
key = RSA.importKey(open(self._app_private_key_string).read())
signer = PKCS1_v1_5.new(key)
signature = signer.sign(SHA.new(unsigned_string.encode()))
# base64 编码,转换为unicode表示并移除回车
# base64 编码,转换为 unicode 表示并移除回车
sign = base64.encodebytes(signature).decode().replace("\n", "")
方法3
echo "abc" | openssl sha1 -sign alipay.key | openssl base64
"""
# 开始计算签名
key = self.app_private_key
Expand All @@ -127,7 +125,7 @@ def _sign(self, unsigned_string):
signature = signer.sign(SHA.new(unsigned_string.encode()))
else:
signature = signer.sign(SHA256.new(unsigned_string.encode()))
# base64 编码,转换为unicode表示并移除回车
# base64 编码,转换为 unicode 表示并移除回车
sign = encodebytes(signature).decode().replace("\n", "")
return sign

Expand Down Expand Up @@ -267,29 +265,29 @@ def api_alipay_trade_page_pay(self, subject, out_trade_no, total_amount,
def api_alipay_trade_query(self, out_trade_no=None, trade_no=None):
"""
response = {
"alipay_trade_query_response": {
"trade_no": "2017032121001004070200176844",
"code": "10000",
"invoice_amount": "20.00",
"open_id": "20880072506750308812798160715407",
"fund_bill_list": [
{
"amount": "20.00",
"fund_channel": "ALIPAYACCOUNT"
}
],
"buyer_logon_id": "csq***@sandbox.com",
"send_pay_date": "2017-03-21 13:29:17",
"receipt_amount": "20.00",
"out_trade_no": "out_trade_no15",
"buyer_pay_amount": "20.00",
"buyer_user_id": "2088102169481075",
"msg": "Success",
"point_amount": "0.00",
"trade_status": "TRADE_SUCCESS",
"total_amount": "20.00"
},
"sign": ""
"alipay_trade_query_response": {
"trade_no": "2017032121001004070200176844",
"code": "10000",
"invoice_amount": "20.00",
"open_id": "20880072506750308812798160715407",
"fund_bill_list": [
{
"amount": "20.00",
"fund_channel": "ALIPAYACCOUNT"
}
],
"buyer_logon_id": "csq***@sandbox.com",
"send_pay_date": "2017-03-21 13:29:17",
"receipt_amount": "20.00",
"out_trade_no": "out_trade_no15",
"buyer_pay_amount": "20.00",
"buyer_user_id": "2088102169481075",
"msg": "Success",
"point_amount": "0.00",
"trade_status": "TRADE_SUCCESS",
"total_amount": "20.00"
},
"sign": ""
}
"""
assert (out_trade_no is not None) or (trade_no is not None),\
Expand Down Expand Up @@ -331,18 +329,17 @@ def api_alipay_trade_pay(
},
"sign": ""
}
succeeded response =
{
"alipay_trade_pay_response": {
succeeded response = {
"alipay_trade_pay_response": {
"trade_no": "2017032121001004070200176846",
"code": "10000",
"invoice_amount": "20.00",
"open_id": "20880072506750308812798160715407",
"fund_bill_list": [
{
"amount": "20.00",
"fund_channel": "ALIPAYACCOUNT"
}
{
"amount": "20.00",
"fund_channel": "ALIPAYACCOUNT"
}
],
"buyer_logon_id": "csq***@sandbox.com",
"receipt_amount": "20.00",
Expand All @@ -353,9 +350,9 @@ def api_alipay_trade_pay(
"point_amount": "0.00",
"gmt_payment": "2017-03-21 15:07:29",
"total_amount": "20.00"
},
"sign": ""
}
},
"sign": ""
}
"""
assert scene in ("bar_code", "wave_code"), 'scene not in ("bar_code", "wave_code")'

Expand Down Expand Up @@ -387,12 +384,12 @@ def api_alipay_trade_refund(self, refund_amount, out_trade_no=None, trade_no=Non
def api_alipay_trade_cancel(self, out_trade_no=None, trade_no=None):
"""
response = {
"alipay_trade_cancel_response": {
"msg": "Success",
"out_trade_no": "out_trade_no15",
"code": "10000",
"retry_flag": "N"
}
"alipay_trade_cancel_response": {
"msg": "Success",
"out_trade_no": "out_trade_no15",
"code": "10000",
"retry_flag": "N"
}
}
"""

Expand Down Expand Up @@ -453,26 +450,26 @@ def api_alipay_trade_precreate(
self, subject, out_trade_no, total_amount, notify_url=None, **kwargs
):
"""
success response = {
"alipay_trade_precreate_response": {
"msg": "Success",
"out_trade_no": "out_trade_no17",
"code": "10000",
"qr_code": "https://qr.alipay.com/bax03431ljhokirwl38f00a7"
},
"sign": ""
success response = {
"alipay_trade_precreate_response": {
"msg": "Success",
"out_trade_no": "out_trade_no17",
"code": "10000",
"qr_code": "https://qr.alipay.com/bax03431ljhokirwl38f00a7"
},
"sign": ""
}
failed response = {
"alipay_trade_precreate_response": {
"msg": "Business Failed",
"sub_code": "ACQ.TOTAL_FEE_EXCEED",
"code": "40004",
"sub_msg": "订单金额超过限额"
},
"sign": ""
"alipay_trade_precreate_response": {
"msg": "Business Failed",
"sub_code": "ACQ.TOTAL_FEE_EXCEED",
"code": "40004",
"sub_msg": "订单金额超过限额"
},
"sign": ""
}
"""
biz_content = {
"out_trade_no": out_trade_no,
Expand Down Expand Up @@ -569,16 +566,15 @@ def _verify_and_return_sync_response(self, raw_string, response_type):
failed response is like this
{
"alipay_trade_query_response": {
"sub_code": "isv.invalid-app-id",
"code": "40002",
"sub_msg": "无效的AppID参数",
"msg": "Invalid Arguments"
}
"alipay_trade_query_response": {
"sub_code": "isv.invalid-app-id",
"code": "40002",
"sub_msg": "无效的AppID参数",
"msg": "Invalid Arguments"
}
}
"""
response = json.loads(raw_string)
# raise exceptions
if "sign" not in response.keys():
result = response[response_type]
raise AliPayException(
Expand Down Expand Up @@ -824,14 +820,14 @@ def build_body(self, *args, **kwargs):
def api_alipay_open_auth_token_app(self, refresh_token=None):
"""
response = {
"code": "10000",
"msg": "Success",
"app_auth_token": "201708BB28623ce3d10f4f62875e9ef5cbeebX07",
"app_refresh_token": "201708BB108a270d8bb6409890d16175a04a7X07",
"auth_app_id": "appid",
"expires_in": 31536000,
"re_expires_in": 32140800,
"user_id": "2088xxxxx
"code": "10000",
"msg": "Success",
"app_auth_token": "201708BB28623ce3d10f4f62875e9ef5cbeebX07",
"app_refresh_token": "201708BB108a270d8bb6409890d16175a04a7X07",
"auth_app_id": "appid",
"expires_in": 31536000,
"re_expires_in": 32140800,
"user_id": "2088xxxxx
}
"""

Expand Down
1 change: 0 additions & 1 deletion alipay/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
compat.py
~~~~~~~~~~
"""
from urllib.parse import quote_plus
from urllib.request import urlopen
Expand Down
1 change: 0 additions & 1 deletion alipay/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
exceptions.py
~~~~~~~~~~
"""


Expand Down
2 changes: 1 addition & 1 deletion alipay/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
alipay/utils.py
~~~~~~~~~~
"""


class AliPayConfig:
def __init__(self, timeout=15):
self.timeout = timeout
Loading

0 comments on commit 1488fd4

Please sign in to comment.