天天看點

支付寶卡包——建立卡劵模闆(alipay.pass.template.add)一、注意事項二、參數說明三、接口請求示例

接口名稱:卡券模闆建立接口

英文名稱:alipay.pass.template.add

上一步:[url]https://openclub.alipay.com/read.php?tid=12967&fid=72&page=1#anchor3[/url]

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

一、注意事項

該接口用于進行建立支付寶卡劵模闆。

1、tpl_content設定的content傳值為pass.json中的參數資訊;

具體content參數說明詳見:[url]https://docs.open.alipay.com/199/105249/[/url]

2、content參數中建議使用雙$符号标志自定義參數,目的是為後續調用流程更便利。

建議必須設定自定義參數的資料為:code、channelID、serialNumber,headFields,詳見接口調用代碼示例。

二、參數說明

1、unique_id:支付寶有唯一性校驗,請保證每次請求該值唯一;

2、tpl_content:content(即pass.json内容,必傳)、icon、logo(圖檔url位址,必傳)、strip(圖檔的url位址);

3、content:模闆中的自定義參數以雙$符号标志,即$ serialNumber $表示自定義參數名為serialNumber,供釋出卡券時使用

三、接口請求示例

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); 
        AlipayPassTemplateAddRequest request = new AlipayPassTemplateAddRequest();
        request.setBizContent(
        //unique_id參數支付寶有唯一性校驗,請保證每次請求該值唯一
         "{"unique_id":"2018062914123889695078785","
         + ""tpl_content":"
         + "{"logo":"https://alipass.alipay.com//temps/free/logo.png","
         + ""strip":"https://alipass.alipay.com//temps/free/strip.png","
         + ""icon":"http://alipassprod.test.alipay.net/temps/free/icon.png","
         + ""content":{"
         + ""evoucherInfo":"
         + "{"title":"可可優惠券","
         + ""type":"coupon","
         + ""product":"free","
         + ""startDate":"$validStartDate$","
         + ""endDate":"$validEndDate$","
         + ""operation":"
         + "[{"format":"barcode","message":"$code$","messageEncoding":"UTF-8","altText":"$code$"}],"
         + ""einfo":{"
         + ""logoText":"$logoText$","
         + ""headFields":"
         + "[{"key":"status","label":"狀态","value":"$useStateDesc$","type":"text"}],"
         + ""primaryFields":"
         + "[{"key":"strip","label":"","value":"$discountInfo$","type":"text"}],"
         + ""secondaryFields":"
         + "[{"key":"validDate","label":"有效期至:","value":"$validEndDate$","type":"text"}],"
         + ""auxiliaryFields":[],"
         + ""backFields":"
         + "[{"key":"description","label":"詳情描述","value":"1.該優惠有效期:截止至2020年06月01日;n2.憑此券可以享受以下優惠:n享門市價優惠n不與其他優惠同享。詳詢商家。","type":"text"},"
         + "{"key":"shops","label":"可用門店","value":"","type":"text"},"
         + "{"key":"disclaimer","label":"負責聲明","value":"除特殊注明外,本優惠不能與其他優惠同時享受;本優惠最終解釋權歸商家所有,如有疑問請與商家聯系。提示:為了使您得到更好的服務,請在進店時出示本券。","type":"text"}"
         + "]},"
         + ""remindInfo":{"offset":"2"}},"
         + ""merchant":{"mname":"hodewu","mtel":"","minfo":""},"
         + ""platform":{"channelID":"$channelID$","webServiceUrl":""},"
         + ""style":{"backgroundColor":"RGB(255,126,0)"},"
         + ""fileInfo":"
         + "{"formatVersion":"2","canShare":true,"canBuy":false,"canPresent":true,"serialNumber":"$serialNumber$","supportTaxi":"true","taxiSchemaUrl":"alipays://platformapi/startapp?appId=20000130&sourceId=20000030&showTitleBar=YES&showToolBar=NO&showLoading=NO&safePayEnabled=YES&readTitle=YES&backBehavior=back&url=/www/index.html"},"
        + ""appInfo":"
        + "{"app":{},"label":"","message":""},"
        + ""source":"alipassprod","
        + ""alipayVerify":[]"
        + "}}}");
         AlipayPassTemplateAddResponse 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_template_add_response":{"code":"10000","msg":"Success","result":"{"errorCode":"KP.AE_SUCCESS","errorMsg":"處理成功","tpl_id":"2019013016274826850929194","tpl_params":["useStateDesc","logoText","discountInfo","validEndDate","validStartDate","code","serialNumber","channelID"]}","success":true},"sign":"PuYva+T+UJsS554x2Q73LXqNJHUp3zjK+N1TOyR4oZgMt6cMmA0kkqCb0N8+08iun1C+QGaipSLJ/iNvsTcwghIvsU/vtS2V5Bu9HD0n0B3rMmpS5bjGuNhOF0hnwJlxoZNI1y+Lwo9h5PqyTMyg/eIKTCPE5WRCcNxpVV8MEsCJEbDPNyHTfiBEkh/tQwael7n7fKrBtN1f7xpqqxrySv1GMdX/jtjFY3X/AEl0dztmX/jgGiH89zIxAEThgA9qR6RWLn1k9ioHfE/l3wMfKAjWo5lavAWzXedExu2NswpU1lgF0GpvVjvq6d4cEwaGW51peU/V2jDrsnMBTPqWdQ=="}      

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 AlipayPassTemplateAddRequest ();
$request->setBizContent(
//unique_id參數支付寶有唯一性校驗,請保證每次請求該值唯一
         '{"unique_id":"2018062914123889695078789",'
         . '"tpl_content":{'
         . '"logo":"https://alipass.alipay.com//temps/free/logo.png",'
         . '"strip":"https://alipass.alipay.com//temps/free/strip.png",'
         . '"icon":"http://alipassprod.test.alipay.net/temps/free/icon.png",'
         . '"content":{'
         . '"evoucherInfo":{'
         . '"title":"可可優惠券",'
         . '"type":"coupon",'
         . '"product":"free",'
         . '"startDate":"$validStartDate$",'
         . '"endDate":"$validEndDate$",'
         . '"operation":'
         . '[{"format":"barcode","message":"$code$","messageEncoding":"UTF-8","altText":"$code$"}],'
         . '"einfo":{'
         . '"logoText":"$logoText$",'
         . '"headFields":'
         . '[{"key":"status","label":"狀态","value":"$useStateDesc$","type":"text"}],'
         . '"primaryFields":'
         . '[{"key":"strip","label":"","value":"$discountInfo$","type":"text"}],'
         . '"secondaryFields":'
         . '[{"key":"validDate","label":"有效期至:","value":"$validEndDate$","type":"text"}],'
         . '"auxiliaryFields":[],'
         . '"backFields":'
         . '[{"key":"description","label":"詳情描述","value":"1.該優惠有效期:截止至2020年06月01日;n2.憑此券可以享受以下優惠:n享門市價優惠n不與其他優惠同享。詳詢商家。","type":"text"},'
         . '{"key":"shops","label":"可用門店","value":"","type":"text"},'
         . '{"key":"disclaimer","label":"負責聲明","value":"除特殊注明外,本優惠不能與其他優惠同時享受;本優惠最終解釋權歸商家所有,如有疑問請與商家聯系。提示:為了使您得到更好的服務,請在進店時出示本券。","type":"text"}'
         . ']},'
         . '"remindInfo":{"offset":"2"}},'
         . '"merchant":{"mname":"hodewu","mtel":"","minfo":""},'
         . '"platform":{"channelID":"$channelID$","webServiceUrl":""},'
         . '"style":{"backgroundColor":"RGB(255,126,0)"},'
         . '"fileInfo":'
         . '{"formatVersion":"2","canShare":true,"canBuy":false,"canPresent":true,"serialNumber":"$serialNumber$","supportTaxi":"true","taxiSchemaUrl":"alipays://platformapi/startapp?appId=20000130&sourceId=20000030&showTitleBar=YES&showToolBar=NO&showLoading=NO&safePayEnabled=YES&readTitle=YES&backBehavior=back&url=/www/index.html"},'
        . '"appInfo":'
        . '{"app":{},"label":"","message":""},'
        . '"source":"alipassprod",'
        . '"alipayVerify":[]'
        . '}}}');
$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_template_add_response' => 
    object(stdClass)[9]
      public 'code' => string '10000' (length=5)
      public 'msg' => string 'Success' (length=7)
      public 'result' => string '{"errorCode":"KP.AE_SUCCESS","errorMsg":"處理成功","tpl_id":"2019022209351735229484926","tpl_params":["useStateDesc","logoText","discountInfo","validEndDate","validStartDate","code","serialNumber","channelID"]}' (length=214)
      public 'success'       

繼續閱讀