Comments (26)
可以把部分代码贴上来看看吗?
from alipay.
from alipay.
证书必须是配置到pem文件里边 然后读文件么?
from alipay.
from alipay.
APP_PRIVATE_KEY = '''-----BEGIN RSA PRIVATE KEY-----
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-----END RSA PRIVATE KEY-----
'''
ALIPAY_PUBLIC_KEY = '''-----BEGIN PUBLIC KEY-----
XXXXXXXXXXXXXXXXXXXXX
-----END PUBLIC KEY-----
'''
我的两个key 直接配置在python文件中,出了问题,调用verify 这个api 验签是false
from alipay.
from alipay.
不是吧,我把后台从asp 移植到python asp用的也是这两个key
asp 就是官网的asp demo
from alipay.
大神 我qq 3031393421 能加我一下么?
from alipay.
from alipay.
import json
from datetime import datetime
from Crypto.Signature import PKCS1_v1_5 as PKCS
from Crypto.Hash import SHA, SHA256
from Crypto.PublicKey import RSA
from urllib import quote_plus
from urllib2 import urlopen
import urlparse
import base64
import logging
import AliConfig
import TradeManager
import ThirdBuild
class BaseAliPay(object):
def __init__(self, appid, app_notify_url, sign_type="RSA2", debug=False):
self.appid = str(appid)
self.app_notify_url = app_notify_url
self.app_private_key = RSA.importKey(AliConfig.APP_PRIVATE_KEY)
self.alipay_public_key = RSA.importKey(AliConfig.ALIPAY_PUBLIC_KEY)
self.sign_type = sign_type
if debug:
self.gateway = "https://openapi.alipaydev.com/gateway.do"
else:
self.gateway = "https://openapi.alipay.com/gateway.do"
logging.debug("app_notify_url=%s sign_type=%s debug=%d",app_notify_url,sign_type,debug)
def u(self,s):
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
def b(self,s):
return s
def sign(self, unsigned_string):
key = self.app_private_key
signer = PKCS.new(key)
if self.sign_type == "RSA":
signature = signer.sign(SHA.new(unsigned_string))
else:
signature = signer.sign(SHA256.new(unsigned_string))
# base64 编码,转换为unicode表示并移除回车
sign = base64.encodestring(signature).decode("utf8").replace("\n", "")
return sign
def ordered_data(self, data):
complex_keys = []
for key, value in data.items():
if isinstance(value, dict):
complex_keys.append(key)
# 将字典类型的数据dump出来
for key in complex_keys:
data[key] = json.dumps(data[key], separators=(',', ':'))
return sorted([(k, v) for k, v in data.items()])
def build_body(self, method, biz_content, return_url=None, notify_url=None, append_auth_token=False):
data = {
"app_id": self.appid,
"method": method,
"charset": "utf-8",
"sign_type": self.sign_type,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"version": "1.0",
"biz_content": biz_content
}
if append_auth_token:
data["app_auth_token"] = self.app_auth_token
if return_url is not None:
data["return_url"] = return_url
methods = ("alipay.trade.app.pay", "alipay.trade.wap.pay", "alipay.trade.page.pay","alipay.trade.pay", "alipay.trade.precreate")
if method in methods:
if self.app_notify_url is not None:
data["notify_url"] = self.app_notify_url
if notify_url is not None:
data["notify_url"] = notify_url
pass
return data
def sign_data(self, data):
data.pop("sign", None)
# 排序后的字符串
unsigned_items = self.ordered_data(data)
unsigned_string = "&".join("{}={}".format(k, v) for k, v in unsigned_items)
sign = self.sign(unsigned_string)
logging.debug("#################################################################")
logging.debug("sign_data unsigned_string=%s",unsigned_string)
logging.debug("sign_data sign=%s",sign)
logging.debug("#################################################################")
ordered_items = self.ordered_data(data)
quoted_string = "&".join("{}={}".format(k, quote_plus(v)) for k, v in ordered_items)
# 获得最终的订单信息字符串
signed_string = quoted_string + "&sign=" + quote_plus(sign)
return signed_string
def _verify(self, raw_content, signature):
# 开始计算签名
key = self.alipay_public_key
signer = PKCS.new(key)
if self.sign_type == "RSA":
digest = SHA.new()
else:
digest = SHA256.new()
digest.update(raw_content.encode("utf8"))
if signer.verify(digest, base64.decodestring(signature.encode("utf8"))):
return True
return False
def verify(self, data, signature):
if "sign_type" in data:
sign_type = data.pop("sign_type")
if sign_type != self.sign_type:
logging.debug("Unknown sign type: %s",sign_type)
# 排序后的字符串
unsigned_items = self.ordered_data(data)
message = "&".join(u"{}={}".format(k, v) for k, v in unsigned_items)
sign = self.sign(message)
logging.debug("verify message=%s",message)
logging.debug("verify sign=%s",sign)
return self._verify(message, signature)
#手机网页支付接口
def api_alipay_trade_wap_pay(self,subject, out_trade_no, total_amount,return_url=None, notify_url=None, **kwargs):
biz_content = {
"subject": subject,
"out_trade_no": out_trade_no,
"total_amount": total_amount,
"product_code": "QUICK_WAP_PAY"
}
biz_content.update(kwargs)
data = self.build_body("alipay.trade.wap.pay",biz_content,return_url=return_url,notify_url=notify_url)
return self.sign_data(data)
def api_alipay_trade_app_pay(self, subject, out_trade_no, total_amount, notify_url=None, **kwargs):
biz_content = {
"subject": subject,
"out_trade_no": out_trade_no,
"total_amount": total_amount,
"product_code": "QUICK_MSECURITY_PAY"
}
biz_content.update(kwargs)
data = self.build_body("alipay.trade.app.pay", biz_content, notify_url=notify_url)
return self.sign_data(data)
def api_alipay_trade_page_pay(self, subject, out_trade_no, total_amount,return_url=None, notify_url=None, **kwargs):
biz_content = {
"subject": subject,
"out_trade_no": out_trade_no,
"total_amount": total_amount,
"product_code": "FAST_INSTANT_TRADE_PAY"
}
biz_content.update(kwargs)
data = self.build_body("alipay.trade.page.pay",biz_content,return_url=return_url,notify_url=notify_url)
return self.sign_data(data)
#交易状态查询接口
def api_alipay_trade_query(self, out_trade_no=None, trade_no=None):
assert (out_trade_no is not None) or (trade_no is not None),"Both trade_no and out_trade_no are None"
biz_content = {}
if out_trade_no:
biz_content["out_trade_no"] = out_trade_no
if trade_no:
biz_content["trade_no"] = trade_no
data = self.build_body("alipay.trade.query", biz_content)
url = self.gateway + "?" + self.sign_data(data)
raw_string = urlopen(url, timeout=15).read().decode("utf-8")
return self._verify_and_return_sync_response(raw_string, "alipay_trade_query_response")
#退款查询
def api_alipay_trade_fastpay_refund_query(self, out_request_no, trade_no=None, out_trade_no=None):
assert (out_trade_no is not None) or (trade_no is not None),"Both trade_no and out_trade_no are None"
biz_content = {"out_request_no": out_request_no}
if trade_no:
biz_content["trade_no"] = trade_no
else:
biz_content["out_trade_no"] = out_trade_no
data = self.build_body("alipay.trade.fastpay.refund.query", biz_content)
url = self.gateway + "?" + self.sign_data(data)
raw_string = urlopen(url, timeout=15).read().decode("utf-8")
return self._verify_and_return_sync_response(raw_string, "alipay_trade_fastpay_refund_query_response")
def api_alipay_fund_trans_toaccount_transfer(self, out_biz_no, payee_type, payee_account, amount, **kwargs):
assert payee_type in ("ALIPAY_USERID", "ALIPAY_LOGONID"), "unknown payee type"
biz_content = {
"out_biz_no": out_biz_no,
"payee_type": payee_type,
"payee_account": payee_account,
"amount": amount
}
biz_content.update(kwargs)
data = self.build_body("alipay.fund.trans.toaccount.transfer", biz_content)
url = self.gateway + "?" + self.sign_data(data)
raw_string = urlopen(url, timeout=15).read().decode("utf-8")
return self._verify_and_return_sync_response(raw_string, "alipay_fund_trans_toaccount_transfer_response")
#订单查询
def api_alipay_fund_trans_order_query(self, out_biz_no=None, order_id=None):
if out_biz_no is None and order_id is None:
raise Exception("Both out_biz_no and order_id are None!")
biz_content = {}
if out_biz_no:
biz_content["out_biz_no"] = out_biz_no
if order_id:
biz_content["order_id"] = order_id
data = self.build_body("alipay.fund.trans.order.query", biz_content)
url = self.gateway + "?" + self.sign_data(data)
raw_string = urlopen(url, timeout=15).read().decode("utf-8")
return self._verify_and_return_sync_response(raw_string, "alipay_fund_trans_order_query_response")
def _verify_and_return_sync_response(self, raw_string, response_type):
response = json.loads(raw_string)
result = response[response_type]
sign = response["sign"]
# locate string to be signed
raw_string = self._get_string_to_be_signed(raw_string, response_type)
if not self._verify(raw_string, sign):
logging.error("_verify_and_return_sync_response")
return result
def _get_string_to_be_signed(self, raw_string, response_type):
"""
https://doc.open.alipay.com/docs/doc.htm?docType=1&articleId=106120
从同步返回的接口里面找到待签名的字符串
"""
left_index = 0
right_index = 0
index = raw_string.find(response_type)
left_index = raw_string.find("{", index)
index = left_index + 1
balance = -1
while balance < 0 and index < len(raw_string) - 1:
index_a = raw_string.find("{", index)
index_b = raw_string.find("}", index)
# 右括号没找到, 退出
if index_b == -1:
break
right_index = index_b
# 左括号没找到,移动到右括号的位置
if index_a == -1:
index = index_b + 1
balance += 1
# 左括号出现在有括号之前,移动到左括号的位置
elif index_a > index_b:
balance += 1
index = index_b + 1
# 左括号出现在右括号之后, 移动到右括号的位置
else:
balance -= 1
index = index_a + 1
return raw_string[left_index: right_index + 1]
class AliPay(BaseAliPay):
def __init__(self,appid,app_notify_url,sign_type="RSA2", debug=False):
super(AliPay, self).__init__(appid, app_notify_url,sign_type, debug)
def pay(self):
pass
class AliGate(object):
def init(self):
self.paytype = 1
pass
def start(self):
TradeManager.instance.registerOrderHandler(self.paytype,self)
def stop(self):
TradeManager.instance.removeOrderHandler(self.paytype)
def onCreateOrderSuc(self,client, uid, tradeid,tradename,paytype, money, valueitems, orderid, ordertime):
logging.debug("uid=%d AliGate onCreateOrderSuc tradeid=%d money=%d valueitems=%s orderid=%d",uid,tradeid,money,valueitems,orderid)
appid = AliConfig.APP_ID
app_notify_url = AliConfig.APP_NOTIFY_URL
sign_type = AliConfig.SIGN_TYPE
debug = AliConfig.DEBUG
pay = AliPay(appid,app_notify_url,sign_type,debug)
sign = pay.api_alipay_trade_app_pay("aaaa",str(orderid),str(money))
logging.debug("uid=%d paytype=%d sign=%s signLen=%d",uid,self.paytype,sign,len(sign))
client.sendPacket(ThirdBuild.aliPay(tradeid,paytype,money,orderid,sign))
pass
instance = AliGate()
2018-01-24 16:55:26,416 DEBUG #################################################################
2018-01-24 16:55:26,416 DEBUG sign_data unsigned_string=app_id=2017062607569111&biz_content={"out_trade_no":"361","product_code":"QUICK_MSECURITY_PAY","total_amount":"1","subject":"aaaa"}&charset=u
tf-8&method=alipay.trade.app.pay¬ify_url=http://114.229.67.15:8088/billalipay?method=payResult&sign_type=RSA2×tamp=2018-01-24 16:55:26&version=1.0
2018-01-24 16:55:26,417 DEBUG sign_data sign=bRcPINPW1eCfD+FF+KNGunrcUXiqIWczY5qL6aaD8Cxh7R6XdaRvJByALnXOQ3zK9YVl+mxaEio+Efoq+oP+er6u7sYMmtXx57bmK15GOIGp+rrxIBtRY1zcq8eTTeyL1Q+ue6wpP3hmij3NnG39pbZn
cpOsdcOhEsFQZr4RK2MCWlMiFIJerOozgl/kC6TgPrOQn46OMpJ2l2ulYK/fMupMMjUix7Rz4nL+XJS+x6ZCesr1MsgGBrXR/oJTaj+DuI8hLikiY73xzf/SQc5vp1xFVW5cA/5gLgoraDWVsjvmUS88qIMvCki+wNSEMj9RKmJTFZf5v218o90sMfspCA==
2018-01-24 16:55:26,417 DEBUG #################################################################
2018-01-24 16:55:26,417 DEBUG uid=23898 paytype=1 sign=app_id=2017062607569111&biz_content=%7B%22out_trade_no%22%3A%22361%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A
%221%22%2C%22subject%22%3A%22aaaa%22%7D&charset=utf-8&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2F114.229.67.15%3A8088%2Fbillalipay%3Fmethod%3DpayResult&sign_type=RSA2×tamp=2018-01-24+
16%3A55%3A26&version=1.0&sign=bRcPINPW1eCfD%2BFF%2BKNGunrcUXiqIWczY5qL6aaD8Cxh7R6XdaRvJByALnXOQ3zK9YVl%2BmxaEio%2BEfoq%2BoP%2Ber6u7sYMmtXx57bmK15GOIGp%2BrrxIBtRY1zcq8eTTeyL1Q%2Bue6wpP3hmij3NnG39pbZ
ncpOsdcOhEsFQZr4RK2MCWlMiFIJerOozgl%2FkC6TgPrOQn46OMpJ2l2ulYK%2FfMupMMjUix7Rz4nL%2BXJS%2Bx6ZCesr1MsgGBrXR%2FoJTaj%2BDuI8hLikiY73xzf%2FSQc5vp1xFVW5cA%2F5gLgoraDWVsjvmUS88qIMvCki%2BwNSEMj9RKmJTFZf5v2
18o90sMfspCA%3D%3D signLen=751
from alipay.
我可能有点看不清楚你的代码逻辑。验证支付宝回传消息的代码是哪一段?
from alipay.
忘记说明了,我是python2环境
from alipay.
sign = pay.api_alipay_trade_app_pay("aaaa",str(orderid),str(money))
我把这个sign 传给客户端,客户端拉起支付宝 报错 ALI38173
from alipay.
你可以用我写的库,用同样的参数试试吗? 我暂时看不出问题所在
from alipay.
好的,谢谢
from alipay.
app_id=2017062607569111&biz_content={"out_trade_no":"362","product_code":"QUICK_MSECURITY_PAY","total_amount":"1","subject":"aaaa"}&charset=u
tf-8&method=alipay.trade.app.pay¬ify_url=http://114.229.67.15:8088/billalipay?method=payResult&sign_type=RSA2×tamp=2018-01-24 17:33:12&version=1.0
这串参数代码签出来的结果是
sign=aZkNr+dnca+Do5NTpcxn4Ph341+btTt/E/sRO4BVpWPWNRuXbZ+vtL1HjHiD0SiCVWDQxUqBDYXs7WTP4i+NReLl3lS8h77XmA4oGvN26C8Ddf0R56/SJYRWjV3hsezWEYzyyEathn/9n822vTRCp9vj
MaFUYq6JS6wSgw5ZYDAcyxiP6cd4+dvQmXU1zWodIXRM4V6sXAK9ADyEHqHfXrXGq3NceytK856YdvIJlQXVV/1F1zR4T405p+U29PbMNlACn1PvSXcId81Zu+VTtOYmGUMt526zGmnUd92mHa4pxhu57UYVcpFYuTzNKXWrpbpKgFcswkJLBvjj11ALzA==
quote_plus(sign)=aZkNr%2Bdnca%2BDo5NTpcxn4Ph341%2BbtTt%2FE%2FsRO4BVpWPWNRuXbZ%2BvtL1HjHiD0SiCVWDQxUqBDYXs7WTP4i%2BNReLl3lS8h77XmA4oGvN26C8Ddf0R56%2FSJYRWjV3h
sezWEYzyyEathn%2F9n822vTRCp9vjMaFUYq6JS6wSgw5ZYDAcyxiP6cd4%2BdvQmXU1zWodIXRM4V6sXAK9ADyEHqHfXrXGq3NceytK856YdvIJlQXVV%2F1F1zR4T405p%2BU29PbMNlACn1PvSXcId81Zu%2BVTtOYmGUMt526zGmnUd92mHa4pxhu57UYVcpF
YuTzNKXWrpbpKgFcswkJLBvjj11ALzA%3D%3D
阿里的工具签名的结果是
WT70Dh13BM0Lpl3NDgnMvs2HYT45FVeFyrtGIXROW0eb7wNEvwURIsAgEynTgkDtAqVNKSxACopLcYv22PTOCRSuJcm0Eg5tc/BUXNojmyjkxarh5s44zuZoXhJBgrlsRFdRel2FSjZtuUH6LePuoWEiIzSIuK+qqrHcbSwWnFRyPWu+WJAhqwTj4zHTDcUMw9gFIOs4quX9HW8xeu/7AiEjCqz7gbhrDU4MdmV3D5HhLs/okERjc+fhLuUnrZiLaQLC0np08MPJvHBnvYEM1c2BL+tanoOmkgsCiS6FbNd+dKOF3SDx7bcQXx6kN8EeRf28F9+24BDSyVGwn+3cRg==
工具签名出来的结果 跟上边哪个都不一样,好奇怪
from alipay.
这一串东西是有问题的。notify url需要转义
app_id=2017062607569111&biz_content={"out_trade_no":"362","product_code":"QUICK_MSECURITY_PAY","total_amount":"1","subject":"aaaa"}&charset=u
tf-8&method=alipay.trade.app.pay¬ify_url=http://114.229.67.15:8088/billalipay?method=payResult&sign_type=RSA2×tamp=2018-01-24 17:33:12&version=1.0
from alipay.
你的意思是 代码里边 notify_url 这个参数的值是要传转义之后的?
还是说我再用工具签名的时候 notify_url 要转义?
from alipay.
notify_url = http://114.229.67.15:8088/billalipay. 这样就够了,添加一个参数method=payResult 是没有意义的
from alipay.
notify_url 去掉method=payResult 而且转义了 还是报错 2个方式签名 还是不一样
app_id=2017062607569111&biz_content={"out_trade_no":"364","product_code":"QUICK_MSECURITY_PAY","total_amount":"1","subject":"aaaa"}&charset=u
tf-8&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2F114.229.67.15%3A8088%2Fbillalipay&sign_type=RSA2×tamp=2018-01-24 18:01:16&version=1.0
这串参数代码签出来的结果是
sign=ZndTXf+cc1vSP8l4XbT45VtzxObg6/SrLIbd/kjO/FqOHhilN+o7E0JV8OkCuvYDYRcI1gctMVa4wSYhGT2eaM1FF0yb/5EgtyaDaIvTPVGgarxrvh3pYIlvijxQFWWQlbeD/JGZBdTnJhglrph7aRqW
+g08TlztcCcWvL7lKYFwzU2xNjJ2MjPdu4FBOeA56XoGpbdNMH49mZUQvhQFv5Dc/97c8AVWEtItdjTaizTfBVicQZ+Tns108+jfQ/ZHSTFxqJtPU3sPeYupmgdVphpozRRsmumXpxbI6VpWs18TPbUI0R0MJKQxNyEK0fHVYXpLzwHnv8iCdpglMCAA9g==
quote_plus(sign)=ZndTXf%2Bcc1vSP8l4XbT45VtzxObg6%2FSrLIbd%2FkjO%2FFqOHhilN%2Bo7E0JV8OkCuvYDYRcI1gctMVa4wSYhGT2eaM1FF0yb%2F5EgtyaDaIvTPVGgarxrvh3pYIlvijxQFWWQ
lbeD%2FJGZBdTnJhglrph7aRqW%2Bg08TlztcCcWvL7lKYFwzU2xNjJ2MjPdu4FBOeA56XoGpbdNMH49mZUQvhQFv5Dc%2F97c8AVWEtItdjTaizTfBVicQZ%2BTns108%2BjfQ%2FZHSTFxqJtPU3sPeYupmgdVphpozRRsmumXpxbI6VpWs18TPbUI0R0MJKQxN
yEK0fHVYXpLzwHnv8iCdpglMCAA9g%3D%3D
阿里的工具签名的结果是
SqNwHZ+b4N6qeXIBH/ITN+a5bMWgxGHHNjGcKEYrRQbpZsL+RK3RymrQ7Owkwxi6RLTz0KmlQO9f4SFcE9euiMTpjDl5vqxSujostC00KfqUqQsbYjM9s2Tp5co35wTUWleHr2IIAAsNnXukvXzOipMRczcj5C7royhpinofZ2PA7WgWdXi6vArHZiQD9IxLoji9XbezRr2CDRf3JV0HhvSAQsqWEkQ0doduUJ3biXTyHX4ONndC/iroN1B3TVu8IlSzF+yLt4nfDhcAiMX1o6ZZzl0vw5B3VBhZ1t1yKBx5L13bR0oRYZLr38dn+NAqLKxIst2AXp/T0yf/vSaftA==
from alipay.
你是用的修改后的库还是直接用我的这个库签名的?
from alipay.
代码如下
def sign_data(self, data):
data.pop("sign", None)
# 排序后的字符串
unsigned_items = self._ordered_data(data)
unsigned_string = "&".join("{}={}".format(k, v) for k, v in unsigned_items)
print("##################################")
print("unsigned_string",unsigned_string)
print("#################################")
sign = self._sign(unsigned_string)
print("sign",sign)
print("#################################")
ordered_items = self._ordered_data(data)
quoted_string = "&".join("{}={}".format(k, quote_plus(v)) for k, v in ordered_items)
print("quoted_string",quoted_string)
print("#################################")
print("quote_plus(sign)",quote_plus(sign))
print("#################################")
# 获得最终的订单信息字符串
signed_string = quoted_string + "&sign=" + quote_plus(sign)
print("signed_string",signed_string)
print("#################################")
return signed_string
def main():
appid = AliConfig.APP_ID,
app_notify_url = AliConfig.APP_NOTIFY_URL,
app_private_key_string=AliConfig.APP_PRIVATE_KEY,
alipay_public_key_string=AliConfig.ALIPAY_PUBLIC_KEY,
pay = BaseAliPay(appid,app_notify_url,None,app_private_key_string,None,alipay_public_key_string)
end = pay.api_alipay_trade_app_pay("aaaa","364","1")
print("end",end)
##################################
('unsigned_string', 'app_id=2017062607569111&biz_content={"out_trade_no":"364","product_code":"QUICK_MSECURITY_PAY","total_amount":"1","subject":"aaaa"}&charset=utf-8&method=alipay.trade.app.pay&no
tify_url=http://114.229.67.15:8088/billalipay&sign_type=RSA2×tamp=2018-01-24 19:27:18&version=1.0')
#################################
('sign', u'YBrtmZPiaI8fzER2XjIqvO8IM50Z4LCzeG68BHoOCwIGJf0u9tlQ0Xy/6IuBwfKXDnL5m9kt8L44tnXV0+d7/rwdOC8H+0E9kvCljZMh+ic6K4kV3YR8uXno/bOJzF2bXka2J9X0U5vd8ijgb2ZnUEn/ukEv4A5HI+7c8IyV4PJ6r8bePdopN8Kv+J
xtVH5cQ+66cY68WGEue2A44cWOcYyf6KJhgCX0r+0xMvNeTvrX/tqHBg/duX5m+6zw2Jyni6ArcZlvAaU3SNxctfWocqEqeaCR66uYKEM7j5dsxlH32IiDl8/SHUWEdh8XwO1kxY2XE5Z6r5m4gbUMw4T0gQ==')
#################################
('quoted_string', 'app_id=2017062607569111&biz_content=%7B%22out_trade_no%22%3A%22364%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%221%22%2C%22subject%22%3A%22aaaa%22
%7D&charset=utf-8&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2F114.229.67.15%3A8088%2Fbillalipay&sign_type=RSA2×tamp=2018-01-24+19%3A27%3A18&version=1.0')
#################################
('quote_plus(sign)', 'YBrtmZPiaI8fzER2XjIqvO8IM50Z4LCzeG68BHoOCwIGJf0u9tlQ0Xy%2F6IuBwfKXDnL5m9kt8L44tnXV0%2Bd7%2FrwdOC8H%2B0E9kvCljZMh%2Bic6K4kV3YR8uXno%2FbOJzF2bXka2J9X0U5vd8ijgb2ZnUEn%2FukEv4A5HI
%2B7c8IyV4PJ6r8bePdopN8Kv%2BJxtVH5cQ%2B66cY68WGEue2A44cWOcYyf6KJhgCX0r%2B0xMvNeTvrX%2FtqHBg%2FduX5m%2B6zw2Jyni6ArcZlvAaU3SNxctfWocqEqeaCR66uYKEM7j5dsxlH32IiDl8%2FSHUWEdh8XwO1kxY2XE5Z6r5m4gbUMw4T0gQ
%3D%3D')
#################################
('signed_string', 'app_id=2017062607569111&biz_content=%7B%22out_trade_no%22%3A%22364%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%221%22%2C%22subject%22%3A%22aaaa%22
%7D&charset=utf-8&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2F114.229.67.15%3A8088%2Fbillalipay&sign_type=RSA2×tamp=2018-01-24+19%3A27%3A18&version=1.0&sign=YBrtmZPiaI8fzER2XjIqvO8IM50
Z4LCzeG68BHoOCwIGJf0u9tlQ0Xy%2F6IuBwfKXDnL5m9kt8L44tnXV0%2Bd7%2FrwdOC8H%2B0E9kvCljZMh%2Bic6K4kV3YR8uXno%2FbOJzF2bXka2J9X0U5vd8ijgb2ZnUEn%2FukEv4A5HI%2B7c8IyV4PJ6r8bePdopN8Kv%2BJxtVH5cQ%2B66cY68WGEu
e2A44cWOcYyf6KJhgCX0r%2B0xMvNeTvrX%2FtqHBg%2FduX5m%2B6zw2Jyni6ArcZlvAaU3SNxctfWocqEqeaCR66uYKEM7j5dsxlH32IiDl8%2FSHUWEdh8XwO1kxY2XE5Z6r5m4gbUMw4T0gQ%3D%3D')
#################################
('end', 'app_id=2017062607569111&biz_content=%7B%22out_trade_no%22%3A%22364%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%221%22%2C%22subject%22%3A%22aaaa%22%7D&charse
t=utf-8&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2F114.229.67.15%3A8088%2Fbillalipay&sign_type=RSA2×tamp=2018-01-24+19%3A27%3A18&version=1.0&sign=YBrtmZPiaI8fzER2XjIqvO8IM50Z4LCzeG68B
HoOCwIGJf0u9tlQ0Xy%2F6IuBwfKXDnL5m9kt8L44tnXV0%2Bd7%2FrwdOC8H%2B0E9kvCljZMh%2Bic6K4kV3YR8uXno%2FbOJzF2bXka2J9X0U5vd8ijgb2ZnUEn%2FukEv4A5HI%2B7c8IyV4PJ6r8bePdopN8Kv%2BJxtVH5cQ%2B66cY68WGEue2A44cWOcY
yf6KJhgCX0r%2B0xMvNeTvrX%2FtqHBg%2FduX5m%2B6zw2Jyni6ArcZlvAaU3SNxctfWocqEqeaCR66uYKEM7j5dsxlH32IiDl8%2FSHUWEdh8XwO1kxY2XE5Z6r5m4gbUMw4T0gQ%3D%3D')
root@jdu4e00u53f7:~/alipay-master#
app_id=2017062607569111&biz_content={"out_trade_no":"364","product_code":"QUICK_MSECURITY_PAY","total_amount":"1","subject":"aaaa"}&charset=utf-8&method=alipay.trade.app.pay&no
tify_url=http://114.229.67.15:8088/billalipay&sign_type=RSA2×tamp=2018-01-24 19:27:18&version=1.0
工具签名结果
hSl5jY/qR52yqk3oJs9opO8TpLr5Qo+Rfx7YRnweoZ0C+Lb6Wk8h1BZt2o+3ta7Dw1/TYadlplIigHNPK182ISZlQe4CxZR/SojrMU10CDhl91vAd7UlSmBr5BPMGk5OsogMSGiJKHLqQLGOGT+oRpp0chOOQg++Tlmh5Zjq4IO8jb+f8jyI8YNjJhFiWsyIkItUIrWazeirqSLDq7yasgVikKUYxAP1eBsbRoWAY6Qbf4WRfm7c9loz++Ha+vh91+RIyzCgs1T+1JvcJ4AjY6+KOkEJr3YlJ/dYm8+bZXWIm3ZAeipbvPfnGK54r6i9g7xCtjHHgewaeTQw/vWcHw==
参数转义后 工具签名
ChgNCPXBemSjWS4GIu35gWY47+BycuidsIoaBmqLFyg1wBihhCgFja7Yl1vFsJ/qVjx6I5eFGke4RbPPa5cpLMhjxELn/5mVowk3027GkdlztC+L0KgYgUE0Aco4GnC8Ln+roKkhRwfQyggpUQ7o+NRSSygwn52F2kADh/C0ZIpY8gmP5aCWmynhRNBtDKGTgdK5CZmSswluv2GL5BfYN61P2A+jwMCfgpvmsmO5bEFCKl7keve0OTkmJ+6FcbeGpTopEg15RP606KBkOyzafC1hFgN24kUBxzOlgQPUtMco7HtxAbZk8/EpkKS7g5dMkMtyuA8pdhZ++fSH84Vusg==
不管哪种 跟工具签名的结果都不一样
from alipay.
最近一次结果 是用的你的代码 我就加个main sign_data里边加日志
from alipay.
我想再确认一下,你现在遇到的问题是支付的时候报错ALI38173, 而不是签名错误吧?
支付宝有一个沙盒环境, 可以用作测试的。
我运行如下代码,可以正常支付没有问题, 因为我这边不好测试app的支付, 我调用的是网页支付接口。
所以这个ALI38173和签名应该不相关
private_key_string = open("certs/app_private_key.pem").read()
public_key_string = open("certs/ali_public_key.pem")
alipay = AliPay(
appid="20161011xxxxxxxx",
app_notify_url="http://114.229.67.15:8088/billalipay",
app_private_key_string=private_key_string,
alipay_public_key_string=public_key_string,
sign_type="RSA2", # RSA or RSA2
debug=True,
)
sign = alipay.api_alipay_trade_page_pay(
"aaaa", "364", "1"
)
print(sign)
from alipay.
我也是ALI38173错误,百思不得其解...检查了很多遍公匙,秘匙之类的。。还在探索中...也是APP支付这一块
from alipay.
请问楼主后来怎么解决的····
from alipay.
Related Issues (20)
- 支付宝公钥已经采用证书的形式,没有提供公钥这种形式,需要自己转换?请问有没有好的解放方案么?谢谢 HOT 3
- 添加支持 alipay.fund.account.query(支付宝资金账户资产查询接口) HOT 2
- alipay.api_alipay_trade_query(out_trade_no=order_id) HOT 4
- uwsgi 无法正常返回 HOT 6
- 验证回调通知错误 HOT 4
- 没有公网ip,怎么样验证支付是否成功 HOT 2
- 能否增加aes支持 HOT 2
- ImportError: cannot import name 'Alipay' from 'alipay'
- 使用支付宝公钥 初始化AliPay时报错 binascii.Error: Incorrect padding HOT 8
- ssl依赖该升级了 HOT 3
- 您好,请问支持分账吗? HOT 11
- 证书方式如何安装 HOT 30
- 是否支持证书方式的签名 HOT 10
- 应用网关是什么 HOT 3
- 3.0如何获取请求返回状态 HOT 10
- 获取用户信息怎么调用 HOT 9
- alipay支付网关已经变更了
- notify 回调消息验证失败 binascii.Error: Invalid base64-encoded string HOT 8
- ValueError: nameserver is not an IP address or valid https URL HOT 2
- 沙箱环境下调用失败(invalid-app-id)及其解决办法 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alipay.