收发现金红包——alipay.fund.coupon.order.disburse(红包打款接口)

接口名称:红包打款接口

英文名称:alipay.fund.coupon.order.disburse

产品首页:[url]https://openclub.alipay.com/read.php?tid=12180&fid=72[/url]

上一步:[url]https://openclub.alipay.com/read.php?tid=13602&fid=72[/url]

下一步:[url]https://openclub.alipay.com/read.php?tid=13610&fid=72[/url]

一、注意事项

1、用户领取红包,通过打款接口实现。

2、若是想实现拆分红包用户分别领取(领取红包A+领取红包B+……+领取红包n<=总红包)。

3、打款接口调用频次:每秒要小于100次;

4、打款接口的发送的异步通知是通过红包打款接口设置的notify_url地址进行接收;

5、使用调用逻辑中,假设支付接口选择红包页面支付接口,且参数设置out_order_no为2017122716463224,out_request_no为201712271645328,其他参数一致。

二、参数说明

1、out_order_no: 商户的授权资金订单号,同一商户不同的订单,不可重复,保持唯一性;

注:打款接口的out_order_no与支付接口的out_order_no不可重复,保持唯一性。

2、out_request_no:商户本次资金操作的请求流水号,同一商户每次不同的资金操作请求,商户请求流水号不要重复;

注:out_order_no不相同的情况下,out_request_no参数值相同可调用成功,建议记录out_order_no参数为准。

3、deduct_auth_no与deduct_out_order_no不能同时为空:

deduct_auth_no::发放红包时产生的支付宝资金订单号(支付接口返回的auth_no);

deduct_out_order_no:发放红包时的商户授权资金订单号(支付接口设置的out_order_no);

4、payee_user_id:收款方支付宝唯一用户号——pid(根据设置的pid,红包金额转入对应账户内);

三、接口请求示例

JAVA版请求示例

1、A用户领取红包

public static void main(String[] args) throws AlipayApiException {
        //在SDK调用前需要进行初始化
		AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
		AlipayFundCouponOrderDisburseRequest request = new AlipayFundCouponOrderDisburseRequest();
		AlipayFundCouponOrderDisburseModel model = new AlipayFundCouponOrderDisburseModel();
        //商户的授权资金订单号,同一商户不同的订单,商户授权资金订单号不能重复
		model.setOutOrderNo("20171228925");
		//本次资金操作的请求流水号,同一商户每次不同的资金操作请求
		model.setOutRequestNo("201712271645335");
        //发放红包时产生的支付宝资金订单号。deduct_auth_no与下面的deduct_out_order_no不能同时为空
        //二者都存在时,以deduct_auth_no为准
        //model.setDeductAuthNo("");
		//该参数为支付接口的OutOrderNo与OutOrderNo
        model.setDeductOutOrderNo("2017122716463224");
        model.setOrderTitle("红包打款");
        model.setAmount("0.01");
        //收款方的支付宝唯一用户号
        model.setPayeeUserId("用户2088开头的信息(此处脱敏)");
        //收款方的支付宝登录号,形式为手机号或邮箱等
       // model.setPayeeLogonId("手机号");
        //该笔订单允许的最晚付款时间,逾期将关闭该笔订单 .取值范围:1m~7d
        model.setPayTimeout("1h");
        request.setBizModel(model);
		AlipayFundCouponOrderDisburseResponse response = alipayClient.execute(request);
		if(response.isSuccess()){
		System.out.println("调用成功");
		} else {
		System.out.println("调用失败");
		}
		System.out.println(response.getBody());
}

2、B用户领取红包

当第二个人领取红包时,参数注意如下:

1、out_order_no:(需改变)为同一商户不同订单的授权资金订单号;

2、out_request_no:为本次交易,资金操作的请求流水号,是否重复都可以调用成功(但建议不要重复);

若out_order_no未改变时,报错UNIQUE_VIOLATION:下单失败,商户订单号重复。

public static void main(String[] args) throws AlipayApiException {
        //在SDK调用前需要进行初始化
		AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
		AlipayFundCouponOrderDisburseRequest request = new AlipayFundCouponOrderDisburseRequest();
		AlipayFundCouponOrderDisburseModel model = new AlipayFundCouponOrderDisburseModel();
        //商户的授权资金订单号,同一商户不同的订单,商户授权资金订单号不能重复
		model.setOutOrderNo("20171228926");
		//本次资金操作的请求流水号,同一商户每次不同的资金操作请求
		model.setOutRequestNo("201712271645335");
        //发放红包时产生的支付宝资金订单号。deduct_auth_no与下面的deduct_out_order_no不能同时为空
        //二者都存在时,以deduct_auth_no为准
        //model.setDeductAuthNo("");
		//该参数为支付接口的OutOrderNo与OutOrderNo
        model.setDeductOutOrderNo("2017122716463224");
        model.setOrderTitle("红包打款给用户B");
        model.setAmount("0.01");
        //收款方的支付宝唯一用户号
        model.setPayeeUserId("用户2088开头的信息(此处脱敏)");
        //收款方的支付宝登录号,形式为手机号或邮箱等
       // model.setPayeeLogonId("手机号");
        //该笔订单允许的最晚付款时间,逾期将关闭该笔订单 .取值范围:1m~7d
        model.setPayTimeout("1h");
        request.setBizModel(model);
		AlipayFundCouponOrderDisburseResponse response = alipayClient.execute(request);
		if(response.isSuccess()){
		System.out.println("调用成功");
		} else {
		System.out.println("调用失败");
		}
		System.out.println(response.getBody());
}


PHP版请求示例

1、A用户领取红包

<?php
require_once 'AopSdk.php';
$aop = new AopClient ();
$aop->appId = '填写您的appid';
$aop->rsaPrivateKey = '填写您的私钥';
$aop->alipayrsaPublicKey='填写您的支付宝公钥';
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='utf-8';
$aop->format='json';
$date=date("YmdHis");
$arr=range(1000,9999);
shuffle($arr);
$request = new AlipayFundCouponOrderDisburseRequest ();
$request->setBizContent("{" .
			""out_order_no":"20171228925"," .
// 			""deduct_auth_no":"2014031600002001260000001024"," .
			""deduct_out_order_no":"2017122716463224"," .
			""out_request_no":"201712271645335"," .
			""order_title":"红包打款"," .
			""amount":0.01," .
			""payee_user_id":"用户2088开头的信息(此处脱敏)"," .
// 			""payee_logon_id":"收款方登录号"," .
			""pay_timeout":"1h"" .
			"}");
$result = $aop->execute ( $request); 
var_dump($result);

2、B用户领取红包

当第二个人领取红包时,参数注意如下:

1、out_order_no:(需改变)为同一商户不同订单的授权资金订单号;

2、out_request_no:为本次交易,资金操作的请求流水号,是否重复都可以调用成功(但建议不要重复);

若out_order_no未改变时,报错UNIQUE_VIOLATION:下单失败,商户订单号重复。

<?php
require_once 'AopSdk.php';
$aop = new AopClient ();
$aop->appId = '填写您的appid';
$aop->rsaPrivateKey = '填写您的私钥';
$aop->alipayrsaPublicKey='填写您的支付宝公钥';
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='utf-8';
$aop->format='json';
$date=date("YmdHis");
$arr=range(1000,9999);
shuffle($arr);
$request = new AlipayFundCouponOrderDisburseRequest ();
$request->setBizContent("{" .
			""out_order_no":"20171228926"," .
// 			""deduct_auth_no":"2014031600002001260000001024"," .
			""deduct_out_order_no":"2017122716463224"," .
			""out_request_no":"201712271645335"," .
			""order_title":"红包打款给用户B"," .
			""amount":0.01," .
			""payee_user_id":"用户2088开头的信息(此处脱敏)"," .
// 			""payee_logon_id":"收款方登录号"," .
			""pay_timeout":"1h"" .
			"}");
$result = $aop->execute ( $request); 
var_dump($result);


.NET版本请求示例

IAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", "RSA2", config.alipay_public_key, config.charset, false);


        AlipayFundCouponOrderDisburseRequest request = new AlipayFundCouponOrderDisburseRequest();
        request.BizContent="{" +
        ""out_order_no":"20171228925"," +
// 			""deduct_auth_no":"2014031600002001260000001024"," +
			""deduct_out_order_no":"2017122716463224"," +
			""out_request_no":"201712271645335"," +
			""order_title
上一篇:STL中实现 iterator trail 的编程技巧


下一篇:C++泛型线性查找算法——find