Browse Source

修改短信接口及用户信息

master
OuGaoHao 3 years ago
parent
commit
aaecf82f25
  1. 14
      numone-admin/src/main/resources/application-dev.yml
  2. 6
      numone-business/src/main/java/com/numone/system/service/impl/RegisterServiceImpl.java
  3. 7
      numone-common/pom.xml
  4. 62
      numone-common/src/main/java/com/numone/common/utils/sms/SmsConfig.java
  5. 157
      numone-common/src/main/java/com/numone/common/utils/sms/server/SmsServerUtil.java
  6. 76
      numone-system/src/main/resources/mapper/system/AppUserInfoMapper.xml

14
numone-admin/src/main/resources/application-dev.yml

@ -89,12 +89,16 @@ minio:
# 阿里云短信
aliyun:
tencent:
sms:
product: Dysmsapi
domain: dysmsapi.aliyuncs.com
accessKeyId: 1400641801
accessKeySecret: 2c3b97ed0de8681ba6d3099d0a6b2069
sdkAppId: 1400640652 #短信应用ID
appKey: 22b7addedb6a231f5a00a128761fcef4 # App Key
signName: #短信签名内容
templateId: #模板 ID
secretId: #秘钥id
secretKey: #密钥对
#小程序配置
wx:

6
numone-business/src/main/java/com/numone/system/service/impl/RegisterServiceImpl.java

