10 changed files with 240 additions and 49 deletions
@ -1,6 +1,6 @@ |
|||||
ALTER TABLE `tduck`.`pr_user_project_result` |
ALTER TABLE `tduck`.`pr_user_project_result` |
||||
ADD COLUMN `wx_open_id` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '微信openId' AFTER `complete_time`, |
ADD COLUMN `wx_open_id` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '微信openId' AFTER `complete_time`, |
||||
ADD COLUMN `wx_user_info` json NULL COMMENT '微信用户信息' AFTER `wx_open_id`, |
ADD COLUMN `wx_user_info` json NULL COMMENT '微信用户信息' AFTER `wx_open_id`; |
||||
|
|
||||
ALTER TABLE `tduck`.`pr_user_project_setting` |
ALTER TABLE `tduck`.`pr_user_project_setting` |
||||
ADD COLUMN `is_wx_write_once` tinyint(1) NULL AFTER `is_wx_write`; |
ADD COLUMN `is_wx_write_once` tinyint(1) NULL AFTER `is_wx_write`; |
@ -0,0 +1,77 @@ |
|||||
|
package com.tduck.cloud.common.sms; |
||||
|
|
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.aliyun.dysmsapi20170525.Client; |
||||
|
import com.aliyun.dysmsapi20170525.models.SendSmsRequest; |
||||
|
import com.aliyun.dysmsapi20170525.models.SendSmsResponse; |
||||
|
import com.aliyun.teaopenapi.models.Config; |
||||
|
import com.google.common.collect.ImmutableMap; |
||||
|
import com.tduck.cloud.common.util.JsonUtils; |
||||
|
import lombok.Data; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @author : smalljop |
||||
|
* @description : 腾讯云短信 |
||||
|
* @create : 2020-12-15 10:33 |
||||
|
**/ |
||||
|
@Data |
||||
|
@Slf4j |
||||
|
public class AliyunSmsServiceImpl extends SmsService { |
||||
|
|
||||
|
|
||||
|
private Client client; |
||||
|
|
||||
|
public AliyunSmsServiceImpl(SmsPlatformProperties properties) { |
||||
|
Config config = new Config() |
||||
|
// 您的AccessKey ID
|
||||
|
.setAccessKeyId(properties.getSecretId()) |
||||
|
// 您的AccessKey Secret
|
||||
|
.setAccessKeySecret(properties.getSecretKey()); |
||||
|
// 访问的域名
|
||||
|
config.endpoint = "dysmsapi.aliyuncs.com"; |
||||
|
try { |
||||
|
client = new Client(config); |
||||
|
this.properties = properties; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public boolean sendSms(String phoneNumber, String templateId, String... templateParams) { |
||||
|
Map<String, Object> params = ImmutableMap.of("code", templateParams); |
||||
|
// 1.发送短信
|
||||
|
SendSmsRequest sendReq = new SendSmsRequest() |
||||
|
.setPhoneNumbers(phoneNumber) |
||||
|
.setSignName(properties.getSign()) |
||||
|
.setTemplateCode(templateId) |
||||
|
.setTemplateParam(JsonUtils.objToJson(params)); |
||||
|
SendSmsResponse sendResp = null; |
||||
|
try { |
||||
|
sendResp = client.sendSms(sendReq); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
String code = sendResp.body.code; |
||||
|
if (!StrUtil.equals(code, "OK")) { |
||||
|
return false; |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean sendValidateSms(String phoneNumber, String... templateParams) { |
||||
|
this.sendSms(phoneNumber, properties.getValidateCodeTemplateId(), templateParams); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean sendRetrievePwdValidateSms(String phoneNumber, String... templateParams) { |
||||
|
this.sendSms(phoneNumber, properties.getValidateCodeTemplateId(), templateParams); |
||||
|
return false; |
||||
|
} |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
package com.tduck.cloud.common.sms; |
||||
|
|
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
|
||||
|
/** |
||||
|
* @author : wangqing |
||||
|
* @description : 短信平台配置 |
||||
|
* @create : 2021/07/19 10:59 |
||||
|
**/ |
||||
|
@Configuration |
||||
|
@RequiredArgsConstructor |
||||
|
public class SmsPlatformConfig { |
||||
|
|
||||
|
private final SmsPlatformProperties properties; |
||||
|
|
||||
|
|
||||
|
@Bean |
||||
|
public SmsService xssFilterRegistration() { |
||||
|
SmsService smsService = null; |
||||
|
switch (properties.getType()) { |
||||
|
case ALIYUN: |
||||
|
smsService = new AliyunSmsServiceImpl(properties); |
||||
|
break; |
||||
|
case TENCENT_CLOUD: |
||||
|
smsService = new TencentSmsServiceImpl(properties); |
||||
|
break; |
||||
|
} |
||||
|
return smsService; |
||||
|
} |
||||
|
} |
@ -0,0 +1,47 @@ |
|||||
|
package com.tduck.cloud.common.sms; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
|
||||
|
/** |
||||
|
* 短信配置类 |
||||
|
* |
||||
|
* @author smalljop |
||||
|
*/ |
||||
|
@Data |
||||
|
@Configuration |
||||
|
@ConfigurationProperties(prefix = "platform.sms") |
||||
|
public class SmsPlatformProperties { |
||||
|
|
||||
|
/** |
||||
|
* secretId |
||||
|
*/ |
||||
|
private String secretId; |
||||
|
|
||||
|
|
||||
|
private SmsTypeEnum type; |
||||
|
/** |
||||
|
* 秘钥 |
||||
|
*/ |
||||
|
private String secretKey; |
||||
|
/** |
||||
|
* appId 腾讯云使用 |
||||
|
*/ |
||||
|
private String appId; |
||||
|
/** |
||||
|
* 短信签名 如【tduck】 需要去短信平台申请 |
||||
|
*/ |
||||
|
private String sign; |
||||
|
/** |
||||
|
* 验证码模板Id |
||||
|
*/ |
||||
|
private String validateCodeTemplateId; |
||||
|
/** |
||||
|
* 找回密码验证码 |
||||
|
*/ |
||||
|
private String retrievePwdValidateCodeTemplateId; |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
package com.tduck.cloud.common.sms; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
|
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
|
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
/** |
||||
|
* @description: Oss类型 |
||||
|
* @author: smalljop |
||||
|
* @create: 2020-02-18 23:06 |
||||
|
**/ |
||||
|
@Getter |
||||
|
public enum SmsTypeEnum { |
||||
|
/** |
||||
|
* 阿里云 |
||||
|
*/ |
||||
|
ALIYUN(1), |
||||
|
|
||||
|
/** |
||||
|
* 腾讯云 |
||||
|
*/ |
||||
|
TENCENT_CLOUD(2); |
||||
|
|
||||
|
|
||||
|
@EnumValue |
||||
|
@JsonValue |
||||
|
public final int value; |
||||
|
|
||||
|
@JsonCreator |
||||
|
SmsTypeEnum(int value) { |
||||
|
this.value = value; |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue