支付宝异步通知验签失败解决方案

原贴地址:https://openclub.alipay.com/read.php?tid=1598&fid=69,欢迎大家访问

说明: 

    验签只需要使用到支付宝公钥 ,而不是使用应用公钥!

错误原因: 
  1.支付宝公钥使用错误导致 
  2.验签方法使用错误 
  3.参数错误导致,例如乱码,带自定义参数,编码格式。 


自查流程(按照推荐流程检查) 

     第一步(重点检查):支付宝公钥使用是否错误

     第二步:验签方法错误(请使用下方的demo中的地址接收异步通知进行验签测试) 

说明: 
    正常接口使用 AlipaySignature.rsaCheckV1,sign_type不参与签名 
    特殊说明:AlipaySignature.rsaCheckV2方法生活号异步通知需要使用,会保留sign_type参数参与验签。 


    异步demo分享(适用于所有支付类接口异步验签)

     java,php,.NET验签demo下载地址:https://docs.open.alipay.com/203/105910 

    注意:请大家使用手机网站demo进行验签测试即可,使用文件中的notify_url相关的文件和方法 

   自行实现验签参考:https://docs.open.alipay.com/200/106120

  第三步:异步通知返回参数检查 
      说明: 

      1.支付返回的通知不会乱码,一般java语言可能会在接收以后出现中文乱码,这个需要自己处理,demo中也给了一个方案(notify_url.jsp页面中。如果出现乱码就开启再测试):   

//获取支付宝POST过来反馈信息
Map params = new HashMap();
Map requestParams = request.getParameterMap();
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
    String name = (String) iter.next();
    String[] values = (String[]) requestParams.get(name);
    String valueStr = "";
    for (int i = 0; i < values.length; i++) {
        valueStr = (i == values.length - 1) ? valueStr + values[i]
                : valueStr + values[i] + ",";
    }
    //乱码解决,这段代码在出现乱码时使用
    //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
    params.put(name, valueStr);
}


分享一个验签成功的示例:

一、验签准备
1.原始报文:
【gmt_create=2018-04-20 17:50:[email protected]&subject=1元礼包&sign=UDKYin8FiNt74XERScJ1/Aw9byEa7Zyc73B0wa3b+TB8zjGY1TiEFgjkt52yQa4l0QBPH7nPj/lxCkXJ3iNCbdtI33llRIbVRw6HSKokrKXRDhLtcC6mRAQxihVPQGCCHU0FaB5kyCDALExT15Liw2We4UPj2RhqTQcK2J+dFfAd/9y1op7652wUz4fTqeag1NnsWW4/8n9U/HCnOcgSKms1W2V/uKeITUu+xGD53Kc5FiuHfhKTncvE8r0d5yiuJIwwMHB1UtwMWb3lDptqfe4RyYIbLAmRZRr3C71Jrsd2buPt/Wfk+7g3bYDmXoLO0uqf/SWgQGj4j5SsAgJBpw==&body=购买1元礼包&buyer_id=2088002909593621&invoice_amount=1.00¬ify_id=53d06fe330f23412ffadf96bedf4b2eksd&fund_bill_list=[{"amount":"1.00","fundChannel":"ALIPAYACCOUNT"}]¬ify_type=trade_status_sync&trade_status=TRADE_SUCCESS&receipt_amount=1.00&app_id=2018041202546065&buyer_pay_amount=1.00&sign_type=RSA2&seller_id=2088031750966038&gmt_payment=2018-04-20 17:50:33¬ify_time=2018-04-20 17:54:23&version=1.0&out_trade_no=102&total_amount=1.00&trade_no=2018042021001004620551077378&auth_app_id=2018041202546065&buyer_logon_id=xie***@126.com&point_amount=0.00】

2.验签公钥:
【MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAj2loMvw06Q7ENphqLI/L/zMq+GbybavY6/zrmMvI3Jbk/U2D/CYRnBwPM0iLvOu1Y/sILeDtsQc7jeKPBYwOWnbO0eXYe6WnEuKSzj1zR+Za2Z4aBBKx/oIp99qvAE6oTk+LtQB5adcvrlLEiiyjD5Ilips+lr7A01AnWeIJ2hlXnDDmWUiMLCFzb6XXovuT2Hl/DqJBO3EAgMlfXSdtpWB41ppXIepIrdmL0hq/Vgvv6sAuqBYqjg+1gaEo6sq9Ev8JRqgCkQJsmhkwz206EBAtAkV4WCQN3tFEvtUBxiCRuNaoObPD+e7S1VTjFzCEyOKIl/RTQpRqhC0SvdyyxQIDAQAB】

