维修人员的接单数量和满意度

master
薛宏祥 1 year ago
parent 49cb10bd8e
commit 1b2462a55e
  1. 39
      src/main/java/org/springblade/modules/business/sms/AliYunSmsConfig.java
  2. 72
      src/main/java/org/springblade/modules/business/sms/AliYunSmsManager.java
  3. 27
      src/main/java/org/springblade/modules/business/sms/SmsConfig.java
  4. 80
      src/main/java/org/springblade/modules/business/sms/SmsService.java
  5. 2
      src/main/resources/application-dev.yml
  6. 4
      src/main/resources/application.yml

@ -1,39 +0,0 @@
package org.springblade.modules.business.sms;
import com.aliyun.teaopenapi.models.*;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author xueyaoxuan
*/
@Data
@Component
@ConfigurationProperties(prefix = "sms.aliyun")
public class AliYunSmsConfig {
private String accessKeyId;
private String accessKeySecret;
private String signName;
private boolean isPushSms;
/**
* 使用AK&SK初始化账号Client
*
* @return Client
* @throws Exception
*/
public com.aliyun.dysmsapi20170525.Client createClient() throws Exception {
Config config = new Config()
// AccessKey ID
.setAccessKeyId(this.getAccessKeyId())
// AccessKey Secret
.setAccessKeySecret(this.getAccessKeySecret());
// 访问的域名
config.endpoint = "dysmsapi.aliyuncs.com";
return new com.aliyun.dysmsapi20170525.Client(config);
}
}

@ -1,72 +0,0 @@
package org.springblade.modules.business.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 lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Component
public class AliYunSmsManager {
@Autowired
private AliYunSmsConfig aliYunSmsConfig;
public String sendSms(List<String> mobiles, String message, String code) {
SendSmsResponse sendSmsResponse = null;
try{
//调用阿里云api手机号上限1000
if (mobiles.size()>1000){
throw new ServiceException("发送短信手机号上限!");
}
//检验手机号格式
mobiles.forEach(mobile->{
if (StrUtil.isAllEmpty(mobile)){
throw new ServiceException("手机号格式错误!");
}
});
sendSmsResponse = sendALiYunSms(mobiles.stream().collect(Collectors.joining(",")),
message, code);
//
if (200 == sendSmsResponse.getStatusCode()) {
// 发送短信成功,返回短信码进行redis存储
return message;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 发送阿里云短信
*
* @param mobiles 手机号列表
* @param message json格式的模板参数
* @param code 阿里云短信模板code
* @return
* @throws Exception
*/
private SendSmsResponse sendALiYunSms(String mobiles, String message, String code) throws Exception {
//初始化Client对象
Client client = aliYunSmsConfig.createClient();
//构建请求参数
SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setPhoneNumbers(mobiles)
.setSignName(aliYunSmsConfig.getSignName())
.setTemplateCode(code)
.setTemplateParam(message);
//发送短信
return client.sendSms(sendSmsRequest);
}
}

@ -0,0 +1,27 @@
package org.springblade.modules.business.sms;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SmsConfig {
@Value("${sms.access-key}")
private String ACCESS_KEY_ID;
@Value("${sms.secret-key}")
private String ACCESS_KEY_SECRET;
@Bean
public Client ClientConfig() throws Exception {
Config config = new Config().setAccessKeyId(ACCESS_KEY_ID)
.setAccessKeySecret(ACCESS_KEY_SECRET);
return new Client(config);
}
}

@ -1,14 +1,17 @@
package org.springblade.modules.business.sms;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody;
import com.aliyun.teautil.models.RuntimeOptions;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@ -16,51 +19,48 @@ import java.util.HashMap;
import java.util.Map;
@Component
@AllArgsConstructor
public class SmsService {
//private static String ACCESS_KEY_ID = "LTAI5tHsaR8S4nFH3nhchQ3Z";
//private static String ACCESS_KEY_SECRET = "PWFmEByyD5YrjMlAyioZZqLtMGxZLu";
//private static String SIGN_NAME = "阿里云短信测试";
//private static String TEMPLATE_CODE = "SMS_476455177";
// @Value("${sms.sign-name}")
// private String SIGN_NAME;
// 阿里云的Access Key ID和Access Key Secret
@Value("${sms.access-key}")
private static String ACCESS_KEY_ID;
@Value("${sms.secret-key}")
private static String ACCESS_KEY_SECRET;
// 短信签名和模板ID
// 短信签名,替换成你在阿里云控制台设置的签名
@Value("${sms.sign-name}")
private static String SIGN_NAME;
@Value("${sms.template-id1}")
private static String TEMPLATE_CODE; // 短信模板ID,替换成你在阿里云控制台设置的模板ID
private final Client client;
public static void sendSms(String phoneNumber, String name) throws ClientException {
try {
// 设置发送短信的相关参数
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", ACCESS_KEY_ID, ACCESS_KEY_SECRET);
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
// 设置短信模板的参数
Map<String, String> templateParam = new HashMap<>();
templateParam.put("name", name); // 这里的 "code" 是短信模板中的占位符
// @Value("${sms.template-id1}")
// private String TEMPLATE_CODE;
request.putQueryParameter("PhoneNumbers", phoneNumber); //手机号
request.putQueryParameter("SignName", ""); //申请的签名名称
request.putQueryParameter("TemplateCode", ""); //模板名称
request.putQueryParameter("TemplateParam", JSONObject.toJSONString(templateParam)); //验证码
public void sendSms(String phoneNumber, String name) throws ClientException {
String templateCode = "SMS_476455177";
SendSmsRequest request = new SendSmsRequest();
// 设置短信模板的参数
Map<String, String> templateParam = new HashMap<>();
templateParam.put("name", name); // 这里的 "name" 是短信模板中的占位符
// 发送短信请求
CommonResponse response = client.getCommonResponse(request);
request.setPhoneNumbers(phoneNumber); //手机号
// request.putQueryParameter("SignName", SIGN_NAME);
request.setTemplateCode(templateCode); //模板名称
request.setTemplateParam(JSONObject.toJSONString(templateParam));
request.setSignName("实验室运维系统");
if (response.getHttpResponse().isSuccess()) {
System.out.println("短信发送成功!");
// 发送短信请求
try {
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(request, new RuntimeOptions());
SendSmsResponseBody body = sendSmsResponse.getBody();
String code = body.getCode();
String message = body.getMessage();
if (StrUtil.equals("OK", code) && StrUtil.equals("OK", message)) {
System.out.println(String.format("向 手机号:%s 用户发送短信成功!", phoneNumber));
} else {
System.out.println("短信发送失败.");
System.out.println(String.format("向 手机号:%s 用户发送短信失败!", phoneNumber));
}
} catch (ClientException e) {
e.printStackTrace();
System.out.println("短信发送异常: " + e.getMessage());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

@ -23,7 +23,7 @@ sms:
template-id: SMS_154950909
template-id1: SMS_476455177
# sms审核通过的短信签名
sign-name: 阿里云短信测试
sign-name: 实验室运维系统
# sms提供的accesskey
access-key: LTAI5tHsaR8S4nFH3nhchQ3Z
# sms提供的secretkey

@ -38,6 +38,8 @@ spring:
exclusions: '*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*'
session-stat-enable: true
session-stat-max-count: 10
profiles:
include: dev
# mybatis
mybatis-plus:
@ -269,4 +271,4 @@ blade:
- blade_user
#分库分表配置
sharding:
enabled: false
enabled: false
Loading…
Cancel
Save