接口名稱:支付寶pass建立卡券執行個體接口
英文名稱:alipay.pass.instance.add
上一步:[url]https://openclub.alipay.com/read.php?tid=13240&fid=72[/url]
下一步:[url]https://openclub.alipay.com/read.php?tid=13243&fid=72[/url]
一、注意事項
該接口用于将卡劵發放到使用者卡包内。
recognition_info中的out_trade_no參數值為支付接口中,交易成功的out_trade_no參數值。
即使交易進行退款等操作,隻有交易成功後,可以根據該參數值進行發放卡劵。
二、參數說明
1、recognition_type:設定固定參數值為“1”——訂單資訊;
2、tpl_id:卡劵模版ID,為模闆建立接口傳回的tpl_id參數值;
3、recognition_info:
(1)partner_id:out_trade_no對應的簽約商戶pid(與調用接口對應的pid可以不一緻);
(2)out_trade_no:必須是交易成功的外部交易号(交易失敗或交易關閉無法發劵);
4、tpl_params:為模闆建立接口傳回的tpl_params參數資訊——自定義參數;
(1)code:支付寶卡劵的外部顯示卡号;
(2)serialNumber:支付寶有唯一性校驗,每次請求請保證唯一性,不要重複 ;
(3)channelID:可設定為APPID(從建立應用處擷取)或者pid ,(與調用接口的appid不是同一個賬戶,不會影響使用,隻與卡劵更新接口的channelID參數有關);
三、接口請求示例
Java版本請求示例
public static void main(String[] args) throws AlipayApiException {
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
AlipayPassInstanceAddRequest request = new AlipayPassInstanceAddRequest();
// 自定義參數
request.setBizContent(
//該值固定為1–訂單資訊
"{"recognition_type":"1","
//建立卡券模闆接口傳回的tpl_id
+ ""tpl_id":"2019013016274826850929194","
+ ""recognition_info":{"partner_id":"2088102180198585","
//partner_id必須是交易建立的外部訂單号對應的商戶pid,可以與調用接口的pid不一緻
//此時我設定的2088102180198585是我賣家沙箱賬戶。
//必須是交易建立的外部訂單号
+ ""out_trade_no":"sao2018816105156165"},"
//模版動态參數資訊
+ ""tpl_params":"
+ "{"
+ ""validStartDate":"2018-06-28 11:55:42","
+ ""validEndDate":"2020-06-01 11:55:42","
+ ""secondLogoText":"我是副标題","
//channelID和調用接口的appid不是同一個賬戶,不會影響使用,隻與更新接口的channelID參數有關
+ ""channelID":"2016101800718925","
+ ""discountInfo":"憑此券即可打0.5折","
//支付寶卡包的劵碼,是更新接口的verify_code參數值,建議實時更新
+ ""code":"2016072325625921","
+ ""useStateDesc":"可使用","
+ ""logoText":"2018年支付寶卡包測試-優惠劵","
//支付寶有唯一性校驗,每次請求請保證唯一性,不要重複
+ ""serialNumber":"20170809147614221"}}");
AlipayPassInstanceAddResponse response=null;
try {
response = alipayClient.execute(request);
System.out.println(response.getBody());
} catch (AlipayApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(response.isSuccess()){
System.out.println("調用成功");
} else {
System.out.println("調用失敗");
}
}
響應參數傳回示例
{"alipay_pass_instance_add_response":{"code":"10000","msg":"Success","result":"{"operate":"ADD","serialNumber":"20170809147614221","passId":"93434757086","errorCode":"SUCCESS","errorMsg":"處理成功"}","success":true},"sign":"Y3USnGyTWvdfoJ5j9mqL0N54yCjhx91HsPQg0eg9XEjxJ++TqQeKHBxTVQbQ7K6qWRUKMv4eka6eUWsW5xdJuLHaUI3lVFIfmH1EZZqgWhpAsVGB8EGusF9WUM5UOOxc/r6tjZe3cwijr//M3X8URsi1deTWRzlaipka8m6gT8iEANGvNb7YTlkIQlGzlvjQLurnwMyVfuY4qnU7vQV8Vtx/2VHoI7ZJBLVL4nE7fta/7JMGH+74R+UzWNzsWHdAO3kDqFe/EJECrQuKGHG+CgZJLvSjGQGB+i6xbhJIMD6HaZkN8NysyH1bTVxeesSctkQUhIYEeWhcIqMOb5dxJA=="}
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 AlipayPassInstanceAddRequest ();
$request->setBizContent(
//該值固定為1–訂單資訊
"{"recognition_type":"1","
//建立卡券模闆接口傳回的tpl_id
. ""tpl_id":"2019022209351735229484926","
. ""recognition_info":{"partner_id":"2088102180198585","
//partner_id必須是交易建立的外部訂單号對應的商戶pid,可以與調用接口的pid不一緻
//此時我設定的2088102180198585是我賣家沙箱賬戶。
//必須是交易建立的外部訂單号
. ""out_trade_no":"sao2018816105156165"},"
//模版動态參數資訊
. ""tpl_params":"
. "{"
. ""validStartDate":"2018-06-28 11:55:42","
. ""validEndDate":"2020-06-01 11:55:42","
. ""secondLogoText":"我是副标題","
//channelID和調用接口的appid不是同一個賬戶,不會影響使用,隻與更新接口的channelID參數有關
. ""channelID":"2016101800718925","
. ""discountInfo":"憑此券即可打0.5折","
//支付寶卡包的劵碼,是更新接口的verify_code參數值,建議實時更新
. ""code":"2016072325625921","
. ""useStateDesc":"可使用","
. ""logoText":"2018年支付寶卡包測試-優惠劵","
//支付寶有唯一性校驗,每次請求請保證唯一性,不要重複
. ""serialNumber":"20170809147614255"}}");
$result = $aop->execute ( $request);
var_dump($result);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";
} else {
echo "失敗";
}
public 'alipay_pass_instance_add_response' =>
object(stdClass)[9]
public 'code' => string '10000' (length=5)
public 'msg' => string 'Success' (length=7)
public 'result' => string '{"operate":"ADD","serialNumber":"20170809147614255","passId":"22589","errorCode":"SUCCESS","errorMsg":"處理成功"}' (length=117)
public 'success' => boolean true
public 'sign' => string 'gSKobcHCKlZXZ01KWNJG18KP+wbmC42xDu6g0KUATmQSmQMsYnjTjP1JBz5QemPsg7mS/4X2+ERYLtMaenHDw0wsqzRArPqPc3Pq3gBFnTS52bFFK/Cj3CGpargIcs34PeqnUJdbbo4NtOKPwMnjIIW44oPKINGgU/GaEb/mD9g65MS2zp7EpX75n+xlHvRNWx4NZWi0IPSK3iENW1zU+VpkD5N0wKl7ADL0y2QqTyEEGctuNtsMbuQoww9dn4qPGGTffme1GSZfR9LNANMlKdAxpluRH/6Kt2fNtzpfH0/3xiwaMMSvQJeQ9IV23qpymJXy+bkwICw0G+U8T+60bw==' (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);
AlipayPassInstanceAddRequest request = new AlipayPassInstanceAddRequest();
request.BizContent = "{"
+ ""recognition_type":"1","
+ ""tpl_id":"2019040215104450132405465","
+ ""recognition_info":{"partner_id":"2088501624560335","
+ ""out_trade_no":"20190218ygyg4544745451"},"
+ ""tpl_params":"
+ "{"
+ ""validStartDate":"2019-02-18 17:00:00","
+ ""validEndDate":"2020-03-30 20:00:00","
+ ""channelID":"2088522421611655","
+ ""discountInfo":"憑煜雨的券即可打8.5折","
+ ""code":"201901295762587i03236","
+ ""useStateDesc":"可使用","
+ ""logoText":"瘋狂來電85折券","
+ ""serialNumber":"20190402ygyg00001"}}";
AlipayPassInstanceAddResponse response = client.Execute(request);
Response.Write(response.Body);
{"alipay_pass_instance_add_response":{"code":"10000","msg":"Success","result":