use of cn.lili.modules.system.entity.dto.SmsSetting in project lilishop by lilishop.
the class SmsUtilAliImplService method createClient.
/**
* 初始化账号Client
*
* @return Client 短信操作util
*/
public com.aliyun.dysmsapi20170525.Client createClient() {
try {
Setting setting = settingService.get(SettingEnum.SMS_SETTING.name());
if (StrUtil.isBlank(setting.getSettingValue())) {
throw new ServiceException(ResultCode.ALI_SMS_SETTING_ERROR);
}
SmsSetting smsSetting = new Gson().fromJson(setting.getSettingValue(), SmsSetting.class);
Config config = new Config();
// 您的AccessKey ID
config.accessKeyId = smsSetting.getAccessKeyId();
// 您的AccessKey Secret
config.accessKeySecret = smsSetting.getAccessSecret();
// 访问的域名
config.endpoint = "dysmsapi.aliyuncs.com";
return new com.aliyun.dysmsapi20170525.Client(config);
} catch (Exception e) {
log.error("短信初始化错误", e);
}
return null;
}
use of cn.lili.modules.system.entity.dto.SmsSetting in project lilishop by lilishop.
the class SmsUtilAliImplService method sendSmsCode.
@Override
public void sendSmsCode(String mobile, VerificationEnums verificationEnums, String uuid) {
// 获取短信配置
Setting setting = settingService.get(SettingEnum.SMS_SETTING.name());
if (StrUtil.isBlank(setting.getSettingValue())) {
throw new ServiceException(ResultCode.ALI_SMS_SETTING_ERROR);
}
SmsSetting smsSetting = new Gson().fromJson(setting.getSettingValue(), SmsSetting.class);
// 验证码
String code = CommonUtil.getRandomNum();
// 准备发送短信参数
Map<String, String> params = new HashMap<>(2);
// 验证码内容
params.put("code", code);
// 模版 默认为登录验证
String templateCode;
// 如果某个模版需要自定义,则在此处进行调整
switch(verificationEnums) {
// 登录
case LOGIN:
{
templateCode = smsTemplateProperties.getLOGIN();
break;
}
// 注册
case REGISTER:
{
templateCode = smsTemplateProperties.getREGISTER();
break;
}
// 找回密码
case FIND_USER:
{
templateCode = smsTemplateProperties.getFIND_USER();
break;
}
// 修改密码
case UPDATE_PASSWORD:
{
Member member = memberService.getById(UserContext.getCurrentUser().getId());
if (member == null || StringUtil.isEmpty(member.getMobile())) {
return;
}
// 更新为用户最新手机号
mobile = member.getMobile();
templateCode = smsTemplateProperties.getUPDATE_PASSWORD();
break;
}
// 设置支付密码
case WALLET_PASSWORD:
{
Member member = memberService.getById(UserContext.getCurrentUser().getId());
// 更新为用户最新手机号
mobile = member.getMobile();
templateCode = smsTemplateProperties.getWALLET_PASSWORD();
break;
}
// 如果不是有效的验证码手段,则此处不进行短信操作
default:
return;
}
// 如果是测试模式 默认验证码 6个1
if (systemSettingProperties.getIsTestModel()) {
code = "111111";
log.info("测试模式 - 接收手机:{},验证码:{}", mobile, code);
} else {
log.info("接收手机:{},验证码:{}", mobile, code);
// 发送短信
this.sendSmsCode(smsSetting.getSignName(), mobile, params, templateCode);
}
// 缓存中写入要验证的信息
cache.put(cacheKey(verificationEnums, mobile, uuid), code, 300L);
}
Aggregations