接口名称:红包协议支付接口
英文名称:alipay.fund.coupon.order.agreement.pay
产品首页:[url]https://openclub.alipay.com/read.php?tid=12180&fid=72[/url]
下一步:[url]https://openclub.alipay.com/read.php?tid=13609&fid=72[/url]
一、注意事项
1、适用于商户直接扣除自己账户中的金额。
2、红包协议支付调用方法是execute();
3、如何获取payee_user_id参数值
payee_user_id:收款方的支付宝唯一用户号,以2088开头的16位纯数字组成;
用户领取红包时需在红包打款接口中设置payee_user_id,该参数值可通过用户信息授权或者调用“APP支付宝登录”接口获得用户支付宝UID,用户领取成功后调用打款接口,资金打款到用户对应支付宝账户。
二、参数说明
1、payer_user_id:付款方的支付宝唯一用户号(必须为调用接口appid对应的pid);
2、 pay_timeout:该笔订单允许的最晚付款时间,逾期将关闭该笔订单,取值范围:1m~7d(可能存在对方账户余额不足或网络、系统等原因没有扣款成功);
3、 extra_param:业务扩展参数,用于商户的特定业务信息的传递,json格式设置,
(1)扩展字段中传入orderExpiredTime=1m(指定创建红包后,超过1分钟未被打款(调用打款接口)则自动退款);
示例:extra_param:{ "merchantExt":"orderExpiredTime=1m"},该参数设定在其他支付接口,没有报错,但是也没有生效,只应用于红包协议支付接口;
(2)pay_timeout是指交易创建后设置的最晚付款时间,不同于orderExpiredTime;
三、接口请求示例
JAVA版请求示例
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); AlipayFundCouponOrderAgreementPayRequest request = new AlipayFundCouponOrderAgreementPayRequest(); AlipayFundCouponOrderAgreementPayModel model = new AlipayFundCouponOrderAgreementPayModel(); //商户的授权资金订单号 (自己填写,必须保证唯一性) model.setOutOrderNo(getoutOrderNo()); //商户本次资金操作的请求流水号 (自己填写,必须保证唯一性) model.setOutRequestNo(getoutOrderNo()+"test"); //订单描述 model.setOrderTitle("红包协议支付接口"); //金额,取值范围:[0.01,100000000.00] model.setAmount("0.01"); //付款方的支付宝唯一用户号,以2088开头的16位纯数字组成,调用接口账户关联的付款账户 model.setPayerUserId("商家2088开头的信息(此处脱敏)"); //该笔订单允许的最晚付款时间 model.setPayTimeout("1h"); request.setBizModel(model); AlipayFundCouponOrderAgreementPayResponse response = alipayClient.execute(request); if(response.isSuccess()){ System.out.println("调用成功!"); }else { System.out.println("调用失败!"); } System.out.println(response.getBody()); } /** * 随机生成订单号 * @return */ private static String getoutOrderNo() { // TODO Auto-generated method stub SimpleDateFormat simpleDateFormat; simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); Date date = new Date(); String str = simpleDateFormat.format(date); Random random = new Random(); int rannum = (int) (random.nextDouble() * (999 - 100 + 1)) + 100;// 获取5位随机数 return str+rannum;// 当前时间 } }
响应参数:
{"alipay_fund_coupon_order_agreement_pay_response":{"code":"10000","msg":"Success","amount":"0.01","auth_no":"2019010210002001330220511356","gmt_trans":"2019-01-02 17:12:30","operation_id":"20190102652066653302","out_order_no":"20190102171229111","out_request_no":"20190102171229648test","status":"SUCCESS"},"sign":"bT6Y1TyQnGxSmylf7HD/lN8+L4kBe5tyyYYiVjcqFnMzkBIbxtAnJfUSV5Luup/puxsJ6Ws8HliTuzvTX3dqk098z3Fv1kYhW2AqNNst20evLn/WzJg7pwRieXcyye2EZJKfO6eF4krLp6Wci0fw7xwspfV9+KiB2W8WtUdGSEwLRi+5CIoYDBQMYZWW8txDWzYKGl6/O+DNn3B+AoinNV4QilL4llp5++B+gOpsNQwdRd62IZ26Zcks1glGJUrixpu0GB+nDHkPn0byYM52OOOATKD/LOTRkWBzf2VYXAjBrecj2vXYbT8AAUud+IH8/fMBfX0wkN/xHaOIIVBbUw=="}
PHP版请求示例
<?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 AlipayFundCouponOrderAgreementPayRequest (); $request->setBizContent("{" . ""out_order_no":"80777352559380458"," . ""out_request_no":"8077735255634078"," . ""order_title":"红包协议支付接口"," . ""amount":1.00," . ""payer_user_id":"商家2088开头的信息(此处脱敏)"," . ""pay_timeout":"1h"" . // ""extra_param":"{\"merchantExt\":\"key=value\"}"". "}"); // $request->setNotifyUrl('请填写您的异步通知地址'); $result = $aop->execute ( $request); var_dump($result);
响应参数
public 'alipay_fund_coupon_order_agreement_pay_response' => object(stdClass)[9] public 'code' => string '10000' (length=5) public 'msg' => string 'Success' (length=7) public 'amount' => string '1.00' (length=4) public 'auth_no' => string '2019030610002001330238463473' (length=28) public 'gmt_trans' => string '2019-03-06 16:51:14' (length=19) public 'operation_id' => string '20190306796824493302' (length=20) public 'out_order_no' => string '80777352559380458' (length=17) public 'out_request_no' => string '8077735255634078' (length=16) public 'status' => string 'SUCCESS' (length=7) public 'sign' => string 'f+z581OHP+jqI/lyPfnEWPeOPiAS0z4HghfC6cyZfw0342lZnfUJBd5XU4ELRrZeSnJHxRx6hByFkeiOKGFZELiUanbcJfoHRJbrLJG0pPU0Y62oTLEzQjFhjPqhmZU6BXzZjgXU0h8WvGQ2x+fErkk0BGqtKkScXIymiVGMj30aswJzaZgHpcuGtg2x0vOdy+kz4rVIha8xCJVIjUXBNMUqfSJw3Mb15HuSVCVi36lCj03AW57BRMe5T2VCGG0SfPDRNWlLIiO9RM1k5hpxC4iSl1quoDfk8NzgoLKkJOMV82p5ySg6+qbqpLh1h0XUkTSbPTdESDX4iNqpyBz9JQ==' (length=344)
.NET版本请求示例
IAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", "RSA2", config.alipay_public_key, config.charset, false); AlipayFundCouponOrderAgreementPayRequest request = new AlipayFundCouponOrderAgreementPayRequest(); request.BizContent="{" + ""out_order_no":"20190102171229111"," + ""out_request_no":"20190102171229648test"," + ""order_title":"红包协议支付接口"," + ""amount":0.01," + ""payer_user_id":"商家2088开头的信息(此处脱敏)"," + ""pay_timeout":"1h"" + // ""extra_param":"{\"merchantExt\":\"key=value\"}""+ " }"; AlipayFundCouponOrderAgreementPayResponse response = client.execute(request); Response.Write(response.Body);
响应参数
{"alipay_fund_coupon_order_agreement_pay_response":{"code":"10000","msg":"Success","amount":"0.01","auth_no":"2019010210002001330220511356","gmt_trans":"2019-01-02 17:12:30","operation_id":"20190102652066653302","out_order_no":"20190102171229111","out_request_no":"20190102171229648test","status":"SUCCESS"},"sign":"bT6Y1TyQnGxSmylf7HD/lN8+L4kBe5tyyYYiVjcqFnMzkBIbxtAnJfUSV5Luup/puxsJ6Ws8HliTuzvTX3dqk098z3Fv1kYhW2AqNNst20evLn/WzJg7pwRieXcyye2EZJKfO6eF4krLp6Wci0fw7xwspfV9+KiB2W8WtUdGSEwLRi+5CIoYDBQMYZWW8txDWzYKGl6/O+DNn3B+AoinNV4QilL4llp5++B+gOpsNQwdRd62IZ26Zcks1glGJUrixpu0GB+nDHkPn0byYM52OOOATKD/LOTRkWBzf2VYXAjBrecj2vXYbT8AAUud+IH8/fMBfX0wkN/xHaOIIVBbUw=="}
四、异步通知
触发通知类型
异步通知示例
支付成功后,触发异步通知,notify_url地址接收通知如下:
http://支付接口设置的异步地址?notify_type=fund_auth_pay¬ify_id=91722adff935e8cfa58b3aabf4dead6ibe¬ify_time=2017-02-16 21:46:15&sign_type=RSA2&sign=WcO+t3D8Kg71dTlKwN7r9PzUOXeaBJwp8/FOuSxcuSkXsoVYxBpsAidprySCjHCjmaglNcjoKJQLJ28/Asl93joTW39FX6i07lXhnbPknezAlwmvPdnQuI01HZsZF9V1i6ggZjBiAd5lG8bZtTxZOJ87ub2i9GuJ3Nr/NUc9VeY=&auth_no=null&out_order_no=null&operation_id=null&out_request_no=null&operation_type=PAY&amount=null&status=SUCCESS&gmt