fzlee/alipay

AliPayValidationError at alipay.fund.trans.toaccount.transfer

onehumanbeing opened this issue · 2 comments

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.

fzlee commented

I saw you initialized Alipay instance with debug=True, which means all requests would be directed to alipay sandbox environment.

Could you please make sure that you got the public cert /alipay/alipay_pubilc_key.pem from sandbox instead of production?

The function _verify_and_return_sync_response is used to validate response from alipay servers, Certs used in production and Sandbox are not indentical

Thank you very much, this problem is really a public key problem.

Although Alipay's public key may be similar to the application's public key, Alipay's public key needs to be provided instead of applying the application's public key.

My Party's technical staff thought that the two were the same and gave me the application public key.

There is no problem with your code, thanks again for your work and help.