25 changed files with 2976 additions and 1787 deletions
@ -0,0 +1,46 @@ |
|||||
|
package com.ruoyi.web.controller.api; |
||||
|
|
||||
|
import com.ruoyi.common.annotation.Anonymous; |
||||
|
import com.ruoyi.web.service.IOnenetReceiveService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
/** |
||||
|
* onenet推送 |
||||
|
* |
||||
|
* @author lijunjie |
||||
|
* @date 2023-01-16 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@Anonymous |
||||
|
@RequestMapping("/api/onenet/record") |
||||
|
public class OnenetRecordController |
||||
|
{ |
||||
|
@Autowired |
||||
|
private IOnenetReceiveService onenetReceiveService; |
||||
|
/** |
||||
|
* 查询onenet参数列表 |
||||
|
*/ |
||||
|
@GetMapping("/receive") |
||||
|
public String receive(@RequestParam("msg") String msg, @RequestParam("nonce") String nonce, @RequestParam("signature") String signature) |
||||
|
{ |
||||
|
System.out.println(msg); |
||||
|
System.out.println(nonce); |
||||
|
System.out.println(signature); |
||||
|
return msg; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@PostMapping("/receive") |
||||
|
public String receive(@RequestBody String request) |
||||
|
{ |
||||
|
System.out.println(request); |
||||
|
|
||||
|
boolean res = onenetReceiveService.addOnenetReceive(request); |
||||
|
|
||||
|
return "ok"; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,105 @@ |
|||||
|
package com.ruoyi.web.controller.device; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
|
||||
|
import com.ruoyi.web.domain.po.OnenetReceive; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.PutMapping; |
||||
|
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
import com.ruoyi.common.annotation.Log; |
||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||
|
import com.ruoyi.common.core.domain.AjaxResult; |
||||
|
import com.ruoyi.common.enums.BusinessType; |
||||
|
import com.ruoyi.web.service.IOnenetReceiveService; |
||||
|
import com.ruoyi.common.utils.poi.ExcelUtil; |
||||
|
import com.ruoyi.common.core.page.TableDataInfo; |
||||
|
|
||||
|
/** |
||||
|
* onenet推送记录Controller |
||||
|
* |
||||
|
* @author lijunjie |
||||
|
* @date 2023-02-02 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("/device/receive") |
||||
|
public class OnenetReceiveController extends BaseController |
||||
|
{ |
||||
|
@Autowired |
||||
|
private IOnenetReceiveService onenetReceiveService; |
||||
|
|
||||
|
/** |
||||
|
* 查询onenet推送记录列表 |
||||
|
*/ |
||||
|
@PreAuthorize("@ss.hasPermi('device:receive:list')") |
||||
|
@GetMapping("/list") |
||||
|
public TableDataInfo list(OnenetReceive onenetReceive) |
||||
|
{ |
||||
|
startPage(); |
||||
|
List<OnenetReceive> list = onenetReceiveService.selectOnenetReceiveList(onenetReceive); |
||||
|
return getDataTable(list); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 导出onenet推送记录列表 |
||||
|
*/ |
||||
|
@PreAuthorize("@ss.hasPermi('device:receive:export')") |
||||
|
@Log(title = "onenet推送记录", businessType = BusinessType.EXPORT) |
||||
|
@PostMapping("/export") |
||||
|
public void export(HttpServletResponse response, OnenetReceive onenetReceive) |
||||
|
{ |
||||
|
List<OnenetReceive> list = onenetReceiveService.selectOnenetReceiveList(onenetReceive); |
||||
|
ExcelUtil<OnenetReceive> util = new ExcelUtil<OnenetReceive>(OnenetReceive.class); |
||||
|
util.exportExcel(response, list, "onenet推送记录数据"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取onenet推送记录详细信息 |
||||
|
*/ |
||||
|
@PreAuthorize("@ss.hasPermi('device:receive:query')") |
||||
|
@GetMapping(value = "/{id}") |
||||
|
public AjaxResult getInfo(@PathVariable("id") Long id) |
||||
|
{ |
||||
|
return success(onenetReceiveService.selectOnenetReceiveById(id)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 新增onenet推送记录 |
||||
|
*/ |
||||
|
@PreAuthorize("@ss.hasPermi('device:receive:add')") |
||||
|
@Log(title = "onenet推送记录", businessType = BusinessType.INSERT) |
||||
|
@PostMapping |
||||
|
public AjaxResult add(@RequestBody OnenetReceive onenetReceive) |
||||
|
{ |
||||
|
return toAjax(onenetReceiveService.insertOnenetReceive(onenetReceive)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改onenet推送记录 |
||||
|
*/ |
||||
|
@PreAuthorize("@ss.hasPermi('device:receive:edit')") |
||||
|
@Log(title = "onenet推送记录", businessType = BusinessType.UPDATE) |
||||
|
@PutMapping |
||||
|
public AjaxResult edit(@RequestBody OnenetReceive onenetReceive) |
||||
|
{ |
||||
|
return toAjax(onenetReceiveService.updateOnenetReceive(onenetReceive)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除onenet推送记录 |
||||
|
*/ |
||||
|
@PreAuthorize("@ss.hasPermi('device:receive:remove')") |
||||
|
@Log(title = "onenet推送记录", businessType = BusinessType.DELETE) |
||||
|
@DeleteMapping("/{ids}") |
||||
|
public AjaxResult remove(@PathVariable Long[] ids) |
||||
|
{ |
||||
|
return toAjax(onenetReceiveService.deleteOnenetReceiveByIds(ids)); |
||||
|
} |
||||
|
} |
@ -0,0 +1,84 @@ |
|||||
|
package com.ruoyi.web.domain.po; |
||||
|
|
||||
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
|
import org.apache.commons.lang3.builder.ToStringStyle; |
||||
|
import com.ruoyi.common.annotation.Excel; |
||||
|
import com.ruoyi.common.core.domain.BaseEntity; |
||||
|
|
||||
|
/** |
||||
|
* onenet推送记录对象 onenet_receive |
||||
|
* |
||||
|
* @author lijunjie |
||||
|
* @date 2023-02-02 |
||||
|
*/ |
||||
|
public class OnenetReceive extends BaseEntity |
||||
|
{ |
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** */ |
||||
|
private Long id; |
||||
|
|
||||
|
/** imei */ |
||||
|
@Excel(name = "imei") |
||||
|
private String imei; |
||||
|
|
||||
|
/** 推送数据 */ |
||||
|
@Excel(name = "推送数据") |
||||
|
private String value; |
||||
|
|
||||
|
/** 消息摘要 |
||||
|
*/ |
||||
|
@Excel(name = "消息摘要") |
||||
|
private String msgSignature; |
||||
|
|
||||
|
public void setId(Long id) |
||||
|
{ |
||||
|
this.id = id; |
||||
|
} |
||||
|
|
||||
|
public Long getId() |
||||
|
{ |
||||
|
return id; |
||||
|
} |
||||
|
public void setImei(String imei) |
||||
|
{ |
||||
|
this.imei = imei; |
||||
|
} |
||||
|
|
||||
|
public String getImei() |
||||
|
{ |
||||
|
return imei; |
||||
|
} |
||||
|
public void setValue(String value) |
||||
|
{ |
||||
|
this.value = value; |
||||
|
} |
||||
|
|
||||
|
public String getValue() |
||||
|
{ |
||||
|
return value; |
||||
|
} |
||||
|
public void setMsgSignature(String msgSignature) |
||||
|
{ |
||||
|
this.msgSignature = msgSignature; |
||||
|
} |
||||
|
|
||||
|
public String getMsgSignature() |
||||
|
{ |
||||
|
return msgSignature; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String toString() { |
||||
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
||||
|
.append("id", getId()) |
||||
|
.append("imei", getImei()) |
||||
|
.append("value", getValue()) |
||||
|
.append("msgSignature", getMsgSignature()) |
||||
|
.append("createBy", getCreateBy()) |
||||
|
.append("createTime", getCreateTime()) |
||||
|
.append("updateBy", getUpdateBy()) |
||||
|
.append("updateTime", getUpdateTime()) |
||||
|
.toString(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,61 @@ |
|||||
|
package com.ruoyi.web.persist.mapper; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import com.ruoyi.web.domain.po.OnenetReceive; |
||||
|
|
||||
|
/** |
||||
|
* onenet推送记录Mapper接口 |
||||
|
* |
||||
|
* @author lijunjie |
||||
|
* @date 2023-02-02 |
||||
|
*/ |
||||
|
public interface OnenetReceiveMapper |
||||
|
{ |
||||
|
/** |
||||
|
* 查询onenet推送记录 |
||||
|
* |
||||
|
* @param id onenet推送记录主键 |
||||
|
* @return onenet推送记录 |
||||
|
*/ |
||||
|
public OnenetReceive selectOnenetReceiveById(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 查询onenet推送记录列表 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return onenet推送记录集合 |
||||
|
*/ |
||||
|
public List<OnenetReceive> selectOnenetReceiveList(OnenetReceive onenetReceive); |
||||
|
|
||||
|
/** |
||||
|
* 新增onenet推送记录 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int insertOnenetReceive(OnenetReceive onenetReceive); |
||||
|
|
||||
|
/** |
||||
|
* 修改onenet推送记录 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int updateOnenetReceive(OnenetReceive onenetReceive); |
||||
|
|
||||
|
/** |
||||
|
* 删除onenet推送记录 |
||||
|
* |
||||
|
* @param id onenet推送记录主键 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int deleteOnenetReceiveById(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除onenet推送记录 |
||||
|
* |
||||
|
* @param ids 需要删除的数据主键集合 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int deleteOnenetReceiveByIds(Long[] ids); |
||||
|
} |
@ -0,0 +1,69 @@ |
|||||
|
package com.ruoyi.web.service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import com.ruoyi.web.domain.po.OnenetReceive; |
||||
|
|
||||
|
/** |
||||
|
* onenet推送记录Service接口 |
||||
|
* |
||||
|
* @author lijunjie |
||||
|
* @date 2023-02-02 |
||||
|
*/ |
||||
|
public interface IOnenetReceiveService |
||||
|
{ |
||||
|
/** |
||||
|
* 查询onenet推送记录 |
||||
|
* |
||||
|
* @param id onenet推送记录主键 |
||||
|
* @return onenet推送记录 |
||||
|
*/ |
||||
|
public OnenetReceive selectOnenetReceiveById(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 查询onenet推送记录列表 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return onenet推送记录集合 |
||||
|
*/ |
||||
|
public List<OnenetReceive> selectOnenetReceiveList(OnenetReceive onenetReceive); |
||||
|
|
||||
|
/** |
||||
|
* 新增onenet推送记录 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public boolean addOnenetReceive(String onenetReceive); |
||||
|
|
||||
|
/** |
||||
|
* 新增onenet推送记录 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int insertOnenetReceive(OnenetReceive onenetReceive); |
||||
|
|
||||
|
/** |
||||
|
* 修改onenet推送记录 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int updateOnenetReceive(OnenetReceive onenetReceive); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除onenet推送记录 |
||||
|
* |
||||
|
* @param ids 需要删除的onenet推送记录主键集合 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int deleteOnenetReceiveByIds(Long[] ids); |
||||
|
|
||||
|
/** |
||||
|
* 删除onenet推送记录信息 |
||||
|
* |
||||
|
* @param id onenet推送记录主键 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int deleteOnenetReceiveById(Long id); |
||||
|
} |
@ -0,0 +1,136 @@ |
|||||
|
package com.ruoyi.web.service.impl; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.alibaba.fastjson2.JSONObject; |
||||
|
import com.ruoyi.common.utils.DateUtils; |
||||
|
import com.ruoyi.web.domain.po.OnenetReceive; |
||||
|
import com.ruoyi.web.persist.mapper.OnenetReceiveMapper; |
||||
|
import com.ruoyi.web.util.OnenetUtil; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import com.ruoyi.web.service.IOnenetReceiveService; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* onenet推送记录Service业务层处理 |
||||
|
* |
||||
|
* @author lijunjie |
||||
|
* @date 2023-02-02 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class OnenetReceiveServiceImpl implements IOnenetReceiveService |
||||
|
{ |
||||
|
@Resource |
||||
|
private OnenetReceiveMapper onenetReceiveMapper; |
||||
|
|
||||
|
/** |
||||
|
* 查询onenet推送记录 |
||||
|
* |
||||
|
* @param id onenet推送记录主键 |
||||
|
* @return onenet推送记录 |
||||
|
*/ |
||||
|
@Override |
||||
|
public OnenetReceive selectOnenetReceiveById(Long id) |
||||
|
{ |
||||
|
return onenetReceiveMapper.selectOnenetReceiveById(id); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查询onenet推送记录列表 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return onenet推送记录 |
||||
|
*/ |
||||
|
@Override |
||||
|
public List<OnenetReceive> selectOnenetReceiveList(OnenetReceive onenetReceive) |
||||
|
{ |
||||
|
return onenetReceiveMapper.selectOnenetReceiveList(onenetReceive); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean addOnenetReceive(String request) { |
||||
|
OnenetUtil.BodyObj obj = OnenetUtil.resolveBody(request, false); |
||||
|
if (obj == null){ |
||||
|
return false; |
||||
|
} |
||||
|
JSONObject jsonObject = JSONObject.parseObject(obj.getMsg().toString()); |
||||
|
String imei = jsonObject.getString("imei"); |
||||
|
|
||||
|
if (StrUtil.hasEmpty(imei)){ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
OnenetReceive onenetReceive = new OnenetReceive(); |
||||
|
onenetReceive.setImei(imei); |
||||
|
onenetReceive.setMsgSignature(obj.getMsgSignature()); |
||||
|
|
||||
|
|
||||
|
List<OnenetReceive> onenetReceives = onenetReceiveMapper.selectOnenetReceiveList(onenetReceive); |
||||
|
if (onenetReceives.size() > 0){ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
onenetReceive.setValue(obj.getMsg().toString()); |
||||
|
|
||||
|
onenetReceive.setCreateTime(DateUtils.getNowDate()); |
||||
|
int insertOnenetReceive = onenetReceiveMapper.insertOnenetReceive(onenetReceive); |
||||
|
if (insertOnenetReceive > 0){ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 新增onenet推送记录 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int insertOnenetReceive(OnenetReceive onenetReceive) |
||||
|
{ |
||||
|
onenetReceive.setCreateTime(DateUtils.getNowDate()); |
||||
|
return onenetReceiveMapper.insertOnenetReceive(onenetReceive); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改onenet推送记录 |
||||
|
* |
||||
|
* @param onenetReceive onenet推送记录 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int updateOnenetReceive(OnenetReceive onenetReceive) |
||||
|
{ |
||||
|
onenetReceive.setUpdateTime(DateUtils.getNowDate()); |
||||
|
return onenetReceiveMapper.updateOnenetReceive(onenetReceive); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量删除onenet推送记录 |
||||
|
* |
||||
|
* @param ids 需要删除的onenet推送记录主键 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int deleteOnenetReceiveByIds(Long[] ids) |
||||
|
{ |
||||
|
return onenetReceiveMapper.deleteOnenetReceiveByIds(ids); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除onenet推送记录信息 |
||||
|
* |
||||
|
* @param id onenet推送记录主键 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int deleteOnenetReceiveById(Long id) |
||||
|
{ |
||||
|
return onenetReceiveMapper.deleteOnenetReceiveById(id); |
||||
|
} |
||||
|
} |
@ -0,0 +1,176 @@ |
|||||
|
package com.ruoyi.web.util; |
||||
|
|
||||
|
import com.alibaba.fastjson2.JSONObject; |
||||
|
import org.apache.tomcat.util.codec.binary.Base64; |
||||
|
import org.bouncycastle.jce.provider.BouncyCastleProvider; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
|
||||
|
import javax.crypto.*; |
||||
|
import javax.crypto.spec.IvParameterSpec; |
||||
|
import javax.crypto.spec.SecretKeySpec; |
||||
|
import java.io.UnsupportedEncodingException; |
||||
|
import java.security.*; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 功能描述: OneNet数据推送接收程序工具类。 |
||||
|
* |
||||
|
* Created by Roy on 2017/5/17. |
||||
|
* |
||||
|
*/ |
||||
|
public class OnenetUtil { |
||||
|
|
||||
|
private static Logger logger = LoggerFactory.getLogger(OnenetUtil.class); |
||||
|
|
||||
|
private static MessageDigest mdInst; |
||||
|
|
||||
|
static { |
||||
|
try { |
||||
|
mdInst = MessageDigest.getInstance("MD5"); |
||||
|
Security.addProvider(new BouncyCastleProvider()); |
||||
|
} catch (NoSuchAlgorithmException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 功能描述:在OneNet平台配置数据接收地址时,平台会发送URL&token验证请求<p> |
||||
|
* 使用此功能函数验证token |
||||
|
* @param msg 请求参数 <msg>的值 |
||||
|
* @param nonce 请求参数 <nonce>的值 |
||||
|
* @param signature 请求参数 <signature>的值 |
||||
|
* @param token OneNet平台配置页面token的值 |
||||
|
* @return token检验成功返回true;token校验失败返回false |
||||
|
*/ |
||||
|
public static boolean checkToken(String msg,String nonce,String signature, String token) throws UnsupportedEncodingException { |
||||
|
|
||||
|
byte[] paramB = new byte[token.length() + 8 + msg.length()]; |
||||
|
System.arraycopy(token.getBytes(), 0, paramB, 0, token.length()); |
||||
|
System.arraycopy(nonce.getBytes(), 0, paramB, token.length(), 8); |
||||
|
System.arraycopy(msg.getBytes(), 0, paramB, token.length() + 8, msg.length()); |
||||
|
String sig = com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode(mdInst.digest(paramB)); |
||||
|
logger.info("url&token validation: result {}, detail receive:{} calculate:{}", sig.equals(signature.replace(' ','+')),signature,sig); |
||||
|
return sig.equals(signature.replace(' ','+')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 功能描述: 检查接收数据的信息摘要是否正确。<p> |
||||
|
* 方法非线程安全。 |
||||
|
* @param obj 消息体对象 |
||||
|
* @param token OneNet平台配置页面token的值 |
||||
|
* @return |
||||
|
*/ |
||||
|
public static boolean checkSignature(BodyObj obj, String token) { |
||||
|
//计算接受到的消息的摘要
|
||||
|
//token长度 + 8B随机字符串长度 + 消息长度
|
||||
|
byte[] signature = new byte[token.length() + 8 + obj.getMsg().toString().length()]; |
||||
|
System.arraycopy(token.getBytes(), 0, signature, 0, token.length()); |
||||
|
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); |
||||
|
return calSig.equals(obj.getMsgSignature()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 功能描述 解密消息 |
||||
|
* @param obj 消息体对象 |
||||
|
* @param encodeKey OneNet平台第三方平台配置页面为用户生成的AES的BASE64编码格式秘钥 |
||||
|
* @return |
||||
|
* @throws NoSuchPaddingException |
||||
|
* @throws NoSuchAlgorithmException |
||||
|
* @throws InvalidAlgorithmParameterException |
||||
|
* @throws InvalidKeyException |
||||
|
* @throws BadPaddingException |
||||
|
* @throws IllegalBlockSizeException |
||||
|
*/ |
||||
|
public static String decryptMsg(BodyObj obj, String encodeKey) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { |
||||
|
byte[] encMsg = Base64.decodeBase64(obj.getMsg().toString()); |
||||
|
byte[] aeskey = Base64.decodeBase64(encodeKey + "="); |
||||
|
SecretKey secretKey = new SecretKeySpec(aeskey, 0, 32, "AES"); |
||||
|
Cipher cipher = null; |
||||
|
cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); |
||||
|
cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(aeskey, 0, 16)); |
||||
|
byte[] allmsg = cipher.doFinal(encMsg); |
||||
|
byte[] msgLenBytes = new byte[4]; |
||||
|
System.arraycopy(allmsg, 16, msgLenBytes, 0, 4); |
||||
|
int msgLen = getMsgLen(msgLenBytes); |
||||
|
byte[] msg = new byte[msgLen]; |
||||
|
System.arraycopy(allmsg, 20, msg, 0, msgLen); |
||||
|
return new String(msg); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 功能描述 解析数据推送请求,生成code>BodyObj</code>消息对象 |
||||
|
* @param body 数据推送请求body部分 |
||||
|
* @param encrypted 表征是否为加密消息 |
||||
|
* @return 生成的<code>BodyObj</code>消息对象 |
||||
|
*/ |
||||
|
public static BodyObj resolveBody(String body, boolean encrypted) { |
||||
|
JSONObject jsonMsg = JSONObject.parseObject(body); |
||||
|
BodyObj obj = new BodyObj(); |
||||
|
obj.setNonce(jsonMsg.getString("nonce")); |
||||
|
obj.setMsgSignature(jsonMsg.getString("msg_signature")); |
||||
|
if (encrypted) { |
||||
|
String enc_msg = jsonMsg.getString("enc_msg"); |
||||
|
if (enc_msg == null) { |
||||
|
return null; |
||||
|
} |
||||
|
obj.setMsg(jsonMsg.getString("enc_msg")); |
||||
|
} else { |
||||
|
Object msg = jsonMsg.get("msg"); |
||||
|
if (msg == null) { |
||||
|
return null; |
||||
|
} |
||||
|
obj.setMsg(jsonMsg.get("msg")); |
||||
|
} |
||||
|
return obj; |
||||
|
} |
||||
|
|
||||
|
private static int getMsgLen(byte[] arrays) { |
||||
|
int len = 0; |
||||
|
len += (arrays[0] & 0xFF) << 24; |
||||
|
len += (arrays[1] & 0xFF) << 16; |
||||
|
len += (arrays[2] & 0xFF) << 8; |
||||
|
len += (arrays[3] & 0xFF); |
||||
|
return len; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static class BodyObj { |
||||
|
private Object msg; |
||||
|
private String nonce; |
||||
|
private String msgSignature; |
||||
|
|
||||
|
public Object getMsg() { |
||||
|
return msg; |
||||
|
} |
||||
|
|
||||
|
public void setMsg(Object msg) { |
||||
|
this.msg = msg; |
||||
|
} |
||||
|
|
||||
|
public String getNonce() { |
||||
|
return nonce; |
||||
|
} |
||||
|
|
||||
|
public void setNonce(String nonce) { |
||||
|
this.nonce = nonce; |
||||
|
} |
||||
|
|
||||
|
public String getMsgSignature() { |
||||
|
return msgSignature; |
||||
|
} |
||||
|
|
||||
|
public void setMsgSignature(String msgSignature) { |
||||
|
this.msgSignature = msgSignature; |
||||
|
} |
||||
|
|
||||
|
public String toString(){ |
||||
|
return "{ \"msg\":"+this.msg+",\"nonce\":"+this.nonce+",\"signature\":"+this.msgSignature+"}"; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,83 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<!DOCTYPE mapper |
||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.ruoyi.web.persist.mapper.OnenetReceiveMapper"> |
||||
|
|
||||
|
<resultMap type="OnenetReceive" id="OnenetReceiveResult"> |
||||
|
<result property="id" column="id" /> |
||||
|
<result property="imei" column="imei" /> |
||||
|
<result property="value" column="value" /> |
||||
|
<result property="msgSignature" column="msg_signature" /> |
||||
|
<result property="createBy" column="create_by" /> |
||||
|
<result property="createTime" column="create_time" /> |
||||
|
<result property="updateBy" column="update_by" /> |
||||
|
<result property="updateTime" column="update_time" /> |
||||
|
</resultMap> |
||||
|
|
||||
|
<sql id="selectOnenetReceiveVo"> |
||||
|
select id, imei, value, msg_signature, create_by, create_time, update_by, update_time from onenet_receive |
||||
|
</sql> |
||||
|
|
||||
|
<select id="selectOnenetReceiveList" parameterType="OnenetReceive" resultMap="OnenetReceiveResult"> |
||||
|
<include refid="selectOnenetReceiveVo"/> |
||||
|
<where> |
||||
|
<if test="imei != null and imei != ''"> and imei = #{imei}</if> |
||||
|
<if test="value != null and value != ''"> and value = #{value}</if> |
||||
|
<if test="msgSignature != null and msgSignature != ''"> and msg_signature = #{msgSignature}</if> |
||||
|
</where> |
||||
|
order by id desc |
||||
|
</select> |
||||
|
|
||||
|
<select id="selectOnenetReceiveById" parameterType="Long" resultMap="OnenetReceiveResult"> |
||||
|
<include refid="selectOnenetReceiveVo"/> |
||||
|
where id = #{id} |
||||
|
</select> |
||||
|
|
||||
|
<insert id="insertOnenetReceive" parameterType="OnenetReceive" useGeneratedKeys="true" keyProperty="id"> |
||||
|
insert into onenet_receive |
||||
|
<trim prefix="(" suffix=")" suffixOverrides=","> |
||||
|
<if test="imei != null">imei,</if> |
||||
|
<if test="value != null">value,</if> |
||||
|
<if test="msgSignature != null">msg_signature,</if> |
||||
|
<if test="createBy != null">create_by,</if> |
||||
|
<if test="createTime != null">create_time,</if> |
||||
|
<if test="updateBy != null">update_by,</if> |
||||
|
<if test="updateTime != null">update_time,</if> |
||||
|
</trim> |
||||
|
<trim prefix="values (" suffix=")" suffixOverrides=","> |
||||
|
<if test="imei != null">#{imei},</if> |
||||
|
<if test="value != null">#{value},</if> |
||||
|
<if test="msgSignature != null">#{msgSignature},</if> |
||||
|
<if test="createBy != null">#{createBy},</if> |
||||
|
<if test="createTime != null">#{createTime},</if> |
||||
|
<if test="updateBy != null">#{updateBy},</if> |
||||
|
<if test="updateTime != null">#{updateTime},</if> |
||||
|
</trim> |
||||
|
</insert> |
||||
|
|
||||
|
<update id="updateOnenetReceive" parameterType="OnenetReceive"> |
||||
|
update onenet_receive |
||||
|
<trim prefix="SET" suffixOverrides=","> |
||||
|
<if test="imei != null">imei = #{imei},</if> |
||||
|
<if test="value != null">value = #{value},</if> |
||||
|
<if test="msgSignature != null">msg_signature = #{msgSignature},</if> |
||||
|
<if test="createBy != null">create_by = #{createBy},</if> |
||||
|
<if test="createTime != null">create_time = #{createTime},</if> |
||||
|
<if test="updateBy != null">update_by = #{updateBy},</if> |
||||
|
<if test="updateTime != null">update_time = #{updateTime},</if> |
||||
|
</trim> |
||||
|
where id = #{id} |
||||
|
</update> |
||||
|
|
||||
|
<delete id="deleteOnenetReceiveById" parameterType="Long"> |
||||
|
delete from onenet_receive where id = #{id} |
||||
|
</delete> |
||||
|
|
||||
|
<delete id="deleteOnenetReceiveByIds" parameterType="String"> |
||||
|
delete from onenet_receive where id in |
||||
|
<foreach item="id" collection="array" open="(" separator="," close=")"> |
||||
|
#{id} |
||||
|
</foreach> |
||||
|
</delete> |
||||
|
</mapper> |
@ -1,8 +1,8 @@ |
|||||
# 页面标题 |
# 页面标题 |
||||
VUE_APP_TITLE = 若依管理系统 |
VUE_APP_TITLE = 传控管理系统 |
||||
|
|
||||
# 生产环境配置 |
# 生产环境配置 |
||||
ENV = 'production' |
ENV = 'production' |
||||
|
|
||||
# 若依管理系统/生产环境 |
# 传控管理系统/生产环境 |
||||
VUE_APP_BASE_API = '/prod-api' |
VUE_APP_BASE_API = '/prod-api' |
||||
|
@ -1,10 +1,10 @@ |
|||||
# 页面标题 |
# 页面标题 |
||||
VUE_APP_TITLE = 若依管理系统 |
VUE_APP_TITLE = 传控管理系统 |
||||
|
|
||||
NODE_ENV = production |
NODE_ENV = production |
||||
|
|
||||
# 测试环境配置 |
# 测试环境配置 |
||||
ENV = 'staging' |
ENV = 'staging' |
||||
|
|
||||
# 若依管理系统/测试环境 |
# 传控管理系统/测试环境 |
||||
VUE_APP_BASE_API = '/stage-api' |
VUE_APP_BASE_API = '/stage-api' |
||||
|
@ -0,0 +1,44 @@ |
|||||
|
import request from '@/utils/request' |
||||
|
|
||||
|
// 查询onenet推送记录列表
|
||||
|
export function listReceive(query) { |
||||
|
return request({ |
||||
|
url: '/device/receive/list', |
||||
|
method: 'get', |
||||
|
params: query |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// 查询onenet推送记录详细
|
||||
|
export function getReceive(id) { |
||||
|
return request({ |
||||
|
url: '/device/receive/' + id, |
||||
|
method: 'get' |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// 新增onenet推送记录
|
||||
|
export function addReceive(data) { |
||||
|
return request({ |
||||
|
url: '/device/receive', |
||||
|
method: 'post', |
||||
|
data: data |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// 修改onenet推送记录
|
||||
|
export function updateReceive(data) { |
||||
|
return request({ |
||||
|
url: '/device/receive', |
||||
|
method: 'put', |
||||
|
data: data |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// 删除onenet推送记录
|
||||
|
export function delReceive(id) { |
||||
|
return request({ |
||||
|
url: '/device/receive/' + id, |
||||
|
method: 'delete' |
||||
|
}) |
||||
|
} |
@ -0,0 +1,291 @@ |
|||||
|
<template> |
||||
|
<div class="app-container"> |
||||
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> |
||||
|
<el-form-item label="imei" prop="imei"> |
||||
|
<el-input |
||||
|
v-model="queryParams.imei" |
||||
|
placeholder="请输入imei" |
||||
|
clearable |
||||
|
@keyup.enter.native="handleQuery" |
||||
|
/> |
||||
|
</el-form-item> |
||||
|
<el-form-item label="创建时间" prop="createTime"> |
||||
|
<el-date-picker clearable |
||||
|
v-model="queryParams.createTime" |
||||
|
type="date" |
||||
|
value-format="yyyy-MM-dd" |
||||
|
placeholder="请选择创建时间"> |
||||
|
</el-date-picker> |
||||
|
</el-form-item> |
||||
|
<el-form-item label="更新时间" prop="updateTime"> |
||||
|
<el-date-picker clearable |
||||
|
v-model="queryParams.updateTime" |
||||
|
type="date" |
||||
|
value-format="yyyy-MM-dd" |
||||
|
placeholder="请选择更新时间"> |
||||
|
</el-date-picker> |
||||
|
</el-form-item> |
||||
|
<el-form-item> |
||||
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> |
||||
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> |
||||
|
</el-form-item> |
||||
|
</el-form> |
||||
|
|
||||
|
<el-row :gutter="10" class="mb8"> |
||||
|
<el-col :span="1.5"> |
||||
|
<el-button |
||||
|
type="primary" |
||||
|
plain |
||||
|
icon="el-icon-plus" |
||||
|
size="mini" |
||||
|
@click="handleAdd" |
||||
|
v-hasPermi="['device:receive:add']" |
||||
|
>新增</el-button> |
||||
|
</el-col> |
||||
|
<el-col :span="1.5"> |
||||
|
<el-button |
||||
|
type="success" |
||||
|
plain |
||||
|
icon="el-icon-edit" |
||||
|
size="mini" |
||||
|
:disabled="single" |
||||
|
@click="handleUpdate" |
||||
|
v-hasPermi="['device:receive:edit']" |
||||
|
>修改</el-button> |
||||
|
</el-col> |
||||
|
<el-col :span="1.5"> |
||||
|
<el-button |
||||
|
type="danger" |
||||
|
plain |
||||
|
icon="el-icon-delete" |
||||
|
size="mini" |
||||
|
:disabled="multiple" |
||||
|
@click="handleDelete" |
||||
|
v-hasPermi="['device:receive:remove']" |
||||
|
>删除</el-button> |
||||
|
</el-col> |
||||
|
<el-col :span="1.5"> |
||||
|
<el-button |
||||
|
type="warning" |
||||
|
plain |
||||
|
icon="el-icon-download" |
||||
|
size="mini" |
||||
|
@click="handleExport" |
||||
|
v-hasPermi="['device:receive:export']" |
||||
|
>导出</el-button> |
||||
|
</el-col> |
||||
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
||||
|
</el-row> |
||||
|
|
||||
|
<el-table v-loading="loading" :data="receiveList" @selection-change="handleSelectionChange"> |
||||
|
<el-table-column type="selection" width="55" align="center" /> |
||||
|
<el-table-column label="" align="center" prop="id" /> |
||||
|
<el-table-column label="imei" align="center" prop="imei" /> |
||||
|
<el-table-column label="推送数据" align="center" prop="value" /> |
||||
|
<el-table-column label="消息摘要 |
||||
|
" align="center" prop="msgSignature" /> |
||||
|
<el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
||||
|
<template slot-scope="scope"> |
||||
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
<el-table-column label="更新时间" align="center" prop="updateTime" width="180"> |
||||
|
<template slot-scope="scope"> |
||||
|
<span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
||||
|
<template slot-scope="scope"> |
||||
|
<el-button |
||||
|
size="mini" |
||||
|
type="text" |
||||
|
icon="el-icon-edit" |
||||
|
@click="handleUpdate(scope.row)" |
||||
|
v-hasPermi="['device:receive:edit']" |
||||
|
>修改</el-button> |
||||
|
<el-button |
||||
|
size="mini" |
||||
|
type="text" |
||||
|
icon="el-icon-delete" |
||||
|
@click="handleDelete(scope.row)" |
||||
|
v-hasPermi="['device:receive:remove']" |
||||
|
>删除</el-button> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
</el-table> |
||||
|
|
||||
|
<pagination |
||||
|
v-show="total>0" |
||||
|
:total="total" |
||||
|
:page.sync="queryParams.pageNum" |
||||
|
:limit.sync="queryParams.pageSize" |
||||
|
@pagination="getList" |
||||
|
/> |
||||
|
|
||||
|
<!-- 添加或修改onenet推送记录对话框 --> |
||||
|
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
||||
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
||||
|
<el-form-item label="imei" prop="imei"> |
||||
|
<el-input v-model="form.imei" placeholder="请输入imei" /> |
||||
|
</el-form-item> |
||||
|
<el-form-item label="推送数据" prop="value"> |
||||
|
<el-input v-model="form.value" type="textarea" placeholder="请输入内容" /> |
||||
|
</el-form-item> |
||||
|
<el-form-item label="消息摘要 |
||||
|
" prop="msgSignature"> |
||||
|
<el-input v-model="form.msgSignature" type="textarea" placeholder="请输入内容" /> |
||||
|
</el-form-item> |
||||
|
</el-form> |
||||
|
<div slot="footer" class="dialog-footer"> |
||||
|
<el-button type="primary" @click="submitForm">确 定</el-button> |
||||
|
<el-button @click="cancel">取 消</el-button> |
||||
|
</div> |
||||
|
</el-dialog> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import { listReceive, getReceive, delReceive, addReceive, updateReceive } from "@/api/device/receive"; |
||||
|
|
||||
|
export default { |
||||
|
name: "Receive", |
||||
|
data() { |
||||
|
return { |
||||
|
// 遮罩层 |
||||
|
loading: true, |
||||
|
// 选中数组 |
||||
|
ids: [], |
||||
|
// 非单个禁用 |
||||
|
single: true, |
||||
|
// 非多个禁用 |
||||
|
multiple: true, |
||||
|
// 显示搜索条件 |
||||
|
showSearch: true, |
||||
|
// 总条数 |
||||
|
total: 0, |
||||
|
// onenet推送记录表格数据 |
||||
|
receiveList: [], |
||||
|
// 弹出层标题 |
||||
|
title: "", |
||||
|
// 是否显示弹出层 |
||||
|
open: false, |
||||
|
// 查询参数 |
||||
|
queryParams: { |
||||
|
pageNum: 1, |
||||
|
pageSize: 10, |
||||
|
imei: null, |
||||
|
value: null, |
||||
|
msgSignature: null, |
||||
|
createTime: null, |
||||
|
updateTime: null |
||||
|
}, |
||||
|
// 表单参数 |
||||
|
form: {}, |
||||
|
// 表单校验 |
||||
|
rules: { |
||||
|
} |
||||
|
}; |
||||
|
}, |
||||
|
created() { |
||||
|
this.getList(); |
||||
|
}, |
||||
|
methods: { |
||||
|
/** 查询onenet推送记录列表 */ |
||||
|
getList() { |
||||
|
this.loading = true; |
||||
|
listReceive(this.queryParams).then(response => { |
||||
|
this.receiveList = response.rows; |
||||
|
this.total = response.total; |
||||
|
this.loading = false; |
||||
|
}); |
||||
|
}, |
||||
|
// 取消按钮 |
||||
|
cancel() { |
||||
|
this.open = false; |
||||
|
this.reset(); |
||||
|
}, |
||||
|
// 表单重置 |
||||
|
reset() { |
||||
|
this.form = { |
||||
|
id: null, |
||||
|
imei: null, |
||||
|
value: null, |
||||
|
msgSignature: null, |
||||
|
createBy: null, |
||||
|
createTime: null, |
||||
|
updateBy: null, |
||||
|
updateTime: null |
||||
|
}; |
||||
|
this.resetForm("form"); |
||||
|
}, |
||||
|
/** 搜索按钮操作 */ |
||||
|
handleQuery() { |
||||
|
this.queryParams.pageNum = 1; |
||||
|
this.getList(); |
||||
|
}, |
||||
|
/** 重置按钮操作 */ |
||||
|
resetQuery() { |
||||
|
this.resetForm("queryForm"); |
||||
|
this.handleQuery(); |
||||
|
}, |
||||
|
// 多选框选中数据 |
||||
|
handleSelectionChange(selection) { |
||||
|
this.ids = selection.map(item => item.id) |
||||
|
this.single = selection.length!==1 |
||||
|
this.multiple = !selection.length |
||||
|
}, |
||||
|
/** 新增按钮操作 */ |
||||
|
handleAdd() { |
||||
|
this.reset(); |
||||
|
this.open = true; |
||||
|
this.title = "添加onenet推送记录"; |
||||
|
}, |
||||
|
/** 修改按钮操作 */ |
||||
|
handleUpdate(row) { |
||||
|
this.reset(); |
||||
|
const id = row.id || this.ids |
||||
|
getReceive(id).then(response => { |
||||
|
this.form = response.data; |
||||
|
this.open = true; |
||||
|
this.title = "修改onenet推送记录"; |
||||
|
}); |
||||
|
}, |
||||
|
/** 提交按钮 */ |
||||
|
submitForm() { |
||||
|
this.$refs["form"].validate(valid => { |
||||
|
if (valid) { |
||||
|
if (this.form.id != null) { |
||||
|
updateReceive(this.form).then(response => { |
||||
|
this.$modal.msgSuccess("修改成功"); |
||||
|
this.open = false; |
||||
|
this.getList(); |
||||
|
}); |
||||
|
} else { |
||||
|
addReceive(this.form).then(response => { |
||||
|
this.$modal.msgSuccess("新增成功"); |
||||
|
this.open = false; |
||||
|
this.getList(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}, |
||||
|
/** 删除按钮操作 */ |
||||
|
handleDelete(row) { |
||||
|
const ids = row.id || this.ids; |
||||
|
this.$modal.confirm('是否确认删除onenet推送记录编号为"' + ids + '"的数据项?').then(function() { |
||||
|
return delReceive(ids); |
||||
|
}).then(() => { |
||||
|
this.getList(); |
||||
|
this.$modal.msgSuccess("删除成功"); |
||||
|
}).catch(() => {}); |
||||
|
}, |
||||
|
/** 导出按钮操作 */ |
||||
|
handleExport() { |
||||
|
this.download('device/receive/export', { |
||||
|
...this.queryParams |
||||
|
}, `receive_${new Date().getTime()}.xlsx`) |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
</script> |
File diff suppressed because it is too large
Loading…
Reference in new issue