Commit 8f8fa6a9 authored by liuchao's avatar liuchao
parents a779a6f4 729db3d3
...@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.qiankun.utils.JwtTokenUtil; import com.qiankun.utils.JwtTokenUtil;
import com.qiankun.utils.UserUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -232,7 +233,7 @@ public class UserController extends BaseController<Object>{ ...@@ -232,7 +233,7 @@ public class UserController extends BaseController<Object>{
user.getContacts().add(contacts2); user.getContacts().add(contacts2);
User u = userService.save(user); User u = userService.save(user);
map.put("user", u); map.put("user", UserUtils.converToVo(u));
map.put("sKey",tokenUtil.generateToken(u.getOpenid())); map.put("sKey",tokenUtil.generateToken(u.getOpenid()));
return map; return map;
} }
......
package com.qiankun.controller.mdp; package com.qiankun.controller.mdp;
import cn.binarywang.wx.miniapp.api.WxMaService; 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.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.qiankun.annotation.Auth; import com.qiankun.annotation.Auth;
import com.qiankun.config.WxMaConfiguration; import com.qiankun.config.WxMaConfiguration;
import com.qiankun.config.WxMaProperties; import com.qiankun.config.WxMaProperties;
import com.qiankun.dao.UserDao;
import com.qiankun.entity.Contacts;
import com.qiankun.entity.User; import com.qiankun.entity.User;
import com.qiankun.service.UserService; import com.qiankun.service.UserService;
import com.qiankun.utils.JwtTokenUtil; import com.qiankun.utils.JwtTokenUtil;
import com.qiankun.utils.UserUtils; import com.qiankun.utils.UserUtils;
import com.qiankun.vo.DecryptedDataVo;
import com.qiankun.vo.PaperIdLoginVo; import com.qiankun.vo.PaperIdLoginVo;
import com.qiankun.vo.UserVo; import com.qiankun.vo.UserVo;
import com.sun.mail.imap.ResyncData;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set;
@RestController @RestController
@RequestMapping("/wx/mdp") @RequestMapping("/wx/mdp")
...@@ -37,6 +53,7 @@ public class MdpController { ...@@ -37,6 +53,7 @@ public class MdpController {
private String getAppid(){ private String getAppid(){
return propertis.getConfigs().get(1).getAppid(); return propertis.getConfigs().get(1).getAppid();
} }
private String uploadAvatarPath = File.separator + "mdp" + File.separator + "uploadAvatar";
@Auth(verifyLogin = false,verifyURL = false) @Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/login",method = RequestMethod.GET) @RequestMapping(value = "/login",method = RequestMethod.GET)
...@@ -76,12 +93,18 @@ public class MdpController { ...@@ -76,12 +93,18 @@ public class MdpController {
User user = userService.findByPaperId(vo.getPaperId(),vo.getPaperType()); User user = userService.findByPaperId(vo.getPaperId(),vo.getPaperType());
Map<String,Object> result = Maps.newConcurrentMap(); Map<String,Object> result = Maps.newConcurrentMap();
if (user == null){ if (user == null){
//新用户
result.put("isExist",false); result.put("isExist",false);
}else { }else {
//老用户
if (!user.getName().equals(vo.getName())){ if (!user.getName().equals(vo.getName())){
result.put("errorMsg","姓名与库中信息不符,请核实后重新提交"); result.put("errorMsg","姓名与库中信息不符,请核实后重新提交");
}else { }else {
user.setOpenid(vo.getOpenid()); user.setOpenid(vo.getOpenid());
if (!Strings.isNullOrEmpty(vo.getPhone())){
//更新微信绑定的手机号
user.setMobile(vo.getPhone());
}
userService.save(user); userService.save(user);
result.put("sKey",tokenUtil.generateToken(user.getOpenid())); result.put("sKey",tokenUtil.generateToken(user.getOpenid()));
result.put("userInfo",UserUtils.converToVo(user)); result.put("userInfo",UserUtils.converToVo(user));
...@@ -101,5 +124,138 @@ public class MdpController { ...@@ -101,5 +124,138 @@ public class MdpController {
User user = userService.findByOpenid(openid); User user = userService.findByOpenid(openid);
return UserUtils.converToVo(user); 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;
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/uploadAvatar",method = RequestMethod.POST)
public Map<String,String> uploadAvatar(MultipartFile file,@RequestHeader String sKey){
Map<String,String> result = Maps.newConcurrentMap();
if (Strings.isNullOrEmpty(sKey)){
result.put("status","error");
result.put("errorMsg","请求参数错误");
return result;
}
String openid = tokenUtil.getUsernameFromToken(sKey);
User user = userService.findByOpenid(openid);
if (user == null){
result.put("status","error");
result.put("errorMsg","用户不存在");
return result;
}
try{
if (file != null && !file.isEmpty()){
String originalFileName = file.getOriginalFilename();
String rootPath = rb.getString("file_path");
File destFile = new File(rootPath + uploadAvatarPath,originalFileName);
FileUtils.writeByteArrayToFile(destFile,file.getBytes());
user.setAvatarImage(uploadAvatarPath + File.separator + originalFileName);
userService.save(user);
result.put("status","ok");
result.put("avatarImage",user.getAvatarImage());
}else {
result.put("status","error");
result.put("errorMsg","上传文件不存在");
return result;
}
}catch (IOException e){
logger.error(e.getMessage(),e);
result.put("status","error");
result.put("errorMsg","上传文件失败");
}
return result;
}
/**
* 获取用户积分、参与的活动等相关信息
* @param sKey
* @return
*/
@Auth(verifyURL = false,verifyLogin = false)
@RequestMapping(value = "/userActivityInfo",method = RequestMethod.GET)
public Map<String,Object> getUserActivityInfo(@RequestHeader String sKey){
Map<String,Object> result = Maps.newConcurrentMap();
if (Strings.isNullOrEmpty(sKey)){
result.put("status","error");
result.put("errorMsg","请求参数错误");
return result;
}
String openid = tokenUtil.getUsernameFromToken(sKey);
User user = userService.findByOpenid(openid);
if (user == null){
result.put("status","error");
result.put("errorMsg","用户不存在");
return result;
}
if (Strings.isNullOrEmpty(user.getName()) ||
Strings.isNullOrEmpty(user.getBirthday()) ||
Strings.isNullOrEmpty(user.getPaperType()) ||
Strings.isNullOrEmpty(user.getPaperId()) ||
Strings.isNullOrEmpty(user.getNation()) ||
Strings.isNullOrEmpty(user.getNationality()) ||
Strings.isNullOrEmpty(user.getNativePlace()) ||
Strings.isNullOrEmpty(user.getAddr()) ||
Strings.isNullOrEmpty(user.getMobile()) ||
Strings.isNullOrEmpty(user.getQq()) ||
!validateContacts(user)){
result.put("userInfoStatus","unComplete");
}else{
result.put("userInfoStatus","complete");
}
result.put("points",getUserPoints(user));
result.put("status","ok");
return result;
}
/**
* 获取用户积分
* @param user
* @return
*/
private int getUserPoints(User user){
return 0;
}
private boolean validateContacts(User user){
boolean flag = true;
Set<Contacts> sets = user.getContacts();
if (sets == null){
flag = false;
}else {
Iterator<Contacts> it = sets.iterator();
while (it.hasNext()){
Contacts c = it.next();
if (Strings.isNullOrEmpty(c.getName()) ||
Strings.isNullOrEmpty(c.getRelation()) ||
Strings.isNullOrEmpty(c.getMobile())){
flag = false;
break;
}
}
}
return flag;
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/loadResource",method = RequestMethod.GET)
public ResponseEntity<byte[]> loadResource(@RequestParam String imageName) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
File file = new File(rb.getString("file_path"),imageName);
return new ResponseEntity<>(FileUtils.readFileToByteArray(file),headers, HttpStatus.OK);
}
} }
...@@ -70,6 +70,7 @@ public class User { ...@@ -70,6 +70,7 @@ public class User {
private String role; //角色 1.管理员 2.志愿者 private String role; //角色 1.管理员 2.志愿者
private String status; //状态 1.未采血 2.已采血 3退库 4 再次采血 private String status; //状态 1.未采血 2.已采血 3退库 4 再次采血
private boolean login = false; //是否可以登后台; private boolean login = false; //是否可以登后台;
private String avatarImage; //头像
private Date createTime = new Date(); private Date createTime = new Date();
private Date updateTime = new Date(); private Date updateTime = new Date();
...@@ -353,7 +354,11 @@ public class User { ...@@ -353,7 +354,11 @@ public class User {
this.login = login; 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 { ...@@ -5,6 +5,7 @@ public class PaperIdLoginVo {
private String paperId; private String paperId;
private String name; private String name;
private String openid; private String openid;
private String phone;//微信绑定的手机号
public String getPaperType() { public String getPaperType() {
return paperType; return paperType;
...@@ -37,4 +38,12 @@ public class PaperIdLoginVo { ...@@ -37,4 +38,12 @@ public class PaperIdLoginVo {
public void setOpenid(String openid) { public void setOpenid(String openid) {
this.openid = openid; this.openid = openid;
} }
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
} }
...@@ -60,6 +60,7 @@ public class UserVo { ...@@ -60,6 +60,7 @@ public class UserVo {
private String searchStr; private String searchStr;
private String order; private String order;
private String sort; private String sort;
private String avatarImage; //头像
public String getId() { public String getId() {
return id; return id;
...@@ -359,8 +360,11 @@ public class UserVo { ...@@ -359,8 +360,11 @@ public class UserVo {
this.userCode = userCode; this.userCode = userCode;
} }
public String getAvatarImage() {
return avatarImage;
}
public void setAvatarImage(String avatarImage) {
this.avatarImage = avatarImage;
}
} }
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