Skip to content

Commit

Permalink
more simple way to get string to be signed
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng committed Oct 1, 2018
1 parent e8ebb20 commit 0be81bd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions alipay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,21 @@ def _verify_and_return_sync_response(self, raw_string, response_type):

def _get_string_to_be_signed(self, raw_string, response_type):
"""
https://doc.open.alipay.com/docs/doc.htm?docType=1&articleId=106120
https://docs.open.alipay.com/200/106120
从同步返回的接口里面找到待签名的字符串
"""
count, start = 0, raw_string.find("{", raw_string.find(response_type))
balance = 0
start = end = raw_string.find("{", raw_string.find(response_type))
# 从response_type之后的第一个{的下一位开始匹配,
# 如果是{则count加1; 如果是}而且count=0,就是待验签字符串的终点
# 如果是{则balance加1; 如果是}而且balance=0,就是待验签字符串的终点
for i, c in enumerate(raw_string[start + 1 :], start + 1):
if c == "{":
count += 1
balance += 1
elif c == "}":
if count == 0:
if balance == 0:
end = i + 1
break
count -= 1
balance -= 1
return raw_string[start:end]


Expand Down

0 comments on commit 0be81bd

Please sign in to comment.