Browse Source

Merge branch 'dev' of yeshijie/wlyy2.0 into dev

叶仕杰 3 years ago
parent
commit
fa9ecb5583

+ 13 - 0
common/common-entity/sql记录

@ -1468,11 +1468,24 @@ CREATE TABLE `base_doctor_service_permissions` (
--2021-09-08 ysj
CREATE TABLE `base_onenet_device` (
  `id` varchar(50) NOT NULL,
  `name` varchar(50) DEFAULT NULL COMMENT '设备名称',
  `sn` varchar(50) DEFAULT NULL COMMENT '设备sn码imei',
  `imsi` varchar(50) DEFAULT NULL COMMENT 'sim的imsi',
  `device_id` varchar(50) DEFAULT NULL COMMENT 'onenet平台设备id',
  `device_type` varchar(10) DEFAULT NULL COMMENT '设备厂商类型1未来鹰2 海康',
  `psk` varchar(50) DEFAULT NULL COMMENT 'onenet DTLS加密所使用的PSK',
  `category_code` varchar(10) DEFAULT NULL COMMENT '设备类型标识 14气感,15烟感',
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='onenet平台设备信息';
CREATE TABLE `base_onenet_receive_record` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `status` tinyint(1) DEFAULT NULL COMMENT '状态 1新增 2已处理',
  `content` varchar(5000) DEFAULT NULL COMMENT '内容',
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='onenet 数据接收记录表';

+ 21 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/OnenetDevice.java

@ -17,11 +17,22 @@ import javax.persistence.Table;
@Table(name = "base_onenet_device")
public class OnenetDevice extends UuidIdentityEntityWithCreateTime{
    private String name;//设备名称
    private String sn;//设备sn码imei
    private String imsi;//sim的imsi
    private String psk;//onenet DTLS加密所使用的PSK
    private String deviceId;//onenet平台设备id
    private String categoryCode;//设备类型标识 14气感,15烟感
    @Column(name="name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name="sn")
    public String getSn() {
        return sn;
@ -38,6 +49,16 @@ public class OnenetDevice extends UuidIdentityEntityWithCreateTime{
    public void setImsi(String imsi) {
        this.imsi = imsi;
    }
    @Column(name="psk")
    public String getPsk() {
        return psk;
    }
    public void setPsk(String psk) {
        this.psk = psk;
    }
    @Column(name="device_id")
    public String getDeviceId() {
        return deviceId;

+ 58 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/OnenetReceiveRecord.java

@ -0,0 +1,58 @@
package com.yihu.jw.entity.care.device;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.IdEntity;
import org.springframework.data.annotation.CreatedDate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/9/9
 * @Description:
 */
@Entity
@Table(name = "base_onenet_receive_record")
@SequenceGenerator(name="id_generated", sequenceName="base_onenet_receive_record")
public class OnenetReceiveRecord extends IdEntity {
    private Integer status;//状态 1新增 2已处理
    private String content;//内容
    //创建时间
    @CreatedDate
    protected Date createTime;
    @Column(name="status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    @Column(name="content")
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "create_time", nullable = false, length = 0,updatable = false)
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

+ 26 - 0
common/common-util/src/main/java/com/yihu/jw/util/common/StringUtil.java

@ -0,0 +1,26 @@
package com.yihu.jw.util.common;
import java.util.Random;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/9/9
 * @Description:
 */
public class StringUtil {
    public static String randomInt(int length) {
        String str = "0123456789";
        StringBuffer buffer = new StringBuffer();
        Random random = new Random();
        for(int i = 0; i < length; ++i) {
            int pos = random.nextInt(str.length());
            buffer.append(str.charAt(pos));
        }
        return buffer.toString();
    }
}

+ 57 - 1
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java

@ -663,6 +663,62 @@ public class HttpClientUtil {
        return result;
    }
    public static void main(String[] args)  {
    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url
     *            发送请求的 URL带上参数
     * @param param
     *            POST参数。
     * @return 所代表远程资源的响应结果
     */
    public String sendPost(String url, String param,Map<String,String> headerMap) {
        StringBuffer buffer = new StringBuffer();
        PrintWriter out = null;
        BufferedReader in = null;
        HttpURLConnection conn = null;
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            conn = (HttpURLConnection) realUrl.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            if(headerMap!=null){
                for (String key:headerMap.keySet()){
                    conn.setRequestProperty(key, headerMap.get(key));
                }
            }
            OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            osw.write(param.toString());
            osw.flush();
            // 读取返回内容
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String temp;
            while ((temp = br.readLine()) != null) {
                buffer.append(temp);
                buffer.append("\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return buffer.toString();
    }
}

+ 48 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/third/yunxin/YunxinEndpoint.java

@ -0,0 +1,48 @@
package com.yihu.jw.care.endpoint.third.yunxin;
import com.yihu.jw.care.service.yunxin.YunxinService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/9/9
 * @Description:
 */
@RestController
@RequestMapping(value = "yunxin")
@Api(value = "云信", description = "云信接口", tags = {"云信接口"})
public class YunxinEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private YunxinService yunxinService;
    @GetMapping(value = "appletSign")
    @ApiOperation(value = "生成小程序秘钥")
    public Envelop appletSign(
            @ApiParam(name = "userId", value = "userId")
            @RequestParam(value = "userId",defaultValue = "",required = true) String userId,
            @ApiParam(name = "channelName", value = "channelName")
            @RequestParam(value = "channelName",defaultValue = "",required = false) String channelName,
            @ApiParam(name = "flag", value = "flag")
            @RequestParam(value = "flag",defaultValue = "",required = false) String flag) throws Exception {
        if (StringUtils.isNoneBlank(flag)&&flag.equalsIgnoreCase("yx")){
            return success(yunxinService.yxToken2(userId,channelName));
        }else {
            return success(yunxinService.appletSign(userId));
        }
    }
}

+ 156 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/yunxin/YunxinService.java

@ -0,0 +1,156 @@
package com.yihu.jw.care.service.yunxin;
import com.yihu.jw.entity.base.yx.YxTokenMappingDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.CheckSumBuilder;
import com.yihu.jw.utils.GenerateUserSig;
import com.yihu.jw.yx.dao.YxTokenMappingDao;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.yihu.jw.util.common.StringUtil.randomInt;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/9/9
 * @Description:
 */
@Service
public class YunxinService {
    private static final Logger logger = LoggerFactory.getLogger(YunxinService.class);
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private YxTokenMappingDao yxTokenMappingDao;
    public String yxToken2(String userId,String channelName){
        YxTokenMappingDO yxTokenMappingDO = yxTokenMappingDao.findMappingByAccid(userId);
        if (yxTokenMappingDO!=null){
            return yxTokenMappingDO.getToken();
        }
        WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");
        WlyyHospitalSysDictDO hospitalSysDictDO =  hospitalSysDictDao.findById("YXAPPSECRET");
        if (sysDictDO==null){
            return  "找不到对应的key";
        }
        String appKey = sysDictDO.getDictValue();
        String appSecret = hospitalSysDictDO.getDictValue();
        String nonce = randomInt(10);
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码
        String url = "https://api.netease.im/nimserver/user/create.action";
        Map<String,Object> httpPost = new HashedMap();
        // 设置请求的header
        httpPost.put("AppKey", appKey);
        httpPost.put("Nonce", nonce);
        httpPost.put("CurTime", curTime);
        httpPost.put("CheckSum", checkSum);
        httpPost.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("accid", userId));
        YxTokenMappingDO yxTokenMappingDO1 = new YxTokenMappingDO();
        if (StringUtils.isNoneBlank(channelName)){
            nvps.add(new BasicNameValuePair("name",channelName));
            yxTokenMappingDO1.setName(channelName);
        }
        String response = httpClientUtil.headerPost(url,nvps,"UTF-8",httpPost);
        logger.info("返回日志"+response);
        if(StringUtils.isNoneBlank(response)){
            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
            if (jsonObject.getString("code").equalsIgnoreCase("200")){
                com.alibaba.fastjson.JSONObject jsonObject1 = com.alibaba.fastjson.JSONObject.parseObject(jsonObject.getString("info"));
                if (StringUtils.isNoneBlank(jsonObject1.getString("token"))){
                    yxTokenMappingDO1.setAccid(userId);
                    yxTokenMappingDO1.setToken(jsonObject1.getString("token"));
                    yxTokenMappingDao.save(yxTokenMappingDO1);
                }
                return jsonObject1.getString("token");
            }else if (jsonObject.getString("code").equalsIgnoreCase("414")&&jsonObject.getString("desc").contains("already")){
                return  refreshToken(userId);
            }
        }
        return null;
    }
    /**
     * 重置云信token
     * @param userId
     * @return
     */
    public String refreshToken(String userId){
        YxTokenMappingDO yxTokenMappingDO = yxTokenMappingDao.findMappingByAccid(userId);
        if (yxTokenMappingDO!=null){
            return yxTokenMappingDO.getToken();
        }
        WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");
        WlyyHospitalSysDictDO hospitalSysDictDO =  hospitalSysDictDao.findById("YXAPPSECRET");
        if (sysDictDO==null){
            return  "找不到对应的key";
        }
        String appKey = sysDictDO.getDictValue();
        String appSecret = hospitalSysDictDO.getDictValue();
        String nonce =  randomInt(10);
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码
        String url = "https://api.netease.im/nimserver/user/refreshToken.action";
        Map<String,Object> httpPost = new HashedMap();
        // 设置请求的header
        httpPost.put("AppKey", appKey);
        httpPost.put("Nonce", nonce);
        httpPost.put("CurTime", curTime);
        httpPost.put("CheckSum", checkSum);
        httpPost.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("accid", userId));
        YxTokenMappingDO yxTokenMappingDO1 = new YxTokenMappingDO();
        String response = httpClientUtil.headerPost(url,nvps,"UTF-8",httpPost);
        logger.info("重置云信"+response);
        if(StringUtils.isNoneBlank(response)){
            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
            if (jsonObject.getString("code").equalsIgnoreCase("200")){
                com.alibaba.fastjson.JSONObject jsonObject1 = com.alibaba.fastjson.JSONObject.parseObject(jsonObject.getString("info"));
                if (StringUtils.isNoneBlank(jsonObject1.getString("token"))){
                    yxTokenMappingDO1.setAccid(userId);
                    yxTokenMappingDO1.setToken(jsonObject1.getString("token"));
                    yxTokenMappingDao.save(yxTokenMappingDO1);
                }
                return jsonObject1.getString("token");
            }
        }
        return null;
    }
    /**
     * 腾讯视频生成签名
     * @param userId
     * @return
     */
    public String appletSign(String userId){
        WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("SDKAPPID");
        WlyyHospitalSysDictDO hospitalSysDictDO =  hospitalSysDictDao.findById("SECRETKEY");
        if (sysDictDO!=null&&hospitalSysDictDO!=null){
            return GenerateUserSig.GenTLSSignature(Long.parseLong(sysDictDO.getDictValue()),userId,604800,null,hospitalSysDictDO.getDictValue());
        }
        return null;
    }
}

+ 7 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/OnenetDeviceDao.java

@ -18,5 +18,11 @@ import java.util.List;
public interface OnenetDeviceDao extends PagingAndSortingRepository<OnenetDevice, String>, JpaSpecificationExecutor<OnenetDevice> {
    @Query("select a from OnenetDevice a where a.deviceId = ?1")
    List<OnenetDevice> findByDeviceId(String deviceId);
    OnenetDevice findByDeviceId(String deviceId);
    @Query("select a from OnenetDevice a where a.sn = ?1")
    OnenetDevice findBySn(String sn);
    @Query(value = "select * from base_onenet_device p where p.device_id is null ",nativeQuery = true)
    List<OnenetDevice> findByDeviceId();
}

+ 17 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/OnenetReceiveRecordDao.java

@ -0,0 +1,17 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.OnenetReceiveRecord;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/9/9
 * @Description:
 */
public interface OnenetReceiveRecordDao extends PagingAndSortingRepository<OnenetReceiveRecord, Long>, JpaSpecificationExecutor<OnenetReceiveRecord> {
}

+ 15 - 10
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/OnenetController.java

@ -11,8 +11,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import static com.yihu.jw.care.util.OneNetUtil.token;
/**
@ -56,13 +54,11 @@ public class OnenetController extends BaseController{
        if (obj != null){
            boolean dataRight = OnenetPushUtil.checkSignature(obj, token);
            if (dataRight){
                onenetService.receive(body);
                logger.info("data receive: content" + obj.toString());
            }else {
                logger.info("data receive: signature error");
            }
        }else {
            logger.info("data receive: body empty error");
        }
@ -116,13 +112,22 @@ public class OnenetController extends BaseController{
    @ApiOperation("触发器消息通知接收--废弃")
    @RequestMapping(value = "triggerMessage",method = {RequestMethod.POST,RequestMethod.GET})
    public String triggerMessage(
            HttpServletRequest request) {
    @RequestMapping(value = "addDevice",method = {RequestMethod.GET})
    public String addDevice() {
        try {
            String str = getRequestBodyData(request);
            onenetService.addDevice();
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"addDevice failure");
        }
    }
            logger.info("======================:"+str);
    @ApiOperation("触发器消息通知接收--废弃")
    @RequestMapping(value = "triggerMessage",method = {RequestMethod.POST,RequestMethod.GET})
    public String triggerMessage(@RequestBody String body) {
        try {
            logger.info("======================:"+body);
            return success();
        } catch (Exception e) {
            e.printStackTrace();

+ 98 - 8
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/OnenetService.java

@ -1,14 +1,20 @@
package com.yihu.jw.care.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.dao.device.OnenetDeviceDao;
import com.yihu.jw.care.dao.device.OnenetReceiveRecordDao;
import com.yihu.jw.entity.care.device.OnenetDevice;
import com.yihu.jw.entity.care.device.OnenetReceiveRecord;
import com.yihu.jw.util.http.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
 * Created with IntelliJ IDEA.
@ -25,23 +31,92 @@ public class OnenetService {
    private HttpClientUtil httpClientUtil;
    @Autowired
    private OnenetDeviceDao onenetDeviceDao;
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private OnenetReceiveRecordDao onenetReceiveRecordDao;
    private static final String MasterAPIkey ="Da0iDvhQ5H8OD6phWq=tMubBcBw=";
    private static final String baseUrl = "http://api.heclouds.com";
    public void receive(){
    private static final String baseUrl = "https://api.heclouds.com";
    /**
     * 为了防止消息重推 这里只做记录不做业务处理
     * (onenet:应用服务器收到平台每一次推送请求后,需要在有限时间内返回响应(目前是5秒),且HTTP响应状态码应设置为200,否则平台会认为请求发送失败,
     * 进行消息重推。重推采用指数退避策略,每条消息最多重推16次。如果某条消息一直失败,那么会在接下来的2小时45分4秒重推16次,之后不再重试)
     * @param body
     */
    public void receive(String body){
        //{"msg":{"at":1630985527067,"imei":"868591057157041","type":1,"ds_id":"3200_0_5505","value":"001f0000041401000000000000005a1300000e01c6ffb1fffa00000e620245ca71","dev_id":768777611},"msg_signature":"qq8nsaH/QEUuDnjK+o8vgw==","nonce":"z8SlxYY%"}
        try {
            JSONObject jsonObject = JSON.parseObject(body);
            OnenetReceiveRecord record = new OnenetReceiveRecord();
            record.setContent(jsonObject.getJSONObject("msg").toJSONString());
            record.setStatus(1);
            record.setCreateTime(new Date());
            onenetReceiveRecordDao.save(record);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 添加设备
     */
    public void addDevice(){
        String url = baseUrl +"/devices";
        List<OnenetDevice> onenetDeviceList = onenetDeviceDao.findByDeviceId();
        List<OnenetDevice> onenetDevices = new ArrayList<>();
        for(OnenetDevice device:onenetDeviceList){
            try {
                JSONObject json = new JSONObject();
                json.put("title",device.getName());
                json.put("protocol","LWM2M");
                JSONObject auth_info = new JSONObject();
                auth_info.put(device.getSn(),device.getImsi());
                json.put("auth_info",auth_info);
                String result = apikeyPost(url,json.toJSONString());
                JSONObject jsonObject = JSON.parseObject(result);
                if(jsonObject.getInteger("errno")==0){
                    String deviceId = jsonObject.getJSONObject("data").getString("device_id");
                    String psk = jsonObject.getJSONObject("data").getString("psk");
                    device.setDeviceId(deviceId);
                    device.setPsk(psk);
                    onenetDevices.add(device);
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        if(onenetDevices.size()>0){
            onenetDeviceDao.save(onenetDevices);
        }
    }
    /**
     * 同步设备
     */
    public void sysDevice(){
        String url = baseUrl +"/";
    public void sysDevice(Integer page){
        page = page==null?1:page;
        String url = baseUrl +"/devices?page="+page+"&per_page=100";
        String result = apikeyGet(url);
        JSONObject jsonObject = JSON.parseObject(result);
        if(jsonObject.getInteger("errno")==0){
            List<OnenetDevice> onenetDeviceList = new ArrayList<>();
            JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("devices");
            for (int i=0;i<jsonArray.size();i++){
                JSONObject json = jsonArray.getJSONObject(0);
                String sn = json.getString("rg_id");
                String id = json.getString("id");
                OnenetDevice device = onenetDeviceDao.findBySn(sn);
                if(device!=null){
                    device.setDeviceId(id);
                    onenetDeviceList.add(device);
                }
            }
            if(onenetDeviceList.size()>0){
                onenetDeviceDao.save(onenetDeviceList);
            }
        }
    }
    /**
@ -53,6 +128,21 @@ public class OnenetService {
        Map<String,String> headerMap = new HashMap<>();
        headerMap.put("api-key", MasterAPIkey);
        String result = httpClientUtil.sendGet(url,headerMap);
        logger.info("apikeyGet="+result);
        return result;
    }
    /**
     * onenet请求post方法
     * @param url
     * @param param
     * @return
     */
    public String apikeyPost(String url,String param){
        Map<String,String> headerMap = new HashMap<>();
        headerMap.put("api-key", MasterAPIkey);
        String result = httpClientUtil.sendPost(url,param,headerMap);
        logger.info("apikeyPost="+result);
        return result;
    }
}

+ 1 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/util/OnenetPushUtil.java

@ -71,7 +71,7 @@ public class OnenetPushUtil {
        System.arraycopy(obj.getNonce().getBytes(), 0, signature, token.length(), 8);
        System.arraycopy(obj.getMsg().toString().getBytes(), 0, signature, token.length() + 8, obj.getMsg().toString().length());
        String calSig = Base64.encodeBase64String(mdInst.digest(signature));
        logger.info("check signature: result:{}  receive sig:{},calculate sig: {}",calSig.equals(obj.getMsgSignature()),obj.getMsgSignature(),calSig);
        //logger.info("check signature: result:{}  receive sig:{},calculate sig: {}",calSig.equals(obj.getMsgSignature()),obj.getMsgSignature(),calSig);
        return calSig.equals(obj.getMsgSignature());
    }