说明: 本帖是利用支付宝正式环境测试账号测试口碑店铺数据接口,请求中根据文档传入了必传参数,大家可以配置自己的环境,根据自己的需求严格按照文档要求添加相关的可选参数,此demo仅供参考
测试环境:Eclipse+JDK1.6及以上+Tomcat6.0及以上
为提升用户使用口碑店铺插件服务的体验,各插件在为用户提供服务的同时,需将相关的数据同步到口碑,口碑会通过更多的入口和统一的样式展示给用户。通过店铺数据接口,可以丰富店铺内容,提升商家店铺曝光量,以及用户使用体验。
接口示例代码
package com.alipay.koubei.ability; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; import com.alipay.api.DefaultAlipayClient; import com.alipay.api.domain.AlipayOfflineProviderShopactionRecordModel; import com.alipay.api.domain.AlipayOfflineProviderUseractionRecordModel; import com.alipay.api.domain.OuterShopDO; import com.alipay.api.request.AlipayOfflineProviderShopactionRecordRequest; import com.alipay.api.request.AlipayOfflineProviderUseractionRecordRequest; import com.alipay.api.response.AlipayOfflineProviderShopactionRecordResponse; import com.alipay.api.response.AlipayOfflineProviderUseractionRecordResponse; import com.alipay.constants.AlipayServiceEnvConstants; /** * * 欢迎访问论坛:https://openclub.alipay.com/index.php * 店铺数据产品介绍 * 本测试demo仅供参考,以实际需求为准 * @author wb-lh269337 2018-3-28 * */ public class AlipayOfflineProviderShopactionAndUseraction { private static AlipayClient alipayClient; /** 年月日时分秒(无下划线) yyyyMMddHHmmss */ private static final String dtLong = "yyyyMMddHHmmss"; public static void main(String[] args) { // alipayOfflineProviderShopactionRecord(); alipayOfflineProviderUseractionRecord(); } /** * 获得API调用客户端 * * @return */ public static AlipayClient getAlipayClient() { if (null == alipayClient) { alipayClient = new DefaultAlipayClient(AlipayServiceEnvConstants.ALIPAY_GATEWAY, AlipayServiceEnvConstants.APP_ID, AlipayServiceEnvConstants.PRIVATE_KEY, "json", AlipayServiceEnvConstants.CHARSET, AlipayServiceEnvConstants.ALIPAY_PUBLIC_KEY, AlipayServiceEnvConstants.SIGN_TYPE); } return alipayClient; } /** * 返回系统当前时间(精确到毫秒),作为一个唯一的订单编号 * * @return 以yyyyMMddHHmmss为格式的当前系统时间 */ private static String getOrderNum() { Date date = new Date(); DateFormat df = new SimpleDateFormat(dtLong); return df.format(date); } /** * 获取系统当前日期(精确到毫秒),格式:yyyy-MM-dd HH:mm:ss * * @return */ private static String getDateFormatter() { Date date = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss"); return simpleDateFormat.format(date); } /** * * alipay.offline.provider.shopaction.record 商户操作行为接口 * 上传商户行为数据,现在包括的商户行为(商户营业状态、菜品变更、餐桌变更) * */ public static void alipayOfflineProviderShopactionRecord() { AlipayClient alipayClient = getAlipayClient(); AlipayOfflineProviderShopactionRecordRequest request = new AlipayOfflineProviderShopactionRecordRequest(); AlipayOfflineProviderShopactionRecordModel model = new AlipayOfflineProviderShopactionRecordModel(); model.setActionType("insert_table"); model.setEntity("shop"); model.setDateTime(getDateFormatter()); model.setOuterShopDo(getShopOuterShopDo()); model.setActionDetail(getShopActionDetail()); model.setIndustry("REPAST"); model.setActionOuterId(getOrderNum()); request.setBizModel(model); AlipayOfflineProviderShopactionRecordResponse response; try { response = alipayClient.execute(request); if (response.isSuccess()) { System.out.println("调用成功"); System.out.println(response.getBody()); } else { System.out.println("调用失败"); System.out.println(response.getBody()); } } catch (AlipayApiException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 详情设置 * * @return */ private static String getShopActionDetail() { // 构建action_detail json,本次是店铺插入餐桌 JSONObject detail = new JSONObject(); detail.put("tableId", getOrderNum()); detail.put("max", 10);// 最大人数 detail.put("min", 1);// 最小人数 detail.put("tableName", "神龙vip包厢"); detail.put("tableType", 0);// 0普通 1 包厢 detail.put("tableNum", "A01"); detail.put("status", 0);// 0空闲 1 占用 2 不可知 -1 删除 默认空闲 return detail.toJSONString(); } /** * 传入店铺关联关系。标记当前接口涉及到的店铺信息,同时如果传入的数据在口碑不存在, 口碑会建立一条shop_id+ outer_id+ * type的关联数据 * * @return */ private static OuterShopDO getShopOuterShopDo() { OuterShopDO outerShopDO = new OuterShopDO(); //填写自己的口碑店铺ID outerShopDO.setShopId("2017031500077000000027299729"); //填写ISV系统中与口碑店铺shop_id关联的ISV店铺主键 outerShopDO.setOuterId("314232"); //传入ISV的域名 outerShopDO.setType("_2dFire"); return outerShopDO; } //************************************************************************************** /** * * alipay.offline.provider.useraction.record 用户操作行为接口 * 上传用户行为数据,现在包括的用户行为(用户点菜订单、预定订单、排号订单) * */ public static void alipayOfflineProviderUseractionRecord() { AlipayClient alipayClient = getAlipayClient(); AlipayOfflineProviderUseractionRecordRequest request = new AlipayOfflineProviderUseractionRecordRequest(); AlipayOfflineProviderUseractionRecordModel model = new AlipayOfflineProviderUseractionRecordModel(); model.setActionType("order_num"); model.setIndustry("REPAST"); model.setDateTime(getDateFormatter()); model.setActionDetail(getUserActionDetail()); model.setOuterShopDo(getUserOuterShopDo()); model.setEntity("user"); model.setActionOuterId(getOrderNum()); request.setBizModel(model); AlipayOfflineProviderUseractionRecordResponse response; try { response = alipayClient.execute(request); if (response.isSuccess()) { System.out.println("调用成功"); System.out.println(response.getBody()); } else { System.out.println("调用失败"); System.out.println(response.getBody()); } } catch (AlipayApiException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 传入店铺关联关系。标记当前接口涉及到的店铺信息,同时如果传入的数据在口碑不存在, 口碑会建立一条shop_id+ outer_id+ * type的关联数据 * * @return */ private static OuterShopDO getUserOuterShopDo() { OuterShopDO outerShopDO = new OuterShopDO(); //填写自己的口碑店铺ID outerShopDO.setShopId("2017031500077000000027299729"); //填写ISV系统中与口碑店铺shop_id关联的ISV店铺主键 outerShopDO.setOuterId("314232"); //传入ISV的域名 outerShopDO.setType("_2dFire"); return outerShopDO; } /** * 详情设置 * * @return */ private static String getUserActionDetail() { JSONObject detail = new JSONObject(); // detail.put("source ", "koube.com"); detail.put("outOrderId", getOrderNum()); detail.put("detailUrl", "www.baidu.com"); detail.put("qattr", "1-2人"); detail.put("people", 6);// 几个人 detail.put("status", 2);// 状态2 取号成功4 叫号 5 就餐 6 过号 7 取消 detail.put("desc", "变更内容"); detail.put("wait", new Random().nextInt(10));// 前面等待的人数 detail.put("passNumType", 1);// 过号后的处理类型(-1:不可知 0 顺延 1:不可顺延) detail.put("passNumDesc", "过号顺延");// 商家设置的过号后的处理文案 return detail.toJSONString(); } }
请求参数注意事项:
1、app_auth_token:ISV/开发者可以通过“第三方应用授权”得到商家授权令牌(app_auth_token)作为请求参数传入,实现代商家发起请求的能力;
2、entity 对于回传的商户操作行为,固定为shop,代表店铺行为 ,对于回传的用户操作行为,固定为user,代表用户行为
3、outer_shop_do 标记当前接口涉及到的店铺信息,同时如果传入的数据在口碑不存在,口碑会建立一条shop_id+ outer_id+ type的关联数据,shop_id传口碑店铺ID,outer_id传入ISV系统中与口碑店铺shop_id关联的ISV店铺主键。type参数直接传入ISV的域名,注意,一旦设置就不能再次变化。
4、action_outer_id 每次请求的唯一id 可以通过当前唯一id进行问题排查。
调用成功返回信息:
{"alipay_offline_provider_shopaction_record_response":{"code":"10000","msg":"Success"},"sign":"PK9mGX8uy3xfwRKygPxPCuf62YQU5JrdY4yDSn5dRhRcjtcTlzm8Gzv1yhnNXOhyITDzY6O8+rwPpSUqrQXT3VvS6dkMvEnoXsT5uKefRKX9PuvwbttN5Vc7Me57aPX9dReiBji4HgBVMI22gcugZ8mBTuNIecYNAAxiVcZjUFQ="} {"alipay_offline_provider_useraction_record_response":{"code":"10000","msg":"Success"},"sign":"PK9mGX8uy3xfwRKygPxPCuf62YQU5JrdY4yDSn5dRhRcjtcTlzm8Gzv1yhnNXOhyITDzY6O8+rwPpSUqrQXT3VvS6dkMvEnoXsT5uKefRKX9PuvwbttN5Vc7Me57aPX9dReiBji4HgBVMI22gcugZ8mBTuNIecYNAAxiVcZjUFQ="}
如有疑问欢迎跟帖提问,不足之处欢迎多多吐槽!!!