From 6cee6c4b10cb4bc97f8fb514bb1f55b66d1a84fa Mon Sep 17 00:00:00 2001
From: 罗元桥 <2376770955@qq.com>
Date: 星期五, 03 九月 2021 09:47:59 +0800
Subject: [PATCH] Merge branch 'zzj' into 'test'
---
springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java | 133 ++++++++++++++++++++++++++++++--------------
1 files changed, 91 insertions(+), 42 deletions(-)
diff --git a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java
index ec5d5af..67f8aa2 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java
@@ -1,33 +1,35 @@
package com.panzhihua.applets.api;
-import cn.binarywang.wx.miniapp.api.WxMaService;
-import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
-import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
-import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
+import javax.annotation.Resource;
+
+import org.springframework.util.ObjectUtils;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
import com.alibaba.fastjson.JSONObject;
import com.panzhihua.applets.config.WxMaConfiguration;
import com.panzhihua.applets.model.vos.LoginRequest;
+import com.panzhihua.common.controller.BaseController;
+import com.panzhihua.common.exceptions.UnAuthenticationException;
import com.panzhihua.common.model.vos.LoginReturnVO;
+import com.panzhihua.common.model.vos.LoginUserInfoVO;
+import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComActVO;
import com.panzhihua.common.model.vos.community.ComMngStructAreaVO;
import com.panzhihua.common.model.vos.user.SysUserAgreementVO;
import com.panzhihua.common.service.auth.TokenService;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.service.user.UserService;
-import com.panzhihua.common.controller.BaseController;
-import com.panzhihua.common.exceptions.UnAuthenticationException;
-import com.panzhihua.common.exceptions.WeiXinException;
-import com.panzhihua.common.model.vos.LoginUserInfoVO;
-import com.panzhihua.common.model.vos.R;
-import com.panzhihua.common.validated.AddGroup;
import com.panzhihua.common.validated.PutGroup;
-import io.swagger.annotations.*;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.util.ObjectUtils;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
-import javax.annotation.Resource;
+import cn.binarywang.wx.miniapp.api.WxMaService;
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
+import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
/**
* @program: springcloud_k8s_panzhihuazhihuishequ
@@ -48,7 +50,7 @@
@Resource
private CommunityService communityService;
- @ApiOperation(value = "登录" ,response =LoginReturnVO.class )
+ @ApiOperation(value = "登录", response = LoginReturnVO.class)
@PostMapping("login")
public R login(@RequestBody LoginRequest loginRequest) {
String code = loginRequest.getCode();
@@ -57,16 +59,16 @@
}
log.info(code);
WxMaService maService = wxMaConfiguration.getMaService();
- WxMaJscode2SessionResult sessionInfo=null;
+ WxMaJscode2SessionResult sessionInfo = null;
try {
- sessionInfo = maService.getUserService().getSessionInfo(code);
+ sessionInfo = maService.getUserService().getSessionInfo(code);
} catch (Exception e) {
log.error("微信登录失败【{}】", e.getMessage());
if (code.equals("22")) {
- sessionInfo=new WxMaJscode2SessionResult();
+ sessionInfo = new WxMaJscode2SessionResult();
sessionInfo.setOpenid("88888888");
sessionInfo.setSessionKey("9999999");
- }else{
+ } else {
return R.fail("微信登录失败");
}
}
@@ -75,16 +77,19 @@
String sessionKey = sessionInfo.getSessionKey();
String unionid = sessionInfo.getUnionid();
if (ObjectUtils.isEmpty(unionid)) {
- unionid="无";
+ unionid = "无";
}
- userService.addOrUpdate(openid,sessionKey,unionid);
+ userService.addOrUpdate(openid, sessionKey, unionid);
return tokenService.loginApplets(openid);
}
@ApiOperation(value = "维护用户基本信息(昵称、性别、头像)")
@PostMapping("updateUserWeiXinInfo")
- public R updateUserWeiXinInfo(@RequestBody LoginRequest loginRequest){
+ public R updateUserWeiXinInfo(@RequestBody LoginRequest loginRequest) {
Long userId = this.getUserId();
+ if (userId == null) {
+ return R.fail(401, "请先登录");
+ }
boolean empty2 = ObjectUtils.isEmpty(userId);
if (empty2) {
throw new UnAuthenticationException();
@@ -96,35 +101,79 @@
String avatarUrl = wxUserInfo.getAvatarUrl();
String gender = wxUserInfo.getGender();
String nickName = wxUserInfo.getNickName();
- return userService.updateUserWeiXinInfo(userId,nickName,Integer.parseInt(gender),avatarUrl);
+ return userService.updateUserWeiXinInfo(userId, nickName, Integer.parseInt(gender), avatarUrl);
}
@ApiOperation(value = "维护微信用户手机号")
@PostMapping("updateUserWeiXinPhone")
- public R updateUserWeiXinPhone(@RequestBody LoginRequest loginRequest){
+ public R updateUserWeiXinPhone(@RequestBody LoginRequest loginRequest) {
String encryptedData = loginRequest.getEncryptedData();
String iv = loginRequest.getIv();
boolean empty = ObjectUtils.isEmpty(iv);
boolean empty1 = ObjectUtils.isEmpty(encryptedData);
- if (empty||empty1) {
+ if (empty || empty1) {
return R.fail("微信用户参数不全");
}
WxMaService maService = wxMaConfiguration.getMaService();
Long userId = this.getUserId();
R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId + "");
LoginUserInfoVO loginUserInfoVO = r.getData();
- WxMaPhoneNumberInfo wxMaPhoneNumberInfo = maService.getUserService().getPhoneNoInfo(loginUserInfoVO.getSessionKey(),
- encryptedData, iv);
+ WxMaPhoneNumberInfo wxMaPhoneNumberInfo =
+ maService.getUserService().getPhoneNoInfo(loginUserInfoVO.getSessionKey(), encryptedData, iv);
if (ObjectUtils.isEmpty(wxMaPhoneNumberInfo) || ObjectUtils.isEmpty(wxMaPhoneNumberInfo.getPhoneNumber())) {
return R.fail("微信解析手机号失败");
}
String purePhoneNumber = wxMaPhoneNumberInfo.getPurePhoneNumber();
- return userService.updateUserWeiXinPhone(userId,purePhoneNumber);
+ return userService.updateUserWeiXinPhone(userId, purePhoneNumber);
+ }
+
+ @ApiOperation(value = "维护微信用户手机号")
+ @PostMapping("updateUserWeiXinPhone2")
+ public R updateUserWeiXinPhone2(@RequestBody LoginRequest loginRequest) {
+ String code = loginRequest.getCode();
+ if (ObjectUtils.isEmpty(code)) {
+ return R.fail("缺少登录参数");
+ }
+ log.info(code);
+ WxMaService maService = wxMaConfiguration.getMaService();
+ WxMaJscode2SessionResult sessionInfo = null;
+ try {
+ sessionInfo = maService.getUserService().getSessionInfo(code);
+ } catch (Exception e) {
+ log.error("微信登录失败【{}】", e.getMessage());
+ if (code.equals("22")) {
+ sessionInfo = new WxMaJscode2SessionResult();
+ sessionInfo.setOpenid("88888888");
+ sessionInfo.setSessionKey("9999999");
+ } else {
+ return R.fail("微信登录失败");
+ }
+ }
+ log.info("微信登录成功【{}】", JSONObject.toJSONString(sessionInfo));
+
+ String encryptedData = loginRequest.getEncryptedData();
+ String iv = loginRequest.getIv();
+ boolean empty = ObjectUtils.isEmpty(iv);
+ boolean empty1 = ObjectUtils.isEmpty(encryptedData);
+ if (empty || empty1) {
+ return R.fail("微信用户参数不全");
+ }
+ // WxMaService maService = wxMaConfiguration.getMaService();
+ Long userId = this.getUserId();
+ // R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId + "");
+ // LoginUserInfoVO loginUserInfoVO = r.getData();
+ WxMaPhoneNumberInfo wxMaPhoneNumberInfo =
+ maService.getUserService().getPhoneNoInfo(sessionInfo.getSessionKey(), encryptedData, iv);
+ if (ObjectUtils.isEmpty(wxMaPhoneNumberInfo) || ObjectUtils.isEmpty(wxMaPhoneNumberInfo.getPhoneNumber())) {
+ return R.fail("微信解析手机号失败");
+ }
+ String purePhoneNumber = wxMaPhoneNumberInfo.getPurePhoneNumber();
+ return userService.updateUserWeiXinPhone(userId, purePhoneNumber);
}
@ApiOperation(value = "用户登出")
@PostMapping("logout")
- public R updateUserWeiXinPhone(){
+ public R updateUserWeiXinPhone() {
String token = this.getToken();
boolean empty2 = ObjectUtils.isEmpty(token);
if (empty2) {
@@ -133,38 +182,38 @@
return tokenService.logout(token);
}
- @ApiOperation(value = "刷新token",response = LoginReturnVO.class)
+ @ApiOperation(value = "刷新token", response = LoginReturnVO.class)
@GetMapping("refreshToken")
- @ApiImplicitParam(name ="refreshToken",value = "登录返回的刷新token")
- public R refreshToken(@RequestParam("refreshToken")String refreshToken){
+ @ApiImplicitParam(name = "refreshToken", value = "登录返回的刷新token")
+ public R refreshToken(@RequestParam("refreshToken") String refreshToken) {
return tokenService.refreshToken(refreshToken);
}
@ApiOperation(value = "查询社区")
@PostMapping("listcommunity")
- public R listCommunity(@RequestBody ComActVO comActVO){
+ public R listCommunity(@RequestBody ComActVO comActVO) {
return communityService.listCommunity(comActVO);
}
- @ApiOperation(value = "查询小区",response = ComMngStructAreaVO.class)
+ @ApiOperation(value = "查询小区", response = ComMngStructAreaVO.class)
@GetMapping("listarea")
- @ApiImplicitParam(name ="communityId",value = "社区id",required = true)
- public R listArea(@RequestParam("communityId") Long communityId){
+ @ApiImplicitParam(name = "communityId", value = "社区id", required = true)
+ public R listArea(@RequestParam("communityId") Long communityId) {
return communityService.listArea(communityId);
}
@ApiOperation(value = "用户绑定社区、小区")
@PutMapping("putusercommunityarea")
- public R putUserCommunityArea(@RequestBody @Validated(PutGroup.class) LoginUserInfoVO loginUserInfoVO){
+ public R putUserCommunityArea(@RequestBody @Validated(PutGroup.class) LoginUserInfoVO loginUserInfoVO) {
Long userId = this.getUserId();
loginUserInfoVO.setUserId(userId);
return userService.putUserCommunityArea(loginUserInfoVO);
}
- @ApiOperation(value = "用户协议和隐私政策",response = SysUserAgreementVO.class)
+ @ApiOperation(value = "用户协议和隐私政策", response = SysUserAgreementVO.class)
@GetMapping("useragreement")
- public R userAgreement(){
- int type=1;
+ public R userAgreement() {
+ int type = 1;
return userService.userAgreement(type);
}
}
--
Gitblit v1.7.1