说明:
ISV下单前,可以通过此接口咨询用户优惠信息。
交互UI示例:
需要注意的点:
1.apdid_token参数为用户设备信息,接口使用方法如下:
// 获取用户信息设备 AlipayJSBridge.call('getO2ODeviceToken', { appName: 'kb_isv_110229', appKey:'98y6VvdaDLpoqWZw' }, function (result) { //回调 //alert(result.appToken); });
这里需要注意的是appName,appKey参数不需要改变它们的值!!!
result数据结构:
1、调用失败: {"error":xxx,"errorMessage":"xxx"}2、调用成功: {'appToken':'xxxssajkjkjkxdkwqkqwb'}
2.goods_info参数中quantity(商品数量),price(商品单价)参数需要满足quantity * price = total_amount,否则接口会报错,报错示例如下:
{"koubei_trade_order_consult_response":{"code":"40004","msg":"Business Failed","sub_code":"INVALID_PARAMETER","sub_msg":"参数有误单品总金额:0.03不能超过订单金额:0.01"},"sign":"iWhTXJRc72PK+AwSKcQGoA206NL8E47Ob9TtqQA6jCSJO02+6dJNm3D3Jg8D7jYKwpFrMndqI50ZWnUgfghjp57CaLD/6ULoOS3V0MFg1XvP+d/ay7h/CAqWd5uAZlUJXmpfRHzLj4hmdfq/sHeqjNUvoSYeYgF9I718HbG033ZhIR/N/OzV2kaxox2ywVvMmdKgoiD0jrWZ2ggFVe/mwJ7pgpwgQisiEMHV0h1bn+95wzGelA1THOhj0M57VRdKWpoag=="}
3.返回参数discount_detail参数中id参数一般有两种格式:
"discount_detail":[ { "discount_type":"M_DISCOUNT", "id":"1801220004000998509",//这种格式一般是活动id,一般是不需要用户领取的 "is_hit":"false", "is_purchased":"false", "name":"1.1折" }, { "discount_type":"M_DISCOUNT", "id":"VOUCHER_DC_VOUCHER_DEFAULT_NULL_2018021100073002403700UQOVTK", //这种格式一般是优惠券id,需要用户领取 "is_hit":"false", "is_purchased":"false", "name":"1.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"); KoubeiTradeOrderConsultRequest request = new KoubeiTradeOrderConsultRequest();request.setBizContent("{" +"\"request_id\":\"20180206134530999\"," +"\"user_id\":\"2088712969xxxxxx\"," +"\"total_amount\":0.01," +"\"undiscountable_amount\":0," +"\"shop_id\":\"2017080300077000000044490772\"," +"\"goods_info\":[{" +"\"goods_id\":\"wuhuo1996\"," +"\"goods_name\":\"武霍專用\"," +"\"goods_category\":\"201701000\"," +"\"quantity\":\"1\"," +"\"price\":0.01" +"}]," +"\"apdid_token\":\"e6yhhS3s6I0rFtB2f/y3doGNY27x0hFzu6vKSPROjXiiVKVYSn108AIxG1H/4SML0pRXZ1DY3b/jG6vWv/eP/GYLmzbKxbqISg8LoyaA29T5oq+ENu3vD6HsClPwHlggetqN4kw3UQxemf5oWuQ/k7oEg4N+amtEzih+hNkTvKLLE5oU0N98wW++uxQWUtNh5N/WRtH0Ric7bMbAc6dYfuc4rbcIaPWgKSr9MPyJa6P11eXzP69/aY34RvAemxg==\"" +"}");KoubeiTradeOrderConsultResponse response;try { response = alipayClient.execute(request); 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 { }
如果大家还有什么疑问欢迎帖子下面跟帖追问吐槽