库存增量更新时间:2019/11/07 10:57

涉及接口 hotel.incr.inv
demo语言: Java
开发环境:
jdk1.7以上


非主线程异步轮询调用库存增量接口获取增量, 通过库存增量接口更新产品库存信息


接口调用

后端通过http协议调用艺龙的hotel.incr.inv接口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class HotelInvIncrApi {
    private static double version = 1.50;
    private static EnumLocal locale = EnumLocal.zh_CN;
    private static boolean isHttps = false;
    ...
    ...
     
    /**
     * 通过http工具类调用艺龙接口,将前端参数拼接为URL
     */
    public InvIncrResult getInvIncr(GetInvIncrRequest condition,
        String userName, String appKey, String secretKey) {
        String url = "";
        String responseData = "";
        InvIncrResult result = new InvIncrResult();
        try{
            BaseRequest<GetInvIncrRequest> req = new BaseRequest<GetInvIncrRequest>();
            req.Version = version;
            req.Local = locale;
            req.Request = condition;
     
            //请求参数转换为Json字符串
            String str = JsonUtil.entity2Json(req);
             
            //产生签名
            long epoch = System.currentTimeMillis()/1000;
            String sig = Tool.md5(epoch + Tool.md5(str + appKey) + secretKey);
             
            //产生请求链接
            url = "http://" + serverHost + "/rest?format=json&method=hotel.incr.inv";
            url += "&user="+ userName +"&timestamp=";
            url += epoch;
            url += "&signature=";
            url += sig;
            url += "&data=" + Tool.encodeUri(str);
             
            //发送请求
            responseData = HttpUtil.Send("GET", url, """application/json");
             
            //返回值处理
            result = JsonUtil.jsonToObject(responseData, InvIncrResult.class);
        catch (Exception e) {
            log.info("[HotelInvIncrApi] 异常: " + e);
            log.info("发送的url: " + url);
            log.info("返回值: " + responseData);
        }
        return result;
    }
 
    ...
    ...
}

增量任务类

增量任务轮询请求增量
1
// 具体实现参考订单增量


更新库存状态

根据增量更新库存状态
1
// 具体实现参考订单增量