先附上官方接口文档地址:[url]https://docs.open.alipay.com/api_5/alipay.marketing.card.template.create[/url]
话不多说,我这里先将测试通过的核心代码贴上
//创建卡模板 public static void template_create(){ AlipayClient alipayClient=alipayclient(); AlipayMarketingCardTemplateCreateRequest request = new AlipayMarketingCardTemplateCreateRequest(); request.setBizContent("{" + "\"request_id\":\"20160726000000441212210001\"," + "\"card_type\":\"OUT_MEMBER_CARD\"," + "\"biz_no_prefix\":\"test_moban\"," + "\"biz_no_suffix_len\":\"10\"," + "\"write_off_type\":\"text\"," + //文本 "\"template_style_info\":{" + "\"card_show_name\":\"刘威测试创建卡模板\"," + "\"logo_id\":\"hkGbT66ZRzamSA0IxQ8EoQAAACMAAQQD\"," + "\"color\":\"rgb(220,20,60)\"," + //深红(猩红) //全棉时代的背景图 "\"background_id\":\"hkGbT66ZRzamSA0IxQ8EoQAAACMAAQQD\"," + "\"bg_color\":\"rgb(219,112,147)\"," + "\"feature_descriptions\":[" + "\"特色信息,用于领卡预览(测试创建卡模板联名卡)\"" + "]," + "\"slogan\":\"会员权益享不停\"," + "\"slogan_img_id\":\"hkGbT66ZRzamSA0IxQ8EoQAAACMAAQQD\"," + "\"brand_name\":\"全棉时代\"" + "}," + //在卡包的卡详情页面会自动添加权益栏位,展现会员卡特权 "\"template_benefit_info\":[{" + "\"title\":\"消费即折扣(权益描述)\"," + "\"benefit_desc\":[" + "\"权益描述信息(消费即折扣)\"" + "]," + "\"start_date\":\"2016-07-18 15:17:23\"," + "\"end_date\":\"2017-08-24 12:12:12\"" + "}]," + "\"column_info_list\":[{" + "\"code\":\"BENEFIT_INFO\"," + "\"more_info\":{" + "\"title\":\"会员专享权益(二级页面标题)\"," + // "\"url\":\"http://www.baidu.com\"," + "\"params\":\"{}\"," + "\"descs\":[" + "\"会员生日7折,这是创建的卡模板信息展示的二级界面\"" + "]" + "}," + "\"title\":\"二级栏目的标题,会员专享\"," + // "\"operate_type\":\"openWeb\"," + "\"operate_type\":\"openNative\"," + "\"value\":\"这个是自定义的第一个栏位信息展示\"}," +"{\"code\":\"BALANCE\",\"title\":\"余额\", \"operate_type\":\"staticinfo\",\"value\":\"\"}," +"{\"code\":\"TELEPHOME\",\"title\":\"手机号码\", \"operate_type\":\"staticinfo\",\"value\":\"13785822461\"}," +"{\"code\":\"LEVEL\",\"title\":\"等级\", \"operate_type\":\"staticinfo\",\"value\":\"\"}," +"{\"code\":\"ZDY\",\"title\":\"自定义栏位2\", \"operate_type\":\"staticinfo\",\"value\":\"自定义第二个\"}," +"{\"code\":\"POINT\",\"title\":\"积分\", \"operate_type\":\"staticinfo\",\"value\":\"\"}" +"]," + "\"field_rule_list\":[{" + "\"field_name\":\"Level\"," + "\"rule_name\":\"ASSIGN_FROM_REQUEST\"," + "\"rule_value\":\"Level\"" + "}]," + "\"open_card_conf\":{" + "\"open_card_source_type\":\"ISV\"," + "\"source_app_id\":\"2014100900013222\"," + "\"open_card_url\":\"https://www.lingka.com\"" + " }," + //"\"service_label_list\":[" + //"\"HUABEI_FUWU\"" + //"]," + "\"shop_ids\":[" + "\"2016083000077000000018269663\"" + "]," + "\"pub_channels\":[{" + "\"pub_channel\":\"SHOP_DETAIL\"," + "\"ext_info\":\"\\\"key\\\":\\\"value\\\"\"" + "}]," + //这里的值会影响开卡接口里面level值的传参 "\"card_level_conf\":[{" + "\"level\":\"VIP88\"," + "\"level_show_name\":\"黄金会员专享\"," + "\"level_icon\":\"1T8Pp00AT7eo9NoAJkMR3AAAACMAAQEC\"," + "\"level_desc\":\"会员级别描述(黄金会员享受免费停车)\"" + "}]" + " }"); AlipayMarketingCardTemplateCreateResponse response = null; try { response = alipayClient.execute(request); System.out.println(response.getBody()); System.out.println(response.getTemplateId());//打印支付宝卡模板ID } catch (AlipayApiException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(response.isSuccess()){ System.out.println("调用成功"); } else { System.out.println("调用失败"); } }
接口返回参数如下:
{"alipay_marketing_card_template_create_response":{"code":"10000","msg":"Success","template_id":"20180131000000000782698000300330"},"sign":"IF5FnUdSn6zggkhzTsoZrPeP7VFOOYC5k8yzoB5peR3xFK4Y9MD0m5PUAE+6aIH2UlFqHKhnyLhl9g0/eD6zNalW9ruyDAtSndEGt8MV/aSsaIPOluCSuJz2z5pluvV7A+LcAKvkcZxoBDYRc3+BdBu027161ClAbFNcyWY3GY4="}
注意点:
1.关于代码中注释的地方,LEVEL,BALANCE,POINT为固定栏位value的值需要为空,只有TELEPHOME才可以赋值
2.service_label_list,服务Code ,HUABEI_FUWU:花呗服务(只有需要花呗服务时,才需要加入该标识)
3.operate_type设置该值为openWeb则栏位value显示这个是自定义的第一个栏位信息展示,点击,会打开more_info中的url(http://www.baidu.com)
4.RGB颜色对照表:[url]http://tool.oschina.net/commons?type=3[/url]
5.logo_id,slogan_img_id等值的获取参考上传图片接口帖:[url]https://openclub.alipay.com/read.php?tid=1030&fid=8[/url]
6.由于目前会员卡改版,没有背面故接口中bg_color该值可预留拓展先不填写,填写之后也不会报错
7.request_id如果要是使用我的代码,该值必改,每次请求必须保证该值的唯一性,其它参数具体参考开头文档描述