|
@@ -15,6 +15,7 @@ import com.uas.platform.b2c.common.weixin.model.resp.TemplateMsgResult;
|
|
|
import com.uas.platform.b2c.common.weixin.service.WeChatService;
|
|
import com.uas.platform.b2c.common.weixin.service.WeChatService;
|
|
|
import com.uas.platform.b2c.common.weixin.util.HttpReqUtil;
|
|
import com.uas.platform.b2c.common.weixin.util.HttpReqUtil;
|
|
|
import com.uas.platform.b2c.common.weixin.util.WeChatUtil;
|
|
import com.uas.platform.b2c.common.weixin.util.WeChatUtil;
|
|
|
|
|
+import com.uas.platform.b2c.core.utils.MessageUtils;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
import com.uas.sso.entity.UserAccount;
|
|
import com.uas.sso.entity.UserAccount;
|
|
@@ -51,10 +52,15 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
private Logger logger = LoggerFactory.getLogger(WeChatServiceImpl.class);
|
|
private Logger logger = LoggerFactory.getLogger(WeChatServiceImpl.class);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 保存到 redis 里的过期时间(second)
|
|
|
|
|
|
|
+ * 保存到 redis 里的 ACCESS_TOKEN 过期时间(second)
|
|
|
*/
|
|
*/
|
|
|
private static final Integer ACCESS_TOKEN_EXPIRES_IN = 3600;
|
|
private static final Integer ACCESS_TOKEN_EXPIRES_IN = 3600;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存到 redis 里的验证码过期时间(second)
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final Integer SMS_EXPIRES_IN = 10 * 60;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public ModelMap getWxUserInfo(String code, String state, String openId) {
|
|
public ModelMap getWxUserInfo(String code, String state, String openId) {
|
|
|
logger.info("得到用户信息 code: {}, state: {}, openId: {}", code, state, openId);
|
|
logger.info("得到用户信息 code: {}, state: {}, openId: {}", code, state, openId);
|
|
@@ -166,7 +172,7 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
List<User> oldUsers = userDao.findUserByUserTel(user.getUserTel());
|
|
List<User> oldUsers = userDao.findUserByUserTel(user.getUserTel());
|
|
|
if (CollectionUtils.isEmpty(oldUsers)) {
|
|
if (CollectionUtils.isEmpty(oldUsers)) {
|
|
|
throw new IllegalOperatorException("未找到用户信息");
|
|
throw new IllegalOperatorException("未找到用户信息");
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
List<User> judgeUser = userDao.findUsersByOpenId(user.getOpenId());
|
|
List<User> judgeUser = userDao.findUsersByOpenId(user.getOpenId());
|
|
|
if (!CollectionUtils.isEmpty(judgeUser)) {
|
|
if (!CollectionUtils.isEmpty(judgeUser)) {
|
|
|
throw new IllegalOperatorException("该微信号已被绑定");
|
|
throw new IllegalOperatorException("该微信号已被绑定");
|
|
@@ -202,6 +208,36 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送验证码
|
|
|
|
|
+ * @param mobile 手机号
|
|
|
|
|
+ * @param code 验证码
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void sendSMS(String mobile, String code) {
|
|
|
|
|
+ redisTemplate.opsForValue().set(mobile, mobile, SMS_EXPIRES_IN, TimeUnit.SECONDS);
|
|
|
|
|
+ logger.info("用户:{},验证码:{},redis's key:{},redis's expires_in:{}", mobile, code, mobile, SMS_EXPIRES_IN);
|
|
|
|
|
+ MessageUtils.sendSms(mobile, code);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 对验证码进行验证
|
|
|
|
|
+ * @param mobile 手机号
|
|
|
|
|
+ * @param code 需要验证的验证码
|
|
|
|
|
+ * @return true 验证成功
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean verifyCode(String mobile, String code) {
|
|
|
|
|
+ logger.info("WeChatServiceImpl#verifyCode 对验证码进行验证:mobile:{},code:{}", mobile, code);
|
|
|
|
|
+ String redisCode = (String) redisTemplate.opsForValue().get(mobile);
|
|
|
|
|
+ if (code.equals(redisCode)) {
|
|
|
|
|
+ logger.info("WeChatServiceImpl#verifyCode 验证成功:mobile:{},code:{}", mobile, code);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ logger.warn("WeChatServiceImpl#verifyCode 验证失败:mobile:{},code:{}", mobile, code);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 通过code获取用户openId
|
|
* 通过code获取用户openId
|
|
|
* @param code
|
|
* @param code
|
|
@@ -264,4 +300,6 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
redisTemplate.opsForValue().set("WX_ACCESS_TOKEN", access_token, ACCESS_TOKEN_EXPIRES_IN, TimeUnit.SECONDS);
|
|
redisTemplate.opsForValue().set("WX_ACCESS_TOKEN", access_token, ACCESS_TOKEN_EXPIRES_IN, TimeUnit.SECONDS);
|
|
|
return access_token;
|
|
return access_token;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|