3.从报文取出签名值sign:
【UDKYin8FiNt74XERScJ1/Aw9byEa7Zyc73B0wa3b+TB8zjGY1TiEFgjkt52yQa4l0QBPH7nPj/lxCkXJ3iNCbdtI33llRIbVRw6HSKokrKXRDhLtcC6mRAQxihVPQGCCHU0FaB5kyCDALExT15Liw2We4UPj2RhqTQcK2J+dFfAd/9y1op7652wUz4fTqeag1NnsWW4/8n9U/HCnOcgSKms1W2V/uKeITUu+xGD53Kc5FiuHfhKTncvE8r0d5yiuJIwwMHB1UtwMWb3lDptqfe4RyYIbLAmRZRr3C71Jrsd2buPt/Wfk+7g3bYDmXoLO0uqf/SWgQGj4j5SsAgJBpw==】

二、组成待验签串:
1.剔除空值参数:
【gmt_create=2018-04-20 17:50:[email protected]&subject=1元礼包&sign=UDKYin8FiNt74XERScJ1/Aw9byEa7Zyc73B0wa3b+TB8zjGY1TiEFgjkt52yQa4l0QBPH7nPj/lxCkXJ3iNCbdtI33llRIbVRw6HSKokrKXRDhLtcC6mRAQxihVPQGCCHU0FaB5kyCDALExT15Liw2We4UPj2RhqTQcK2J+dFfAd/9y1op7652wUz4fTqeag1NnsWW4/8n9U/HCnOcgSKms1W2V/uKeITUu+xGD53Kc5FiuHfhKTncvE8r0d5yiuJIwwMHB1UtwMWb3lDptqfe4RyYIbLAmRZRr3C71Jrsd2buPt/Wfk+7g3bYDmXoLO0uqf/SWgQGj4j5SsAgJBpw==&body=购买1元礼包&buyer_id=2088002909593621&invoice_amount=1.00¬ify_id=53d06fe330f23412ffadf96bedf4b2eksd&fund_bill_list=[{"amount":"1.00","fundChannel":"ALIPAYACCOUNT"}]¬ify_type=trade_status_sync&trade_status=TRADE_SUCCESS&receipt_amount=1.00&app_id=2018041202546065&buyer_pay_amount=1.00&sign_type=RSA2&seller_id=2088031750966038&gmt_payment=2018-04-20 17:50:33¬ify_time=2018-04-20 17:54:23&version=1.0&out_trade_no=102&total_amount=1.00&trade_no=2018042021001004620551077378&auth_app_id=2018041202546065&buyer_logon_id=xie***@126.com&point_amount=0.00】

2.剔除sign、sign_type参数:
【gmt_create=2018-04-20 17:50:[email protected]&subject=1元礼包&body=购买1元礼包&buyer_id=2088002909593621&invoice_amount=1.00¬ify_id=53d06fe330f23412ffadf96bedf4b2eksd&fund_bill_list=[{"amount":"1.00","fundChannel":"ALIPAYACCOUNT"}]¬ify_type=trade_status_sync&trade_status=TRADE_SUCCESS&receipt_amount=1.00&app_id=2018041202546065&buyer_pay_amount=1.00&seller_id=2088031750966038&gmt_payment=2018-04-20 17:50:33¬ify_time=2018-04-20 17:54:23&version=1.0&out_trade_no=102&total_amount=1.00&trade_no=2018042021001004620551077378&auth_app_id=2018041202546065&buyer_logon_id=xie***@126.com&point_amount=0.00】

3、排序:
【app_id=2018041202546065&auth_app_id=2018041202546065&body=购买1元礼包&buyer_id=2088002909593621&buyer_logon_id=xie***@126.com&buyer_pay_amount=1.00&charset=utf-8&fund_bill_list=[{"amount":"1.00","fundChannel":"ALIPAYACCOUNT"}]&gmt_create=2018-04-20 17:50:32&gmt_payment=2018-04-20 17:50:33&invoice_amount=1.00¬ify_id=53d06fe330f23412ffadf96bedf4b2eksd¬ify_time=2018-04-20 17:54:23¬ify_type=trade_status_sync&out_trade_no=102&point_amount=0.00&receipt_amount=1.00&seller_email=888@ymgxjy.com&seller_id=2088031750966038&subject=1元礼包&total_amount=1.00&trade_no=2018042021001004620551077378&trade_status=TRADE_SUCCESS&version=1.0】

三、验签结果:
【验签成功】




你可能感兴趣的:(支付宝接口,手机网站支付,蚂蚁金服开放平台接口解惑)