说明:
这里讲的是使用用户信息授权来开卡的流程,如有疑问欢迎追问
用户信息授权参考该文档:[url]https://docs.open.alipay.com/289/105656[/url]
注意:会员卡的scope值为auth_ecard
如何获取会员信息(java版):[url]https://openclub.alipay.com/read.php?tid=921&fid=43[/url]
开卡之前需要先创建卡模板,参考该帖:[url]https://openclub.alipay.com/read.php?tid=1577&fid=8&page=1[/url]
代码如下:
//alipay.marketing.card.open会员卡开卡 public static void card_open(){ AlipayClient alipayClient=alipayclient(); AlipayMarketingCardOpenRequest request = new AlipayMarketingCardOpenRequest(); request.setBizContent("{" + //这个参数要改动,如果重新开卡的话 "\"out_serial_no\":\"201606270000000000000012001\"," + //支付宝卡模板ID "\"card_template_id\":\"20180131000000000782698000300330\"," + "\"card_user_info\":{" + "\"user_uni_id\":\"这里我隐藏自己的信息,填写2088开头的数字\"," + "\"user_uni_id_type\":\"UID\"" + "}," + "\"card_ext_info\":{" + "\"biz_card_no\":\"test_opencard\"," + "\"external_card_no\":\"waibu_carhao\"," + "\"open_date\":\"2018-01-31 15:58:46\"," + "\"valid_date\":\"2020-02-20 21:20:46\"," + //参数有误。会员等级参数有误;必须和卡模板中的等级匹配 "\"level\":\"VIP88\"," + "\"point\":\"1888\"," + "\"balance\":\"2000\"" + "}," + "\"member_ext_info\":{" + "\"name\":\"这里我隐藏自己的信息\"," + "\"gende\":\"MALE\"," + "\"birth\":\"这里我隐藏自己的信息\"," + "\"cell\":\"这里我隐藏自己的信息\"" + " }" + " }"); AlipayMarketingCardOpenResponse response = null; try { response = alipayClient.execute(request,"elccardB0ca3d252ab56404eac4f6f449b64cX44"); System.out.println(response.getBody()); } catch (AlipayApiException e) { e.printStackTrace(); } if(response.isSuccess()){ System.out.println("调用成功"); } else { System.out.println("调用失败"); } }
接口返回信息:
{"alipay_marketing_card_open_response":{"code":"10000","msg":"Success","card_info":{"balance":"2000","biz_card_no":"test_moban0000090544","external_card_no":"waibu_carhao","open_date":"2018-01-31 15:58:46","point":"1888","valid_date":"2020-02-20 21:20:46"}},"sign":"S22Xbk8GGU7DQQpzaMwGVQe55UPvH85d3Iu8iHLBnRtUDPklNSPSX6spff7sb5WSv5lLeZnnNjI9sJB4hKv7hld1TGoIK2GGDsUUQOSPcqpl9/otTbas0nP8OW48rH8hUfikNyRLI/WKb2fTQNd7HalKFc7Y+8d0+vA4MIgBjic="}
注意点:
1.out_serial_no为唯一标识号,每次请求保障唯一;
2.card_template_id为模板id,通过会员卡模板创建接口获取;
3.user_uni_id为支付宝账户userid,为2088开头的16为数字,通过用户信息授权获取,如我上面所写;
效果图展示如下(在支付宝卡包内查看):