该接口用于用户在商户PC页进行红包的发放,付款时会链接到支付宝PC登录页面进行登录和后续的支付,在支付成功后跳转回商户页。参数详情点击参考文档 我这边分享一下java版的示例供大家参考,适用于jdk版本1.5及以上的开发环境
1.代码示例:
/**
*
*/
/**
* @author wb-jm273093
*
*/
package alipay.com.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayFundCouponOrderPagePayModel;
import com.alipay.api.request.AlipayFundCouponOrderPagePayRequest;
import com.alipay.api.response.AlipayFundCouponOrderPagePayResponse;
import alipay.com.config.Config;
/**
* alipay.fund.coupon.order.page.pay(红包页面支付接口)
* @author wb-wly251833
* 文档链接:https://docs.open.alipay.com/api_5/alipay.fund.coupon.order.page.pay
*/
public class AlipayFundCouponOrderPagePay{
public static void main(String[] args) throws AlipayApiException {
//在SDK调用前需要进行初始化
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", Config.appId, Config.privateKey, "json","utf-8", Config.alipayPulicKey, "RSA");
AlipayFundCouponOrderPagePayRequest request = new AlipayFundCouponOrderPagePayRequest();
AlipayFundCouponOrderPagePayModel model = new AlipayFundCouponOrderPagePayModel();
////商户的授权资金订单号 (后面可用此参数用于打款接口)
model.setOutOrderNo("2017122716463213");
//商户本次资金操作的请求流水号
model.setOutRequestNo("201712271645325");
model.setOrderTitle("红包页面支付接口发送红包");
model.setAmount("0.03");
request.setBizModel(model);
AlipayFundCouponOrderPagePayResponse response = alipayClient.pageExecute(request,"get");
if(response.isSuccess()){
System.out.println("调用成功");
} else {
System.out.println("调用失败");
}
System.out.println(response.getBody());
}
}
我们上面使用的是get方式,调用成功则返回访问链接(这个不是同步返回,是请求成功返回):
https://openapi.alipay.com/gateway.do?alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016112803499836&biz_content=%7B%22amount%22%3A%220.03%22%2C%22order_title%22%3A%22%E7%BA%A2%E5%8C%85%E9%A1%B5%E9%9D%A2%E6%94%AF%E4%BB%98%E6%8E%A5%E5%8F%A3%E5%8F%91%E9%80%81%E7%BA%A2%E5%8C%85%22%2C%22out_order_no%22%3A%222017122716463213%22%2C%22out_request_no%22%3A%22201712271645325%22%7D&charset=utf-8&format=json&method=alipay.fund.coupon.order.page.pay&return_url=https%3A%2F%2Fopenhome.alipay.com%2FdevelopmentDocument.htm&sign=MPLStxWVevgN6QNH1HjwtkNqM6Y0NNzPj%2B3asC71baZ4MMuHsZ7IK99U9nVoWq0yhvS%2FXXuELgd4CdXQaXCsiEN5okJioJchD4Lp4V4ycFomTOGygFGRhTcM6CqMQps%2Bm0YSaFPxwCa4wBJv%2FBq%2BaunFez3rcDsjFB9fiZYV3VA%3D&sign_type=RSA×tamp=2017-12-27+16%3A47%3A11&version=1.0&sign=MPLStxWVevgN6QNH1HjwtkNqM6Y0NNzPj%2B3asC71baZ4MMuHsZ7IK99U9nVoWq0yhvS%2FXXuELgd4CdXQaXCsiEN5okJioJchD4Lp4V4ycFomTOGygFGRhTcM6CqMQps%2Bm0YSaFPxwCa4wBJv%2FBq%2BaunFez3rcDsjFB9fiZYV3VA%3D
使用链接访问,则会跳到扫码支付页面,使用手机扫码支付或者登陆账号支付
如果我们去掉get,直接alipayClient.pageExecute(request);则返回
<form name="punchout_form" method="post" action="https://openapi.alipay.com/gateway.do?charset=utf-8&method=alipay.fund.coupon.order.page.pay&sign=SKLQtYB%2FoM5DdeAmhR8ZecWdxeU9rrRU%2FMSXnxPSkwDvZE7IVe57OOkjYG%2FCKV0rRzr9ThMJDXajUDxNFMzID1Jz3ffHGpOwiF2cDxCOSuYI%2BBwPebLuHXY%2FVG0Yq2gyeM2r8z%2BzFFaTiINbG7lmJfgT3b%2BFPP2Fkc8I2e2YuB4%3D&return_url=https%3A%2F%2Fopenhome.alipay.com%2FdevelopmentDocument.htm&version=1.0&app_id=2016112803499836&sign_type=RSA×tamp=2017-12-27+16%3A53%3A17&alipay_sdk=alipay-sdk-java-dynamicVersionNo&format=json">
<input type="hidden" name="biz_content" value="{"amount":"0.03","order_title":"红包页面支付接口发送红包","out_order_no":"2017122716463213","out_request_no":"201712271645325"}">
<input type="submit" value="立即支付" style="display:none" >
form>
<script>document.forms[0].submit();
script>
将form表单放传入前台访问即可成功显示如上图一样的扫码页面 大家记住这里调用的是 alipayClient.pageExecute(request);不要调用错用execute了,否则会报错的!!! 如有其它问题,欢迎论坛评论留言,如有不足之处也欢迎多多吐槽!!!