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