package com.caimei.service.wechat.impl; import com.caimei.components.RedisService; import com.caimei.mapper.cmMapper.*; import com.caimei.model.ResponseJson; import com.caimei.model.vo.AuthFormVo; import com.caimei.model.vo.ShopFormVo; import com.caimei.model.vo.WxClubUserVo; import com.caimei.service.auth.ShopService; import com.caimei.service.wechat.WxUserService; import com.caimei.utils.CodeUtil; import com.caimei.utils.Md5Util; import com.caimei.utils.SmsUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * Description * * @author : Aslee * @date : 2021/7/15 */ @Slf4j @Service public class WxUserServiceImpl implements WxUserService { @Resource private RedisService redisService; @Resource private ClubMapper clubMapper; @Resource private AuthMapper authMapper; @Resource private ShopMapper shopMapper; @Value("${spring.profiles.active}") private String active; @Override public ResponseJson> getUserInfo(String mobile, Integer authUserId, Integer clubUserId, Integer authId) { HashMap map = new HashMap<>(2); // 机构用户 WxClubUserVo clubUser = clubMapper.getWxClubUser(mobile, null, authUserId, null, clubUserId); // 授权机构 AuthFormVo auth = null; // 机构用户已注册 if (null != clubUser && null != clubUser.getAuthId()) { auth = authMapper.getAuthBaseInfo(authUserId, clubUser.getAuthId()); } if (null != authId) { auth = authMapper.getAuthBaseInfo(authUserId, authId); } map.put("clubUser", clubUser); map.put("auth", auth); return ResponseJson.success(map); } @Override public ResponseJson sendLoginCode(String mobile, Integer authUserId, Integer type) { if (2 == type) { // 获取手机号对应机构用户 WxClubUserVo clubUser = clubMapper.getWxClubUser(mobile, null, authUserId, null, null); if (null == clubUser || 1 != clubUser.getStatus()) { return ResponseJson.error("用户不存在"); } } // 获取供应商名称 ShopFormVo shop = shopMapper.getShopByUserId(authUserId); String shopName = ""; if (null == shop) { return ResponseJson.error("供应商不存在"); } else { shopName = shop.getShopName(); } String verifyCode = "prod".equals(active) ? CodeUtil.generateCodeInt(6) : "666666"; String content = "("+ shopName +")您认证通短信验证码为:" + verifyCode + ",该验证码 " + (1 == type ? 30 : 5) + " 分钟内有效,请勿泄漏于他人。【采美网提供技术支持】"; Boolean sendSms = SmsUtils.sendSms(1, mobile, content); String msgType = 1 == type ? "注册" : 2 == type ? "忘记密码" : ""; if (!sendSms) { log.info(msgType + "验证码发送失败,手机号:" + mobile); return ResponseJson.error("发送失败,请确认手机号无误"); } else { log.info(msgType + "验证码发送成功,手机号:" + mobile + ",验证码:" + verifyCode); } log.info(content); long expireTime = 300L; if (1 == type) { expireTime = 60 * 30L; } redisService.set("code:" + mobile, verifyCode, expireTime); return ResponseJson.success("发送成功"); } @Override public ResponseJson updatePassword(String mobile, String verifyCode, String password, Integer authUserId) { // 获取手机号对应机构用户 WxClubUserVo clubUser = clubMapper.getWxClubUser(mobile, null, authUserId, null, null); if (null == clubUser || 1 != clubUser.getStatus()) { return ResponseJson.error("用户不存在"); } // 校验验证码是否正确 String redisVerifyCode = null == redisService.get("code:" + mobile) ? null : redisService.get("code:" + mobile).toString(); if (!verifyCode.equals(redisVerifyCode)) { return ResponseJson.error("验证码错误,请重新输入", null); } String md5Password = Md5Util.md5(password); clubMapper.updatePassword(mobile, md5Password, authUserId); return ResponseJson.success("密码修改成功"); } }