@ -123,9 +123,9 @@ public class RegisterServiceImpl implements RegisterService {
throw new AppException("手机号未注册");
}
}
// if (!smsServerUtil.sendSms(phonenumberParams.getPhonenumber(), newCode, smsServerUtil.REG_CODE)){
// throw new AppException("验证码发送失败");
// }
if (!smsServerUtil.sendSms(phonenumberParams.getPhonenumber(), newCode, smsServerUtil.REG_CODE)){
throw new AppException("验证码发送失败");
}
redisCache.setCacheObject(RedisCacheConstant.SMS_CAPTCHA_CODE_KEY + phonenumberParams.getPhonenumber(), newCode, RedisCacheConstant.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
return newCode;

7
numone-common/pom.xml

@ -165,6 +165,13 @@
<version>5.6.3</version>
</dependency>
<!-- 腾讯云短信-->
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.270</version><!-- 注:这里只是示例版本号(可直接使用),可获取并替换为 最新的版本号,注意不要使用4.0.x版本(非最新版本) -->
</dependency>
</dependencies>
</project>

62
numone-common/src/main/java/com/numone/common/utils/sms/SmsConfig.java

@ -11,48 +11,68 @@ import org.springframework.stereotype.Component;
* 阿里云短信配置信息
*/
@Component
@ConfigurationProperties(prefix = "aliyun.sms")
@ConfigurationProperties(prefix = "tencent.sms")
public class SmsConfig {
private String product ;
private String sdkAppId ;
private String domain ;
private String appKey ;
private String accessKeyId ;
private String secretId ;
private String accessKeySecret ;
private String secretKey ;
private String signName;
public String getProduct() {
return product;
private String templateId;
public String getSdkAppId() {
return sdkAppId;
}
public void setSdkAppId(String sdkAppId) {
this.sdkAppId = sdkAppId;
}
public String getAppKey() {
return appKey;
}
public void setProduct(String product) {
this.product = product;
public void setAppKey(String appKey) {
this.appKey = appKey;
}
public String getDomain() {
return domain;
public String getSecretId() {
return secretId;
}
public void setDomain(String domain) {
this.domain = domain;
public void setSecretId(String secretId) {
this.secretId = secretId;
}
public String getAccessKeyId() {
return accessKeyId;
public String getSecretKey() {
return secretKey;
}
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public String getAccessKeySecret() {
return accessKeySecret;
public String getSignName() {
return signName;
}
public void setAccessKeySecret(String accessKeySecret) {
this.accessKeySecret = accessKeySecret;
public void setSignName(String signName) {
this.signName = signName;
}
public String getTemplateId() {
return templateId;
}
public void setTemplateId(String templateId) {
this.templateId = templateId;
}
}

157
numone-common/src/main/java/com/numone/common/utils/sms/server/SmsServerUtil.java

@ -3,13 +3,21 @@ package com.numone.common.utils.sms.server;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.numone.common.exception.UtilException;
import com.numone.common.utils.sms.SmsConfig;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,7 +45,6 @@ public class SmsServerUtil {
*/
public static final String REG_CODE = "";
/**
* 根据手机号码发送code
*
@ -46,33 +53,127 @@ public class SmsServerUtil {
* @return
* @throws ClientException
*/
public boolean sendSms(String phone, String code, String smsTempCode) throws ClientException {
//初始化acsClient,暂不支持region化
System.out.println(smsConfig.getAccessKeyId());
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", smsConfig.getAccessKeyId(), smsConfig.getAccessKeySecret());
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", smsConfig.getProduct(), smsConfig.getDomain());
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
//必填:待发送手机号
request.setPhoneNumbers(phone);
//必填:短信签名-可在短信控制台中找到
request.setSignName("一号藏馆");
//必填:短信模板-可在短信控制台中找到
request.setTemplateCode(smsTempCode);
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.setTemplateParam("{'code':'" + code + "'}");
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
logger.debug(" 短信:" + phone + " 验证码: " + code + " 发送成功");
return true;
} else {
logger.debug(" 短信:" + phone + " 验证码: " + code + " 发送失败");
throw new UtilException(sendSmsResponse.getMessage(), null);
public boolean sendSms(String phone, String code, String smsTempCode){
try {
/* 必要步骤
* 实例化一个认证对象入参需要传入腾讯云账户密钥对secretIdsecretKey
* 这里采用的是从环境变量读取的方式需要在环境变量中先设置这两个值
* 你也可以直接在代码中写死密钥对但是小心不要将代码复制上传或者分享给他人
* 以免泄露密钥对危及你的财产安全
* SecretIdSecretKey 查询: https://console.cloud.tencent.com/cam/capi */
Credential cred = new Credential(smsConfig.getSecretId(),smsConfig.getSecretKey());
// 实例化一个http选项,可选,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
// 设置代理
// httpProfile.setProxyHost("真实代理ip");
// httpProfile.setProxyPort(真实代理端口);
/* SDK默认使用POST方法
* 如果你一定要使用GET方法可以在这里设置GET方法无法处理一些较大的请求 */
httpProfile.setReqMethod("POST");
/* SDK有默认的超时时间非必要请不要进行调整
* 如有需要请在代码中查阅以获取最新的默认值 */
httpProfile.setConnTimeout(60);
/* 指定接入地域域名,默认就近地域接入域名为 sms.tencentcloudapi.com ,也支持指定地域域名访问,例如广州地域的域名为 sms.ap-guangzhou.tencentcloudapi.com */
httpProfile.setEndpoint("sms.tencentcloudapi.com");
/* 非必要步骤:
* 实例化一个客户端配置对象可以指定超时时间等配置 */
ClientProfile clientProfile = new ClientProfile();
/* SDK默认用TC3-HMAC-SHA256进行签名
* 非必要请不要修改这个字段 */
clientProfile.setSignMethod("HmacSHA256");
clientProfile.setHttpProfile(httpProfile);
/* 实例化要请求产品(以sms为例)的client对象
* 第二个参数是地域信息可以直接填写字符串ap-guangzhou支持的地域列表参考 https://cloud.tencent.com/document/api/382/52071#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8 */
SmsClient client = new SmsClient(cred, "ap-guangzhou",clientProfile);
/* 实例化一个请求对象根据调用的接口和实际情况可以进一步设置请求参数
* 你可以直接查询SDK源码确定接口有哪些属性可以设置
* 属性可能是基本类型也可能引用了另一个数据结构
* 推荐使用IDE进行开发可以方便的跳转查阅各个接口和数据结构的文档说明 */
SendSmsRequest req = new SendSmsRequest();
/* 填充请求参数,这里request对象的成员变量即对应接口的入参
* 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义
* 基本类型的设置:
* 帮助链接
* 短信控制台: https://console.cloud.tencent.com/smsv2
* sms helper: https://cloud.tencent.com/document/product/382/3773 */
/* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */
String sdkAppId = smsConfig.getSdkAppId();
req.setSmsSdkAppId(sdkAppId);
/* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名,签名信息可登录 [短信控制台] 查看 */
String signName = smsConfig.getSignName();
req.setSignName(signName);
/* 模板 ID: 必须填写已审核通过的模板 ID。模板ID可登录 [短信控制台] 查看 */
String templateId = smsConfig.getTemplateId();
req.setTemplateId(templateId);
/* 下发手机号码采用 E.164 标准+[国家或地区码][手机号]
* 示例如+8613711112222 其中前面有一个+ 86为国家码13711112222为手机号最多不要超过200个手机号 */
String[] phoneNumberSet = {"+86"+code};
req.setPhoneNumberSet(phoneNumberSet);
/* 模板参数: 若无模板参数,则设置为空 */
String[] templateParamSet = {""};
req.setTemplateParamSet(templateParamSet);
/* 通过 client 对象调用 SendSms 方法发起请求注意请求方法名与请求对象是对应的
* 返回的 res 是一个 SendSmsResponse 类的实例与请求对象对应 */
SendSmsResponse res = client.SendSms(req);
// 输出json格式的字符串回包
System.out.println(SendSmsResponse.toJsonString(res));
// 也可以取出单个值,你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义
System.out.println(res.getRequestId());
} catch (TencentCloudSDKException e) {
e.printStackTrace();
}
return true;
}
// /**
// * 根据手机号码发送code
// *
// * @param phone
// * @param code
// * @return
// * @throws ClientException
// */
// public boolean sendSms(String phone, String code, String smsTempCode) throws ClientException {
// //初始化acsClient,暂不支持region化
// System.out.println(smsConfig.getAccessKeyId());
// IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", smsConfig.getAccessKeyId(), smsConfig.getAccessKeySecret());
// DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", smsConfig.getProduct(), smsConfig.getDomain());
// IAcsClient acsClient = new DefaultAcsClient(profile);
//
// SendSmsRequest request = new SendSmsRequest();
// //必填:待发送手机号
// request.setPhoneNumbers(phone);
// //必填:短信签名-可在短信控制台中找到
// request.setSignName("一号藏馆");
// //必填:短信模板-可在短信控制台中找到
// request.setTemplateCode(smsTempCode);
// //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
// request.setTemplateParam("{'code':'" + code + "'}");
//
// SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
//
// if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
// logger.debug(" 短信:" + phone + " 验证码: " + code + " 发送成功");
// return true;
// } else {
// logger.debug(" 短信:" + phone + " 验证码: " + code + " 发送失败");
// throw new UtilException(sendSmsResponse.getMessage(), null);
// }
// }
}

76
numone-system/src/main/resources/mapper/system/AppUserInfoMapper.xml

@ -115,57 +115,57 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
END sexName,
CASE
WHEN t2.stone_num >= 1
AND t2.stone_num &lt;= 50 THEN
AND t2.stone_num &lt;= 500 THEN
"炼气期"
WHEN t2.stone_num >= 51
AND t2.stone_num &lt;= 100 THEN
WHEN t2.stone_num >= 501
AND t2.stone_num &lt;= 2000 THEN
"筑基期"
WHEN t2.stone_num >= 101
AND t2.stone_num &lt;= 300 THEN
WHEN t2.stone_num >= 2001
AND t2.stone_num &lt;= 8000 THEN
"金丹期"
WHEN t2.stone_num >= 301
AND t2.stone_num &lt;= 800 THEN
WHEN t2.stone_num >= 8001
AND t2.stone_num &lt;= 20000 THEN
"元婴期"
WHEN t2.stone_num >= 801
AND t2.stone_num &lt;= 1500 THEN
WHEN t2.stone_num >= 20001
AND t2.stone_num &lt;= 50000 THEN
"化神期"
WHEN t2.stone_num >= 1501
AND t2.stone_num &lt;= 3000 THEN
WHEN t2.stone_num >= 50001
AND t2.stone_num &lt;= 10000 THEN
"合体期"
WHEN t2.stone_num >= 3001
AND t2.stone_num &lt;= 5000 THEN
WHEN t2.stone_num >= 10001
AND t2.stone_num &lt;= 500000 THEN
"渡劫期"
WHEN t2.stone_num >= 5001
AND t2.stone_num &lt;= 9999 THEN
WHEN t2.stone_num >= 500001
AND t2.stone_num &lt;= 999999 THEN
"大乘期"
ELSE
"虚仙"
END realm,
CASE
WHEN t2.stone_num >= 1
AND t2.stone_num &lt;= 50 THEN
50
WHEN t2.stone_num >= 51
AND t2.stone_num &lt;= 100 THEN
100
WHEN t2.stone_num >= 101
AND t2.stone_num &lt;= 300 THEN
300
WHEN t2.stone_num >= 301
AND t2.stone_num &lt;= 800 THEN
800
WHEN t2.stone_num >= 801
AND t2.stone_num &lt;= 1500 THEN
1500
WHEN t2.stone_num >= 1501
AND t2.stone_num &lt;= 3000 THEN
3000
WHEN t2.stone_num >= 3001
AND t2.stone_num &lt;= 5000 THEN
5000
WHEN t2.stone_num >= 5001
AND t2.stone_num &lt;= 9999 THEN
9999
AND t2.stone_num &lt;= 500 THEN
500
WHEN t2.stone_num >= 501
AND t2.stone_num &lt;= 2000 THEN
2000
WHEN t2.stone_num >= 2001
AND t2.stone_num &lt;= 8000 THEN
8000
WHEN t2.stone_num >= 8001
AND t2.stone_num &lt;= 20000 THEN
20000
WHEN t2.stone_num >= 20001
AND t2.stone_num &lt;= 50000 THEN
50000
WHEN t2.stone_num >= 50001
AND t2.stone_num &lt;= 10000 THEN
10000
WHEN t2.stone_num >= 100001
AND t2.stone_num &lt;= 500000 THEN
500000
WHEN t2.stone_num >= 500001
AND t2.stone_num &lt;= 999999 THEN
999999
ELSE
10000
END boundary,

Loading…
Cancel
Save