安徽省公司短信平台
This commit is contained in:
parent
3bc6e80c1c
commit
60667991c7
|
|
@ -1,59 +1,54 @@
|
|||
//package com.bonus.common.core.utils.sms;
|
||||
//
|
||||
//import cn.hutool.json.JSONObject;
|
||||
//import com.ah.sbd.SmsTool;
|
||||
//import com.ah.sbd.utils.param.BatchSmsByContentParam;
|
||||
//import com.ah.sbd.utils.param.SmsParam;
|
||||
//import com.alibaba.fastjson2.JSON;
|
||||
//import com.bonus.common.core.utils.StringUtils;
|
||||
//import com.bonus.common.core.utils.encryption.Sm4Utils;
|
||||
//import com.bonus.common.core.utils.http.HttpRequestHelper;
|
||||
//import org.springframework.util.CollectionUtils;
|
||||
//
|
||||
//import java.net.URLEncoder;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//public class SmsUtils {
|
||||
// // 安徽省公司短信平台key
|
||||
// public static final String ANHUI_COMPANY_SMS_KEY = "Wq1FZobZC5iJIAGKWh6gpKUmdGKBOQq7koHmx+Vg49g/dSjSFlw+2qRQmMmyXvJT";
|
||||
// /**
|
||||
// * 发送短信验证码
|
||||
// *
|
||||
// * @param mobile 发信发送的目的号码.多个号码之间用半角逗号隔开
|
||||
// * @param content 短信的内容,内容需要UTF-8编码
|
||||
// * @param sendTime 为空表示立即发送,定时发送格式:20101024090810
|
||||
// * @return 是否发送成功
|
||||
// */
|
||||
// public static String smsToken(String mobile, String content, String sendTime) {
|
||||
// Map<String, String> headers = new HashMap<>();
|
||||
// Map<String, Object> mapJson = new HashMap<>(6);
|
||||
// mapJson.put("ddtkey", SmsConfig.DDT_KEY);
|
||||
// mapJson.put("secretkey", SmsConfig.SECRET_KEY);
|
||||
// mapJson.put("mobile", mobile);
|
||||
// mapJson.put("content", SmsConfig.SMS_SIGNATURE + content);
|
||||
// mapJson.put("sendTime", sendTime);
|
||||
// mapJson.put("extno", "");
|
||||
//
|
||||
// // 将mapJson转换为URL查询参数格式
|
||||
// StringBuilder urlBuilder = new StringBuilder(SmsConfig.SMS_TOKEN + "?");
|
||||
// for (Map.Entry<String, Object> entry : mapJson.entrySet()) {
|
||||
// try {
|
||||
// String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8");
|
||||
// String encodedValue = URLEncoder.encode(entry.getValue().toString(), "UTF-8");
|
||||
// urlBuilder.append(encodedKey).append("=").append(encodedValue).append("&");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// // 移除最后一个&符号
|
||||
// urlBuilder.setLength(urlBuilder.length() - 1);
|
||||
// String urlWithParams = urlBuilder.toString();
|
||||
//
|
||||
// String json = JSON.toJSONString(mapJson);
|
||||
// return HttpRequestHelper.postJson(SmsConfig.DOMAIN, urlWithParams, json, headers);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
package com.bonus.common.core.utils.sms;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.encryption.Sm4Utils;
|
||||
import com.bonus.common.core.utils.http.HttpRequestHelper;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SmsUtils {
|
||||
/**
|
||||
* 发送短信验证码
|
||||
*
|
||||
* @param mobile 发信发送的目的号码.多个号码之间用半角逗号隔开
|
||||
* @param content 短信的内容,内容需要UTF-8编码
|
||||
* @param sendTime 为空表示立即发送,定时发送格式:20101024090810
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
public static String smsToken(String mobile, String content, String sendTime) {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
Map<String, Object> mapJson = new HashMap<>(6);
|
||||
mapJson.put("ddtkey", SmsConfig.DDT_KEY);
|
||||
mapJson.put("secretkey", SmsConfig.SECRET_KEY);
|
||||
mapJson.put("mobile", mobile);
|
||||
mapJson.put("content", SmsConfig.SMS_SIGNATURE + content);
|
||||
mapJson.put("sendTime", sendTime);
|
||||
mapJson.put("extno", "");
|
||||
|
||||
// 将mapJson转换为URL查询参数格式
|
||||
StringBuilder urlBuilder = new StringBuilder(SmsConfig.SMS_TOKEN + "?");
|
||||
for (Map.Entry<String, Object> entry : mapJson.entrySet()) {
|
||||
try {
|
||||
String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8");
|
||||
String encodedValue = URLEncoder.encode(entry.getValue().toString(), "UTF-8");
|
||||
urlBuilder.append(encodedKey).append("=").append(encodedValue).append("&");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 移除最后一个&符号
|
||||
urlBuilder.setLength(urlBuilder.length() - 1);
|
||||
String urlWithParams = urlBuilder.toString();
|
||||
|
||||
String json = JSON.toJSONString(mapJson);
|
||||
return HttpRequestHelper.postJson(SmsConfig.DOMAIN, urlWithParams, json, headers);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +1,56 @@
|
|||
//package com.bonus.common.security.service;
|
||||
//
|
||||
//import com.bonus.common.core.constant.CacheConstants;
|
||||
//import com.bonus.common.core.exception.CaptchaException;
|
||||
//import com.bonus.common.core.utils.StringUtils;
|
||||
//import com.bonus.common.core.utils.VerificationCodeUtils;
|
||||
//import com.bonus.common.core.utils.sms.SmsUtils;
|
||||
//import com.bonus.common.redis.service.RedisService;
|
||||
//import com.bonus.common.security.config.VerificationCodeConfig;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//import static com.bonus.common.core.utils.VerificationCodeUtils.CodeType.NUMERIC;
|
||||
//
|
||||
///**
|
||||
// * @author bonus
|
||||
// */
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//public class SmsService {
|
||||
// @Resource
|
||||
// private VerificationCodeConfig verificationCodeConfig;
|
||||
// @Resource
|
||||
// private RedisService redisService;
|
||||
//
|
||||
// /**
|
||||
// * 生成手机验证码
|
||||
// *
|
||||
// * @return AjaxResult
|
||||
// * @throws CaptchaException 自定义captcha 异常
|
||||
// */
|
||||
// public void sendSimplePhone(String to) {
|
||||
// if (StringUtils.isEmpty(to)) {
|
||||
// throw new CaptchaException("手机号不能为空");
|
||||
// }
|
||||
// String code = VerificationCodeUtils.generateVerificationCode(NUMERIC);
|
||||
// String str = verificationCodeConfig.getContent().replace("<code>", code);
|
||||
// str = str.replace("<time>", verificationCodeConfig.getTime().toString());
|
||||
// String s = SmsUtils.smsToken(to, str, "");
|
||||
// log.error("省公司短信平台发送短信返回结果=" + s);
|
||||
// if (StringUtils.isNotEmpty(s)) {
|
||||
// if (s.contains("ok")) {
|
||||
// String verifyKey = CacheConstants.VERIFICATION_CODE + StringUtils.nvl(to, "");
|
||||
// redisService.setCacheObject(verifyKey, code, verificationCodeConfig.getTime(), TimeUnit.MINUTES);
|
||||
// } else {
|
||||
// throw new CaptchaException("获取短信失败");
|
||||
// }
|
||||
// } else {
|
||||
// throw new CaptchaException("获取短信失败");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
package com.bonus.common.security.service;
|
||||
|
||||
import com.bonus.common.core.constant.CacheConstants;
|
||||
import com.bonus.common.core.exception.CaptchaException;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.VerificationCodeUtils;
|
||||
import com.bonus.common.core.utils.sms.SmsUtils;
|
||||
import com.bonus.common.redis.service.RedisService;
|
||||
import com.bonus.common.security.config.VerificationCodeConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.bonus.common.core.utils.VerificationCodeUtils.CodeType.NUMERIC;
|
||||
|
||||
/**
|
||||
* @author bonus
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SmsService {
|
||||
@Resource
|
||||
private VerificationCodeConfig verificationCodeConfig;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 生成手机验证码
|
||||
*
|
||||
* @return AjaxResult
|
||||
* @throws CaptchaException 自定义captcha 异常
|
||||
*/
|
||||
public void sendSimplePhone(String to) {
|
||||
if (StringUtils.isEmpty(to)) {
|
||||
throw new CaptchaException("手机号不能为空");
|
||||
}
|
||||
String code = VerificationCodeUtils.generateVerificationCode(NUMERIC);
|
||||
String str = verificationCodeConfig.getContent().replace("<code>", code);
|
||||
str = str.replace("<time>", verificationCodeConfig.getTime().toString());
|
||||
String s = SmsUtils.smsToken(to, str, "");
|
||||
log.error("省公司短信平台发送短信返回结果=" + s);
|
||||
if (StringUtils.isNotEmpty(s)) {
|
||||
if (s.contains("ok")) {
|
||||
String verifyKey = CacheConstants.VERIFICATION_CODE + StringUtils.nvl(to, "");
|
||||
redisService.setCacheObject(verifyKey, code, verificationCodeConfig.getTime(), TimeUnit.MINUTES);
|
||||
} else {
|
||||
throw new CaptchaException("获取短信失败");
|
||||
}
|
||||
} else {
|
||||
throw new CaptchaException("获取短信失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import com.bonus.common.core.utils.SpringUtils;
|
|||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.bean.BeanValidators;
|
||||
import com.bonus.common.core.utils.encryption.Sm4Utils;
|
||||
//import com.bonus.common.core.utils.sms.SmsUtils;
|
||||
import com.bonus.common.core.utils.sms.SmsUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.domain.BaseEntity;
|
||||
import com.bonus.common.datascope.annotation.DataScope;
|
||||
|
|
@ -600,9 +600,9 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
}
|
||||
Integer i = userMapper.approvalStatus(userId);
|
||||
if (i > 0) {
|
||||
// if (StringUtils.isNotEmpty(sysUser.getPhonenumber())) {
|
||||
// SmsUtils.smsToken(sysUser.getPhonenumber(), "您的账号:" + sysUser.getUserName() + "已通过审批,请登录系统", "");
|
||||
// }
|
||||
if (StringUtils.isNotEmpty(sysUser.getPhonenumber())) {
|
||||
SmsUtils.smsToken(sysUser.getPhonenumber(), "您的账号:" + sysUser.getUserName() + "已通过审批,请登录系统", "");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(sysUser.getEmail())) {
|
||||
sendSimpleEmail(sysUser.getEmail(), "您的账号:" + sysUser.getUserName() + "已通过审批,请登录系统");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue