官方接口文档:https://docs.open.alipay.com/199/105250/
基本操作流程
1.创建应用等流程不概述了,调用该接口主要第一步是模板设计:推荐使用卡券平(https://alipassprod.alipay.com).
在线编辑获取JSON模板,具体的获取JSON模板参考该文档(必读):https://docs.open.alipay.com/199/105249/
2.提取到JSON模板信息,即我们所需的tpl_content字段,然后传入到请求参数中.
详见下面代码信息
//创建卡券模板接口(alipay.pass.template.add) public static void PassTemplateAdd(){ AlipayClient alipayClient=alipayclient(); AlipayPassTemplateAddRequest request = new AlipayPassTemplateAddRequest(); request.setBizContent( "{\"unique_id\":\"14351263934680000_lw\"," + "\"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.该优惠有效期:截止至2024年06月18日;\ 2.凭此券可以享受以下优惠:\ 享门市价优惠\ 不与其他优惠同享。详询商家。\",\"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":"2017082810350676154413356","tpl_params":["useStateDesc","logoText","","validEndDate","validStartDate","code","serialNumber","channelID"]}","success":true},"sign":"MrTvYVSB2PHrV8MdzuXbiiVoGLIWsLMihg7Mz6pPGDiLQH724ToC0FSXpMFG75GmvYfCjlHAADsD1cZeZbYe+HgrcGkyYkCfW3sjur2iq6wcsVUTEzaYp3RGdyJVGdz1pYhSJjMwD4WFVVc17/GAz97/S+UnOZhW9biUu+kALhw="}
注意点:
1.unique_id:参数支付宝有唯一性校验,请保证每次请求该值唯一;
2.模板中的自定义参数以双$符号标志,即$serialNumber$表示自定义参数名为serialNumber,供发放卡券时使用
3.第三方授权开发的话,需要在请求参数setBizContent前添加一行代码
request.putOtherTextParam("app_auth_token", appAuthToken);
接下来你可以操作以下接口流程(参考具体的帖子):
更新模板接口(alipay.pass.template.update):https://openclub.alipay.com/read.php?tid=2231&fid=8
OR 发放卡券接口(alipay.pass.instance.add):https://openclub.alipay.com/read.php?tid=2193&fid=8