fzlee / alipay Goto Github PK
View Code? Open in Web Editor NEWPython Alipay(支付宝) SDK with SHA1/SHA256 support
License: Other
Python Alipay(支付宝) SDK with SHA1/SHA256 support
License: Other
想确认个小问题。在alipay.verify过程中是不是已经考虑了证书的验证,如此的话原则上如果返回成功就能够相信得到的信息。 因为在官方的说明里面强调了除了验证sign,还要验证其他所有的信息。这使得我有点不放心。(https://openclub.alipay.com/read.php?tid=1314&fid=69&ant_source=zsearch)
抱歉实在麻烦作者了,有个问题想问一下,
如果app直接把支付宝返回的结果交给网站来做同步验签,请问能否使用这个sdk来完成。样例如下:
{'sign_type': 'RSA2', 'sign': 'Iril1rkvl7KUifMM0j7LyTgSMW/XnwnK7kVfVN42Gtvv+2dWpOUvEY8PEXavAldQIyL6YPg074BJema3s3ineer53X61AeXEPfnz6uHQHjDYSYf1AVn/uOfsCtRxdWRDlV4rPsf4ARTPlPf4rcTEcyTbsviPKi/dAvsN3mo1yBfZH2KX2qw6VGOAAqeinMLDf78reCWyp8KHPMBl1+iPDa2Bzg8l2U0rD5p/C+p+3Ou8tLHOEa0p+agjM11Z585yxctA/DdTgVgkPL0YeSv4zz6A/GAzmySzi61M5Clf/mXib3VdZrseObPNDW4hKtvfFXhIgU1egFdpbOZD7CCGIw==', 'alipay_trade_app_pay_response': {'charset': 'utf-8', 'msg': 'Success', 'seller_id': '2088821540881344', 'timestamp': '2018-04-24 01:48:58', 'out_trade_no': 'CO_322_0_1524505548', 'auth_app_id': '2017111409922946', 'code': '10000', 'trade_no': '2018042421001004700254850965', 'app_id': '2017111409922946', 'total_amount': '39.00'}}
读取了alipay_trade_app_pay_response是一个字典
如下:
order_string = alipay.create_web_trade(out_trade_no=o.order_no, total_amount=str(o.total_fee), subject=o.subject, return_url="http://pay.xxxx.com/alipay/sz_return_result/")
File "/usr/local/lib/python2.7/dist-packages/alipay/init.py", line 206, in create_web_trade
"&sign_type=" + self.__sign_type
File "/usr/local/lib/python2.7/dist-packages/alipay/init.py", line 209, in _sign_data
sign = self._sign_data_with_private_key(data, private_key_path)
File "/usr/local/lib/python2.7/dist-packages/alipay/init.py", line 138, in _sign_data_with_private_key
unsigned_string = "&".join("{}={}".format(k, v) for k, v in unsigned_items)
File "/usr/local/lib/python2.7/dist-packages/alipay/init.py", line 138, in
unsigned_string = "&".join("{}={}".format(k, v) for k, v in unsigned_items)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-6: ordinal not in range(128)
不能处理下面的报错
{
"alipay_trade_query_response": {
"sub_code": "isv.invalid-app-id",
"code": "40002",
"sub_msg": "无效的AppID参数",
"msg": "Invalid Arguments"
}
}
你好,环境是:ubuntu14、python27、flask
data=request.form.to_dict()
success = alipay_wap.verify_wap_notify(data, signature)
`
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in ca ll
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi _app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in hand le_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi _app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full _dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in hand le_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full _dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in disp atch_request
return self.view_functionsrule.endpoint
File "/var/www/pay.***.com/views/merchant.py", line 241, in alipay_mobile_n otify_result
success = alipay_wap.verify_wap_notify(data, signature)
File "/usr/local/lib/python2.7/dist-packages/alipay/init.py", line 221, in verify_wap_notify
return self.verify_app_notify(data, signature)
File "/usr/local/lib/python2.7/dist-packages/alipay/init.py", line 218, in verify_app_notify
return self._verify_data(data, signature, self.__app_alipay_public_key_path)
File "/usr/local/lib/python2.7/dist-packages/alipay/init.py", line 247, in _verify_data
message = "&".join("{}={}".format(k, v) for k, v in unsigned_items)
File "/usr/local/lib/python2.7/dist-packages/alipay/init.py", line 247, in
message = "&".join("{}={}".format(k, v) for k, v in unsigned_items)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-13: ordi nal not in range(128)
`
接收回调验签时报错
Traceback (most recent call last):
File "/Users/wuyazi/Workspace/env/italki/lib/python2.7/site-packages/tornado/web.py", line 1042, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "/Users/wuyazi/italki/italki_one_backend/src/italki/payment/views/api_payment.py", line 1164, in get
return self._do_task()
File "/Users/wuyazi/italki/italki_one_backend/src/italki/payment/views/api_payment.py", line 1158, in _do_task
if order_id and alipay_notify_method(self, order_id=order_id, **req_args):
File "/Users/wuyazi/italki/italki_one_backend/src/italki/payment/alipaycn/__init__.py", line 91, in alipay_wap_notify
verify_result = self.alipay_wap.verify(params, signature)
File "/Users/wuyazi/italki/italki_one_backend/src/italkiexts/alipay/__init__.py", line 183, in verify
return self._verify(message, signature)
File "/Users/wuyazi/italki/italki_one_backend/src/italkiexts/alipay/__init__.py", line 171, in _verify
if signer.verify(digest, decodebytes(signature.encode("utf8")[:-2])):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 321, in decodestring
return binascii.a2b_base64(s)
Error: Incorrect padding
alipay.trade.order.settle(统一收单交易结算接口)
没有封装这个接口
https://docs.open.alipay.com/api_1/alipay.trade.order.settle/
Hello, 非常感谢你提供的这个支付宝 API SDK。学习了很多。
关于签名验证这块,支付宝文档 一节说只对返回的 xx_response
的内容进行校验。目前的代码中好像没有这种验证方式吧,不知道能不能帮忙看看。Thanks
app_id=2017062607569111&biz_content=%7B%22out_trade_no%22%3A332%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A1%2C%22subject%2
2%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-23+10%3A36%3A36&version=1
.0&sign=EdE8z%2B6%2B31GgxXF4fa468vteX3lqqmCvHbkc1PxjYosrsUzbX%2FEaRtFhnMbSyFYh6%2B3S8vgSaQqs%2BMaz1qsFXqgFVgq3ohhU%2BmhTIp0CDDOxN4ZNK5HsA4ZgnTP92ixI18KR0Eq6tz0OYs3xwLPS9jyzKt6yH%2Fg4geEfai45aPdVP9f
fwlodW5NQfFTjCIFKwFIzBERmKsfgoPLWw8dLDDkjk2O46b1xlmus0HS%2B68xYKJbvoL59NfIMMUv0aJ9%2FtbJJ8oNoSS1mFjosy7yGZyvCQgnTkfjdiEN1KGnUii9dFLV1UHdYiBqMcsYKAfzkdSQmH%2BnYFr4sQX080rDZyQ%3D%3D
如例子中那样,alipay = AliPay(appid="", ...),我直接运行
result = alipay.api_alipay_trade_query(out_trade_no='....')
print(result.get("trade_status", ""))
Traceback (most recent call last):
File "/home/PROJECT/aripayExample/MyAlipayInterface.py", line 111, in
result = f.AliPayClient.api_alipay_trade_query(out_trade_no='201808020882')
File "/home/PROJECT/code/LibEnv/lib/python3.5/site-packages/alipay/init.py", line 305, in api_alipay_trade_query
return self._verify_and_return_sync_response(raw_string, "alipay_trade_query_response")
File "/home/PROJECT/code/LibEnv/lib/python3.5/site-packages/alipay/init.py", line 517, in _verify_and_return_sync_response
sign = response["sign"]
KeyError: 'sign'
subject = "话费余额充值",
out_trade_no =int(time.time())
total_amount = 0.01
#print(out_trade_no)
# create an order
result = alipay.api_alipay_trade_precreate(
subject=subject,
out_trade_no=out_trade_no,
total_amount=total_amount)
print('返回值:',result)
#输出
返回值: {'code': '40004', 'msg': 'Business Failed', 'sub_code': 'ACQ.INVALID_PARAMETER', 'sub_msg': '参数无效'}
#开启debug
File "C:\Users\ELI\Envs\py3_env\lib\site-packages\python_alipay_sdk-1.7.1-py3.6.egg\alipay_init_.py", line 451, in api_alipay_trade_precreate
File "C:\Users\ELI\Envs\py3_env\lib\site-packages\python_alipay_sdk-1.7.1-py3.6.egg\alipay_init_.py", line 517, in _verify_and_return_sync_response
KeyError: 'sign'
请问哪里错了?
你好,证书信息是否可以直接存数据库,而不是文件,这样多用户时比较好处理,谢谢
I run the examples on your document(thanks for this wonderful solution) and there is one point that I'm confuse about:
File "/alipay/alipay/alipay/__init__.py", line 488, in api_alipay_fund_trans_toaccount_transfer
raw_string, "alipay_fund_trans_toaccount_transfer_response"
File "/alipay/alipay/alipay/__init__.py", line 524, in _verify_and_return_sync_response
raise AliPayValidationError
alipay.alipay.exceptions.AliPayValidationError
When running the demo code of alipay.fund.trans.toaccount.transfer
I saw one issues about it but I think my key is right because I actually saw the transfer result success in the sandbox app.(It raise the error at verification)
Here is my code
app_private_key_path="/alipay/app_private_key.pem"
alipay_public_key_path="/alipay/alipay_pubilc_key.pem"
with open(app_private_key_path) as fp:
app_private_key_string = open(app_private_key_path).read()#RSA.importKey(fp.read())
with open(alipay_public_key_path) as fp:
alipay_public_key_string = open(alipay_public_key_path).read()#RSA.import_key(fp.read())
alipay = AliPay(
appid="", # my code number which I didn't forget it
app_notify_url="http://0.0.0.0:5000/",
app_private_key_string=app_private_key_string,
alipay_public_key_string=alipay_public_key_string,
sign_type="RSA2",
debug=True,
)
result = alipay.api_alipay_fund_trans_toaccount_transfer(
out_biz_no=datetime.now().strftime("%Y%m%d%H%M%S"),
payee_type="ALIPAY_LOGONID",
payee_account=person_acount,
amount=1.91,
**{
"payer_show_name":"test",
# payee_real_name:"",
"remark":"test",
}
)
the same error happens on alipay.fund.trans.order.query
too.
现在在开发支付宝小程序,只想获得用户信息,却不知道如何下手
运行如下命令:
$ git clone [email protected]:xxx/alipay.git
$ cd alipay
$ virtualenv --python=python venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python -m unittest discover
测试没通过:
..............Invalid command 'sha'; type "help" for a list.
FInvalid command 'sha'; type "help" for a list.
F..
======================================================================
FAIL: test_sign_data_with_private_key_sha1 (tests.test.AliPayTestCase)
openssl 以及aliapy分别对数据进行签名,得到同样的结果
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vagrant/coding/alipay/tests/test.py", line 108, in test_sign_data_with_private_key_sha1
self.assertEqual(result1, result2)
AssertionError: u'Q7kdCF6TYdKFOFAjrlmi910KVZ7NnDY+/DeQVe3Qd81BhGSF2ChutTqQB2skMbqBgAzZrBj9kIrty7 [truncated]... != u''
- Q7kdCF6TYdKFOFAjrlmi910KVZ7NnDY+/DeQVe3Qd81BhGSF2ChutTqQB2skMbqBgAzZrBj9kIrty7vBzY5LxdiUQbWGsM7THGb9w7MYqFpTKKtAy4ZJUUpCxQ0gqEvoSAR21F288IgJIuBZc1MJbBr6n2uMPVHl3zc0Box8trDPjqiVOWpDLrfFcBdQeFj4udPemGc8MbWvv6MZNIsGrBJKi5zYGlbv+hsooVgjNNWWrWkIBRivMxMfA2K4CKl3kJoxflEwGr5G9o/qGPXb7xCS7NZWU9F+DQeiw7R4GRyRqtFOUMEWE5uR/rLUoFVdmhgFcgSoIbw9Bpe1XLc8SQ==
+
======================================================================
FAIL: test_sign_data_with_private_key_sha256 (tests.test.AliPayTestCase)
openssl 以及aliapy分别对数据进行签名,得到同样的结果
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vagrant/coding/alipay/tests/test.py", line 120, in test_sign_data_with_private_key_sha256
self.assertEqual(result1, result2)
AssertionError: u'N1IQLlHVZSmai3D0kF2r3IZTwrpUQdh0pbUAjE8bbiKBjRUvXX2T127yJW2pre4kPlS2HWgdbV6yDq [truncated]... != u''
- N1IQLlHVZSmai3D0kF2r3IZTwrpUQdh0pbUAjE8bbiKBjRUvXX2T127yJW2pre4kPlS2HWgdbV6yDqk2ykIDHldFnJBkhs/UPwt4D1Lt2rKgGETH1Tn98vgvbmYtAXNZDCAK6CcA+FTVFrpsHmBC4AkUppOb97gzmDeTRh9vTOXzNoMBv7bYktdCRPBODQEXhcTfYNS57JgB25+uuHeAQdju3TdMeupHj2K0ktpBCLNwc9FOXAjOBil0Bo3aEV4+RLllGcsig5oe3vrKL5OfenSzA9YbgiGhHC8lWtYYeeBlOY0zijRTb+uCnnwMQTKbLHY/1HoY/D9b7n1uBAL1Bw==
+
----------------------------------------------------------------------
Ran 18 tests in 0.941s
FAILED (failures=2)
操作系统和python版本如下:
$ cat /etc/issue
Ubuntu 18.04 LTS \n \l
$ python -V
Python 2.7.15rc1
怎么才能让测试通过呀?
报错:init() got an unexpected keyword argument 'notify_url'
could support tornado’s asynchronous feature?
create_wap_trade方法里,biz_content最终并没有赋值,会造成跳转到支付宝支付时出现 ALI38173错误
返回参数
{'gmt_create': ['2017-12-13 11:23:37'],
'charset': ['utf-8'],
'invoice_amount': ['0.01'],
'notify_id': ['023944d368078f9803caa42ec8fc825m3l'],
'notify_type': ['trade_status_sync'],
'trade_status': ['TRADE_SUCCESS'],
'receipt_amount': ['0.01'],
'buyer_pay_amount': ['0.01'],
'sign_type': ['RSA'],
point_amount': ['0.00']}>
验证
success = alipay.verify(data, signature)
def verify(self, data, signature):
if "sign_type" in data:
sign_type = data.pop("sign_type")
if sign_type != self._sign_type:
raise AliPayException(None, "Unknown sign type: {}".format(sign_type))
ISV初始化方法是没有支持app_private_key_string和alipay_public_key_string的吗,使用了Guide里面的样例,报TypeError: __init__() got an unexpected keyword argument 'app_private_key_srting'
ISVAliPay中build_body函数
return super(ISVAliPay, self).build_body(method, biz_content, return_url, append_auth_token)
BaseAliPay类中build_body函数
def build_body(self, method, biz_content, return_url=None, notify_url=None, append_auth_token=False):
调用父类函数少了notify_url
参数,代码参数错位,导致代码https://github.com/fzlee/alipay/blob/master/alipay/init.py#L155报错。
错误代码 invalid-signature 错误原因: 无效签名(我使用沙箱),已验证过,私钥签名的字符串公钥可以解密
即时到账退款的接口只有一个合作者身份ID,没有APPID,以及其余参数和refund_web_order也不同,接口走的是 https://mapi.alipay.com/gateway.do
。即时到账接口文档:
https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.LnFTM0&treeId=62&articleId=104744&docType=1
支付成功后,查看支付结果,遇到错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/thinkgamer/Documents/github/travel/line/views.py", line 74, in check_pay
response = alipay.api_alipay_trade_query(out_trade_no=order_id) # response是一个字典
File "/usr/local/lib/python3.5/dist-packages/alipay/init.py", line 284, in api_alipay_trade_query
return self._verify_and_return_sync_response(raw_string, "alipay_trade_query_response")
File "/usr/local/lib/python3.5/dist-packages/alipay/init.py", line 496, in _verify_and_return_sync_response
sign = response["sign"]
KeyError: 'sign'
能否帮助解决一下
网页支付。给出的例子运行之后报错如题。钱到是打过去了。请问一下这是什么问题?
另外我还有个问题。我注意到官方也出了一个SDK(然而目前并不好用),其中需要输入sub_merchant这个参数(商户ID),为什么你的库里面不需要这个信息呢? 将来会不会出现接口不想容的问题呢?
这是alipay返回的错误
调试错误,请回到请求来源地,重新发起请求。
错误代码 invalid-signature 错误原因: 验签出错,建议检查签名字符串或签名私钥与应用公钥是否匹配,网关生成的验签字符串为:app_id=2018062460380864&biz_content={out_trade_no:20161112,product_code:QUICK_WAP_PAY,total_amount:0.01,subject:subject}&charset=utf-8&method=alipay.trade.wap.pay¬ify_url= http://www.getsms.club/&sign_type=RSA2&timestamp=2018-06-26 21:26:52&version=1.0
这是sdk生成的链接
前者乱入了一些奇怪的amp;
加回调参数passback_params不起作用。
然后异步检测是否收款的
hi:
i suspect you were Chinese, so i write in Chinese.
当我使用 alipay sdk 创建, alipay_fund_trans_toaccount_transfer
支付的时候
会报 alipay.exceptions.AliPayValidationError
的异常, 但是支付确实成功了. 支付宝同步接口验证签名的问题, 我这边一直没有解决, 你有没有好的解决方案呢?
/usr/local/lib/python3.7/site-packages/alipay/__init__.py in api_alipay_fund_trans_toaccount_transfer(self, out_biz_no, payee_type, payee_account, amount, **kwargs)
479 raw_string = urlopen(url, timeout=15).read().decode("utf-8")
480 return self._verify_and_return_sync_response(
--> 481 raw_string, "alipay_fund_trans_toaccount_transfer_response"
482 )
483
> /usr/local/lib/python3.7/site-packages/alipay/__init__.py(556)_verify_and_return_sync_response()
554
555 if not self._verify(raw_string, sign):
--> 556 raise AliPayValidationError
557 return result
558
ipdb> raw_string
'{"code":"10000","msg":"Success","order_id":"20181103110070001502900057938805","out_biz_no":"20181103104340","pay_date":"2018-11-03 18:43:39"}'
python3对中文的支持比较好,如果无需兼容python2的话,代码会优雅很多,更符合python之禅,所以建议完全迁移到py3
是否在初始化时增加app_auth_token字段,这要ISV即可以实现整个过程
很奇怪,我这边无论是windows还是linux在调用verify_app_notify这个函数的时候都报下面那个错
"RSA key format is not supported"
跟进去看了下,错在__init__.py 121行key = RSA.importKey(fp.read()),查了下 因为我的privatekey是base64编码,而importKey接受二进制,要么key = RSA.importKey(b64decode(fp.read())),要么 open的时候用"rb"模式,不然不可能能通过测试啊。。
======代码
@app.route('/check_pay/', methods=['POST'])
def check_pay():
# 创建用于进行支付宝支付的工具对象
order_id = flask.request.form.get("order_id")
alipay = AliPay(
appid=ALIPAY_APPID,
app_notify_url=None, # 默认回调url
app_private_key_path=os.path.join(BASE_DIR, "malipay/app_private_key.pem"),
alipay_public_key_path=os.path.join(BASE_DIR, "malipay/alipay_public_key.pem"),
# 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
sign_type="RSA2", # RSA2,官方推荐,配置公钥的时候能看到
debug=True # 默认False 配合沙箱模式使用
)
# raw_string = urlopen(url, timeout=15).read().decode("utf-8")
while True:
# 调用alipay工具查询支付结果
response = alipay.api_alipay_trade_query(out_trade_no=order_id) # response是一个字典
# 判断支付结果
code = response.get("code") # 支付宝接口调用成功或者错误的标志
trade_status = response.get("trade_status") # 用户支付的情况
if code == "10000" and trade_status == "TRADE_SUCCESS":
# 表示用户支付成功
# 返回前端json,通知支付成功
return flask.jsonify({"code": 0, "message": "支付成功"})
elif code == "40004" or (code == "10000" and trade_status == "WAIT_BUYER_PAY"):
# 表示支付宝接口调用暂时失败,(支付宝的支付订单还未生成) 后者 等待用户支付
# 继续查询
print(code)
print(trade_status)
continue
else:
# 支付失败
# 返回支付失败的通知
return flask.jsonify({"code": 1, "message": "支付失败"})
=====
报错信息
raise ValueError("Not a valid PEM post boundary")
ValueError: Not a valid PEM post boundary
可以支付,但是不能查询。希望帮忙看下。
`from alipay import AliPay
import qrcode # 导入模块
import time
out_trade_no = 'eb0d16e5-38d9-4fc4-ba6b-59787532eba1'
alipay = AliPay(
appid='2017071207730100',
app_notify_url='http://www.example.io/pay/alipay/verify',
app_private_key_path='../rsa_private_key.pem',
alipay_public_key_path='../rsa_public_key.pem',
sign_type="RSA", # RSA or RSA2
)
result = alipay.api_alipay_trade_precreate(
subject='vip1month',
out_trade_no=out_trade_no,
total_amount=0.01
)`
返回内容:
{"code":"10000","msg":"Success","out_trade_no":"eb0d16e5-38d9-4fc4-ba6b-59787532eba1","qr_code":"https://qr.alipay.com/bax04455bp1jlvn7mx0h60ea"}
返回sign:
OTpTRfQ6ChZsjo/5gbMHJpF2p/2C6UHuZVYNG13yOityCpCZOIDCrLEKYwOIQFJsFuEhLxEX7RQLD1c7mfPEKC63GD4WYKuSMeZVkX7QLTb0UdU8XNtsIbt5Hqti4OD4jcVDJ4IyzgcycxtYDZfk232xvrqgs9z1tHUchhNF8Mw=
看上去创建qr_code成功了,但是_verify_and_return_sync_response的时候所签名不对
签名功能我用支付宝提供的接口验证是正确的,这会是什么问题尼?
环境:Python3.6.1 windows10
上传到服务器之后报错,
Exception Value:
cannot import name OSRNG
Exception Location:
/usr/local/lib/python2.7/dist-packages/alipay/init.py in , line 12
生成的 order_string 加 https://openapi.alipay.com/gateway.do? 后报错,无效的AppID参数
支付宝接口需要 “商户请求参数的签名串,详见签名“
亲自使用过,没有问题。
你好,调试不过,是否可以发邮件给我,[email protected],涉及隐私信息,邮件比较好
官方文档返回是:
"alipay_trade_precreate_response": {
"code": "10000",
"msg": "Success",
"out_trade_no": "6823789339978248",
"qr_code": "https://qr.alipay.com/bavh4wjlxf12tper3a"
},
"sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}
其中,qr_code用来生成二维码让客人扫码支付,我看咱们SDK的例程里面没有返回好像
我自己写的代码,“同步返回验签”总是通不过,不知 作者有么有时间帮忙指导下呢?
自己实现的扫码付接口 https://github.com/wsqy/ALIPay
其中签名、 验签部分大量使用了你的项目中的代码 请多多批评
在主页介绍中,app_notify_url设置为一个空的字符串,但是在实际测试中,如果不使用app_notify_url,那么一定要设置为None,不然就算是私钥和公钥设置好了,支付宝还是会提示验证签名失败
data = urlparse.parse_qs(request.body)
signature = data.pop('sign')
success = alipay.verify(data, signature)
request.body如下:
gmt_create=2018-07-10+14%3A50%3A18&charset=utf-8&gmt_payment=2018-07-10+14%3A50%3A30¬ify_time=2018-07-10+14%3A50%3A30&subject=%E5%85%85%E5%80%BC1%E5%85%83&sign=NwhSk2DWQRiV25HQXRXzwvcFh0jJy2D3zQBG%2Bp%2BAzVNFx8whfj0Zmm6eFmX19F2HhiDpqOXJ9NY5lUU0KyugsAbEEOYnc%2Fvrx3KeVniSW7G5jExL8n42tvvVqOgRgwsf7eQqiStEkvgOX55olPeX7JaJS0A0dh%2BlgvScSXR3u330x6xu%2BiX0RXzkBm9%2FhuxDufQ5eR3jJNBWl0nC6NBhjHCwcwZDclo0SEfljSW4wUhN%2FEwLEQvcbU2ghwHQUT1awtZtgA2YEHLDt14S2nz4hre3wFr8LP%2F92Kl1fV2At7tbh7Yej5fQppavtm7huMfHbo7PwIfO94YAAb1wz4G1uQ%3D%3D&buyer_id=2088802801047800&invoice_amount=0.01&version=1.0¬ify_id=5ca5872707f24d41d27ff65d6afc6f5m6d&fund_bill_list=%5B%7B%22amount%22%3A%220.01%22%2C%22fundChannel%22%3A%22ALIPAYACCOUNT%22%7D%5D¬ify_type=trade_status_sync&out_trade_no=2016111118&total_amount=0.01&trade_status=TRADE_SUCCESS&trade_no=2018071021001004800520919284&auth_app_id=2018062460380864&receipt_amount=0.01&point_amount=0.00&app_id=2018062460380864&buyer_pay_amount=0.01&sign_type=RSA2&seller_id=2088102323393514urlparse.parse_qs(request.body) :
{'app_id': ['2018062460380864'], 'auth_app_id': ['2018062460380864'], 'buyer_id': ['2088802801047800'], 'buyer_pay_amount': ['0.01'], 'charset': ['utf-8'], 'fund_bill_list': ['[{"amount":"0.01","...CCOUNT"}]'], 'gmt_create': ['2018-07-10 14:50:18'], 'gmt_payment': ['2018-07-10 14:50:30'], 'invoice_amount': ['0.01'], 'notify_id': ['5ca5872707f24d41d27...afc6f5m6d'], 'notify_time': ['2018-07-10 14:50:30'], 'notify_type': ['trade_status_sync'], 'out_trade_no': ['2016111118'], 'point_amount': ['0.00'], ...}
当我调用api_alipay_trade_query去查询订单信息的时候
阿里返回的数据里面没有Sign
{u'alipay_trade_query_response':
{u'msg': u'Invalid Arguments',
u'sub_code': u'isv.invalid-app-id',
u'code': u'40002',
u'sub_msg': u'\u65e0\u6548\u7684AppID\u53c2\u6570'}
}
所以_verify_and_return_sync_response
方法里面的
sign = response["sign"]
会报报KeyError: 'sign'
求解答。
这个APPID是可以用来下单的。我测试了一下网页下单。可以到支付宝去支付。
但是为什么查询的时候会说APPID不可用????感觉也是很奇怪。。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.