|
@@ -0,0 +1,466 @@
|
|
|
|
+package com.zhichen.modules.alisms.service.impl;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
|
+import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
|
|
|
+import com.zhichen.common.constant.Constants;
|
|
|
|
+import com.zhichen.common.core.domain.entity.SysUser;
|
|
|
|
+import com.zhichen.common.core.redis.RedisCache;
|
|
|
|
+import com.zhichen.common.exception.CustomException;
|
|
|
|
+import com.zhichen.common.type.EncryptHandler;
|
|
|
|
+import com.zhichen.common.utils.*;
|
|
|
|
+import com.zhichen.common.utils.ip.IpUtils;
|
|
|
|
+import com.zhichen.modules.alisms.service.IAliSmsService;
|
|
|
|
+import com.zhichen.modules.alisms.service.TengXunSmsService;
|
|
|
|
+import com.zhichen.modules.alisms.vo.ResultBean;
|
|
|
|
+import com.zhichen.modules.base.bo.SmsAddBo;
|
|
|
|
+import com.zhichen.modules.base.domain.Sms;
|
|
|
|
+import com.zhichen.modules.base.service.ISmsService;
|
|
|
|
+import com.zhichen.modules.distribution.service.IDistributionSellerService;
|
|
|
|
+import com.zhichen.modules.system.domain.SysTenant;
|
|
|
|
+import com.zhichen.modules.system.service.ISysConfigService;
|
|
|
|
+import com.zhichen.modules.system.service.ISysTenantService;
|
|
|
|
+import com.zhichen.modules.system.service.ISysUserService;
|
|
|
|
+import com.zhichen.modules.user.domain.User;
|
|
|
|
+import com.zhichen.modules.user.service.IUserService;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class TengXunSmsServiceImpl implements TengXunSmsService {
|
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(TengXunSmsServiceImpl.class);
|
|
|
|
+
|
|
|
|
+ private String SIGNNAME;
|
|
|
|
+ @Value("${tengxun.sms.signName}")
|
|
|
|
+ private String DEFAULT_SIGNNAME;
|
|
|
|
+ @Value("${tengxun.sms.sdkAppId}")
|
|
|
|
+ private String SDKAPPID;
|
|
|
|
+ @Value("${tengxun.sms.registerTemplateId}")
|
|
|
|
+ private String REGISTERTEMPLATECODE;
|
|
|
|
+ @Value("${tengxun.sms.secretld}")
|
|
|
|
+ private String ACCESSKEYID;
|
|
|
|
+ @Value("${tengxun.sms.secretkey}")
|
|
|
|
+ private String ACCESSKEYSECRET;
|
|
|
|
+ @Value("${tengxun.sms.loginTemplateId}")
|
|
|
|
+ private String LOGINTEMPLATECODE;
|
|
|
|
+ @Value("${tengxun.sms.forgetTemplateId}")
|
|
|
|
+ private String FORGETTEMPLATECODE;
|
|
|
|
+ @Value("${tengxun.sms.pwdTemplateId}")
|
|
|
|
+ private String PWDTEMPLATECODE;
|
|
|
|
+ @Value("${tengxun.sms.bindNewTelId}")
|
|
|
|
+ private String BINDNEWTELCODE;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserService iUserService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISmsService iSmsService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IDistributionSellerService iDistributionSellerService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysUserService iSysUserService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysTenantService iSysTenantService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysConfigService configService;
|
|
|
|
+
|
|
|
|
+ public void initData(){
|
|
|
|
+ if(Validator.isNotEmpty(configService.selectConfigByKeyNoCache("sms.signName"))){
|
|
|
|
+ SIGNNAME = configService.selectConfigByKeyNoCache("sms.signName");
|
|
|
|
+ }else{
|
|
|
|
+ SIGNNAME = DEFAULT_SIGNNAME;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResultBean sendSms(String tel, String param) {
|
|
|
|
+ initData();
|
|
|
|
+ try{
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,REGISTERTEMPLATECODE,param,ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ System.out.println(response);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResultBean sendInformSms(String tel, String param,String code) {
|
|
|
|
+ initData();
|
|
|
|
+ //发送带指定短信code带参数发送不同短信内容
|
|
|
|
+ try{
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,code,param,ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ LOGGER.error("发送短信结果:"+JSON.toJSONString(response));
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(param);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(9L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return new ResultBean(response);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendRegisterSms(String tel) {
|
|
|
|
+ checkCodeFrequency();
|
|
|
|
+ initData();
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
|
+ .eq(User::getTelphone,EncryptHandler.encrypt(tel)).last("limit 1"));
|
|
|
|
+ if(Validator.isNotNull(user)){
|
|
|
|
+ throw new CustomException("该手机号已注册");
|
|
|
|
+ }
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.REGISTER_SMS + tel;
|
|
|
|
+ redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,REGISTERTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(1L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendForgetSms(String tel) {
|
|
|
|
+ initData();
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
|
+ .eq(User::getTelphone,EncryptHandler.encrypt(tel)).last("limit 1"));
|
|
|
|
+ if(Validator.isEmpty(user)){
|
|
|
|
+ throw new CustomException("该手机号未注册");
|
|
|
|
+ }
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.FORGET_SMS + tel;
|
|
|
|
+ redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,FORGETTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(2L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendLoginSms(String tel) {
|
|
|
|
+ //校验短信频率
|
|
|
|
+ checkCodeFrequency();
|
|
|
|
+ initData();
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
|
+ .eq(User::getTelphone,EncryptHandler.encrypt(tel)).last("limit 1"));
|
|
|
|
+ if(Validator.isEmpty(user)){
|
|
|
|
+ throw new CustomException("该手机号未注册");
|
|
|
|
+ }
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.LOGIN_SMS + tel;
|
|
|
|
+ redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,LOGINTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(3L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验短信发送频率(一个ip 60秒一次)
|
|
|
|
+ */
|
|
|
|
+ private void checkCodeFrequency() {
|
|
|
|
+ String ipAddr = IpUtils.getIpAddr(ServletUtils.getRequest());
|
|
|
|
+ Sms sms = iSmsService.getOne(new LambdaQueryWrapper<Sms>().eq(Sms::getIp, ipAddr)
|
|
|
|
+ .orderByDesc(Sms::getCreateTime).last("limit 1"));
|
|
|
|
+ if (ObjectUtils.isNull(sms)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Long createTime = sms.getCreateTime();
|
|
|
|
+ if (DateUtils.getNowTime() - createTime < 60){
|
|
|
|
+ throw new CustomException("请在60秒后重试!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendPwdSms(String tel,String code) {
|
|
|
|
+ initData();
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("name","");
|
|
|
|
+ param.put("password",code);
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(4L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,PWDTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ System.out.println(e);
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendBindNewTelSms(String tel) {
|
|
|
|
+ initData();
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
|
+ .eq(User::getTelphone, EncryptHandler.encrypt(tel)).last("limit 1"));
|
|
|
|
+ if(Validator.isNotEmpty(user)){
|
|
|
|
+ throw new CustomException("该手机号已被使用");
|
|
|
|
+ }
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.LOGIN_SMS + tel;
|
|
|
|
+ redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,BINDNEWTELCODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(5L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendSellerRegisterSms(String tel) {
|
|
|
|
+ initData();
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ SysUser seller = iSysUserService.getOneByTenant(tel);
|
|
|
|
+ if(Validator.isNotNull(seller)){
|
|
|
|
+ SysTenant tenant = iSysTenantService.getById(seller.getTenantId());
|
|
|
|
+ throw new CustomException(String.format("该手机号已在【%s】注册过!",tenant.getTenantName()));
|
|
|
|
+ }
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.REGISTER_SMS + tel;
|
|
|
|
+ redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,REGISTERTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(6L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendSellerForgetSms(String tel) {
|
|
|
|
+ initData();
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ SysUser user = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
|
+ .eq(SysUser::getPhonenumber,tel).last("limit 1"));
|
|
|
|
+ if(Validator.isEmpty(user)){
|
|
|
|
+ throw new CustomException("该手机号未注册");
|
|
|
|
+ }
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.FORGET_SMS + tel;
|
|
|
|
+ redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,FORGETTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(7L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendSellerLoginSms(String tel) {
|
|
|
|
+ initData();
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ SysUser user = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
|
+ .eq(SysUser::getPhonenumber,tel).last("limit 1"));
|
|
|
|
+ if(Validator.isEmpty(user)){
|
|
|
|
+ throw new CustomException("该手机号未注册");
|
|
|
|
+ }
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.LOGIN_SMS + tel;
|
|
|
|
+ redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,LOGINTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(8L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean sendLiveSms(String tel) {
|
|
|
|
+ initData();
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ User user = iUserService.getUserByTelNotTenant(tel).stream().findFirst().orElse(null);
|
|
|
|
+ if(Validator.isEmpty(user)){
|
|
|
|
+ throw new CustomException("该手机号未注册");
|
|
|
|
+ }
|
|
|
|
+ ServletUtils.getResponse().setHeader("TenantId",user.getTenantId().toString());
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.LOGIN_SMS + tel;
|
|
|
|
+ redisCache.setCacheObjectTenant(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,SIGNNAME,LOGINTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(3L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void ceshi(String tel) {
|
|
|
|
+ if(tel==null){
|
|
|
|
+ throw new CustomException("手机号码不能为空");
|
|
|
|
+ }
|
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
|
+ .eq(User::getTelphone,EncryptHandler.encrypt(tel)).last("limit 1"));
|
|
|
|
+ if(Validator.isEmpty(user)){
|
|
|
|
+ throw new CustomException("该手机号未注册");
|
|
|
|
+ }
|
|
|
|
+ String code = ToolsUtils.getSmsCode();
|
|
|
|
+ String key = Constants.LOGIN_SMS + tel;
|
|
|
|
+ redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
|
|
|
|
+ try{
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("code",code);
|
|
|
|
+ SendSmsResponse response = TengXunSmsUtils.sendSms(tel,DEFAULT_SIGNNAME,LOGINTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET,SDKAPPID);
|
|
|
|
+ if(response.getSendStatusSet()[0].getCode().equals("OK")){
|
|
|
|
+ SmsAddBo smsAddBo = new SmsAddBo();
|
|
|
|
+ smsAddBo.setCode(code);
|
|
|
|
+ smsAddBo.setTel(tel);
|
|
|
|
+ smsAddBo.setType(3L);
|
|
|
|
+ smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ iSmsService.insertByAddBo(smsAddBo);
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new CustomException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|