说明:
在用户查询口碑优惠资产信息,查看可享受的优惠。
调用流程:
需要注意的点:
1.该接口有三个枚举,分别是:
A 用户所有资产(USER_ALL_ASSET),
B 用户指定商户可用资产(USER_MERCHANT_ASSET),
C 用户指定门店可用资产(USER_SHOP_ASSET)
2.因为接口是用户查询口碑优惠资产信息,所以肯定是需要【用户信息授权】的,在唤起用户授权页面的过程中,需在拼接跳转的url中指定固定的scope参数值,此参数可保证较长时间的有效性(为期一年),即用户仅需授权一次后即可维持一年的授权有效期,参数值为scope=auth_user_assets。 针对其他场景,比如会员卡,闪电开票,生活缴费等不同产品,scope是不同的,如果scope传递错误,相当于用户并没有授权给ISV这个产品的权限,所以在调用接口时会报错“无效的访问令牌”。
【“无效的访问令牌”排查方案】
3.如果您是代商户开发集成,在查询用户指定商户可用资产(USER_MERCHANT_ASSET)、用户指定门店可用资产(USER_SHOP_ASSET)时还需要用到【第三方应用授权】;指定USER_SHOP_ASSET必须传递shop_id参数
4.如果接口中既需要第三方应用授权,又需要用户信息授权,相当于用户是授权给商户,而不是ISV。所以在拼接用户信息授权的url时,url链接中的APPID和redirect_uri参数需要传递商户的
代码示例:
1.查询用户所有资产
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",AlipayConfig.app_id,AlipayConfig.merchant_private_key,"json","GBK",AlipayConfig.alipay_public_key,"RSA2"); KoubeiMarketingCampaignUserAssetQueryRequest request = new KoubeiMarketingCampaignUserAssetQueryRequest(); request.setBizContent("{" + ""scope":"USER_ALL_ASSET"," + ""page_num":1," + ""page_size":50" + "}"); KoubeiMarketingCampaignUserAssetQueryResponse response; try { response = alipayClient.execute(request,"uassetsBcf4f2ca7d4ae4d50960995fea73b8X40"); if(response.isSuccess()){ System.out.println("调用成功"+response.getBody()); } else { System.out.println("调用失败"+response.getBody()); } } catch (AlipayApiException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { }
2.查询用户指定商户可用资产
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",AlipayConfig.app_id,AlipayConfig.merchant_private_key,"json","GBK",AlipayConfig.alipay_public_key,"RSA2"); KoubeiMarketingCampaignUserAssetQueryRequest request = new KoubeiMarketingCampaignUserAssetQueryRequest(); request.putOtherTextParam("app_auth_token","201803BBbb7ea300ac0342b78d34bd9ea3a96X35"); request.setBizContent("{" + ""scope":"USER_MERCHANT_ASSET"," + ""page_num":1," + ""page_size":50" + "}"); KoubeiMarketingCampaignUserAssetQueryResponse response; try { response = alipayClient.execute(request,"uassetsB05f0c40dee374f7db6d0c72d93c8eX40"); if(response.isSuccess()){ System.out.println("调用成功"+response.getBody()); } else { System.out.println("调用失败"+response.getBody()); } } catch (AlipayApiException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { }
3.查询用户指定门店可用资产
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",AlipayConfig.app_id,AlipayConfig.merchant_private_key,"json","GBK",AlipayConfig.alipay_public_key,"RSA2"); KoubeiMarketingCampaignUserAssetQueryRequest request = new KoubeiMarketingCampaignUserAssetQueryRequest(); request.putOtherTextParam("app_auth_token","201803BBbb7ea300ac0342b78d34bd9ea3a96X35"); request.setBizContent("{" + ""scope":"USER_MERCHANT_ASSET"," + ""page_num":1," + ""shop_id":"20170xxxxxxxxxxxxxx"," + ""page_size":50" + "}"); KoubeiMarketingCampaignUserAssetQueryResponse response; try { response = alipayClient.execute(request,"uassetsB05f0c40dee374f7db6d0c72d93c8eX40"); if(response.isSuccess()){ System.out.println("调用成功"+response.getBody()); } else { System.out.println("调用失败"+response.getBody()); } } catch (AlipayApiException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { }
如果大家还有什么疑问欢迎帖子下面跟帖追问吐槽