代付下单
# 代码示例
- 代码示例仅供参考,具体参数说明请参考请求参数说明
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.util.Map;
import java.util.TreeMap;
public class TopCashDemo {
//MCH_ID: 商户ID
//请登录商户后台,点击 个人中心 > 个人信息 在基本信息中获取商户ID
private static final String MCH_ID = "S820250514103726000009";
// 平台公钥
private static final String PLAT_PUBLIC_KEY = "MIGfMA0GC..........oQIDAQAB";
// 商户私钥
private static final String MCH_PRIVATE_KEY = "MIICeA2n2Rut..........NxI2kXf3Vp";
private static final String cashUrl = "https://vnm-openapi.toppay.asia/gateway/payOut";
private static final String cashNotify = "http://xxxxx";
public static void main(String[] args) throws Exception {
cash();
}
private static void cash() throws Exception {
Map<String, String> requestParams = new TreeMap<>();
requestParams.put("merchantCode", MCH_ID);
requestParams.put("orderNum", "T1234567890"); // 商户订单号
requestParams.put("method", "DISBURSEMENT"); // 收款方式(默认传DISBURSEMENT)
requestParams.put("orderType", "0"); // 订单类型默认传0
requestParams.put("money", "20000"); // 订单金额(仅支持正整数格式金额)
requestParams.put("feeType", "0"); // 手续费类型(0-帐内扣除,1-帐外扣除)
requestParams.put("dateTime", "20200101235959");// 时间戳 格式 yyyyMMddHHmmss
requestParams.put("bankCard", "1154149865112"); // 客户银行卡号
requestParams.put("bankCode", "SCB"); // 银行编码:参考附录I 代付
requestParams.put("accountName", "accountName"); // 客户名称
requestParams.put("extendParam", "TEST"); // 透传参数
requestParams.put("notifyUrl", cashNotify); // 回调地址
List<String> paramNameList = new ArrayList<>();
for (String key : requestParams.keySet()) {
paramNameList.add(key);
}
Collections.sort(paramNameList);
StringBuilder stringBuilder = new StringBuilder();
for (String key : paramNameList) {
stringBuilder.append(requestParams.get(key)); // 拼接参数
}
String keyStr = stringBuilder.toString(); // 得到待加密的字符串
System.out.println("keyStr:" + keyStr);
String signedStr = TopPayRequestUtil.privateEncrypt(keyStr, TopPayRequestUtil.getPrivateKey(MCH_PRIVATE_KEY)); // 私钥加密
requestParams.put("sign", signedStr);
String postJson = new Gson().toJson(requestParams);
System.out.println("Post Json Params:" + postJson);
String responseJson = TopPayRequestUtil.doPost(cashUrl, postJson); // 发送 post json请求
System.out.println("Response Msg:" + responseJson);
boolean pass = TopPayRequestUtil.verifySign(new Gson().fromJson(responseJson, JsonObject.class), PLAT_PUBLIC_KEY); // 签名验证
if (pass) {
// ... 签名验证通过,执行正常的业务逻辑
} else {
// ... 签名验证错误
}
}
}
# 请求地址
- 请求方式 : POST
- 请求地址 : https://vnm-openapi.toppay.asia/gateway/payOut
# 请求参数
注:所有的参数中,不要填写中文!!!
| 参数 | 类型 | 必填 | 描述 | 示例 |
|---|---|---|---|---|
| merchantCode | String | Y | 商户ID,在商户平台获取 | S820250514103726000009 |
| orderType | string(10) | Y | 订单类型 | 默认传0 |
| method | string(10) | Y | 收款方式 | 默认传DISBURSEMENT |
| orderNum | String | Y | 商户订单号 | 10000001 |
| money | String | Y | 代付金额 | 10000(仅支持正整数格式金额) |
| feeType | String | Y | 手续费类型 | 0 : 代付金额内扣除(实际到账金额=下单金额-手续费) 1 : 手续费另计(实际到账金额=下单金额) |
| bankCode | String | Y | 银行编号 | SCB 点击查看支持的银行编码 |
| bankCard | String | Y | 客户银行卡号 | 12312431241 |
| accountName | String | Y | 客户名称 | accountName |
| notifyUrl | String | Y | 回调地址 | https://123123.com |
| dateTime | String | Y | 时间戳格式:yyyyMMddHHmmss | 20200101235959 |
| extendParam | String | Y | 按请求参数返回 | 代付下单 |
| sign | String | Y | 签名 | Yg+ePvTFhiRrARcZKBcRG0l8 ... |
# 请求报文示例
{
"merchantCode": "S820250514103726000009",
"orderType": "0",
"method": "DISBURSEMENT",
"orderNum": "T1234567890",
"money": "10000",
"feeType": "1",
"bankCode": "SCB",
"bankCard": "2021071209403321313122",
"accountName": "test cash accountName",
"notifyUrl": "your notify url",
"dateTime": "20220101235959",
"extendParam": "test cash",
"sign": "Yg+ePvTFhiRrARcZKBcRG0l89rqisPIuZQStYqBIwSMPaqwH77qRXI1J+jElOBpa"
}
# 响应参数
| 参数 | 类型 | 必填 | 描述 | 示例 |
|---|---|---|---|---|
| platRespCode | String | Y | 请求业务是否成功 | FAIL:失败\SUCCESS:成功 |
| platRespMessage | String | Y | 接口响应信息提示 | 请求成功 |
| platOrderNum | String | Y | 平台订单号 | PI1453242857400963072 |
| orderNum | String | Y | 商户订单号 | 23645782 |
| status | Int | Y | 订单状态 | 查看订单状态描述 |
| statusMsg | String | Y | 订单状态信息 | Apply |
| money | String | Y | 代付金额 | 10000 |
| feeType | String | Y | 手续费类型 | 0:订单内扣除, 1:手续费另计 |
| bankCode | String | N | 银行编号 | SCB 点击查看支持的银行编码 |
| bankCard | String | Y | 客户银行卡号 | 12312431241 |
| accountName | String | Y | 客户名称 | accountName |
| extendParam | String | Y | 按请求参数返回 | 代付下单 |
| platSign | String | Y | 签名 | PI1453242857400963072 |
# 代付响应报文示例
{
"platRespCode": "SUCCESS",
"platRespMessage": "Request success",
"platOrderNum": "W0620220119174331000001",
"orderNum": "T1234567890",
"status": 0,
"statusMsg": "Apply",
"money": "10000",
"feeType": "0",
"bankCode": "SCB",
"bankCard": "2021071209403321313122",
"accountName": "test cash accountName",
"extendParam": "test cash",
"platSign": "E5uNF7B9NXyhtlRo2I7/KVHN4Sbz0c3VbwCLpH3vjUpv6Cai+bmJA/Q8dVE2RJRe1+dsbzg=="
}
# 代付异步通知
- 进行验签时,要用 商户后台-收付款配置-API配置中提供的平台公钥进行解密!!!
- 进行验签时,以实际回调的参数为准,不要验签固定的参数
- 订单的最终状态以通知的status为准!!!
- TopPay结果异步通知后,需响应
SUCCESS字符串,否则TopPay将继续向下游发起5次通知。 - TopPay结果异步通知,我们的通知IP为
35.240.188.94请将我们的通知IP加入白名单。
# 通知参数
| 参数 | 描述 | 示例 |
|---|---|---|
| platOrderNum | 平台订单号 | BK_1563278763273 |
| orderNum | 商户订单号 | T1231511321515 |
| money | 代付金额 | 10000(仅支持正整数格式金额) |
| feeType | 手续费类型 | 手续费类型 0:订单内扣除, 1:手续费另计 |
| accountName | 客户名称 | accountName |
| bankCard | 客户银行卡号 | 45649849659456 |
| bankCode | 到账银行 | SCB 点击查看支持的银行编码 |
| status | 订单状态 | 查看订单状态描述 |
| statusMsg | 订单状态描述 | Payout Success |
| extendParam | 透传参数 | 商户上传原样返回 |
| platSign | 平台签名 | ja6R8eukQY9jc8... |
# 异步通知报文示例
{
"platOrderNum": "W0620220119174331000001",
"orderNum": "T1234567890",
"money": "10000",
"feeType": "0",
"accountName": "test cash accountName",
"bankCard": "2021071209403321313122",
"bankCode": "SCB",
"status": "2",
"statusMsg": "SUCCESS",
"extendParam": "test cash",
"platSign": "LGEpz2LjbZ6Iyvn+zLc/+t26AaH0aEhHVD62lSCdo6XIkAg86AUncCvmym62wVoE3r2+dHnv27qi/01UQDcqFK8DYioRCcydYSjB4QRVezG3fcZlhWrACmWGacnXkE7p5zChL7pK5h0HuBhbo1zKt4FunQR6QMmcBVfv7YfB3W0"
}