异步消息

简介

针对交易结果,Adapay 系统会通过异步消息的方式通知客户系统。

HTTP(S)异步通知使用说明

url为http/https路径:服务器为POST回调,默认超时时间为5秒,超时后会重试3次;不支持HTTP重定向;服务器对应答不是200~300之间的错误,会默认重试3次;异步通知服务器对HTTPS不认证验签和ALLOW_ALL_HOSTNAME_VERIFIER;如商户自定义通知端口,请使用8000-9005内端口,否则无法通知;URL 上请勿附带参数;异步回调请求编码集为:UTF-8。 异步回调参数为:Event对象,以key=value方式POST发送数据

签名验证,签名原数据为data中的数据。为了安全,请验证签名,签名认证为SHA1withRSA签名,请参照SDK中Adapay同步返回验签方法进行验证。 收到通知后请返回状态码“200”,响应异步。

  • 返回示例

{
    "created_time":"1578019908",
    "data": "{"created_time":"20200103105148","expend":{"bank_type":"OTHERS","open_id":"o8jhot9m_XUMbgqrv-XqIxgq5ZLs","sub_open_id":"onAQQxJrB1Iy4xm5PrUucOP-eds4","buyer_logon_id":"123****@huifu.com"},"id":"002112020010310514810059003925284544512","order_no":"PY_20200103105147517447","pay_amt":"0.01","pay_channel":"wx_pub","status":"succeeded"}",
    "prod_mode":"true",
    "sign":"Fm0NMFZA7NJk48jEiaEucgsUoGM4tRHHu1JRLFu/V2k28Ki7MZ6p9GFf0b0YiRAl6nacP4UfbZjbSZ44xunfX7Utmxq2oUbpjLjuWp5H97yOvGFYznTquktC1RuOCJtqSpvEAsIP20ZIQKNZgLMwXrTXofXiWqkiF6PLy8zIlvU=",
    "id":"002110059003969967001600",
    "type":"payment.succeeded",
    "app_id":"app_16fa681b-fd42-435c-8f8f-0adce9962a94",
    "object":"payment"
}

实现您自己的异步消息接受和处理接口,启动异步消息的接收,通过此方法,商户可对 HTTP 回调参数进行签名验证和消息处理。

代码示例

@PostMapping("/callback")
public void callback(HttpServletRequest request) {
    try {
        //验签请参data
        String data = request.getParameter("data");
        //验签请参sign
        String sign = request.getParameter("sign");
        //验签标记
        boolean checkSign;
        //验签请参publicKey
        String publicKey = AdapayCore.PUBLIC_KEY;
            log.info("验签请参:data={}sign={}");
            //验签
            checkSign = AdapaySign.verifySign(data, sign, publicKey);
            if(checkSign){
                //验签成功逻辑
                System.out.println("成功返回数据data:"+data);
            }else {
                //验签失败逻辑
            }
    }catch (Exception e){
        log.info("异步回调开始,参数,request={}");
    }
    return ;
}

创建支付对象

当您想发起一次支付请求时需要通过 Adapay 提供的创建方法获取一个新的 Payment对象,您可使用此 Payment对象 发起支付。 对于支付结果,Adapay会发送异步消息通知, 其中需要传notify_url参数的相关接口有:创建支付对象,支付关单,创建退款对象,创建企业用户对象,支付撤销对象。

调用示例

Java

// 请求参数
Map<String, Object> paymentParams = new HashMap<String, Object>();
paymentParams.put("order_no",  "123456789");
paymentParams.put("pay_amt", "0.05");
paymentParams.put("app_id", "app_XXXXXXXX");
paymentParams.put("pay_channel",  "alipay");
paymentParams.put("goods_title",  "Your goods_title");
paymentParams.put("goods_desc",  "Your goods_desc");
paymentParams.put("description",  "payment Discription");
paymentParams.put("div_members",  "[{"amount":"0.05", "fee_flag":"Y", "member_id":"member_id_test"}]");
//异步通知地址,url为http/https路径,服务器POST回调,URL 上请勿附带参数
paymentParams.put("notify_url", "http://www.xxx.com/api/v1/callback");

