|
@@ -0,0 +1,75 @@
|
|
|
+package com.example.xiaoshiweixinback.service.common;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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.example.xiaoshiweixinback.business.utils.RabbitMQUtils;
|
|
|
+import com.example.xiaoshiweixinback.entity.shortMessage.ShortMessageVO;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class NoticeService {
|
|
|
+ @Autowired
|
|
|
+ private RabbitMQUtils rabbitMQUtils;
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${SMS.regionId}")
|
|
|
+ private String regionId;
|
|
|
+
|
|
|
+ @Value("${SMS.accessKeyId}")
|
|
|
+ private String accessKeyId;
|
|
|
+
|
|
|
+ @Value("${SMS.secret}")
|
|
|
+ private String secret;
|
|
|
+ public String noticeAdminToHandle() {
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+ map.put("title", "任务通知");
|
|
|
+ String name = "";
|
|
|
+ //判断是否为内部人员
|
|
|
+
|
|
|
+
|
|
|
+ map.put("template", "mail/SyneryInside.html");
|
|
|
+ map.put("value1", "张三");
|
|
|
+ map.put("email", "2232623707@qq.com");
|
|
|
+ map.put("img", "/logo.png");
|
|
|
+ map.put("value2", "11");
|
|
|
+ rabbitMQUtils.sendEmailMessage(map);
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendShortMessage(ShortMessageVO shortMessageVO){
|
|
|
+ DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
|
|
|
+ IAcsClient client = new DefaultAcsClient(profile);
|
|
|
+ SendSmsRequest request = new SendSmsRequest();
|
|
|
+// String templateParam = "{\"code\":\"" + random + "\",\"message\":\"" + "为您的登陆验证码" + "\",\"validTime\":\"" + "5分钟" + "\"}";
|
|
|
+ String templateParam =shortMessageVO.getTemplateParam();
|
|
|
+ request.setPhoneNumbers(shortMessageVO.getPhoneNum());//接收短信的手机号码
|
|
|
+ request.setSignName(shortMessageVO.getSignName());//短信签名名称
|
|
|
+ request.setTemplateCode(shortMessageVO.getTemplateCode());//短信模板CODE
|
|
|
+ request.setTemplateParam(templateParam);//短信模板变量对应的实际值
|
|
|
+ try {
|
|
|
+ SendSmsResponse response = client.getAcsResponse(request);
|
|
|
+ System.out.println(new Gson().toJson(response));
|
|
|
+ } catch (ClientException e) {
|
|
|
+ System.out.println("ErrCode:" + e.getErrCode());
|
|
|
+ System.out.println("ErrMsg:" + e.getErrMsg());
|
|
|
+ System.out.println("RequestId:" + e.getRequestId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|