记得上下班打卡 | git大法好,push需谨慎

Commit 9becb120 authored by 张国柄's avatar 张国柄

+aliyun dysms短信服务;

parent 9c322356
......@@ -21,5 +21,10 @@
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-base</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.liquidnet.common.sms.constant;
public class SmsEnum {
/**
* AD:AliyunDysms
* 短信签名
*/
public enum ADSignName {
摩登天空,正在现场,新血计划,摩登小家伙,五百里Live;
}
/**
* AD:AliyunDysms
* 短信模版
*/
public enum ADTemplate {
/**
* 验证码:验证码
* - 您的验证码是:${code}。该验证码15分钟内有效,请不要把验证码泄露给其他人。
* - "{\"code\":\"?1\"}"
*/
SMS_109535335,
/**
* 短信通知:票务 - 用户购票成功后短信通知
* - 尊敬的${userName},您已成功购买${aName},演出时间${time},地点${siteName},此短信不作为入场凭证。您可以登录“正在现场”app查询您的订单及入场方式。也可点此http://ticket.zhengzai.tv${url}
*/
SMS_107075073,
;
}
}
package com.liquidnet.common.sms.processor;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.liquidnet.commons.lang.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Slf4j
@Component
public class SmsProcessor {
/* ================================================================== | aliyun dysms */
@Value("${liquidnet.aliyun.dysms.accessKeyId}")
private String aliyunDysmsAccessKeyId;
@Value("${liquidnet.aliyun.dysms.accessKeySecret}")
private String aliyunDysmsAccessKeySecret;
private static Client aliyunDysmsAcsClient;
/* ================================================================== | */
@PostConstruct
private void init() throws Exception {
Config config = new Config()
.setAccessKeyId(aliyunDysmsAccessKeyId)
.setAccessKeySecret(aliyunDysmsAccessKeySecret)
.setEndpoint("dysmsapi.aliyuncs.com");
aliyunDysmsAcsClient = new Client(config);
}
/**
* AliyunDysms.send
* - link: https://help.aliyun.com/document_detail/101414.htm?spm=a2c4g.11186623.2.8.302f56958lnARh#t83759.html
*
* @param phoneNumber 接收短信的手机号码(国内短信:+/+86/0086/86或无任何前缀的11位手机号码;国际/港澳台消息:国际区号+号码)
* @param signName 短信签名名称
* @param templateCode 短信模板ID
* @param templateParam 短信模板变量对应的实际值,JSON格式(建议使用com.liquidnet.commons.lang.util.JsonUtils.OM().createObjectNode())
* @return boolean
*/
public boolean aliyunDysmsSend(String phoneNumber, String signName, String templateCode, String templateParam) {
SendSmsRequest smsRequest = new SendSmsRequest()
.setPhoneNumbers(phoneNumber)
.setSignName(signName)
.setTemplateCode(templateCode)
.setTemplateParam(templateParam);
try {
SendSmsResponse smsResponse = aliyunDysmsAcsClient.sendSms(smsRequest);
SendSmsResponseBody smsResponseBody = smsResponse.getBody();
return null != smsResponseBody && smsResponseBody.getCode().equalsIgnoreCase("OK");
} catch (Exception e) {
log.error("API处理异常", e);
}
return false;
}
/**
* AliyunDysms.sendBatch
* - note: 在一次请求中,最多可以向100个手机号码分别发送短信(整体请求量限定在128k以内)
* - link: https://help.aliyun.com/document_detail/102364.html?spm=a2c4g.11186623.6.633.3d855ecb5j4CR8
*
* @param phoneNumberJson 接收短信的手机号码(国内短信:+/+86/0086/86或无任何前缀的11位手机号码;国际/港澳台消息:国际区号+号码),JSON数组格式(建议使用com.liquidnet.commons.lang.util.JsonUtils.OM().createArrayNode())
* @param signNameJson 短信签名名称,JSON数组格式(建议使用com.liquidnet.commons.lang.util.JsonUtils.OM().createArrayNode())
* @param templateCode 短信模板CODE
* @param templateParamJson 短信模板变量对应的实际值,JSON格式(建议使用com.liquidnet.commons.lang.util.JsonUtils.OM().createObjectNode())
* @return boolean
*/
public boolean aliyunDysmsSendBatch(String phoneNumberJson, String signNameJson, String templateCode, String templateParamJson) {
SendBatchSmsRequest batchSmsRequest = new SendBatchSmsRequest()
.setPhoneNumberJson(phoneNumberJson)
.setSignNameJson(signNameJson)
.setTemplateCode(templateCode)
.setTemplateParamJson(templateParamJson);
try {
SendBatchSmsResponse batchSmsResponse = aliyunDysmsAcsClient.sendBatchSms(batchSmsRequest);
log.info(JsonUtils.toJson(batchSmsResponse));
SendBatchSmsResponseBody batchSmsResponseBody = batchSmsResponse.getBody();
return null != batchSmsResponseBody && batchSmsResponseBody.getCode().equalsIgnoreCase("OK");
} catch (Exception e) {
log.error("API处理异常", e);
}
return false;
}
}
......@@ -160,6 +160,7 @@
<version>1.1.3</version>
</dependency>
<!-- 短信SDK -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
......
......@@ -80,4 +80,13 @@ liquidnet:
sk: 21e9a70f677a2bf29dfa2b3bead4f018
appid: 557104628450889728
custid: 7551234567
#application-dev-end
aliyun:
dypns:
accessKeyId: LTAI4FvoqxJUT5T1ydJSyhUn
accessKeySecret: WNCgFn9dSjnoDdej2YTvR0v0216WWU
dysms:
accessKeyId: LTAI5tHt7yvm97G8zxackcMK
accessKeySecret: xC3i5qEptJ3JIIRaYLaKvhk4gVASfl
#application-dev-end
\ No newline at end of file
......@@ -30,12 +30,8 @@ liquidnet:
disable: false
redis:
host: r-2ze7002ckw5u75fgukpd.redis.rds.aliyuncs.com
# host: r-2zefzyjbij5vbez65y.redis.rds.aliyuncs.com
port: 6380
password: PO@B!Iud32
# host: r-2ze7002ckw5u75fguk.redis.rds.aliyuncs.com
# port: 6380
# password: PO@B!Iud32
mongodb:
host: s-2zef656730e5a1d4-pub.mongodb.rds.aliyuncs.com:3717,s-2ze49872ed6aeb14-pub.mongodb.rds.aliyuncs.com:3717
port: 3717
......@@ -84,3 +80,13 @@ liquidnet:
sk: 21e9a70f677a2bf29dfa2b3bead4f018
appid: 557104628450889728
custid: 7551234567
aliyun:
dypns:
accessKeyId: LTAI4FvoqxJUT5T1ydJSyhUn
accessKeySecret: WNCgFn9dSjnoDdej2YTvR0v0216WWU
dysms:
accessKeyId: LTAI5tHt7yvm97G8zxackcMK
accessKeySecret: xC3i5qEptJ3JIIRaYLaKvhk4gVASfl
#application-test-end
\ No newline at end of file
......@@ -26,9 +26,6 @@ liquidnet:
callback: ${liquidnet.service.adam.url-pay.callback}
url-service:
url: ${liquidnet.service.adam.url-service.url}
aliyun:
accessKeyId: LTAI4FvoqxJUT5T1ydJSyhUn
accessSecret: WNCgFn9dSjnoDdej2YTvR0v0216WWU
reviewer:
app-login:
mobile: 13724286255
......
......@@ -26,9 +26,6 @@ liquidnet:
callback: ${liquidnet.service.adam.url-pay.callback}
url-service:
url: ${liquidnet.service.adam.url-service.url}
aliyun:
accessKeyId: LTAI4FvoqxJUT5T1ydJSyhUn
accessSecret: WNCgFn9dSjnoDdej2YTvR0v0216WWU
reviewer:
app-login:
mobile: 13724286255
......
......@@ -54,6 +54,12 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-sms</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
......
......@@ -8,14 +8,14 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class AliyunDypnsConfigure {
@Value("${liquidnet.aliyun.accessKeyId}")
@Value("${liquidnet.aliyun.dypns.accessKeyId}")
private String accessKeyId;
@Value("${liquidnet.aliyun.accessSecret}")
private String accessSecret;
@Value("${liquidnet.aliyun.dypns.accessKeySecret}")
private String accessKeySecret;
@Bean
public DefaultAcsClient initAcsClient() {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", accessKeyId, accessKeySecret);
return new DefaultAcsClient(profile);
}
}
......@@ -5,10 +5,14 @@ import com.aliyuncs.dypnsapi.model.v20170525.GetMobileRequest;
import com.aliyuncs.dypnsapi.model.v20170525.GetMobileResponse;
import com.aliyuncs.exceptions.ClientException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.common.cache.redisson.util.RedisLockUtil;
import com.liquidnet.common.sms.constant.SmsEnum;
import com.liquidnet.common.sms.processor.SmsProcessor;
import com.liquidnet.commons.lang.constant.LnsEnum;
import com.liquidnet.commons.lang.core.JwtValidator;
import com.liquidnet.commons.lang.util.*;
......@@ -69,6 +73,8 @@ public class AdamLoginController {
AdamRdmService adamRdmService;
@Autowired
IAdamUserService adamUserService;
@Autowired
SmsProcessor smsProcessor;
@Value("${liquidnet.reviewer.app-login.mobile}")
private String reviewMobile;
......@@ -96,6 +102,43 @@ public class AdamLoginController {
log.debug("nextMilliId:{}", IDGenerator.nextMilliId());
log.debug("nextMilliId:{}", IDGenerator.nextTimeId());
log.debug("nextMilliId:{}", IDGenerator.get32UUID());
ObjectNode smsNode = JsonUtils.OM().createObjectNode();
smsNode.put("code", "123456");
smsProcessor.aliyunDysmsSend("13753596360",
SmsEnum.ADSignName.正在现场.name(), SmsEnum.ADTemplate.SMS_109535335.name(),
smsNode.toString());
ArrayNode smsBatchPhones = JsonUtils.OM().createArrayNode(),
smsBatchSignNames = JsonUtils.OM().createArrayNode(),
smsBatchTemplateParams = JsonUtils.OM().createArrayNode();
ObjectNode smsBatchTemplateParam = JsonUtils.OM().createObjectNode();
smsBatchPhones.add("13753596360");
smsBatchPhones.add("17701223310");
smsBatchSignNames.add(SmsEnum.ADSignName.正在现场.name());
smsBatchSignNames.add(SmsEnum.ADSignName.正在现场.name());
smsBatchTemplateParam.put("userName", "张某人");
smsBatchTemplateParam.put("aName", "大美");
smsBatchTemplateParam.put("time", "2021-07-10");
smsBatchTemplateParam.put("siteName", "北京");
smsBatchTemplateParam.put("url", "show");
smsBatchTemplateParams.add(smsBatchTemplateParam.deepCopy());
smsBatchTemplateParam.put("userName", "张某人");
smsBatchTemplateParam.put("aName", "大美2");
smsBatchTemplateParam.put("time", "2021-07-11");
smsBatchTemplateParam.put("siteName", "天津");
smsBatchTemplateParam.put("url", "show2");
smsBatchTemplateParams.add(smsBatchTemplateParam);
smsProcessor.aliyunDysmsSendBatch(smsBatchPhones.toPrettyString(), smsBatchSignNames.toString(), SmsEnum.ADTemplate.SMS_109535335.name(), smsBatchTemplateParams.toString());
}
@ApiOperationSupport(order = 2)
......
......@@ -105,12 +105,12 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.2</version>
<version>4.5.22</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dypnsapi</artifactId>
<version>1.1.3</version>
<version>1.2.1</version>
</dependency>
<dependency>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment