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;
|
}
|
|
|
// public static void main(String[] args) {
|
// SwitchwayGateService switchwayGateService = new SwitchwayGateService();
|
// SwitchwayGateReq req = new SwitchwayGateReq();
|
// req.setAction("close");
|
// req.setChannel("001");
|
// Boolean success = switchwayGateService.gateService(req);
|
// if(success){
|
// log.info("调用成功");
|
// }else{
|
// log.info("调用失败");
|
// }
|
// }
|
}
|