// 调用创建方法,获取 Payment对象_
Map<String, Object> response = Payment.create(paymentParams);

注意事项

在实现异步消息接收的同时,都建议您在重要的业务环节,通过反查接口确认 非终态 支付订单的状态,以保证在发生异步消息延迟或无法送达情况下的支付结果一致性。

Event对象

异步消息内容是通过 Event对象 来传递的。其中包含了不同类型的 Event 以及对应的消息体。

对象的定义

属性

描述

id

事件 id , Adapay 系统内唯一

type

事件类型,详见 Event事件类型

created_time

事件发生的时间点,Unix 时间戳

prod_mode

是否为生产环境事件

app_id

商户在Adapay系统下的应用id

data

消息数据,JSON格式 对象,根据事件类型不同对应的数据对象也不同,详见

Event事件 返回数据

Event事件类型

类型

描述

payment.succeeded

详见 支付成功

payment.failed

详见 支付失败

payment.close.succeeded

详见 支付关单成功

payment.close.failed

详见 支付关单失败

refund.succeeded

详见 退款成功

refund.failed

详见 退款失败

corp_member.succeeded

详见 开户成功

corp_member.failed

详见 开户失败

payment_reverse.succeeded

详见 支付撤销成功

payment_reverse.failed

详见 支付撤销失败

cash.succeeded

详见 取现成功

cash.failed

详见 取现失败

account_payment.succeeded

详见 钱包支付成功

account_payment.failed

详见 钱包支付失败

fastpay.succeeded

详见 快捷支付确认成功

fastpay.failed

详见 快捷支付确认失败

fast_card.succeeded

详见 快捷绑卡确认成功

fast_card.failed

详见 快捷绑卡确认失败

unbind_fast_card.succeeded

详见 快捷卡解绑成功

unbind_fast_card.failed

详见 快捷卡解绑失败

corp_member_update.succeeded

详见 更新企业用户对象成功

corp_member_update.failed

详见 更新企业用户对象失败

Event事件 返回数据

payment.succeeded - 支付成功

data 参数中为一个 支付对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "payment.succeeded",
  "data": {
    "id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
    "created_time": 1410778843,
    "order_no": "123456789",
    "prod_mode": "true",
    "app_id": "sfjeijibbTe5jLGCi5rzfH4OqPW9KCif913",
    "pay_channel": "alipay",
    "pay_amt": "998.00",
    "fee_amt": "1.00",
    "currency": "cny",
    "query_url": "https://AdaPay.cloudpnr.com/payment/tmp?token=5jLGCi5rzfH4OqPW9KCi",
    "status": "succeeded",
    "expend": {
    "pay_info": "bax028781ovixf6i8xyf60be"
    }
  }
}

payment.failed - 支付失败

data参数中为一个 支付对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "payment.failed",
  "data": {
    "id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
    "created_time": 1410778843,
    "order_no": "123456789",
    "prod_mode": "true",
    "app_id": "sfjeijibbTe5jLGCi5rzfH4OqPW9KCif913",
    "pay_channel": "alipay",
    "pay_amt": "998.00",
    "currency": "cny",
    "query_url": "https://AdaPay.cloudpnr.com/payment/tmp?token=5jLGCi5rzfH4OqPW9KCi",
    "status": "failed",
    "expend": {
    "pay_info": "bax028781ovixf6i8xyf60be"
    }
  }
}

payment.close.succeeded - 支付关单成功

data参数中为一个 关单对象

{
    "id": "0017018667756060672",
    "prod_mode": "true",
    "createdTime": "1568009842",
    "type": "payment.close.succeeded",
    "data": {
        "object": "payment",
        "status": "succeeded",
        "payment_id": "002112019090914152710017018183717306368",
        "created_time": "1568009841000"
    },
    "sign": "lzvOa3DmTrNrXgujkA4Db/Ow0aEW7A0uave5p1kn5c3x6+zzIcG8nDWzKhwo2KQyvgYvrEaE9BeEn1zYe8Z4J27zEuZV7yPM6WHGmDsVoGrS4odqZAaniLR5hIlmdxXPOPJazxVklvw2av+RuH0LUFACIzM82dCnTbYkBL8lZ0w="
}

