|  | @ -12,6 +12,7 @@ import com.yihu.jw.entity.care.device.DevicePatientDevice;
 | 
												
													
														
															|  | import com.yihu.jw.entity.util.AesEncryptUtils;
 |  | import com.yihu.jw.entity.util.AesEncryptUtils;
 | 
												
													
														
															|  | import com.yihu.jw.exception.business.file_upload.*;
 |  | import com.yihu.jw.exception.business.file_upload.*;
 | 
												
													
														
															|  | import com.yihu.jw.patient.dao.BasePatientDao;
 |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.restmodel.ResponseContant;
 | 
												
													
														
															|  | import com.yihu.jw.restmodel.iot.common.UploadVO;
 |  | import com.yihu.jw.restmodel.iot.common.UploadVO;
 | 
												
													
														
															|  | import com.yihu.jw.util.common.LatitudeUtils;
 |  | import com.yihu.jw.util.common.LatitudeUtils;
 | 
												
													
														
															|  | import com.yihu.jw.util.http.HttpClientUtil;
 |  | import com.yihu.jw.util.http.HttpClientUtil;
 | 
												
											
												
													
														
															|  | @ -25,9 +26,15 @@ import org.slf4j.Logger;
 | 
												
													
														
															|  | import org.slf4j.LoggerFactory;
 |  | import org.slf4j.LoggerFactory;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Autowired;
 |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Value;
 |  | import org.springframework.beans.factory.annotation.Value;
 | 
												
													
														
															|  | 
 |  | import org.springframework.data.redis.core.StringRedisTemplate;
 | 
												
													
														
															|  | 
 |  | import org.springframework.http.HttpEntity;
 | 
												
													
														
															|  | 
 |  | import org.springframework.http.HttpMethod;
 | 
												
													
														
															|  | import org.springframework.jdbc.core.JdbcTemplate;
 |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
												
													
														
															|  | import org.springframework.mock.web.MockMultipartFile;
 |  | import org.springframework.mock.web.MockMultipartFile;
 | 
												
													
														
															|  | 
 |  | import org.springframework.scheduling.annotation.Async;
 | 
												
													
														
															|  | import org.springframework.stereotype.Service;
 |  | import org.springframework.stereotype.Service;
 | 
												
													
														
															|  | 
 |  | import org.springframework.util.LinkedMultiValueMap;
 | 
												
													
														
															|  | 
 |  | import org.springframework.util.MultiValueMap;
 | 
												
													
														
															|  | import org.springframework.web.multipart.MultipartFile;
 |  | import org.springframework.web.multipart.MultipartFile;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | import javax.crypto.Cipher;
 |  | import javax.crypto.Cipher;
 | 
												
											
												
													
														
															|  | @ -43,6 +50,7 @@ import java.util.ArrayList;
 | 
												
													
														
															|  | import java.util.HashMap;
 |  | import java.util.HashMap;
 | 
												
													
														
															|  | import java.util.List;
 |  | import java.util.List;
 | 
												
													
														
															|  | import java.util.Map;
 |  | import java.util.Map;
 | 
												
													
														
															|  | 
 |  | import java.util.concurrent.TimeUnit;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | /**
 |  | /**
 | 
												
													
														
															|  |  * Created by Bing on 2021/6/1.
 |  |  * Created by Bing on 2021/6/1.
 | 
												
											
												
													
														
															|  | @ -68,6 +76,84 @@ public class YsDeviceService {
 | 
												
													
														
															|  |     private String fastdfs_file_url;
 |  |     private String fastdfs_file_url;
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private SecurityOrderUtil orderUtil;
 |  |     private SecurityOrderUtil orderUtil;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private StringRedisTemplate redisTemplate;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 获取萤石设备assesToken
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public String getAccessToken() throws Exception {
 | 
												
													
														
															|  | 
 |  |         if(redisTemplate.hasKey(YsConfig.redisKey)){
 | 
												
													
														
															|  | 
 |  |             return redisTemplate.opsForValue().get(YsConfig.redisKey);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         JSONObject param = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         param.put("appKey",YsConfig.AppKey);
 | 
												
													
														
															|  | 
 |  |         param.put("appSecret",YsConfig.Secret);
 | 
												
													
														
															|  | 
 |  |         HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.saasAssesToken,param, HttpMethod.POST);
 | 
												
													
														
															|  | 
 |  |         JSONObject responseBody = response.getBody();
 | 
												
													
														
															|  | 
 |  |         String assToken = null;
 | 
												
													
														
															|  | 
 |  |         if (responseBody.getInteger("code")==200){
 | 
												
													
														
															|  | 
 |  |             assToken = responseBody.getJSONObject("data").getString("accessToken");
 | 
												
													
														
															|  | 
 |  |             Long expireTime = responseBody.getJSONObject("data").getLong("expiresIn");//token有效期
 | 
												
													
														
															|  | 
 |  |             redisTemplate.opsForValue().set(YsConfig.redisKey,assToken,expireTime, TimeUnit.SECONDS);
 | 
												
													
														
															|  | 
 |  | //            Long ss= redisTemplate.getExpire(YsConfig.redisKey);
 | 
												
													
														
															|  | 
 |  | //            System.out.println(expireTime+"---"+ss);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         }else {
 | 
												
													
														
															|  | 
 |  |             throw new Exception("获取token失败");
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return assToken;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 获取IOT开放平台assesToken
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      * @throws Exception
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public String getIotAccessToken() throws Exception {
 | 
												
													
														
															|  | 
 |  |         if(redisTemplate.hasKey(YsConfig.iotRedisKey)){
 | 
												
													
														
															|  | 
 |  |             return redisTemplate.opsForValue().get(YsConfig.iotRedisKey);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         JSONObject param = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         param.put("accessToken",getAccessToken());
 | 
												
													
														
															|  | 
 |  |         HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
 | 
												
													
														
															|  | 
 |  |         JSONObject responseBody = response.getBody();
 | 
												
													
														
															|  | 
 |  |         String assToken = null;
 | 
												
													
														
															|  | 
 |  |         if (responseBody.getInteger("code")==200){
 | 
												
													
														
															|  | 
 |  |             assToken = responseBody.getJSONObject("data").getString("ezOpenAccessToken");
 | 
												
													
														
															|  | 
 |  |             Long expireTime = responseBody.getJSONObject("data").getLong("expireTime");//token有效截止日期
 | 
												
													
														
															|  | 
 |  |             Long nowTime = System.currentTimeMillis();
 | 
												
													
														
															|  | 
 |  |             expireTime = expireTime-nowTime;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             redisTemplate.opsForValue().set(YsConfig.iotRedisKey,assToken,expireTime, TimeUnit.MILLISECONDS);
 | 
												
													
														
															|  | 
 |  |             //设备解密密钥
 | 
												
													
														
															|  | 
 |  |             String secretKey = responseBody.getJSONObject("data").getString("secretKey");
 | 
												
													
														
															|  | 
 |  |             redisTemplate.opsForValue().set(YsConfig.secretKey,secretKey,expireTime, TimeUnit.MILLISECONDS);
 | 
												
													
														
															|  | 
 |  | //            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
 | 
												
													
														
															|  | 
 |  | //            System.out.println(expireTime+"---"+ss);
 | 
												
													
														
															|  | 
 |  |         }else {
 | 
												
													
														
															|  | 
 |  |             throw new Exception("获取token失败");
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return assToken;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 获取设备解密密钥
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      * @throws Exception
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public String getSecretKey() throws Exception {
 | 
												
													
														
															|  | 
 |  |         if(redisTemplate.hasKey(YsConfig.secretKey)){
 | 
												
													
														
															|  | 
 |  |             return redisTemplate.opsForValue().get(YsConfig.secretKey);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         else {
 | 
												
													
														
															|  | 
 |  |             getIotAccessToken();
 | 
												
													
														
															|  | 
 |  |             return redisTemplate.opsForValue().get(YsConfig.secretKey);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * 消息推送
 |  |      * 消息推送
 | 
												
											
												
													
														
															|  | @ -153,6 +239,55 @@ public class YsDeviceService {
 | 
												
													
														
															|  |         //https://www.yuque.com/u1400669/kb/div5py
 |  |         //https://www.yuque.com/u1400669/kb/div5py
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     @Async
 | 
												
													
														
															|  | 
 |  |     public void videoOpen(String deviceSn,HttpServletRequest request) throws Exception {
 | 
												
													
														
															|  | 
 |  |         StringBuilder responseStr = new StringBuilder("--"+deviceSn+"-- ");
 | 
												
													
														
															|  | 
 |  |         MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
 | 
												
													
														
															|  | 
 |  |         param.add("accessToken",getIotAccessToken());
 | 
												
													
														
															|  | 
 |  |         param.add("source",deviceSn+":"+1);
 | 
												
													
														
															|  | 
 |  |         HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.openChannelNo,param, HttpMethod.POST);
 | 
												
													
														
															|  | 
 |  |         JSONObject responseBody = response.getBody();
 | 
												
													
														
															|  | 
 |  |         responseStr.append("->开通通道:"+responseBody.getInteger("code"));
 | 
												
													
														
															|  | 
 |  |         JSONObject param2 = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         param2.put("accessToken",getAccessToken());
 | 
												
													
														
															|  | 
 |  |         param2.put("deviceSerial",deviceSn);
 | 
												
													
														
															|  | 
 |  |         param2.put("channelNo","1");
 | 
												
													
														
															|  | 
 |  |         param2.put("isTrust",0);
 | 
												
													
														
															|  | 
 |  |         response = httpClientUtil.assesTokenPostHttp(YsConfig.surveillanceWay,param2,HttpMethod.POST);
 | 
												
													
														
															|  | 
 |  |         responseBody = response.getBody();
 | 
												
													
														
															|  | 
 |  |         responseStr.append("->获取通道详情:"+responseBody.getInteger("code"));
 | 
												
													
														
															|  | 
 |  |         if (responseBody.getInteger("code")==200){
 | 
												
													
														
															|  | 
 |  |             try {
 | 
												
													
														
															|  | 
 |  |                 JSONObject tmp =  responseBody.getJSONObject("data");
 | 
												
													
														
															|  | 
 |  |                 String validateCode = tmp.getString("ipcValidateCode");
 | 
												
													
														
															|  | 
 |  |                 param2 = new JSONObject();
 | 
												
													
														
															|  | 
 |  |                 param2.put("accessToken",getAccessToken());
 | 
												
													
														
															|  | 
 |  |                 param2.put("deviceSerial",deviceSn);
 | 
												
													
														
															|  | 
 |  |                 param2.put("isEncrypt","0");
 | 
												
													
														
															|  | 
 |  |                 validateCode = messageDecrypt(validateCode,getSecretKey());
 | 
												
													
														
															|  | 
 |  |                 param2.put("validateCode",validateCode);
 | 
												
													
														
															|  | 
 |  |                 response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceEncrypt,param2,HttpMethod.POST);
 | 
												
													
														
															|  | 
 |  |                 responseBody = response.getBody();
 | 
												
													
														
															|  | 
 |  |                 responseStr.append("->视频解密:"+responseBody.getInteger("code"));
 | 
												
													
														
															|  | 
 |  |             }catch (Exception e){
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | //        //设置编码格式
 | 
												
													
														
															|  | 
 |  | //
 | 
												
													
														
															|  | 
 |  | //
 | 
												
													
														
															|  | 
 |  | //        //设置活动检测
 | 
												
													
														
															|  | 
 |  | //        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
 | 
												
													
														
															|  | 
 |  | //        param.add("accessToken",getIotAccessToken());
 | 
												
													
														
															|  | 
 |  | //        param.add("deviceSerial",deviceSn);
 | 
												
													
														
															|  | 
 |  | //        param.add("enable","1");
 | 
												
													
														
															|  | 
 |  | //        param.add("channelNo","1");
 | 
												
													
														
															|  | 
 |  | //        HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp("https://open.ys7.com/api/lapp/device/intelligence/detection/switch/set",param, HttpMethod.POST);
 | 
												
													
														
															|  | 
 |  | //        JSONObject responseBody = response.getBody();
 | 
												
													
														
															|  | 
 |  | //        responseStr.append("->活动检测:"+responseBody.getInteger("code"));
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         logger.info(responseStr.toString());
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * 消息解密
 |  |      * 消息解密
 |