luodangjia
2024-10-31 e25b31c6abf9b26f2b61768ad6039961574b10a1
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
package com.ruoyi.integration.barrierGate.server;
 
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.integration.api.vo.SwitchwayGateReq;
import com.ruoyi.integration.barrierGate.model.SwitchwayGate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
/**
 * @author zhibing.pu
 * @Date 2024/9/10 9:44
 */
@Slf4j
@Service
public class SwitchwayGateService {
 
    private final String url = "http://8.137.103.127/universal";
    
    
    /**
     * 开关道闸
     * @param req
     * @return
     */
    public Boolean gateService(SwitchwayGateReq req){
        SwitchwayGate switchwayGate = new SwitchwayGate()
                .setAppkey(req.getAppkey())
                .setAction(req.getAction())
                .setChannel(req.getChannel())
                .setTimestamp(System.currentTimeMillis() + "")
                .build(req.getSecretkey());
        String body = JSON.toJSONString(switchwayGate);
        String result = HttpUtil.post(url + "/gateService", body);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if(!success){
            log.warn("调用开关道闸失败:\n请求参数:{}\n返回结果:{}", body, result);
        }
        return success;
    }
}