| | |
| | | package com.smartor.common; |
| | | |
| | | import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.PatWildcardMapper; |
| | | import com.smartor.service.DingTalkService; |
| | | import com.smartor.service.ISmsParamService; |
| | | import com.smartor.service.WeChatService; |
| | | import com.smartor.service.impl.BaseSmsaccountServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.lang.reflect.Field; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | /** |
| | | * 发送服务工具类 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class SendService { |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private WeChatService weChatService; |
| | | |
| | | public Boolean sendMsg(SendMagParam sendMagParam) { |
| | | @Autowired |
| | | ISmsParamService iSmsParamService; |
| | | |
| | | @Value("${xhsmsPath}") |
| | | private String xhsmsPath; |
| | | // 帐号 |
| | | @Value("${xhsmsAccount}") |
| | | private String xhsmsAccount; |
| | | // 接口密码 |
| | | @Value("${xhsmsPwd}") |
| | | private String xhsmsPwd; |
| | | // 虚拟接入码 |
| | | @Value("${xhsmsjrm}") |
| | | private String xhsmsjrm; |
| | | |
| | | public Boolean sendMsg(SendMagParam sendMagParam) throws UnsupportedEncodingException, JsonProcessingException { |
| | | // 1,多媒体 2,纸质 3,电话 4,短信 5.微信公众号 6.微信小程序 7.支付宝 8.智能小程序 9.钉钉 |
| | | switch (sendMagParam.getType()) { |
| | | case ("1"): |
| | |
| | | case ("3"): |
| | | |
| | | case ("4"): |
| | | BaseSmsRequest baseSmsRequest = new BaseSmsRequest(); |
| | | baseSmsRequest.setPhoneNumber(sendMagParam.getPhone()); |
| | | baseSmsRequest.setTemplateCode("SMS_461860582"); |
| | | SendSmsResponseBody sendSmsResponseBody = baseSmsaccountService.sendMsg(baseSmsRequest); |
| | | if (sendSmsResponseBody.getCode().equals("OK")) { |
| | | return true; |
| | | //短信 |
| | | Map<String, String> map2 = new HashMap<>(); |
| | | map2.put("action", "send"); |
| | | map2.put("account", xhsmsAccount); |
| | | map2.put("password", xhsmsPwd); |
| | | map2.put("mobile", sendMagParam.getPhone()); |
| | | map2.put("content", sendMagParam.getContent()); |
| | | map2.put("extno", xhsmsjrm); |
| | | map2.put("rt", "json"); |
| | | StringBuilder encodedParams = new StringBuilder(); |
| | | |
| | | for (Map.Entry<String, String> entry : map2.entrySet()) { |
| | | if (encodedParams.length() > 0) { |
| | | encodedParams.append("&"); |
| | | } |
| | | // 对键和值进行URL编码 |
| | | String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8"); |
| | | String encodedValue = URLEncoder.encode(entry.getValue(), "UTF-8"); |
| | | encodedParams.append(encodedKey).append("=").append(encodedValue); |
| | | } |
| | | |
| | | String result = HttpUtils.sendPost(xhsmsPath, encodedParams.toString()); |
| | | ObjectMapper objectMapper2 = new ObjectMapper(); |
| | | Map<String, Object> map3 = objectMapper2.readValue(result, new TypeReference<Map<String, Object>>() { |
| | | }); |
| | | if (ObjectUtils.isNotEmpty(map3)) { |
| | | String status = map3.get("status").toString(); |
| | | if (status.equals("0")) { |
| | | return true; |
| | | } |
| | | } |
| | | log.error("短信发送失败map:{}, 返回的信息为:{}", map2, result); |
| | | return false; |
| | | case ("5"): |
| | | //公众号 |
| | | // String params = "service=smarthos.yygh.ApiService.push&idcard=" + sendMagParam.getIdcard() + "&url=" + sendMagParam.getUrl() + "&keyword1=null&keyword2=null&keyword3=null&keyword4=null"; |
| | | // String result = HttpUtils.sendPost("/api", params); |
| | | // JSONObject jsonObject = JSONObject.parseObject(result); |
| | | // String code = (String) jsonObject.get("code"); |
| | | // if (!code.equals(0)) { |
| | | // log.error("微信公众号消息发送失败了:{}", sendMagParam); |
| | | // return false; |
| | | // } |
| | | // return true; |
| | | |
| | | WeChatSendVo weChatSendVo = new WeChatSendVo(); |
| | | weChatSendVo.setUrl(sendMagParam.getUrl()); |
| | | weChatSendVo.setTemplateId(sendMagParam.getTmpCode()); |
| | | ObjectMapper objectMapper=new ObjectMapper(); |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map map = null; |
| | | try { |
| | | map = objectMapper.readValue(sendMagParam.getContent(), Map.class); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | weChatSendVo.setContent(map); |
| | | weChatSendVo.setOpenid(sendMagParam.getOpenid()); |
| | | Boolean aBoolean1 = weChatService.sendMessageToFollowers(weChatSendVo); |
| | | return aBoolean1; |
| | | case ("6"): |