商戶簽署無密支付協定,然後通過代扣的方式發紅包,參數詳情點選 參考文檔 我這邊分享一下java版的示例供大家參考,适用于jdk版本1.5及以上的開發環境 ,sdk可點選 下載下傳 2.代碼示例:
/**
*
*/
/**
* @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.AlipayFundCouponOrderAgreementPayModel;
import com.alipay.api.request.AlipayFundCouponOrderAgreementPayRequest;
import com.alipay.api.response.AlipayFundCouponOrderAgreementPayResponse;
import alipay.com.config.Config;
/**
* 紅包協定支付接口(商戶即請求的appid賬号付款,無需輸入密碼)
* @author wb-wly251833
* 文檔連結:https://docs.open.alipay.com/api_5/alipay.fund.coupon.order.agreement.pay
*/
public class AlipayFundCouponOrderAgreementPay {
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");
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("2088411964648546");
//該筆訂單允許的最晚付款時間
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":"40004","msg":"Business Failed","sub_code":"ERROR_BALANCE_PAYMENT_DISABLE","sub_msg":"餘額支付功能關閉","amount":"0.01","auth_no":"2018010410002001540285562705","operation_id":"20180104462225275402","out_order_no":"20180104145007943","out_request_no":"20180104145007657test","status":"INIT"},"sign":"XXXX"}
由于這邊權限過期了,是以沒有成功傳回的資訊,但是代碼運作是沒問題的 該接口是直接使用的alipayClient.execute(request);,幾個紅包接口調用的方法都不一樣,大家要差別開來,不要混用了。 如有其它問題,歡迎論壇評論留言,如有不足之處也歡迎多多吐槽!!!