controller 层
private static final Logger logger = LoggerFactory.getLogger(TranslaterLoginController.class);
@Autowired
private TranslaterLoginService translaterLoginService;
/*
* 生成编译器二维码图片
*/
@RequestMapping("TranslaterGenerateCode")
@ResponseBody
public Map<String, Object> TranslaterGenerateCode(HttpServletRequest request,HttpServletResponse response) throws Exception {
String realPath = request.getSession().getServletContext().getRealPath("/");
return translaterLoginService.TranslaterGenerateCode(realPath);
}
/*
* 编译器循环请求 是否登录
*
*/
@RequestMapping("TranslaterCircularRequest")
@ResponseBody
public Map<String, Object> TranslaterCircularRequest(String code) throws Exception {
return translaterLoginService.TranslaterCircularRequest(code);
}
/*
* APP扫描编译器二维码登录
*
*/
@RequestMapping("AppScanningQRCode")
@ResponseBody
public Map<String, Object> AppScanningQRCode(String code,String userId) throws Exception {
return translaterLoginService.AppScanningQRCode(code,userId);
}
二、接口
//生成编译器二维码图片
public Map<String, Object> TranslaterGenerateCode(String realPath)throws Exception;
//编译器循环请求 是否登录
public Map<String, Object> TranslaterCircularRequest(String code)throws Exception;
//APP扫描编译器二维码登录
public Map<String, Object> AppScanningQRCode(String code,String userId)throws Exception;
三、dao层
@Autowired
private UserAccountMapper userAccountMapper;
@Autowired
private UserIdentificationMapper userIdentificationMapper;
@Autowired
private EditorVersionMapper editorVersionMapper;
@Autowired
private JedisPool jedisPool;
@Value("
R
E
D
I
S
P
H
O
N
E
C
O
D
E
E
X
P
I
R
E
"
)
p
r
i
v
a
t
e
i
n
t
R
E
D
I
S
P
H
O
N
E
C
O
D
E
E
X
P
I
R
E
;
@
V
a
l
u
e
(
"
{REDIS_PHONECODE_EXPIRE}") private int REDIS_PHONECODE_EXPIRE; @Value("
REDISPHONECODEEXPIRE")privateintREDISPHONECODEEXPIRE;@Value("{STUDIO_EXPIRE}")
private int STUDIO_EXPIRE;
@Override
public Map<String, Object> TranslaterGenerateCode(String realPath) throws Exception {
Map<String, Object> map=new HashMap<>();
//生成带logo 的二维码
/*String text = “http://my.csdn.net/ljheee”;
QRCodeUtil.encode(text, “11.JPG”, “d:/WPS”, true); */
//生成不带logo 的二维码
int i = new Random().nextInt(99999999);
String string = Integer.toString(i);
final String id = UUID.randomUUID().toString();
String code =string+id;
QRCodeUtil.encode(code,"",realPath,true);
//指定二维码图片,解析返回数据
// System.out.println(QRCodeUtil.decode("D:/WPS/WOYIHOME.jpg"));
BufferedInputStream in = new BufferedInputStream(new FileInputStream(realPath+"WOYIHOME.jpg"));
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
in.close();
byte[] content = out.toByteArray();
map.put("content", content);
map.put("code", code);
return map;
}
@Override
public Map<String, Object> TranslaterCircularRequest(String code) throws Exception {
Map<String , Object> map=new HashMap<>();
Jedis jedis = jedisPool.getResource();
if (jedis != null) {
String jedisCode =null;
try {
jedisCode = jedis.get(code);
} catch (Exception e) {
e.printStackTrace();
jedis.close();
}
if(jedisCode!=null){
UserAccount userAccount = userAccountMapper.selectByPrimaryKey(jedisCode);
map.put("userAccount", userAccount);
map.put("msg", 200);
}else{
map.put("msg", 500);
}
}
jedis.close();
return map;
}
@Override
public Map<String, Object> AppScanningQRCode(String code, String userId) throws Exception {
Map<String , Object> map=new HashMap<>();
Jedis jedis = jedisPool.getResource();
if (jedis != null) {
jedis.set(code, userId);
logger.info("ValidCode:{}", code.toString());
// 设置短信的有效期为15分钟900秒
jedis.expire(code, REDIS_PHONECODE_EXPIRE);
map.put("msg", 200);
}
jedis.close();
return map;
}