14 changed files with 437 additions and 35 deletions
@ -0,0 +1,16 @@ |
|||||
|
package com.yxt.supervise.report.ds.rms; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @author wangpengfei |
||||
|
* @date 2023/9/3 17:06 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class Device { |
||||
|
|
||||
|
private String name; |
||||
|
private String serialNumber; |
||||
|
private String status; |
||||
|
|
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
package com.yxt.supervise.system.device; |
||||
|
|
||||
|
import com.alibaba.nacos.common.model.RestResult; |
||||
|
import com.yxt.common.core.result.ResultBean; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* @author wangpengfei |
||||
|
* @date 2023/9/9 10:30 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("/device") |
||||
|
public class DeviceRest { |
||||
|
@Autowired |
||||
|
private DeviceService deviceService; |
||||
|
@GetMapping("/token") |
||||
|
public ResultBean token (){ |
||||
|
ResultBean rb=new ResultBean(); |
||||
|
String token=deviceService.spToken(); |
||||
|
return rb.success().setData(token); |
||||
|
} |
||||
|
} |
@ -0,0 +1,57 @@ |
|||||
|
package com.yxt.supervise.system.device; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.yxt.common.base.utils.HttpUtils; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.security.KeyManagementException; |
||||
|
import java.security.KeyStoreException; |
||||
|
import java.security.NoSuchAlgorithmException; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @author wangpengfei |
||||
|
* @date 2023/9/9 10:30 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class DeviceService { |
||||
|
@Value("${haiKangConsumer.clientId}") |
||||
|
private String clientId; |
||||
|
|
||||
|
@Value("${haiKangConsumer.clientSecret}") |
||||
|
private String clientSecret; |
||||
|
public static String haiKangToken = ""; |
||||
|
public static String haiKangMessageConsumer = ""; |
||||
|
public void initMain() { |
||||
|
// 先登录
|
||||
|
String loginUrl = "https://api2.hik-cloud.com/oauth/token"; |
||||
|
Map<String, Object> tokenParam = new HashMap<>(); |
||||
|
tokenParam.put("client_id", clientId); // 客户端ID String
|
||||
|
tokenParam.put("client_secret", clientSecret); //访问密钥 String
|
||||
|
tokenParam.put("grant_type", "client_credentials"); //认证模式 String 目前仅支持client_credentials
|
||||
|
String tokenResult = HttpUtils.sendPostMap(loginUrl, tokenParam, ""); |
||||
|
JSONObject tokenObject = JSONObject.parseObject(tokenResult); |
||||
|
haiKangToken = tokenObject.get("access_token").toString(); |
||||
|
} |
||||
|
public String spToken(){ |
||||
|
initMain(); |
||||
|
String lUrl = "https://api2.hik-cloud.com/v1/ezviz/account/info"; |
||||
|
String qlToken=""; |
||||
|
try { |
||||
|
String result=HttpUtils.sendGet(lUrl,haiKangToken); |
||||
|
JSONObject jsonObject = JSONObject.parseObject(result); |
||||
|
JSONObject dataJson = (JSONObject) jsonObject.get("data"); |
||||
|
String appKey = dataJson.get("appKey").toString(); |
||||
|
qlToken = dataJson.get("token").toString(); |
||||
|
} catch (Exception e) { |
||||
|
throw new RuntimeException(e); |
||||
|
} |
||||
|
return qlToken; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue