SmsService移动到系统模块

This commit is contained in:
张松 2025-03-10 11:14:06 +08:00
parent f5af188439
commit 09e1937c8e
5 changed files with 39 additions and 27 deletions

View File

@ -0,0 +1,8 @@
package com.czg.system.service;
/**
* @author Administrator
*/
public interface SmsService {
void sendCode(String phone, String s);
}

View File

@ -9,8 +9,9 @@ import com.czg.config.RedisCst;
import com.czg.exception.ApiNotPrintException;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.utils.SmsUtil;
import com.czg.system.service.SmsService;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
/**
@ -18,8 +19,8 @@ import org.springframework.stereotype.Service;
*/
@Service
public class CommonServiceImpl implements CommonService {
@Resource
private SmsUtil smsUtil;
@DubboReference
private SmsService smsService;
@Resource
private SysUserService sysUserService;
@Resource
@ -33,7 +34,7 @@ public class CommonServiceImpl implements CommonService {
}
int code = RandomUtil.randomInt(100000, 1000000);
redisService.set(RedisCst.SMS_CODE + sysUser.getPhone() + ":" + type, code, 300);
smsUtil.sendCode(sysUser.getPhone(), String.valueOf(code));
smsService.sendCode(sysUser.getPhone(), String.valueOf(code));
return true;
}

View File

@ -55,10 +55,17 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
@Override
public String getPhone(GetPhoneDTO phoneDTO) {
String mobile;
String openId;
UserInfo userInfo;
if (UserAuthSourceEnum.ALIPAY.getValue().equals(phoneDTO.getSource())) {
openId = alipayUtil.getOpenId(phoneDTO.getCode(), true);
mobile = alipayUtil.getMobile(phoneDTO.getEncryptedData());
userInfo = userInfoService.queryChain().eq(UserInfo::getWechatOpenId, openId).one();
} else {
String sessionKey = wechatAuthUtil.getSessionKey(phoneDTO.getCode(), "session_key");
JSONObject session = wechatAuthUtil.getSession(phoneDTO.getCode());
String sessionKey = session.getString("session_key");
openId = session.getString("openId");
userInfo = userInfoService.queryChain().eq(UserInfo::getAlipayOpenId, openId).one();
String data = WxMaCryptUtils.decrypt(sessionKey, phoneDTO.getEncryptedData(), phoneDTO.getIv());
JSONObject jsonObject = JSONObject.parseObject(data);
if (jsonObject.containsKey("phoneNumber")) {

View File

@ -8,20 +8,17 @@ import com.czg.account.dto.user.userinfo.UserInfoAssetsSummaryDTO;
import com.czg.account.dto.user.userinfo.UserInfoDTO;
import com.czg.account.dto.user.userinfo.UserInfoEditDTO;
import com.czg.account.dto.user.userinfo.UserInfoPwdEditDTO;
import com.czg.account.entity.ShopUser;
import com.czg.account.entity.SysUser;
import com.czg.account.entity.UserInfo;
import com.czg.account.service.UserInfoService;
import com.czg.config.RedisCst;
import com.czg.exception.ApiNotPrintException;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.service.account.mapper.ShopUserMapper;
import com.czg.service.account.mapper.UserInfoMapper;
import com.czg.utils.SmsUtil;
import com.mybatisflex.core.query.QueryWrapper;
import com.czg.system.service.SmsService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
/**
@ -36,8 +33,9 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
private ShopUserMapper shopUserMapper;
@Resource
private RedisService redisService;
@Resource
private SmsUtil smsUtil;
@DubboReference
private SmsService smsService;
@Override
public UserInfoDTO getInfo(long userInfoId) {
@ -67,7 +65,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
}
int code = RandomUtil.randomInt(100000, 1000000);
redisService.set("%s%s:%s".formatted(RedisCst.SMS_CODE, userInfo.getPhone(), type), String.valueOf(code), 300);
smsUtil.sendCode(userInfo.getPhone(), String.valueOf(code));
smsService.sendCode(userInfo.getPhone(), String.valueOf(code));
return true;
}

View File

@ -1,4 +1,4 @@
package com.czg.utils;
package com.czg.service.system.service.impl;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
@ -6,11 +6,13 @@ import com.aliyun.teaopenapi.models.Config;
import com.czg.exception.ApiNotPrintException;
import com.czg.resp.CzgResult;
import com.czg.system.dto.SysParamsDTO;
import com.czg.system.service.SmsService;
import com.czg.system.service.SysParamsService;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
@ -19,13 +21,10 @@ import org.springframework.stereotype.Component;
*
* @author Administrator
*/
@Component
@DubboService
@Slf4j
public class SmsUtil {
public class SmsServiceImpl implements SmsService {
@Resource
private ApplicationContext applicationContext;
// @DubboReference(check = false)
private SysParamsService remoteSysParamsService;
private SysParamsService sysParamsService;
/**
@ -46,14 +45,13 @@ public class SmsUtil {
@PostConstruct
public void init() {
// sysParamsService = remoteSysParamsService == null ? applicationContext.getBean(SysParamsService.class): remoteSysParamsService;
// CzgResult<SysParamsDTO> aliSmsKey = sysParamsService.getParamsByCode("ali_sms_key");
// CzgResult<SysParamsDTO> aliSmsSecret = sysParamsService.getParamsByCode("ali_sms_secret");
// CzgResult<SysParamsDTO> aliSmsTemplateCode = sysParamsService.getParamsByCode("ali_sms_template_code");
// key = aliSmsKey.getData().getParamValue();
// secret = aliSmsSecret.getData().getParamValue();
// templateCode = aliSmsTemplateCode.getData().getParamValue();
// log.info("短信工具类初始化完毕key: {}, secret: {}, templateCode: {}", key, secret, templateCode);
CzgResult<SysParamsDTO> aliSmsKey = sysParamsService.getParamsByCode("ali_sms_key");
CzgResult<SysParamsDTO> aliSmsSecret = sysParamsService.getParamsByCode("ali_sms_secret");
CzgResult<SysParamsDTO> aliSmsTemplateCode = sysParamsService.getParamsByCode("ali_sms_template_code");
key = aliSmsKey.getData().getParamValue();
secret = aliSmsSecret.getData().getParamValue();
templateCode = aliSmsTemplateCode.getData().getParamValue();
log.info("短信工具类初始化完毕key: {}, secret: {}, templateCode: {}", key, secret, templateCode);
}
public Client createClient() throws Exception {