payment.close.failed - 支付关单失败

{
  "id": "0017060140534431744",
  "prod_mode": "false",
  "created_time": "1568019730",
  "type": "payment.close.failed",
  "data": {
    "object": "pay",
    "status": "failed",
    "payment_id": "002112019090914152710017018183717306368",
    "error_type": "channel_error",
    "error_code": "channel_close_fail",
    "error_msg": "通道关单失败"
  },
  "sign": "X9LFB5wJmGtIccp6Pd7d72Ksa3aBWcGdozE7FVx5+JwPZdVP2pMlc3cm/ld+dTlPEk+gMIVEPnsh5q0w1ZY7wVKxhzAj80brJhqfB5Gm9DUykIfnO/faT89D6x694izzfZwMIkrEzSXGxLzMdH7wVeAszBig6TxYK6AMgv93B9k="
}

refund.succeeded - 退款成功

data参数中为一个 退款对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "refund.succeeded",
  "data": {
    "payment_id": "002112019072917310300001847119303360512",
    "created_time": "1564736347000",
    "error_code": "",
    "error_msg": "",
    "fee_amt": "0.00",
    "id": "002112019080216590600003288632355946496",
    "status": "succeeded",
    "pay_amt": "0.04",
    "error_type": ""
  }
}

refund.failed - 退款失败

data参数中为一个 退款对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "refund.failed",
  "data": {
    "payment_id": "002112019072917310300001847119303360512",
    "created_time": "1564736347000",
    "error_code": "channel_unexpected_error",
    "error_msg": "支付渠道遇到未知错误。",
    "fee_amt": "0.00",
    "id": "002112019080216590600003288632355946496",
    "status": "failed",
    "pay_amt": "0.04",
    "error_type": "channel_error"
  }
}

corp_member.succeeded - 开户成功

data参数中为一个 企业用户对象

{
  "id": "0003288641923156729",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "corp_member.succeeded",
  "data": {
    "member_id": "2019072601295",
    "created_time": "1564736349",
    "object":"corp_member",
    "order_no": "123456789",
    "prod_mode": "true",
    "app_id": "sfjeijibbTe5jLGCi5rzfH4OqPW9KCif913",
    "audit_state": "D",
    "audit_desc": "开户成功",
    "settle_account_id": "0006440476699456"
  }
}

corp_member.failed - 开户失败

data参数中为一个 企业用户对象

{
  "id": "0003288641923156729",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "corp_member.failed",
  "data": {
    "member_id": "2019072601295",
    "created_time": "1564736349",
    "object":"corp_member",
    "order_no": "123456789",
    "prod_mode": "true",
    "app_id": "sfjeijibbTe5jLGCi5rzfH4OqPW9KCif913",
    "audit_state": "C",
    "audit_desc": "开户失败"
  }
}

payment_reverse.succeeded - 支付撤销成功

data参数中为一个 支付撤销对象

{
  "prod_mode":  "true",
  "sign":  "NQZKHeGKuOWkRITBJ9FfYwpfGPVxIuqeRlfmPTPA6EbRf8oeW0qIuhu3axmIQLdUvL/0fzDgt9/GOSDRXOET+93KxH28USlC+nmX8AU1xvPY1wch9cjfitNxHdCI8O4DFzEV4Mn9mV+ByoVHEyhSTPV7vEq0pt31Dr4WW3Gh2ME=",
  "id":  "0038738132613365760",
  "type":  "payment_reverse.succeeded",
  "created_time":  "1573188166",
  "data":  {
    "object":  "payment_reverse",
    "status":  "succeeded",
    "prod_mode":  "true",
    "id":  "002112019110812421800038738014804242432",
    "order_no":  "jsdk_reverse1573188134999",
    "payment_id":  "002112019110812410010038737686305361920",
    "reverse_amt":  "0.02",
    "reversed_amt":  "0.02",
    "confirmed_amt":  "0.00",
    "refunded_amt":  "0.00",
    "created_time":  "1573188139000",
    "succeed_time":  "1573188166000",
    "channel_no":  "2019110821R968rt",
    "notify_url":  "",
    "reason":  ""
  }
}

