weixin_39985279
weixin_39985279
2020-11-25 10:20

生成的sign与网关验签字符串不对应

这是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&notify_url= http://www.getsms.club/&sign_type=RSA2&timestamp=2018-06-26 21:26:52&version=1.0

这是sdk生成的链接

https://openapi.alipay.com/gateway.do?app_id=2018062460380864&biz_content=%7B%22out_trade_no%22%3A%2220161112%22%2C%22product_code%22%3A%22QUICK_WAP_PAY%22%2C%22total_amount%22%3A0.01%2C%22subject%22%3A%22subject%22%7D&charset=utf-8&method=alipay.trade.wap.pay&notify_url=+http%3A%2F%2Fwww.getsms.club%2F&return_url=&sign_type=RSA2&timestamp=2018-06-26+21%3A26%3A52&version=1.0&sign=略

前者乱入了一些奇怪的amp;

该提问来源于开源项目:fzlee/alipay

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

12条回答

  • weixin_39985279 weixin_39985279 4月前

    这是我的配置

    
    # -*- coding: utf-8 -*-
    from alipay import AliPay
    from alipay import ISVAlipay
    app_private_key_string = open("key/app_private_key.pem").read()
    alipay_public_key_string = open("key/alipay_public_key.pem").read()
    
    alipay = AliPay(
        appid="2018062460380864",
        app_notify_url=" http://www.getsms.club/",  # 默认回调url
        app_private_key_string=app_private_key_string,
        alipay_public_key_string=alipay_public_key_string,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
        sign_type="RSA2", # RSA 或者 RSA2
        debug=False  # 默认False
    )
    
    
    # If you don't know what ISV is, then forget about what I mentioned below
    # either app_auth_code or app_auth_token should not be None
    
    
    # 手机网站支付,需要跳转到https://openapi.alipay.com/gateway.do? + order_string
    order_string = alipay.api_alipay_trade_wap_pay(
        out_trade_no="20161112",
        total_amount=0.01,
        subject="subject",
        return_url="",
        notify_url="" # 可选, 不填则使用默认notify url
    )
    
    url =  'https://openapi.alipay.com/gateway.do?' + order_string
    print url
    
    点赞 评论 复制链接分享
  • weixin_39985279 weixin_39985279 4月前

    搜了下&amp好像就是&

    私钥公钥都是按教程生产的,公钥也放到支付宝后台了,后台上验证私钥公钥是配对的。appid也是对应的。不知道为什么一直说签名错

    点赞 评论 复制链接分享
  • weixin_39958137 weixin_39958137 4月前
    python
    app_notify_url=" http://www.getsms.club/",  # 默认回调url
    

    你看看是不是多了个空格

    点赞 评论 复制链接分享
  • weixin_39958137 weixin_39958137 4月前

    有两个地方尝试一下, 第一个是url里面的空格,第二个是设置return_url="http:example.com/", 不要设置为空字符串

    点赞 评论 复制链接分享
  • weixin_39985279 weixin_39985279 4月前
    
    # -*- coding: utf-8 -*-
    from alipay import AliPay
    # from alipay import ISVAlipay
    app_private_key_string = open("key/app_private_key.pem").read()
    alipay_public_key_string = open("key/alipay_public_key.pem").read()
    
    alipay = AliPay(
        appid="2018062460380864",
        app_notify_url="http://www.getsms.club/",  # 默认回调url
        app_private_key_string=app_private_key_string,
        alipay_public_key_string=alipay_public_key_string,  # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
        sign_type="RSA2", # RSA 或者 RSA2
        debug=False  # 默认False
    )
    
    
    # If you don't know what ISV is, then forget about what I mentioned below
    # either app_auth_code or app_auth_token should not be None
    
    # isv_alipay = ISVAliPay(
    #     appid="",
    #     app_notify_url=None,  # 默认回调url
    #     app_private_key_srting="",
    #     alipay_public_key_string="", # alipay public key, do not use your public key!
    #     sign_type="RSA", # RSA or RSA2
    #     debug=False,  # False by default,
    #     app_auth_code=None,
    #     app_auth_token=None
    # )
    
    
    # 如果你是Python 2用户(考虑考虑升级到Python 3吧),请确保非ascii的字符串为utf8编码:
    subject = u"aaa".encode("utf8")
    
    
    # 手机网站支付,需要跳转到https://openapi.alipay.com/gateway.do? + order_string
    order_string = alipay.api_alipay_trade_wap_pay(
        out_trade_no="20161112",
        total_amount=0.01,
        subject=subject,
        return_url="http://example.com",
        notify_url="" # 可选, 不填则使用默认notify url
    )
    # url =  'https://openapi.alipaydev.com/gateway.do?' + order_string
    url = 'https://openapi.alipay.com/gateway.do?' + order_string
    print url
    

    输出

    https://openapi.alipay.com/gateway.do?app_id=2018062460380864&biz_content=%7B%22out_trade_no%22%3A%2220161112%22%2C%22product_code%22%3A%22QUICK_WAP_PAY%22%2C%22total_amount%22%3A0.01%2C%22subject%22%3A%22aaa%22%7D&charset=utf-8&method=alipay.trade.wap.pay&notify_url=http%3A%2F%2Fwww.getsms.club%2F&return_url=http%3A%2F%2Fexample.com&sign_type=RSA2&timestamp=2018-06-27+21%3A11%3A44&version=1.0&sign=Iu%2Fq%2BkQwJQ%2BsH%2FtTEXAck54OOSnoF1DsgPELgxRgxa670yORDNIRdastkSmbtyAfZlqd2%2FGyyjyJThJ7WmKqgAooqb%2BHoBSnxCusCf0d1D3nPFf2MCidnacB6ZPTcbBxI7CUzC4PKhvZ15b6svUu7rGzIU8pwPRxffwYPOhC%2F6uTl3PBSWuhjXKLHwj%2BQBaikpMREBg7aRHLjby1mtTbEHVQfp6%2BlIAuz4C4SHg84osein8TDEidiToPaH7F%2F01LZChkYc%2BjO3vo%2B4CZalivpSEfnOpJw3TM0znVL0e6DJhkYHboWPfwqypYeobFbS9MloCmgH9TVvMr9T6%2F3KIheg%3D%3D

    支付宝返回的信息

    调试错误,请回到请求来源地,重新发起请求。 错误代码 invalid-signature 错误原因: 验签出错,建议检查签名字符串或签名私钥与应用公钥是否匹配,网关生成的验签字符串为:app_id=2018062460380864&biz_content={out_trade_no:20161112,product_code:QUICK_WAP_PAY,total_amount:0.01,subject:aaa}&charset=utf-8&method=alipay.trade.wap.pay&notify_url=http://www.getsms.club/&return_url=http://example.com&sign_type=RSA2&timestamp=2018-06-27 21:11:44&version=1.0

    query参数

    app_id: 2018062460380864 biz_content: {out_trade_no:20161112,product_code:QUICK_WAP_PAY,total_amount:0.01,subject:aaa} charset: utf-8 method: alipay.trade.wap.pay notify_url: http://www.getsms.club/ return_url: http://example.com sign_type: RSA2 timestamp: 2018-06-27+21:11:44 version: 1.0 sign: Iu/q+kQwJQ+sH/tTEXAck54OOSnoF1DsgPELgxRgxa670yORDNIRdastkSmbtyAfZlqd2/GyyjyJThJ7WmKqgAooqb+HoBSnxCusCf0d1D3nPFf2MCidnacB6ZPTcbBxI7CUzC4PKhvZ15b6svUu7rGzIU8pwPRxffwYPOhC/6uTl3PBSWuhjXKLHwj+QBaikpMREBg7aRHLjby1mtTbEHVQfp6+lIAuz4C4SHg84osein8TDEidiToPaH7F/01LZChkYc+jO3vo+4CZalivpSEfnOpJw3TM0znVL0e6DJhkYHboWPfwqypYeobFbS9MloCmgH9TVvMr9T6/3KIheg==

    点赞 评论 复制链接分享
  • weixin_39985279 weixin_39985279 4月前

    按您说的试改过来了,还是不行~

    点赞 评论 复制链接分享
  • weixin_39958137 weixin_39958137 4月前

    这个事情有些奇怪,因为我点击你最后一次生成的链接, 直接在电脑浏览器或者手机浏览器里面是可以代开的。

    点赞 评论 复制链接分享
  • weixin_39985279 weixin_39985279 4月前

    神奇了,我也能打开了T_T 昨晚发帖的时候还是失败的

    点赞 评论 复制链接分享
  • weixin_39985279 weixin_39985279 4月前

    很奇怪,难道有延迟?因为我改了一些参数又不行了

    点赞 评论 复制链接分享
  • weixin_39958137 weixin_39958137 4月前

    改了些什么参数?理论上应该是立即生效的

    On Thu, 28 Jun 2018 at 12:03, zzm88 wrote:

    很奇怪,难道有延迟?因为我改了一些参数又不行了

    — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fzlee/alipay/issues/54#issuecomment-400904164, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2FtS9thNY9JYcQuuGxlGl8QhxCldCeks5uBFWrgaJpZM4U38py .

    点赞 评论 复制链接分享
  • weixin_39985279 weixin_39985279 4月前

    原因找到了:vscode 最后print出来那个url,如果直接ctrl点击打开,链接里的ascii码的符号就会被decode,然后链接就不对了~谢谢po主:)

    错误链接示范 ,可以看到里面包含了{ 等符号,在ascii里面是%7B%22

    https://openapi.alipay.com/gateway.do?app_id=2018062460380864&biz_content={out_trade_no:20161112,product_code:QUICK_WAP_PAY,total_amount:0.01,subject:aaa}&charset=utf-8&method=alipay.trade.wap.pay&notify_url=http://www.getsms.club/&return_url=http://example.com&sign_type=RSA2&timestamp=2018-06-28+20:10:54&version=1.0&sign=cupJhme+lXVkTj9Yqd1ioNKEWAXPGveeJwTBDMXJH+o+KyiHImjo1BA+63XotpkAwqvdBo7pb9kEaR6P8363f+nao4GKIqQOP5is5uiqdsXxEoLAgAJ2pS9DmbhfEfFVXX41yCyKHwfUkXq6VY8+3tJbFYzFcC3NW3Ojd4aY0QTh8OyPdX6LDtYNW++zBusBeFgDWjx6QsYnGwvV9cxeEAXIgppOxl2l6QDMPZA1x0bGdhzEaHLQurwoIS2mndy03TTHSgEZ48yBz0w/yRY2LfnOjm8apg594GyY1tAUY9/yPBqUxATfUWkIP5QwXXeEeLM2xaJzAbFUoRJwawhWgQ==

    点赞 评论 复制链接分享
  • u010214300 u010214300 21天前

    怎么解决的

    点赞 评论 复制链接分享