|
@@ -12,26 +12,22 @@ import com.ylx.common.constant.Constants;
|
|
|
import com.ylx.common.core.controller.BaseController;
|
|
import com.ylx.common.core.controller.BaseController;
|
|
|
import com.ylx.common.core.domain.AjaxResult;
|
|
import com.ylx.common.core.domain.AjaxResult;
|
|
|
import com.ylx.common.core.domain.R;
|
|
import com.ylx.common.core.domain.R;
|
|
|
|
|
+import com.ylx.common.core.domain.model.BindPhoneBody;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
import com.ylx.common.core.redis.RedisCache;
|
|
import com.ylx.common.core.redis.RedisCache;
|
|
|
import com.ylx.common.enums.BusinessType;
|
|
import com.ylx.common.enums.BusinessType;
|
|
|
import com.ylx.common.utils.MessageUtils;
|
|
import com.ylx.common.utils.MessageUtils;
|
|
|
import com.ylx.common.utils.StringUtils;
|
|
import com.ylx.common.utils.StringUtils;
|
|
|
import com.ylx.common.utils.file.FileUploadUtils;
|
|
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.AsyncManager;
|
|
|
import com.ylx.framework.manager.factory.AsyncFactory;
|
|
import com.ylx.framework.manager.factory.AsyncFactory;
|
|
|
import com.ylx.framework.web.service.WxTokenService;
|
|
import com.ylx.framework.web.service.WxTokenService;
|
|
|
-import com.ylx.massage.domain.CouponReceive;
|
|
|
|
|
import com.ylx.massage.domain.TJs;
|
|
import com.ylx.massage.domain.TJs;
|
|
|
import com.ylx.massage.domain.TWxUser;
|
|
import com.ylx.massage.domain.TWxUser;
|
|
|
-import com.ylx.massage.domain.TbFile;
|
|
|
|
|
import com.ylx.massage.service.CouponReceiveService;
|
|
import com.ylx.massage.service.CouponReceiveService;
|
|
|
import com.ylx.massage.service.TJsService;
|
|
import com.ylx.massage.service.TJsService;
|
|
|
import com.ylx.massage.service.TWxUserService;
|
|
import com.ylx.massage.service.TWxUserService;
|
|
|
import com.ylx.massage.service.TbFileService;
|
|
import com.ylx.massage.service.TbFileService;
|
|
|
-import com.ylx.massage.utils.DateTimeUtils;
|
|
|
|
|
import com.ylx.massage.utils.JsSignUtil;
|
|
import com.ylx.massage.utils.JsSignUtil;
|
|
|
import com.ylx.massage.utils.StringUtilsMassage;
|
|
import com.ylx.massage.utils.StringUtilsMassage;
|
|
|
import com.ylx.massage.utils.WeChatUtil;
|
|
import com.ylx.massage.utils.WeChatUtil;
|
|
@@ -40,8 +36,8 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
@@ -49,7 +45,6 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
-import java.net.MalformedURLException;
|
|
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
@@ -106,6 +101,18 @@ public class WeChatController extends BaseController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送验证码开关(true:调用真实发送接口,false:验证码写死123456)
|
|
|
|
|
+ */
|
|
|
|
|
+ @Value("${ylx.sendSmsEnabled:false}")
|
|
|
|
|
+ private boolean sendSmsEnabled;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 写死的验证码(sendSmsEnabled为false时使用)
|
|
|
|
|
+ */
|
|
|
|
|
+ @Value("${ylx.fixedVerifyCode:123456}")
|
|
|
|
|
+ private String fixedVerifyCode;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 微信Token验证
|
|
* 微信Token验证
|
|
|
*
|
|
*
|
|
@@ -140,7 +147,7 @@ public class WeChatController extends BaseController {
|
|
|
@GetMapping("/setMenu")
|
|
@GetMapping("/setMenu")
|
|
|
@ApiOperation("设置菜单")
|
|
@ApiOperation("设置菜单")
|
|
|
@Log(title = "设置菜单", businessType = BusinessType.OTHER)
|
|
@Log(title = "设置菜单", businessType = BusinessType.OTHER)
|
|
|
- public Map<?,?> setMenu() {
|
|
|
|
|
|
|
+ public Map<?, ?> setMenu() {
|
|
|
|
|
|
|
|
//获取access_token
|
|
//获取access_token
|
|
|
String token = weChatUtil.getToken();
|
|
String token = weChatUtil.getToken();
|
|
@@ -151,20 +158,21 @@ public class WeChatController extends BaseController {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 前端获取jssdk签名
|
|
* 前端获取jssdk签名
|
|
|
|
|
+ *
|
|
|
* @param url
|
|
* @param url
|
|
|
- * @return Map<?,?>
|
|
|
|
|
|
|
+ * @return Map<?, ?>
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/getSignature")
|
|
@GetMapping("/getSignature")
|
|
|
@ApiOperation("前端获取jssdk签名")
|
|
@ApiOperation("前端获取jssdk签名")
|
|
|
@Log(title = "前端获取jssdk签名", businessType = BusinessType.OTHER)
|
|
@Log(title = "前端获取jssdk签名", businessType = BusinessType.OTHER)
|
|
|
- public Map<?,?> getSignature(String url) {
|
|
|
|
|
|
|
+ public Map<?, ?> getSignature(String url) {
|
|
|
|
|
|
|
|
//获取access_token
|
|
//获取access_token
|
|
|
String token = weChatUtil.getToken();
|
|
String token = weChatUtil.getToken();
|
|
|
//获取jsapi_ticket
|
|
//获取jsapi_ticket
|
|
|
String jsapiTicket = weChatUtil.getJsapiTicket(token);
|
|
String jsapiTicket = weChatUtil.getJsapiTicket(token);
|
|
|
//生成签名
|
|
//生成签名
|
|
|
- return jsSignUtil.sign(url,jsapiTicket);
|
|
|
|
|
|
|
+ return jsSignUtil.sign(url, jsapiTicket);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -255,7 +263,7 @@ public class WeChatController extends BaseController {
|
|
|
private String getString(Map<String, String> encryptMap) throws Exception {
|
|
private String getString(Map<String, String> encryptMap) throws Exception {
|
|
|
// 返回消息时ToUserName的值与FromUserName的互换
|
|
// 返回消息时ToUserName的值与FromUserName的互换
|
|
|
Map<String, String> returnMap = new HashMap<>();
|
|
Map<String, String> returnMap = new HashMap<>();
|
|
|
- String content ="欢迎来到广誉源"+"\n" +
|
|
|
|
|
|
|
+ String content = "欢迎来到广誉源" + "\n" +
|
|
|
"\n" +
|
|
"\n" +
|
|
|
"广誉源是一家快速上门服务预约平台,提供正规 绿色 快捷上门服务,提供按摩、推拿、养生、SPA等服务,专业针对居家、差旅、酒店等顾客提供便捷健康养生服务";
|
|
"广誉源是一家快速上门服务预约平台,提供正规 绿色 快捷上门服务,提供按摩、推拿、养生、SPA等服务,专业针对居家、差旅、酒店等顾客提供便捷健康养生服务";
|
|
|
//添加新用户
|
|
//添加新用户
|
|
@@ -318,13 +326,12 @@ public class WeChatController extends BaseController {
|
|
|
* 获取token和userInfo
|
|
* 获取token和userInfo
|
|
|
*
|
|
*
|
|
|
* @param code 微信授权码
|
|
* @param code 微信授权码
|
|
|
- * @return 访问令牌
|
|
|
|
|
|
|
+ * @return R<WxLoginUser> 访问令牌
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/getAccessToken")
|
|
@GetMapping("/getAccessToken")
|
|
|
@ApiOperation("公众号网页登录")
|
|
@ApiOperation("公众号网页登录")
|
|
|
@Log(title = "公众号网页登录", businessType = BusinessType.OTHER)
|
|
@Log(title = "公众号网页登录", businessType = BusinessType.OTHER)
|
|
|
public R<WxLoginUser> getAccessToken(@RequestParam String code) {
|
|
public R<WxLoginUser> getAccessToken(@RequestParam String code) {
|
|
|
-
|
|
|
|
|
// 发送get请求获取 AccessToken
|
|
// 发送get请求获取 AccessToken
|
|
|
Map<?, ?> result = weChatUtil.getAccessToken(code);
|
|
Map<?, ?> result = weChatUtil.getAccessToken(code);
|
|
|
String accessToken = result.get(ACCESS_TOKEN).toString();
|
|
String accessToken = result.get(ACCESS_TOKEN).toString();
|
|
@@ -336,24 +343,16 @@ public class WeChatController extends BaseController {
|
|
|
String userInfoJsom = weChatUtil.getUserInfo(accessToken, openid);
|
|
String userInfoJsom = weChatUtil.getUserInfo(accessToken, openid);
|
|
|
// 解析JSON数据
|
|
// 解析JSON数据
|
|
|
JSONObject jsonObject = new JSONObject(userInfoJsom);
|
|
JSONObject jsonObject = new JSONObject(userInfoJsom);
|
|
|
- log.info("公众号网页登录,{}",jsonObject);
|
|
|
|
|
|
|
+ log.info("公众号网页登录:{}", jsonObject);
|
|
|
// 将用户信息保存到数据库中
|
|
// 将用户信息保存到数据库中
|
|
|
LambdaQueryWrapper<TWxUser> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<TWxUser> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
objectLambdaQueryWrapper.eq(TWxUser::getcOpenid, openid);
|
|
objectLambdaQueryWrapper.eq(TWxUser::getcOpenid, openid);
|
|
|
TWxUser user = wxUserService.getOne(objectLambdaQueryWrapper);
|
|
TWxUser user = wxUserService.getOne(objectLambdaQueryWrapper);
|
|
|
if (user == null || StringUtils.isEmpty(user.getcNickName())) {
|
|
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.setcOpenid(openid);
|
|
|
user.setcNickName(jsonObject.get("nickname").toString());
|
|
user.setcNickName(jsonObject.get("nickname").toString());
|
|
|
user.setcIcon(jsonObject.get("headimgurl").toString());
|
|
user.setcIcon(jsonObject.get("headimgurl").toString());
|
|
|
user.setcSessionKey(refreshToken);
|
|
user.setcSessionKey(refreshToken);
|
|
|
-// user.setcPhone(phoneNumber);
|
|
|
|
|
wxUserService.saveOrUpdate(user);
|
|
wxUserService.saveOrUpdate(user);
|
|
|
user.setId(user.getId());
|
|
user.setId(user.getId());
|
|
|
}
|
|
}
|
|
@@ -362,6 +361,7 @@ public class WeChatController extends BaseController {
|
|
|
BeanUtils.copyProperties(user, wxUser);
|
|
BeanUtils.copyProperties(user, wxUser);
|
|
|
// 生成并返回令牌
|
|
// 生成并返回令牌
|
|
|
String token = wxTokenService.createToken(wxUser);
|
|
String token = wxTokenService.createToken(wxUser);
|
|
|
|
|
+ log.info("生成的token值:{}", token);
|
|
|
if (token == null || token.isEmpty()) {
|
|
if (token == null || token.isEmpty()) {
|
|
|
return R.fail("生成令牌失败");
|
|
return R.fail("生成令牌失败");
|
|
|
}
|
|
}
|
|
@@ -436,10 +436,10 @@ public class WeChatController extends BaseController {
|
|
|
*/
|
|
*/
|
|
|
@ApiOperation("兑换技师公众号二维码")
|
|
@ApiOperation("兑换技师公众号二维码")
|
|
|
@RequestMapping(value = "getJSwxQrCodeDh", method = RequestMethod.GET)
|
|
@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 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);
|
|
log.info("二维码地址:{}", filePath);
|
|
|
|
|
|
|
|
try (InputStream in = new URL(qrCodeUrl).openStream();
|
|
try (InputStream in = new URL(qrCodeUrl).openStream();
|
|
@@ -458,7 +458,6 @@ public class WeChatController extends BaseController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
@ApiOperation("获取公众号网页二维码")
|
|
@ApiOperation("获取公众号网页二维码")
|
|
|
@GetMapping("/getweQrCode")
|
|
@GetMapping("/getweQrCode")
|
|
|
public AjaxResult weiXinLogin1(String openId) {
|
|
public AjaxResult weiXinLogin1(String openId) {
|
|
@@ -474,4 +473,106 @@ public class WeChatController extends BaseController {
|
|
|
MultipartFile multipartFile = FileUploadUtils.getMultipartFile(generate);
|
|
MultipartFile multipartFile = FileUploadUtils.getMultipartFile(generate);
|
|
|
return tbFileService.uploadFile(multipartFile);
|
|
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);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|