netty增加接口二维码通知接口

This commit is contained in:
limqhz
2020-07-03 22:07:46 +08:00
parent d8dea80696
commit 76b362c269
3 changed files with 112 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package com.sv.netty.config;
import io.netty.channel.Channel;
import io.netty.util.internal.PlatformDependent;
import java.util.concurrent.ConcurrentMap;
public class ClientChannelCache {
/**
* 存储用户和通道类型
* value: 1Tcp 2WebSocket
*/
public static final ConcurrentMap<String, Channel> channelTypes = PlatformDependent.newConcurrentHashMap();
/**
* 缓存通道
*/
public static void putChannelType(String clientId, Channel channel) {
channelTypes.put(clientId, channel);
}
/**
* 获取通道
*/
public static Channel getChannelType(String clientId) {
return channelTypes.get(clientId);
}
/**
* 判断通道是否存在
*/
public static boolean contains(Integer clientId) {
return channelTypes.containsKey(clientId);
}
/**
* 移除通道
*/
public static void removeChannelType(Integer clientId) {
channelTypes.remove(clientId);
}
}

View File

@@ -0,0 +1,31 @@
package com.sv.netty.config;
public enum ErrorCode {
MEMBER_NOT_EXIST(10001,"用户校验失败"),
NO_ENOUGH_AMOUNT(10002,"余额不足");
private int code;
private String msg;
ErrorCode(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}

View File

@@ -0,0 +1,39 @@
package com.sv.netty.controller;
import com.sv.entity.face.FaceRecognizeResponse;
import com.sv.netty.config.ErrorCode;
import com.sv.netty.netty.ResponseDTO;
import com.sv.netty.service.impl.TcpMessageHandlerAdapter;
import com.sv.service.oms.DeviceService;
import com.sv.service.oms.VenueService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class QRCodeControler {
/**
* 微信小程序扫码之后,通知对应的线程进入加载界面,然后随即开始判断逻辑
* @return
*/
@RequestMapping("/scanQRCode")
public ResponseDTO scanQRCode(@RequestParam String venueId,
@RequestParam String cardType,@RequestParam String memberId) {
// 1、获取到请求说明扫码成功预校验余额成功通知客户端(Android)进行加载状态。
// 2、进行预校验判断是否可以进行扫码通行 // TODO check余额方法
boolean checkResult = true;
if(checkResult){
// 如果是成功的 通知客户端(Android)进行开门
return ResponseDTO.ok();
}else {
return new ResponseDTO(ErrorCode.MEMBER_NOT_EXIST.getCode(),
ErrorCode.MEMBER_NOT_EXIST.getMsg(),System.currentTimeMillis());
}
}
}