payment_reverse.failed - 支付撤销失败

data参数中为一个 支付撤销对象

{
  "prod_mode":  "true",
  "sign":  "NQZKHeGKuOWkRITBJ9FfYwpfGPVxIuqeRlfmPTPA6EbRf8oeW0qIuhu3axmIQLdUvL/0fzDgt9/GOSDRXOET+93KxH28USlC+nmX8AU1xvPY1wch9cjfitNxHdCI8O4DFzEV4Mn9mV+ByoVHEyhSTPV7vEq0pt31Dr4WW3Gh2ME=",
  "id":  "0038738132613365760",
  "type":  "payment_reverse.failed",
  "created_time":  "1573188166",
  "data":  {
    "object":  "payment_reverse",
    "status":  "failed",
    "error_code":  "channel_unexpected_error",
    "error_msg":  "支付渠道遇到未知错误。",
    "error_type":  "channel_error",
    "prod_mode":  "true",
    "id":  "002112019110812421800038738014804242432",
    "order_no":  "jsdk_reverse1573188134999",
    "payment_id":  "002112019110812410010038737686305361920",
    "reverse_amt":  "0.02",
    "reversed_amt":  "0.02",
    "confirmed_amt":  "0.00",
    "refunded_amt":  "0.00",
    "created_time":  "1573188139000",
    "succeed_time":  "1573188166000",
    "channel_no":  "2019110821R968rt",
    "notify_url":  "",
    "reason":  ""
  }
}

cash.succeeded - 取现成功

data参数中为 创建取现对象 响应

{
  "created_time": "1579229221",
  "data": {
    "app_id": "app_XXXXXXXX",
    "cash_amt": "0.02",
    "cash_type": "T1",
    "created_time": "1579174344",
    "fee_amt": "0.01",
    "id": "0021110063845979510771712",
    "object": "cash",
    "order_no": "jdskjdd_1414212450",
    "real_amt": "0.01",
    "status": "succeeded",
    "prod_mode": "true"
  },
  "prod_mode": "true",
  "sign": "fqj%2FUMCQjr9t9NJIFx7aOvaB4VpmgKRsNo1ER8%2Bc1qyoC2p9g7YZOZgewhruNKZ9tezfvaw0T2GVjhPfPWd2q%2BMfXxvVSTdcIEaFL6lzNXE60wkg8xIbOmttaHBPmCgOCmQ6aldTifTSbv90CC3EtxLIM%2F2Z40WHJiSkdeXG2AA%3D",
  "id": "0064076152682098688",
  "type": "cash.succeeded"
}

cash.failed - 取现失败

data参数中为 创建取现对象 响应

{
  "created_time": "1579229221",
  "data": {
    "app_id": "app_XXXXXXXX",
    "cash_amt": "0.02",
    "cash_type": "T1",
    "created_time": "1579174344",
    "fee_amt": "0.00",
    "id": "0021110063845979510771712",
    "object": "cash",
    "order_no": "jdskjdd_1414212450",
    "real_amt": "0.00",
    "status": "failed",
    "prod_mode": "true"
  },
  "prod_mode": "true",
  "sign": "fqj%2FUMCQjr9t9NJIFx7aOvaB4VpmgKRsNo1ER8%2Bc1qyoC2p9g7YZOZgewhruNKZ9tezfvaw0T2GVjhPfPWd2q%2BMfXxvVSTdcIEaFL6lzNXE60wkg8xIbOmttaHBPmCgOCmQ6aldTifTSbv90CC3EtxLIM%2F2Z40WHJiSkdeXG2AA%3D",
  "id": "0064076152682098688",
  "type": "cash.failed"
}

