统一收单交易结算接口(alipay.trade.order.settle)调用示例分享(Java版本)

来自    当面付 | 
作者:天籁  |  更新于:2018-12-07 16:17:49     

说明:

1.alipay.trade.order.settle(统一收单交易结算接口)也就是分账接口,主要是用于当面付接口交易成功后分账给指定用户 详细的api文档:点击查看   

 

2.交易结算接口是属于当面付的辅助接口必须拥有当面付的接口权限才可以调用的。且只能用于当面付接口产生的交易结算,如何签约当面付请参考:https://openclub.alipay.com/read.php?tid=276&fid=72 

调用流程:

1.获取分账收款账户的pid

建议使用用户信息授权接口获取pid,详细的获取方案:https://openclub.alipay.com/read.php?tid=1813&fid=68

2.获取分出账户,也就是收款账户的pid

登录商家账户访问:https://openhome.alipay.com/platform/keyManage.htm?keyType=partner

在下图位置获取:

3.接口调用示例代码

json格式传值:

AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","您的APPID","您的私钥","json","GBK","您的支付宝公钥","RSA2");

AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest();
		request.setBizContent("{" +
		"\"out_request_no\":\"20181207001\"," +//该笔分账的请求单号,每一次请求保证唯一
		"\"trade_no\":\"2018120722001473951020023000\"," +//分账的交易的支付宝交易号
		"      \"royalty_parameters\":[{" +
		"        \"trans_out\":\"2088702939*****\"," +//分出账户,也就是商家的账户pid
		"\"trans_in\":\"20882123868*****\"," +//分账金额收款账户pid
		"\"amount\":0.1," +
		//"\"amount_percentage\":100," +//分账百分比
		"\"desc\":\"分账给2088212386*****\"" +
		"        }]" +
		"  }");
		AlipayTradeOrderSettleResponse response = alipayClient.execute(request);
//使用第三方应用授权app_auth_token传值方式
		//AlipayTradeOrderSettleResponse response = alipayClient.execute(request,null,"app_auth_token");
		if(response.isSuccess()){
		System.out.println("调用成功");
		System.out.println(response.getBody());
		} else {
		System.out.println("调用失败");
		System.out.println(response.getBody());
		}

 

model方式传值

AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","您的APPID","您的私钥","json","GBK","您的支付宝公钥","RSA2");
AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest();
		AlipayTradeOrderSettleModel  model=new AlipayTradeOrderSettleModel();
		model.setOutRequestNo("20181207001");//该笔分账的请求单号,每一次请求保证唯一
		model.setTradeNo("2018120722001473951020023000");//分账的交易的支付宝交易号
		//声明OpenApiRoyaltyDetailInfoPojo方法用于传入royaltyParameters
		OpenApiRoyaltyDetailInfoPojo royaltyParameters=new  OpenApiRoyaltyDetailInfoPojo();
		royaltyParameters.setTransOut("20887**95***");//分出账户,也就是商家的账户pid
		royaltyParameters.setTransIn("208821238***");//分账金额收款账户pid
		royaltyParameters.setAmount((long)0.1);//分账金额
		//royaltyParameters.setAmountPercentage((long)100);//分账百分比
		List<OpenApiRoyaltyDetailInfoPojo> royaltyParameters1=new ArrayList<>();
		royaltyParameters1.add(royaltyParameters);
		model.setRoyaltyParameters(royaltyParameters1);
		request.setBizModel(model);
		AlipayTradeOrderSettleResponse response = alipayClient.execute(request);
		//使用第三方应用授权app_auth_token传值方式
		//AlipayTradeOrderSettleResponse response = alipayClient.execute(request,null,"app_auth_token");
		if(response.isSuccess()){
			System.out.println("调用成功");
			System.out.println(response.getBody());
			} else {
			System.out.println("调用失败");
			System.out.println(response.getBody());
			}

注:

1.amount_percentage分账百分比指的是分出金额占该笔交易的百分比,目前只支持传入0和100不支持其他值,建议直接使用amount参数,分出多少传入多少金额。两个同时传入以amount_percentage为准。

2.amount金额不能超出该笔交易的总金额,且分出账户余额不能低于amount金额。

3.该接口支持一次性分账给多人,分账代码如下:

request.setBizContent("{" +
		"\"out_request_no\":\"2018120700123\"," +//该笔分账的请求单号,每一次请求保证唯一
		"\"trade_no\":\"2018120722001473951020023000\"," +//分账的交易的支付宝交易号
		"      \"royalty_parameters\":[{" +
		"        \"trans_out\":\"20887029395***\"," +//分出账户,也就是商家的账户pid
		"\"trans_in\":\"20882123868***\"," +//第一个分账金额收款账户pid
		"\"amount\":0.1," +
		//"\"amount_percentage\":100," +//分账百分比
		"\"desc\":\"分账给2088212386*****\"" +
		"        },{" +
		"        \"trans_out\":\"20887029395****\"," +//分出账户,也就是商家的账户pid
		"\"trans_in\":\"208880250057****\"," +//第二个分账金额收款账户pid
		"\"amount\":0.1," +
		//"\"amount_percentage\":100," +//分账百分比
		"\"desc\":\"分账给208880250057*****\"" +
		"        }]" +
		"  }");

 

调用成功返回参数示例:

{"alipay_trade_order_settle_response":{"code":"10000","msg":"Success","trade_no":"2018120722001473951020023000"},"sign":"EXeinY2Ln9ZnN9oqp6HWOo2LxtG5ZDaWSD+MDr+gTpGSy3joAsfEks11mW057NDMvkoPCgQMNavo1zDU4smwO7YeuBWMFYrnE5FA4/o+m1nGwBckBUuCqKTXq1gZY60x3S2Cxmc9v0a1TUQmFWImlosCTVVnqC3FvYqIkp6d54TdND0bbCNadEcRq12ADufRgRYTXXTemduo6Za6gvGZ6CabI8jhajSP+NlgmIncUZYV5Jc0X3XI1MNf+SFKd7qdLagYiEOo8qdsnm/b69d5nMihtrlIBlLOliDlGZGu1OOhiEV82D+zboo88s16MvD11OAYM1cU/RC2/Ga4UntofQ=="}

4.Java版本demo分享

json传值demo:
download:交易结算接口demo分享-json传值.zip

model传值demo:

download:交易结算接口demo分享-model传值.zip

黑桃A丶 | 2018-12-24 11:53:02
分账收款账户的pid可以与收款账户的pid 获取方式一样吗,而不用 用户信息授权接口获取pid
天籁 | 2018-12-24 14:13:02
黑桃A丶:分账收款账户的pid可以与收款账户的pid 获取方式一样吗,而不用 用户信息授权接口获取pid回到原帖
你自己测试可以让获取分账的用户来访问那个地址来获取pid,但是如果是实际使用让商户大规模的使用这个方式获取体验很不好的,所以建议使用用户信息授权来获取
我的回复
回复数
  2
阅读数
  30863

返回顶部