|
|
@@ -2,9 +2,11 @@ package com.ylx.web.controller.massage;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.ylx.common.annotation.Log;
|
|
|
import com.ylx.common.config.RuoYiConfig;
|
|
|
@@ -12,36 +14,38 @@ import com.ylx.common.constant.Constants;
|
|
|
import com.ylx.common.core.controller.BaseController;
|
|
|
import com.ylx.common.core.domain.AjaxResult;
|
|
|
import com.ylx.common.core.domain.R;
|
|
|
+import com.ylx.common.core.domain.model.BindPhoneBody;
|
|
|
+import com.ylx.common.core.domain.model.PhoneLoginBody;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
+import com.ylx.common.core.domain.model.aliyun.SMSVerificationCode;
|
|
|
+import com.ylx.common.core.domain.model.aliyun.SendSmsComponents;
|
|
|
+import com.ylx.common.core.domain.model.aliyun.SendSmsEnum;
|
|
|
import com.ylx.common.core.redis.RedisCache;
|
|
|
import com.ylx.common.enums.BusinessType;
|
|
|
import com.ylx.common.utils.MessageUtils;
|
|
|
import com.ylx.common.utils.StringUtils;
|
|
|
import com.ylx.common.utils.file.FileUploadUtils;
|
|
|
-import com.ylx.common.utils.file.FileUtils;
|
|
|
-import com.ylx.framework.config.ServerConfig;
|
|
|
import com.ylx.framework.manager.AsyncManager;
|
|
|
import com.ylx.framework.manager.factory.AsyncFactory;
|
|
|
import com.ylx.framework.web.service.WxTokenService;
|
|
|
-import com.ylx.massage.domain.CouponReceive;
|
|
|
import com.ylx.massage.domain.TJs;
|
|
|
import com.ylx.massage.domain.TWxUser;
|
|
|
-import com.ylx.massage.domain.TbFile;
|
|
|
import com.ylx.massage.service.CouponReceiveService;
|
|
|
import com.ylx.massage.service.TJsService;
|
|
|
import com.ylx.massage.service.TWxUserService;
|
|
|
import com.ylx.massage.service.TbFileService;
|
|
|
-import com.ylx.massage.utils.DateTimeUtils;
|
|
|
import com.ylx.massage.utils.JsSignUtil;
|
|
|
import com.ylx.massage.utils.StringUtilsMassage;
|
|
|
import com.ylx.massage.utils.WeChatUtil;
|
|
|
+import com.ylx.usercenter.domain.vo.OneAccountVO;
|
|
|
+import com.ylx.usercenter.service.UnifiedUserCenterService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -49,7 +53,6 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
-import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.file.Files;
|
|
|
@@ -74,6 +77,10 @@ public class WeChatController extends BaseController {
|
|
|
private final static String REFRESH_TOKEN = "refresh_token";
|
|
|
private final static String OPEN_ID = "openid";
|
|
|
|
|
|
+ public static final String PHONE_VERIFICATION_CODE_KEY = "sys:clientLogin:phone:";
|
|
|
+
|
|
|
+ public static final Integer PHONE_VERIFICATION_CODE_KEY_TIME = 5;
|
|
|
+
|
|
|
/**
|
|
|
* 二维码保存路径
|
|
|
*/
|
|
|
@@ -103,9 +110,27 @@ public class WeChatController extends BaseController {
|
|
|
|
|
|
@Resource
|
|
|
private TJsService jsService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SendSmsComponents sendSms;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送验证码开关(true:调用真实发送接口,false:验证码写死123456)
|
|
|
+ */
|
|
|
+ @Value("${ylx.sendSmsEnabled:false}")
|
|
|
+ private boolean sendSmsEnabled;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写死的验证码(sendSmsEnabled为false时使用)
|
|
|
+ */
|
|
|
+ @Value("${ylx.fixedVerifyCode:123456}")
|
|
|
+ private String fixedVerifyCode;
|
|
|
+ @Resource
|
|
|
+ private UnifiedUserCenterService unifiedUserCenterService;
|
|
|
+
|
|
|
/**
|
|
|
* 微信Token验证
|
|
|
*
|
|
|
@@ -137,29 +162,38 @@ public class WeChatController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置服务号的菜单
|
|
|
+ *
|
|
|
+ * @return Map<?, ?>
|
|
|
+ */
|
|
|
@GetMapping("/setMenu")
|
|
|
@ApiOperation("设置菜单")
|
|
|
@Log(title = "设置菜单", businessType = BusinessType.OTHER)
|
|
|
- public Map<?,?> setMenu() {
|
|
|
-
|
|
|
+ public Map<?, ?> setMenu() {
|
|
|
//获取access_token
|
|
|
String token = weChatUtil.getToken();
|
|
|
//获取的二维码ticket
|
|
|
return weChatUtil.menuUtil(token);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 前端获取jssdk签名
|
|
|
+ *
|
|
|
+ * @param url
|
|
|
+ * @return Map<?, ?>
|
|
|
+ */
|
|
|
@GetMapping("/getSignature")
|
|
|
@ApiOperation("前端获取jssdk签名")
|
|
|
@Log(title = "前端获取jssdk签名", businessType = BusinessType.OTHER)
|
|
|
- public Map<?,?> getSignature(String url) {
|
|
|
+ public Map<?, ?> getSignature(String url) {
|
|
|
|
|
|
//获取access_token
|
|
|
String token = weChatUtil.getToken();
|
|
|
//获取jsapi_ticket
|
|
|
String jsapiTicket = weChatUtil.getJsapiTicket(token);
|
|
|
//生成签名
|
|
|
- return jsSignUtil.sign(url,jsapiTicket);
|
|
|
+ return jsSignUtil.sign(url, jsapiTicket);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -250,7 +284,7 @@ public class WeChatController extends BaseController {
|
|
|
private String getString(Map<String, String> encryptMap) throws Exception {
|
|
|
// 返回消息时ToUserName的值与FromUserName的互换
|
|
|
Map<String, String> returnMap = new HashMap<>();
|
|
|
- String content ="欢迎来到广誉源"+"\n" +
|
|
|
+ String content = "欢迎来到广誉源" + "\n" +
|
|
|
"\n" +
|
|
|
"广誉源是一家快速上门服务预约平台,提供正规 绿色 快捷上门服务,提供按摩、推拿、养生、SPA等服务,专业针对居家、差旅、酒店等顾客提供便捷健康养生服务";
|
|
|
//添加新用户
|
|
|
@@ -296,16 +330,9 @@ public class WeChatController extends BaseController {
|
|
|
@Log(title = "获取微信code", businessType = BusinessType.OTHER)
|
|
|
@GetMapping("/getCode")
|
|
|
public String weiXinLogin(String state) {
|
|
|
-// QrConfig config = new QrConfig(300, 300);
|
|
|
- // 设置边距,即二维码和背景之间的边距
|
|
|
-// config.setMargin(1);
|
|
|
- // 生成二维码到文件,也可以到流
|
|
|
String code = weChatUtil.getCode(state);
|
|
|
log.info("code的值:{}", code);
|
|
|
redisCache.setCacheObject("code", state, 10, TimeUnit.MINUTES);
|
|
|
-
|
|
|
-// QrCodeUtil.generate(code, config,
|
|
|
-// FileUtil.file(IMG_PATH));
|
|
|
return code;
|
|
|
}
|
|
|
|
|
|
@@ -313,13 +340,11 @@ public class WeChatController extends BaseController {
|
|
|
* 获取token和userInfo
|
|
|
*
|
|
|
* @param code 微信授权码
|
|
|
- * @return 访问令牌
|
|
|
+ * @return R<WxLoginUser> 访问令牌
|
|
|
*/
|
|
|
@GetMapping("/getAccessToken")
|
|
|
@ApiOperation("公众号网页登录")
|
|
|
- @Log(title = "公众号网页登录", businessType = BusinessType.OTHER)
|
|
|
public R<WxLoginUser> getAccessToken(@RequestParam String code) {
|
|
|
-
|
|
|
// 发送get请求获取 AccessToken
|
|
|
Map<?, ?> result = weChatUtil.getAccessToken(code);
|
|
|
String accessToken = result.get(ACCESS_TOKEN).toString();
|
|
|
@@ -331,24 +356,16 @@ public class WeChatController extends BaseController {
|
|
|
String userInfoJsom = weChatUtil.getUserInfo(accessToken, openid);
|
|
|
// 解析JSON数据
|
|
|
JSONObject jsonObject = new JSONObject(userInfoJsom);
|
|
|
- log.info("公众号网页登录,{}",jsonObject);
|
|
|
+ log.info("公众号网页登录:{}", jsonObject);
|
|
|
// 将用户信息保存到数据库中
|
|
|
LambdaQueryWrapper<TWxUser> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
objectLambdaQueryWrapper.eq(TWxUser::getcOpenid, openid);
|
|
|
TWxUser user = wxUserService.getOne(objectLambdaQueryWrapper);
|
|
|
if (user == null || StringUtils.isEmpty(user.getcNickName())) {
|
|
|
- if(user == null){
|
|
|
- user = new TWxUser();
|
|
|
- user.setcOpenid(openid);
|
|
|
- TWxUser finalUser = user;
|
|
|
- //异步 添加新人优惠卷
|
|
|
-// threadPoolTaskExecutor.submit(() -> couponReceiveService.submit(new CouponReceive().setOpenid(finalUser.getcOpenid()).setCouponId("1")));
|
|
|
- }
|
|
|
user.setcOpenid(openid);
|
|
|
user.setcNickName(jsonObject.get("nickname").toString());
|
|
|
user.setcIcon(jsonObject.get("headimgurl").toString());
|
|
|
user.setcSessionKey(refreshToken);
|
|
|
-// user.setcPhone(phoneNumber);
|
|
|
wxUserService.saveOrUpdate(user);
|
|
|
user.setId(user.getId());
|
|
|
}
|
|
|
@@ -357,6 +374,7 @@ public class WeChatController extends BaseController {
|
|
|
BeanUtils.copyProperties(user, wxUser);
|
|
|
// 生成并返回令牌
|
|
|
String token = wxTokenService.createToken(wxUser);
|
|
|
+ log.info("生成的token值:{}", token);
|
|
|
if (token == null || token.isEmpty()) {
|
|
|
return R.fail("生成令牌失败");
|
|
|
}
|
|
|
@@ -391,14 +409,24 @@ public class WeChatController extends BaseController {
|
|
|
return accessToken;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("获取公众号二维码")
|
|
|
+ /**
|
|
|
+ * 获取服务号二维码
|
|
|
+ *
|
|
|
+ * @param openId
|
|
|
+ * @return Map<?, ?> 包含二维码ticket的Map
|
|
|
+ */
|
|
|
+ @ApiOperation("获取服务号二维码")
|
|
|
@RequestMapping(value = "getwxQrCode", method = RequestMethod.GET)
|
|
|
public Map<?, ?> getWxQrCodeUtil(@RequestParam String openId) {
|
|
|
-
|
|
|
- //获取access_token
|
|
|
- String token = weChatUtil.getToken();
|
|
|
- //获取的二维码ticket
|
|
|
- return weChatUtil.getTicket(token, openId);
|
|
|
+ try {
|
|
|
+ //获取access_token
|
|
|
+ String token = weChatUtil.getToken();
|
|
|
+ //获取的二维码ticket
|
|
|
+ return weChatUtil.getTicket(token, openId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@ApiOperation("获取JS公众号二维码ticket")
|
|
|
@@ -431,10 +459,10 @@ public class WeChatController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("兑换技师公众号二维码")
|
|
|
@RequestMapping(value = "getJSwxQrCodeDh", method = RequestMethod.GET)
|
|
|
- public String getJSwxQrCode1(@RequestParam String ticket,@RequestParam String id) throws UnsupportedEncodingException {
|
|
|
+ public String getJSwxQrCode1(@RequestParam String ticket, @RequestParam String id) throws UnsupportedEncodingException {
|
|
|
|
|
|
String qrCodeUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + URLEncoder.encode(ticket, "UTF-8");
|
|
|
- String filePath = RuoYiConfig.getUploadEwmPath() + id +".png";
|
|
|
+ String filePath = RuoYiConfig.getUploadEwmPath() + id + ".png";
|
|
|
log.info("二维码地址:{}", filePath);
|
|
|
|
|
|
try (InputStream in = new URL(qrCodeUrl).openStream();
|
|
|
@@ -453,7 +481,6 @@ public class WeChatController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@ApiOperation("获取公众号网页二维码")
|
|
|
@GetMapping("/getweQrCode")
|
|
|
public AjaxResult weiXinLogin1(String openId) {
|
|
|
@@ -469,4 +496,209 @@ public class WeChatController extends BaseController {
|
|
|
MultipartFile multipartFile = FileUploadUtils.getMultipartFile(generate);
|
|
|
return tbFileService.uploadFile(multipartFile);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送验证码
|
|
|
+ *
|
|
|
+ * @param phone 手机号
|
|
|
+ * @return R<?> 发送结果
|
|
|
+ */
|
|
|
+ @ApiOperation("发送绑定手机号验证码")
|
|
|
+ @PostMapping("/sendBindPhoneCode")
|
|
|
+ public R<?> sendBindPhoneCode(@RequestParam String phone) {
|
|
|
+ if (StringUtils.isEmpty(phone)) {
|
|
|
+ return R.fail("手机号不能为空");
|
|
|
+ }
|
|
|
+ if (!phone.matches("^1[3-9]\\d{9}$")) {
|
|
|
+ return R.fail("手机号格式不正确");
|
|
|
+ }
|
|
|
+ // 根据开关判断是否调用真实发送接口
|
|
|
+ if (sendSmsEnabled) {
|
|
|
+ // TODO: 调用真实发送验证码接口
|
|
|
+ log.info("发送验证码到手机号: {}", phone);
|
|
|
+ } else {
|
|
|
+ // 使用写死的验证码
|
|
|
+ log.info("发送验证码开关关闭,使用写死验证码: {}, 手机号: {}", fixedVerifyCode, phone);
|
|
|
+ }
|
|
|
+ return R.ok("验证码发送成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定手机号
|
|
|
+ *
|
|
|
+ * @param bindPhoneBody 绑定手机号请求参数
|
|
|
+ * @return R<?> 绑定结果
|
|
|
+ */
|
|
|
+ @ApiOperation("绑定手机号")
|
|
|
+ @PostMapping("/bindPhone")
|
|
|
+ public R<?> bindPhone(@RequestBody BindPhoneBody bindPhoneBody) {
|
|
|
+ String openId = bindPhoneBody.getOpenId();
|
|
|
+ String phone = bindPhoneBody.getPhone();
|
|
|
+ String code = bindPhoneBody.getCode();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(openId)) {
|
|
|
+ return R.fail("openId不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(phone)) {
|
|
|
+ return R.fail("手机号不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
+ return R.fail("验证码不能为空");
|
|
|
+ }
|
|
|
+ if (!phone.matches("^1[3-9]\\d{9}$")) {
|
|
|
+ return R.fail("手机号格式不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验验证码
|
|
|
+ if (!validateVerifyCode(phone, code)) {
|
|
|
+ return R.fail("验证码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询当前用户
|
|
|
+ TWxUser currentUser = wxUserService.getByOpenId(openId);
|
|
|
+ if (currentUser == null) {
|
|
|
+ return R.fail("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查手机号是否已被其他用户绑定
|
|
|
+ TWxUser existUser = wxUserService.getByPhone(phone);
|
|
|
+ if (existUser != null && !existUser.getId().equals(currentUser.getId())) {
|
|
|
+ return R.fail("手机号已被其他用户绑定");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果该用户已经绑定过此手机号,直接返回成功(无变化)
|
|
|
+ if (StringUtils.isNotEmpty(currentUser.getcPhone()) && currentUser.getcPhone().equals(phone)) {
|
|
|
+ return R.ok("手机号已绑定,无需重复绑定");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定手机号
|
|
|
+ boolean success = wxUserService.bindPhone(openId, phone);
|
|
|
+ if (!success) {
|
|
|
+ return R.fail("绑定失败");
|
|
|
+ }
|
|
|
+ log.info("用户openId: {} 绑定手机号: {} 成功", openId, phone);
|
|
|
+ return R.ok("绑定成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验验证码
|
|
|
+ *
|
|
|
+ * @param phone 手机号
|
|
|
+ * @param code 用户输入的验证码
|
|
|
+ * @return boolean 校验是否通过
|
|
|
+ */
|
|
|
+ private boolean validateVerifyCode(String phone, String code) {
|
|
|
+ if (sendSmsEnabled) {
|
|
|
+ // TODO: 从Redis或其他存储中获取真实发送的验证码进行校验
|
|
|
+ // String realCode = redisCache.getCacheObject("sms:bindPhone:" + phone);
|
|
|
+ // return code.equals(realCode);
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ // 使用写死的验证码进行校验
|
|
|
+ return fixedVerifyCode.equals(code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手机号登录
|
|
|
+ *
|
|
|
+ * @param phoneLoginBody 手机号登录请求参数
|
|
|
+ * @return R<WxLoginUser> 登录结果
|
|
|
+ */
|
|
|
+ @ApiOperation("手机号登录")
|
|
|
+ @PostMapping("/phoneLogin")
|
|
|
+ //@Log(title = "手机号登录", businessType = BusinessType.OTHER)
|
|
|
+ public R<WxLoginUser> phoneLogin(@RequestBody PhoneLoginBody phoneLoginBody) {
|
|
|
+ String phone = phoneLoginBody.getPhone();
|
|
|
+ String code = phoneLoginBody.getCode();
|
|
|
+
|
|
|
+ // 校验验证码(验证码不为空且为6位数字在@Valid注解中已校验)
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
+ return R.fail("验证码不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 手机号登录获取用户
|
|
|
+ TWxUser user = wxUserService.phoneLogin(phone);
|
|
|
+ if (user == null) {
|
|
|
+ return R.fail("登录失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建WxLoginUser
|
|
|
+ WxLoginUser wxUser = new WxLoginUser();
|
|
|
+ BeanUtils.copyProperties(user, wxUser);
|
|
|
+
|
|
|
+ // 生成并返回令牌
|
|
|
+ String token = wxTokenService.createToken(wxUser);
|
|
|
+ log.info("手机号登录生成的token值:{}", token);
|
|
|
+ if (StringUtils.isEmpty(token)) {
|
|
|
+ return R.fail("生成令牌失败");
|
|
|
+ }
|
|
|
+ wxUser.setToken(token);
|
|
|
+ // 记录登录信息
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(phone, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
+ log.info("手机号: {} 登录成功", phone);
|
|
|
+ return R.ok(wxUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送短信验证码
|
|
|
+ *
|
|
|
+ * @param phone 手机号
|
|
|
+ * @return R<String> 发送结果
|
|
|
+ */
|
|
|
+ @GetMapping("/sendMsg")
|
|
|
+ @ApiOperation(value = "发送短信验证码", notes = "发送短信验证码")
|
|
|
+ public R<String> sendMsg(@RequestParam String phone, HttpServletRequest request) {
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isEmpty(phone)) {
|
|
|
+ return R.fail("手机号不能为空");
|
|
|
+ }
|
|
|
+ Random rand = new Random();
|
|
|
+ // randNumber 将被赋值为一个 MIN 和 MAX 范围内的随机数
|
|
|
+ int randNumber = rand.nextInt(9999 - 1000 + 1) + 1000;
|
|
|
+ // 保存验证码到redis
|
|
|
+ redisCache.setCacheObject(PHONE_VERIFICATION_CODE_KEY + phone, String.valueOf(randNumber), PHONE_VERIFICATION_CODE_KEY_TIME, TimeUnit.MINUTES);
|
|
|
+ try {
|
|
|
+ SMSVerificationCode smsVerificationCode = new SMSVerificationCode(String.valueOf(randNumber));
|
|
|
+ String jsonString = JSON.toJSONString(smsVerificationCode);
|
|
|
+ sendSms.sendSms(phone, SendSmsEnum.SMS_220650023, jsonString);
|
|
|
+ return R.ok("发送成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return R.fail("发送失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("uuid登录")
|
|
|
+ @PostMapping("/uuidLogin")
|
|
|
+ @Log(title = "uuid登录", businessType = BusinessType.OTHER)
|
|
|
+ public R<WxLoginUser> uuidLogin(@RequestBody PhoneLoginBody phoneLoginBody) {
|
|
|
+ String uuid = phoneLoginBody.getUuid();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(uuid)) {
|
|
|
+ return R.fail("uuid不能为空");
|
|
|
+ }
|
|
|
+ OneAccountVO oneAccountVO = this.unifiedUserCenterService.queryClients(phoneLoginBody.getUuid());
|
|
|
+ if (ObjUtil.isNull(oneAccountVO)) {
|
|
|
+ return R.fail("未查询到用户信息");
|
|
|
+ }
|
|
|
+ TWxUser user = wxUserService.getById(oneAccountVO.getUserId());
|
|
|
+ if (ObjUtil.isNull(user)) {
|
|
|
+ return R.fail("登录失败");
|
|
|
+ }
|
|
|
+ // 构建WxLoginUser
|
|
|
+ WxLoginUser wxUser = new WxLoginUser();
|
|
|
+ BeanUtils.copyProperties(user, wxUser);
|
|
|
+ // 生成并返回令牌
|
|
|
+ String token = wxTokenService.createToken(wxUser);
|
|
|
+ log.info("uuid登录生成的token值:{}", token);
|
|
|
+ if (StringUtils.isEmpty(token)) {
|
|
|
+ return R.fail("生成令牌失败");
|
|
|
+ }
|
|
|
+ wxUser.setToken(token);
|
|
|
+ // 记录登录信息
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(uuid, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
+ log.info("uuid: {} 登录成功", uuid);
|
|
|
+ return R.ok(wxUser);
|
|
|
+ }
|
|
|
+
|
|
|
}
|