account_payment.succeeded - 钱包支付成功

data参数中为 钱包支付对象 响应

{
  "created_time": "1579229221",
  "data": {
      "order_no": "payment_sdk_123456789",
      "created_time": "1582795442",
      "time_expire": "20200227192402",
      "pay_amt": "0.01",
      "goods_desc": "goods_desc",
      "callback_url": "https://www.baidu.com",
      "goods_title": "goods_title",
      "prod_mode": "true",
      "currency": "cny",
      "id": "002112020022717240210079033970230317056",
      "app_id": "app_XXXXXXXX",
      "object": "account_payment",
      "status": "succeeded"
  },
  "prod_mode": "true",
  "sign": "fqj%2FUMCQjr9t9NJIFx7aOvaB4VpmgKRsNo1ER8%2Bc1qyoC2p9g7YZOZgewhruNKZ9tezfvaw0T2GVjhPfPWd2q%2BMfXxvVSTdcIEaFL6lzNXE60wkg8xIbOmttaHBPmCgOCmQ6aldTifTSbv90CC3EtxLIM%2F2Z40WHJiSkdeXG2AA%3D",
  "id": "0064076152682098688",
  "type": "account_payment.succeeded"
}

account_payment.failed - 钱包支付失败

data参数中为 钱包支付对象 响应

{
  "created_time": "1579229221",
  "data": {
      "order_no": "payment_sdk_123456789",
      "created_time": "1582795442",
      "time_expire": "20200227192402",
      "pay_amt": "0.01",
      "goods_desc": "goods_desc",
      "callback_url": "https://www.baidu.com",
      "goods_title": "goods_title",
      "prod_mode": "true",
      "currency": "cny",
      "id": "002112020022717240210079033970230317056",
      "app_id": "app_XXXXXXXX",
      "object": "account_payment",
      "status": "failed"
  },
  "prod_mode": "true",
  "sign": "fqj%2FUMCQjr9t9NJIFx7aOvaB4VpmgKRsNo1ER8%2Bc1qyoC2p9g7YZOZgewhruNKZ9tezfvaw0T2GVjhPfPWd2q%2BMfXxvVSTdcIEaFL6lzNXE60wkg8xIbOmttaHBPmCgOCmQ6aldTifTSbv90CC3EtxLIM%2F2Z40WHJiSkdeXG2AA%3D",
  "id": "0064076152682098688",
  "type": "account_payment.failed"
}

fast_card.succeeded - 快捷绑卡确认成功

data参数中为 快捷绑卡确认对象 响应

{
  "created_time": "1579229221",
  "data": {
      "app_id": "app_f8b14a77-dc24-433b-864f-98a62209d6c4",
      "apply_id": "0184446014369996800",
      "card_id": "622166602********1",
      "created_time": "1582795442",
      "id":"0177859088938876928",
      "member_id": "user_0000002",
      "notify_url": "https://www.baidu.com",
      "object": "fast_card",
      "prod_mode": "true",
      "status": "succeeded",
      "tel_no": "1344444****",
      "order_no": "order_no_****",
      "token_no": "10000068432"
  },
  "prod_mode": "true",
  "sign": "fqj%2FUMCQjr9t9NJIFx7aOvaB4VpmgKRsNo1ER8%2Bc1qyoC2p9g7YZOZgewhruNKZ9tezfvaw0T2GVjhPfPWd2q%2BMfXxvVSTdcIEaFL6lzNXE60wkg8xIbOmttaHBPmCgOCmQ6aldTifTSbv90CC3EtxLIM%2F2Z40WHJiSkdeXG2AA%3D",
  "type": "fast_card.succeeded"
}

fast_card.failed - 快捷绑卡确认失败

data参数中为 快捷绑卡确认对象 响应

{
  "created_time": "1579229221",
  "data": {
      "app_id": "app_f8b14a77-dc24-433b-864f-98a62209d6c4",
      "apply_id": "0184446014369996800",
      "card_id": "622166602********1",
      "created_time": "1582795442",
      "id":"0177859088938876928",
      "member_id": "user_0000002",
      "notify_url": "https://www.baidu.com",
      "object": "fast_card",
      "prod_mode": "true",
      "status": "failed",
      "tel_no": "1344444****",
      "order_no": "order_no****",
      "error_msg": "绑卡失败",
      "token_no": "10000068432"
  },
  "prod_mode": "true",
  "sign": "fqj%2FUMCQjr9t9NJIFx7aOvaB4VpmgKRsNo1ER8%2Bc1qyoC2p9g7YZOZgewhruNKZ9tezfvaw0T2GVjhPfPWd2q%2BMfXxvVSTdcIEaFL6lzNXE60wkg8xIbOmttaHBPmCgOCmQ6aldTifTSbv90CC3EtxLIM%2F2Z40WHJiSkdeXG2AA%3D",
  "type": "fast_card.failed"
}

fastpay.succeeded - 快捷支付确认成功

data 参数中为一个 快捷支付确认对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "payment.succeeded",
  "data": {
     "app_id":"app_XXXXXXXX",
     "created_time":"1606440833",
     "id":"002112020112709335210178209923564879872",
     "object":"payment",
     "order_no":"123456789",
     "pay_amt":"0.05",
     "pay_channel":"fast_pay",
     "prod_mode":"true",
     "status":"succeeded"
  }
}

fastpay.failed - 快捷支付确认失败

data参数中为一个 快捷支付确认对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "payment.failed",
  "data": {
     "app_id":"app_XXXXXXXX",
     "created_time":"1606440833",
     "id":"002112020112709335210178209923564879872",
     "object":"payment",
     "order_no":"123456789",
     "pay_amt":"0.05",
     "pay_channel":"fast_pay",
     "prod_mode":"true",
     "status":"failed"
  }
}

unbind_fast_card.succeeded - 快捷卡解绑成功

data 参数中为一个 解绑快捷卡对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "unbind_fast_card.succeeded",
  "data": {
     "app_id":"app_XXXXXXXX",
     "created_time":"1606440833",
     "object":"unbind_fast_card",
     "order_no":"123456789",
     "member_id":"0123456789",
     "token_no":"token_no1212",
     "prod_mode":"true",
     "status":"succeeded"
  }
}

unbind_fast_card.failed - 快捷卡解绑失败

data参数中为一个 解绑快捷卡对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "unbind_fast_card.failed",
  "data": {
     "app_id":"app_XXXXXXXX",
     "created_time":"1606440833",
     "object":"unbind_fast_card",
     "order_no":"123456789",
     "member_id":"12565656",
     "token_no":"token_no1212",
     "prod_mode":"true",
     "status":"failed"
  }
}

corp_member_update.succeeded - 更新企业用户对象成功

data参数中为一个 更新企业用户对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "corp_member_update.succeeded",
  "data": {
     "app_id":"app_XXXXXXXX",
     "created_time":"1606440833",
     "id":"002112020112709335210178209923564879872",
     "object":"corp_member_update",
     "order_no":"123456789",
     "member_id":"adapay_001",
     "prod_mode":"true",
     "audit_state":"S",
     "audit_desc":"更新企业用户对象成功"
  }
}

corp_member_update.failed - 更新企业用户对象失败

data参数中为一个 更新企业用户对象

{
  "id": "0003288641923153920",
  "created_time": "1564736349",
  "prod_mode": "true",
  "type": "corp_member_update.failed",
  "data": {
     "app_id":"app_XXXXXXXX",
     "created_time":"1606440833",
     "id":"002112020112709335210178209923564879872",
     "object":"corp_member_update",
     "order_no":"123456789",
     "member_id":"adapay_001",
     "prod_mode":"true",
     "audit_state":"F",
     "audit_desc":"更新企业用户对象失败"
  }
}