官方接口文档:https://docs.open.alipay.com/199/105250/
使用场景介绍对于已经发布的卡券,商户可通过此接口进行更新,更新卡券接口包含三大主要功能:核销卡券、失效卡券、更新卡券样式内容
核销卡券功能
核销卡券主要描述开发者如何将发放出去的卡券进行核销,使卡券在用户的支付宝客户端展示为已使用状态。对于支付宝卡券而言,核销操作只是将卡券状态变更为USED(已使用),用户客户端展示为已使用状态,未涉及资金流的核销。仅支持核销有效状态的卡券,若卡券处于卡券删除或者已转赠,不可进行核销操作
失效卡券功能
失效卡券主要描述开发者如何将发放出去的卡券进行作废,让卡券在用户的支付宝客户端消失的过程
更新卡券功能 更新卡券样式内容,包括内容、logo、背景图、样式等(要支持更新,必须在模板中将对应字段设置成可变参数)
其核心代码如下:
//更新卡券接口(alipay.pass.instance.update) public static void alipaypassinstanceupdate(){ AlipayClient alipayClient=alipayclient(); AlipayPassInstanceUpdateRequest request = new AlipayPassInstanceUpdateRequest(); request.setBizContent( "{\"status\":\"USED\"," //channl_id取发放卡券时候设置的值 + "\"channel_id\":\"2014100900013222\"," //serial_number取发放成功的卡券的值 + "\"serial_number\":\"xm4333673662423559_lw_006\"," + "\"tpl_params\":" + "{" + "\"validStartDate\":\"2017-08-28 08:00:00\"," + "\"validEndDate\":\"2024-08-09 20:00:00\"," + "\"channelID\":\"2014100900013222\"," + "\"discountInfo\":\"凭此券即可打0.5折\"," + "\"code\":\"201607232562587i\"," + "\"useStateDesc\":\"不可使用\"," + "\"logoText\":\"2017年七夕8月28日优惠券\"," + "\"serialNumber\":\"xm4333673662423559_lw_006\"}," +"\"verify_code\":\"201607232562587i\"," +"\"verify_type\":\"barcode\"" + "}"); AlipayPassInstanceUpdateResponse 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_update_response":{ "code":"10000","msg":"Success","result":"{"operate":"UPDATE","serialNumber":"xm4333673662423559_lw_006"}","success":true},"sign":"AKSe17jNvsZAC2SPv3kwrApJfOXTgAzZ628jBuumLSVrF3g424BYCMx9aGqI+mzDphH7DnmTTR/39sVDeLZD8buaXl3h6VBkcdq3LAqY7K2JK60Nk7t0tTNz1tXAL1xflaq8P0t1K3k81EuVXGbyiMxRHg0Q2yZ3koOOXcnnNOY="}
注意点:
1.channl_id取发放卡券时候设置的值
2.serial_number取发放成功的卡券的值
3.当status传值为USED后更新卡券,会在对应的支付宝的失效卡券里面看到,也就是上面说的核销卡券功能
4.当status传值为CLOSED后更新卡券,支付宝对应的卡券包会消失对应的卡券,也就是上面说的失效卡券功能
5.更新卡券功能参考对应的参数文档示例(在发放卡券接口示例,完成卡券发放的基础上,调用更新卡券接口(更新优惠描述信息和logoText),对卡券进行更新):https://docs.open.alipay.com/199/105249/
调用接口后对应的效果图如下: