Commit 7c603f42 authored by liuyang's avatar liuyang

完成登陆注册

parent 264c4b96
package com.qiankun.controller.mdp;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.qiankun.annotation.Auth;
......@@ -11,6 +13,7 @@ import com.qiankun.entity.User;
import com.qiankun.service.UserService;
import com.qiankun.utils.JwtTokenUtil;
import com.qiankun.utils.UserUtils;
import com.qiankun.vo.DecryptedDataVo;
import com.qiankun.vo.PaperIdLoginVo;
import com.qiankun.vo.UserVo;
import me.chanjar.weixin.common.error.WxErrorException;
......@@ -37,6 +40,7 @@ public class MdpController {
private String getAppid(){
return propertis.getConfigs().get(1).getAppid();
}
private Map<String,String> wxSessionKeyCache = Maps.newConcurrentMap();
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/login",method = RequestMethod.GET)
......@@ -51,6 +55,7 @@ public class MdpController {
WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
this.logger.info(session.getSessionKey());
this.logger.info(session.getOpenid());
wxSessionKeyCache.put(session.getOpenid(),session.getSessionKey());
Map<String,Object> result = Maps.newConcurrentMap();
User userInfo = userService.findByOpenid(session.getOpenid());
......@@ -76,12 +81,18 @@ public class MdpController {
User user = userService.findByPaperId(vo.getPaperId(),vo.getPaperType());
Map<String,Object> result = Maps.newConcurrentMap();
if (user == null){
//新用户
result.put("isExist",false);
}else {
//老用户
if (!user.getName().equals(vo.getName())){
result.put("errorMsg","姓名与库中信息不符,请核实后重新提交");
}else {
user.setOpenid(vo.getOpenid());
if (!Strings.isNullOrEmpty(vo.getPhone())){
//更新微信绑定的手机号
user.setMobile(vo.getPhone());
}
userService.save(user);
result.put("sKey",tokenUtil.generateToken(user.getOpenid()));
result.put("userInfo",UserUtils.converToVo(user));
......@@ -101,5 +112,22 @@ public class MdpController {
User user = userService.findByOpenid(openid);
return UserUtils.converToVo(user);
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/decryptedData",method = RequestMethod.POST)
public Map<String,Object> decryptedData(@RequestBody DecryptedDataVo dataVo){
Map<String,Object> result = Maps.newConcurrentMap();
final WxMaService wxService = WxMaConfiguration.getMaService(getAppid());
try {
WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(dataVo.getCode());
WxMaUserService wxUserService = wxService.getUserService();
WxMaPhoneNumberInfo phoneInfo = wxUserService.getPhoneNoInfo(session.getSessionKey(),dataVo.getEncryptedData(),dataVo.getIv());
result.put("status","ok");
result.put("phoneInfo",phoneInfo);
} catch (WxErrorException e) {
result.put("status","error");
result.put("errorMsg","微信登陆失败");
}
return result;
}
}
......@@ -70,6 +70,7 @@ public class User {
private String role; //角色 1.管理员 2.志愿者
private String status; //状态 1.未采血 2.已采血 3退库 4 再次采血
private boolean login = false; //是否可以登后台;
private String avatarImage; //头像
private Date createTime = new Date();
private Date updateTime = new Date();
......@@ -353,7 +354,11 @@ public class User {
this.login = login;
}
public String getAvatarImage() {
return avatarImage;
}
public void setAvatarImage(String avatarImage) {
this.avatarImage = avatarImage;
}
}
package com.qiankun.vo;
public class DecryptedDataVo {
private String encryptedData;
private String iv;
private String code;
public String getEncryptedData() {
return encryptedData;
}
public void setEncryptedData(String encryptedData) {
this.encryptedData = encryptedData;
}
public String getIv() {
return iv;
}
public void setIv(String iv) {
this.iv = iv;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
......@@ -5,6 +5,7 @@ public class PaperIdLoginVo {
private String paperId;
private String name;
private String openid;
private String phone;//微信绑定的手机号
public String getPaperType() {
return paperType;
......@@ -37,4 +38,12 @@ public class PaperIdLoginVo {
public void setOpenid(String openid) {
this.openid = openid;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment