diff --git a/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java b/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java new file mode 100644 index 0000000..d6b0664 --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java @@ -0,0 +1,42 @@ +package com.java3y.austin.enums; + + +/** + * 发送渠道类型枚举 + */ +public enum ChannelType { + IM(10, "IM(站内信)"), + PUSH(20, "push(通知栏)"), + SMS(30, "sms(短信)"), + EMAIL(40, "email(邮件)"), + OFFICIAL_ACCOUNT(50, "OfficialAccounts(服务号)"), + MINI_PROGRAM(60, "miniProgram(小程序)") + ; + + + private Integer code; + private String description; + + ChannelType(Integer code, String description) { + this.code = code; + this.description = description; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + +} diff --git a/austin-common/src/main/java/com/java3y/austin/enums/IdType.java b/austin-common/src/main/java/com/java3y/austin/enums/IdType.java new file mode 100644 index 0000000..113a17d --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/enums/IdType.java @@ -0,0 +1,37 @@ +package com.java3y.austin.enums; + + +/** + * 发送ID类型枚举 + */ +public enum IdType { + USER_ID(10, "userid"), + DID(20, "did"), + PHONE(30, "phone"), + OPEN_ID(40, "openId"), + EMAIL(50, "email"); + + IdType(Integer code, String description) { + this.code = code; + this.description = description; + } + + private Integer code; + private String description; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java b/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java new file mode 100644 index 0000000..8642174 --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java @@ -0,0 +1,40 @@ +package com.java3y.austin.enums; + +/** + * 发送的消息类型 + */ +public enum MessageType { + NOTICE(10,"通知类消息"), + MARKETING(20,"营销类消息"), + AUTH_CODE(30,"验证码消息") + ; + + /** + * `msg_type` tinyint(4) + * NOT NULL DEFAULT '0' COMMENT '10.通知类消息 20.营销类消息 30.验证码类消息', + */ + + private Integer code; + private String description; + + MessageType(Integer code, String description) { + this.code = code; + this.description = description; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/austin-common/src/main/java/com/java3y/austin/enums/SmsStatus.java b/austin-common/src/main/java/com/java3y/austin/enums/SmsStatus.java new file mode 100644 index 0000000..1ee5b69 --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/enums/SmsStatus.java @@ -0,0 +1,32 @@ +package com.java3y.austin.enums; + +public enum SmsStatus { + + SEND_SUCCESS(10,"调用渠道接口发送成功"), + RECEIVE_SUCCESS(20,"用户收到短信(收到渠道短信回执,状态成功)"), + RECEIVE_FAIL(30, "用户收不到短信(收到渠道短信回执,状态失败)"); + + private Integer code; + private String description; + + SmsStatus(Integer code, String description) { + this.code = code; + this.description = description; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/austin-common/src/main/java/com/java3y/austin/enums/TemplateType.java b/austin-common/src/main/java/com/java3y/austin/enums/TemplateType.java new file mode 100644 index 0000000..a113e4a --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/enums/TemplateType.java @@ -0,0 +1,32 @@ +package com.java3y.austin.enums; + +public enum TemplateType { + + OPERATION(10, "运营类的模板"), + TECHNOLOGY(20, "技术类的模板"), + ; + + private Integer code; + private String description; + + TemplateType(Integer code, String description) { + this.code = code; + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } +} diff --git a/austin-common/src/main/java/com/java3y/austin/pojo/SmsParam.java b/austin-common/src/main/java/com/java3y/austin/pojo/SmsParam.java index 0b19f07..521966a 100644 --- a/austin-common/src/main/java/com/java3y/austin/pojo/SmsParam.java +++ b/austin-common/src/main/java/com/java3y/austin/pojo/SmsParam.java @@ -14,6 +14,11 @@ import java.util.Set; @Builder public class SmsParam { + /** + * 业务Id + */ + private Long messageTemplateId; + /** * 需要发送的手机号 */ @@ -23,4 +28,14 @@ public class SmsParam { * 发送文案 */ private String content; + + /** + * 渠道商Id + */ + private Integer supplierId; + + /** + * 渠道商名字 + */ + private String supplierName; } diff --git a/austin-common/src/main/java/com/java3y/austin/pojo/TaskInfo.java b/austin-common/src/main/java/com/java3y/austin/pojo/TaskInfo.java new file mode 100644 index 0000000..b108882 --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/pojo/TaskInfo.java @@ -0,0 +1,73 @@ +package com.java3y.austin.pojo; + +import lombok.Builder; +import lombok.Data; + +import java.util.Set; + +/** + * 发送任务信息 + */ +@Data +@Builder +public class TaskInfo { + + /** + * 消息模板Id + */ + private Long messageTemplateId; + + /** + * 业务Id + */ + private Long businessId; + + /** + * 接收者 + */ + private Set receiver; + + /** + * 发送的Id类型 + */ + private Integer idType; + + /** + * 发送渠道 + */ + private Integer sendChannel; + + /** + * 模板类型 + */ + private Integer templateType; + + /** + * 消息类型 + */ + private Integer msgType; + + /** + * 发送文案内容 + */ + private String content; + + /** + * 发送账号(邮件下可有多个发送账号、短信可有多个发送账号..) + */ + private Integer sendAccount; + + /** + * 消息去重时间 单位小时 + */ + private Integer deduplicationTime; + + /** + * 是否夜间屏蔽 + * 0:不屏蔽 + * 1:屏蔽 + */ + private Integer isNightShield; + + +} diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java b/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java new file mode 100644 index 0000000..8fbcc47 --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java @@ -0,0 +1,14 @@ +package com.java3y.austin.handler; + +import com.java3y.austin.domain.MessageTemplate; +import com.java3y.austin.pojo.TaskInfo; + +public interface Handler { + + boolean doHandler(TaskInfo TaskInfo); + + + + + +} diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java new file mode 100644 index 0000000..6c25e9e --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java @@ -0,0 +1,41 @@ +package com.java3y.austin.handler; + +import cn.hutool.core.collection.CollUtil; +import com.java3y.austin.dao.SmsRecordDao; +import com.java3y.austin.domain.MessageTemplate; +import com.java3y.austin.domain.SmsRecord; +import com.java3y.austin.pojo.SmsParam; +import com.java3y.austin.pojo.TaskInfo; +import com.java3y.austin.script.SmsScript; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class SmsHandler implements Handler { + @Autowired + private SmsRecordDao smsRecordDao; + + @Autowired + private SmsScript smsScript; + + @Override + public boolean doHandler(TaskInfo taskInfo) { + + SmsParam smsParam = SmsParam.builder() + .phones(taskInfo.getReceiver()) + .content(taskInfo.getContent()) + .messageTemplateId(taskInfo.getMessageTemplateId()) + .supplierId(10) + .supplierName("腾讯云通知类消息渠道").build(); + List recordList = smsScript.send(smsParam); + + if (CollUtil.isNotEmpty(recordList)) { + smsRecordDao.saveAll(recordList); + return true; + } + + return false; + } +} diff --git a/austin-handler/src/main/java/com/java3y/austin/script/SmsScript.java b/austin-handler/src/main/java/com/java3y/austin/script/SmsScript.java new file mode 100644 index 0000000..fe34b7c --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/script/SmsScript.java @@ -0,0 +1,17 @@ +package com.java3y.austin.script; + +import com.java3y.austin.domain.SmsRecord; +import com.java3y.austin.pojo.SmsParam; + +import java.util.List; + +public interface SmsScript { + + + /** + * @param smsParam 发送短信参数 + * @return 渠道商接口返回值 + */ + List send(SmsParam smsParam); + +} diff --git a/austin-handler/src/main/java/com/java3y/austin/script/TencentSmsScript.java b/austin-handler/src/main/java/com/java3y/austin/script/TencentSmsScript.java index c2134af..eddc237 100644 --- a/austin-handler/src/main/java/com/java3y/austin/script/TencentSmsScript.java +++ b/austin-handler/src/main/java/com/java3y/austin/script/TencentSmsScript.java @@ -1,8 +1,13 @@ package com.java3y.austin.script; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.google.common.base.Throwables; +import com.java3y.austin.domain.SmsRecord; +import com.java3y.austin.enums.SmsStatus; import com.java3y.austin.pojo.SmsParam; import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.exception.TencentCloudSDKException; @@ -11,12 +16,15 @@ 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 lombok.Getter; +import com.tencentcloudapi.sms.v20210111.models.SendStatus; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + /** * @author 3y * @date 2021/11/6 @@ -26,7 +34,9 @@ import org.springframework.stereotype.Service; */ @Service @Slf4j -public class TencentSmsScript { +public class TencentSmsScript implements SmsScript { + + private static final Integer PHONE_NUM = 11; /** * api相关 @@ -52,44 +62,82 @@ public class TencentSmsScript { @Value("${tencent.sms.account.sign_name}") private String SIGN_NAME; - - public String send(SmsParam smsParam) { + @Override + public List send(SmsParam smsParam) { try { + SmsClient client = init(); - /** - * 初始化 client - */ - Credential cred = new Credential(SECRET_ID, SECRET_KEY); - HttpProfile httpProfile = new HttpProfile(); - httpProfile.setEndpoint(URL); - ClientProfile clientProfile = new ClientProfile(); - clientProfile.setHttpProfile(httpProfile); - SmsClient client = new SmsClient(cred, REGION, clientProfile); - - /** - * 组装发送短信参数 - */ - SendSmsRequest req = new SendSmsRequest(); - String[] phoneNumberSet1 = smsParam.getPhones().toArray(new String[smsParam.getPhones().size() - 1]); - req.setPhoneNumberSet(phoneNumberSet1); - req.setSmsSdkAppId(SMS_SDK_APP_ID); - req.setSignName(SIGN_NAME); - req.setTemplateId(TEMPLATE_ID); - String[] templateParamSet1 = {smsParam.getContent()}; - req.setTemplateParamSet(templateParamSet1); - req.setSessionContext(IdUtil.fastSimpleUUID()); - - /** - * 请求,返回结果 - */ - SendSmsResponse resp = client.SendSms(req); - return SendSmsResponse.toJsonString(resp); + SendSmsRequest request = assembleReq(smsParam); + + SendSmsResponse response = client.SendSms(request); + + return assembleSmsRecord(smsParam,response); } catch (TencentCloudSDKException e) { log.error("send tencent sms fail!{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(smsParam)); return null; } + } + + private List assembleSmsRecord(SmsParam smsParam, SendSmsResponse response) { + if (response == null || ArrayUtil.isEmpty(response.getSendStatusSet())) { + return null; + } + + List smsRecordList = new ArrayList<>(); + + for (SendStatus sendStatus : response.getSendStatusSet()) { + String phone = new StringBuilder(new StringBuilder(sendStatus.getPhoneNumber()) + .reverse().substring(0, PHONE_NUM)).reverse().toString(); + + SmsRecord smsRecord = SmsRecord.builder() + .sendDate(Integer.valueOf(DateUtil.format(new Date(), "yyyyMMdd"))) + .messageTemplateId(smsParam.getMessageTemplateId()) + .phone(Long.valueOf(phone)) + .supplierId(smsParam.getSupplierId()) + .supplierName(smsParam.getSupplierName()) + .seriesId(sendStatus.getSerialNo()) + .chargingNum(Math.toIntExact(sendStatus.getFee())) + .status(SmsStatus.SEND_SUCCESS.getCode()) + .reportContent(sendStatus.getCode()) + .created(Math.toIntExact(DateUtil.currentSeconds())) + .updated(Math.toIntExact(DateUtil.currentSeconds())) + .build(); + smsRecordList.add(smsRecord); + } + return smsRecordList; + } + + /** + * 组装发送短信参数 + */ + private SendSmsRequest assembleReq(SmsParam smsParam) { + SendSmsRequest req = new SendSmsRequest(); + String[] phoneNumberSet1 = smsParam.getPhones().toArray(new String[smsParam.getPhones().size() - 1]); + req.setPhoneNumberSet(phoneNumberSet1); + req.setSmsSdkAppId(SMS_SDK_APP_ID); + req.setSignName(SIGN_NAME); + req.setTemplateId(TEMPLATE_ID); + String[] templateParamSet1 = {smsParam.getContent()}; + req.setTemplateParamSet(templateParamSet1); + req.setSessionContext(IdUtil.fastSimpleUUID()); + return req; } + + /** + * 初始化 client + */ + private SmsClient init() { + Credential cred = new Credential(SECRET_ID, SECRET_KEY); + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint(URL); + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + SmsClient client = new SmsClient(cred, REGION, clientProfile); + return client; + } + } + diff --git a/austin-support/pom.xml b/austin-support/pom.xml index 0363790..1d51ced 100644 --- a/austin-support/pom.xml +++ b/austin-support/pom.xml @@ -13,6 +13,11 @@ + + com.java3y.austin + austin-common + 0.0.1-SNAPSHOT + org.springframework.boot spring-boot-starter @@ -42,15 +47,11 @@ com.alibaba fastjson - - - - - src/main/resources - true - - - + + org.springframework.boot + spring-boot-starter-data-jpa + + \ No newline at end of file diff --git a/austin-support/src/main/java/com/java3y/austin/dao/MessageTemplateDao.java b/austin-support/src/main/java/com/java3y/austin/dao/MessageTemplateDao.java new file mode 100644 index 0000000..3553e97 --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/dao/MessageTemplateDao.java @@ -0,0 +1,8 @@ +package com.java3y.austin.dao; + +import com.java3y.austin.domain.MessageTemplate; +import org.springframework.data.repository.CrudRepository; + +public interface MessageTemplateDao extends CrudRepository { + +} diff --git a/austin-support/src/main/java/com/java3y/austin/dao/SmsRecordDao.java b/austin-support/src/main/java/com/java3y/austin/dao/SmsRecordDao.java new file mode 100644 index 0000000..516782b --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/dao/SmsRecordDao.java @@ -0,0 +1,9 @@ +package com.java3y.austin.dao; + +import com.java3y.austin.domain.SmsRecord; +import org.springframework.data.repository.CrudRepository; + +public interface SmsRecordDao extends CrudRepository { + + +} diff --git a/austin-support/src/main/java/com/java3y/austin/domain/MessageTemplate.java b/austin-support/src/main/java/com/java3y/austin/domain/MessageTemplate.java new file mode 100644 index 0000000..57408dc --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/domain/MessageTemplate.java @@ -0,0 +1,141 @@ +package com.java3y.austin.domain; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Entity +/** + * @autor 3y + * 消息模板DO + */ +public class MessageTemplate { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + /** + * 模板标题 + */ + private String name; + + /** + * 审核状态 + */ + private Integer auditStatus; + + /** + * 工单ID(审核模板走工单) + */ + private String flowId; + + /** + * 消息状态 + */ + private Integer msgStatus; + + /** + * 发送的Id类型 + */ + private Integer idType; + + /** + * 发送渠道 + */ + private Integer sendChannel; + + /** + * 模板类型 + */ + private Integer templateType; + + /** + * 消息类型 + */ + private Integer msgType; + + /** + * 推送消息的时间 + * 0:立即发送 + * else:crontab 表达式 + */ + private String expectPushTime; + + /** + * 消息内容 {$var} 为占位符 + */ + private String msgContent; + + /** + * 发送账号(邮件下可有多个发送账号、短信可有多个发送账号..) + */ + private Integer sendAccount; + + /** + * 创建者 + */ + private String creator; + + /** + * 修改者 + */ + private String updator; + + /** + * 审核者 + */ + private String auditor; + + /** + * 业务方团队 + */ + private String team; + + /** + * 业务方 + */ + private String proposer; + + /** + * 是否删除 + * 0:已删除 + * 1:删除 + */ + private Integer isDeleted; + + /** + * 创建时间 单位 s + */ + private Integer created; + + /** + * 更新时间 单位s + */ + private Integer updated; + + /** + * 消息去重时间 单位小时 + */ + private Integer deduplicationTime; + + /** + * 是否夜间屏蔽 + * 0:不屏蔽 + * 1:屏蔽 + */ + private Integer isNightShield; + + +} diff --git a/austin-support/src/main/java/com/java3y/austin/domain/SmsRecord.java b/austin-support/src/main/java/com/java3y/austin/domain/SmsRecord.java new file mode 100644 index 0000000..ad66edb --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/domain/SmsRecord.java @@ -0,0 +1,81 @@ +package com.java3y.austin.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Entity +/** + * 短信(回执和发送记录) + */ +public class SmsRecord { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + /** + * 消息模板Id + */ + private Long messageTemplateId; + + /** + * 手机号 + */ + private Long phone; + + /** + * 渠道商Id + */ + private Integer supplierId; + + /** + * 渠道商名字 + */ + private String supplierName; + + /** + * 批次号Id + */ + private String seriesId; + + /** + * 计费条数 + */ + private Integer chargingNum; + + /** + * 回执信息 + */ + private String reportContent; + + /** + * 短信状态 + */ + private Integer status; + + /** + * 发送日期 + */ + private Integer sendDate; + + /** + * 创建时间 + */ + private Integer created; + + /** + * 更新时间 + */ + private Integer updated; +} diff --git a/austin-web/src/main/java/com/java3y/austin/AustinApplication.java b/austin-web/src/main/java/com/java3y/austin/AustinApplication.java index 5f5f217..2fd6b32 100644 --- a/austin-web/src/main/java/com/java3y/austin/AustinApplication.java +++ b/austin-web/src/main/java/com/java3y/austin/AustinApplication.java @@ -1,5 +1,9 @@ package com.java3y.austin; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.java3y.austin.dao.MessageTemplateDao; +import com.java3y.austin.domain.MessageTemplate; import com.java3y.austin.pojo.SmsParam; import com.java3y.austin.script.TencentSmsScript; import org.springframework.beans.factory.annotation.Autowired; @@ -13,32 +17,8 @@ import java.util.HashSet; @SpringBootApplication -@RestController public class AustinApplication { - - @Autowired - private TencentSmsScript tencentSmsScript; public static void main(String[] args) { SpringApplication.run(AustinApplication.class, args); } - - /** - * @param phone 手机号 - * @return - */ - @GetMapping("/sendSms") - public String sendSms(String phone,String content) { - - /** - * 这里的content指的是模板占位符的参数值 - */ - SmsParam smsParam = SmsParam.builder() - .phones(new HashSet<>(Arrays.asList(phone))) - .content(content) - .build(); - - return tencentSmsScript.send(smsParam); - - } - } diff --git a/austin-web/src/main/java/com/java3y/austin/controller/MessageTemplateController.java b/austin-web/src/main/java/com/java3y/austin/controller/MessageTemplateController.java new file mode 100644 index 0000000..aeb8790 --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/controller/MessageTemplateController.java @@ -0,0 +1,69 @@ +package com.java3y.austin.controller; + +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.java3y.austin.dao.MessageTemplateDao; +import com.java3y.austin.domain.MessageTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + + + +/** + * + */ +@RestController +public class MessageTemplateController { + + @Autowired + private MessageTemplateDao messageTemplateDao; + + /** + * test insert + */ + @GetMapping("/insert") + public String insert() { + + MessageTemplate messageTemplate = MessageTemplate.builder() + .name("test短信") + .auditStatus(10) + .flowId("yyyy") + .msgStatus(10) + .idType(10) + .sendChannel(10) + .templateType(10) + .msgType(10) + .expectPushTime("0") + .msgContent("3333333m") + .sendAccount(66) + .creator("yyyyc") + .updator("yyyyu") + .team("yyyt") + .proposer("yyyy22") + .auditor("yyyyyyz") + .isDeleted(0) + .created(Math.toIntExact(DateUtil.currentSeconds())) + .updated(Math.toIntExact(DateUtil.currentSeconds())) + .deduplicationTime(1) + .isNightShield(0) + .build(); + + MessageTemplate info = messageTemplateDao.save(messageTemplate); + + return JSON.toJSONString(info); + + } + + /** + * test query + */ + @GetMapping("/query") + public String query() { + Iterable all = messageTemplateDao.findAll(); + for (MessageTemplate messageTemplate : all) { + return JSON.toJSONString(messageTemplate); + } + return null; + } +} diff --git a/austin-web/src/main/java/com/java3y/austin/controller/SendController.java b/austin-web/src/main/java/com/java3y/austin/controller/SendController.java new file mode 100644 index 0000000..88a1791 --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/controller/SendController.java @@ -0,0 +1,38 @@ +package com.java3y.austin.controller; + +import com.alibaba.fastjson.JSON; +import com.java3y.austin.handler.SmsHandler; +import com.java3y.austin.pojo.SmsParam; +import com.java3y.austin.pojo.TaskInfo; +import com.java3y.austin.script.TencentSmsScript; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.HashSet; + +@RestController +public class SendController { + + + @Autowired + private SmsHandler smsHandler; + + /** + * 测试发送短信 + * @param phone 手机号 + * @return + */ + @GetMapping("/sendSms") + public boolean sendSms(String phone,String content,Long messageTemplateId ) { + + TaskInfo taskInfo = TaskInfo.builder().receiver(new HashSet<>(Arrays.asList(phone))) + .content(content).messageTemplateId(messageTemplateId).build(); + + return smsHandler.doHandler(taskInfo); + + + } + +} diff --git a/austin-web/src/main/java/com/java3y/austin/controller/SmsRecordController.java b/austin-web/src/main/java/com/java3y/austin/controller/SmsRecordController.java new file mode 100644 index 0000000..513331a --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/controller/SmsRecordController.java @@ -0,0 +1,32 @@ +package com.java3y.austin.controller; + +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.java3y.austin.dao.SmsRecordDao; +import com.java3y.austin.domain.MessageTemplate; +import com.java3y.austin.domain.SmsRecord; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; + +public class SmsRecordController { + + @Autowired + private SmsRecordDao smsRecordDao; + + /** + * test insert + */ + @GetMapping("/insert") + public String insert(Integer phone) { + return null; + } + + /** + * test query + */ + @GetMapping("/query") + public String query() { + + return null; + } +} diff --git a/austin-web/src/main/resources/application.yml b/austin-web/src/main/resources/application.yml index c831477..d05fae7 100644 --- a/austin-web/src/main/resources/application.yml +++ b/austin-web/src/main/resources/application.yml @@ -1,18 +1,29 @@ -# HTTP 连接配置 TODO +# HTTP 连接配置 T0D0 ok: - http: - connect-timeout: 30 - keep-alive-duration: 300 - max-idle-connections: 200 - read-timeout: 30 - write-timeout: 30 + http: + connect-timeout: 30 + keep-alive-duration: 300 + max-idle-connections: 200 + read-timeout: 30 + write-timeout: 30 # 腾讯云账号相关的信息配置 TODO tencent: - sms: - account: - secret-id: - secret-key: - sign_name: - sms-sdk-app-id: - template-id: + sms: + account: + secret-id: + secret-key: + sign_name: + sms-sdk-app-id: + template-id: + + +# 数据库相关的信息配置 TODO +spring: + datasource: + url: + username: + password: + driver-class-name: + +# tomcat / HikariPool(数据库连接池 配置) TODO \ No newline at end of file