测试企微通知

This commit is contained in:
shuo.wang
2025-02-11 16:31:50 +08:00
parent 8b485f1840
commit ca23967be2
6 changed files with 160 additions and 13 deletions

View File

@@ -192,4 +192,7 @@ public class CommonConstants {
public static final String ONLINE_ENV = "online";
public static final String AMOUNT_KEY = "amount:{0}:{1}";
public static final String WX_SELF_AUTH_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
}

View File

@@ -0,0 +1,89 @@
package com.cool.store.enums;
import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils;
import com.cool.store.constants.CommonConstants;
import lombok.extern.slf4j.Slf4j;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.StringJoiner;
/**
* @Author: WangShuo
* @Date: 2025/02/11/16:06
* @Version 1.0
* @注释:
*/
@Slf4j
public enum QWMessageEnum {
MESSAGE_1("common","您有一个待办任务,请尽快处理。", ""),
;
private String target;
private String title;
private String content;
QWMessageEnum(String target,String title, String content) {
this.target = target;
this.title = title;
this.content = content;
}
public String getTitle() {
return title;
}
public String getTarget() {
return target;
}
public String getContent() {
return content;
}
public String getContent(Map<String, String> paramMap) {
String result = this.content;
for (String key : paramMap.keySet()) {
result = result.replace("${" + key + "}", paramMap.get(key));
}
return result;
}
public String getQWMessageUrl(String qywxUrl2, String corpId, Map<String, String> paramMap) {
if (StringUtils.isAnyBlank(qywxUrl2, corpId) ) {
return "";
}
String messageUrl = null;
try {
String noticeUrl = String.format(qywxUrl2, corpId, "qw_private_zx",this.target);
String finalUrl = buildUrlWithParams(noticeUrl, paramMap);
log.info("finalUrl:{}", finalUrl);
messageUrl = URLEncoder.encode(finalUrl, "UTF-8");
messageUrl = String.format(CommonConstants.WX_SELF_AUTH_URL, corpId, messageUrl);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return messageUrl;
}
/**
* 拼接参数
* @param url
* @param paramMap
* @return
*/
public static String buildUrlWithParams(String url, Map<String, String> paramMap) {
// 检查 URL 是否已经包含参数
StringJoiner urlWithParams = new StringJoiner("&", url.contains("?") ? "&" : "?", "");
// 遍历 Map拼接参数
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
urlWithParams.add(entry.getKey() + "=" + entry.getValue());
}
// 返回拼接后的 URL
return url + urlWithParams.toString();
}
}

View File

@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dysmsapi20170525.models.*;
import com.aliyun.sdk.service.dysmsapi20170525.*;
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
import com.cool.store.dao.EnterpriseUserDAO;
import com.cool.store.dto.message.SendMessageDTO;
@@ -13,7 +12,6 @@ import com.cool.store.mq.producer.SimpleMessageService;
import com.cool.store.request.AuditResultRequest;
import com.cool.store.utils.UUIDUtils;
import com.cool.store.utils.poi.constant.Constants;
import com.google.gson.Gson;
import darabonba.core.client.ClientOverrideConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -24,14 +22,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
/**
@@ -64,6 +57,10 @@ public class CommonService {
private String smsAccessKeySecret;
@Value("${aliyun.sms.signName}")
private String signName;
@Value("${qywx.task.notice.url1}")
private String qywxUrl1;
@Value("${qywx.task.notice.url2}")
private String qywxUrl2;
public LineFlowService getLineFlowService(Integer workflowSubStage){
WorkflowSubStageEnum workflowSubStageEnum = WorkflowSubStageEnum.getWorkflowSubStageEnum(workflowSubStage);
@@ -181,4 +178,56 @@ public class CommonService {
}
}
/**
* 消息通知
* @param userIds 消息接收人列表
* @param message 消息内容
* @param requestMap 参数
*/
public void sendQWMessage(List<String> userIds, QWMessageEnum message, Map<String, String> requestMap){
log.info("message:{}, request:{}, userIds:{}", message.getTitle(), JSONObject.toJSONString(requestMap), JSONObject.toJSONString(userIds));
if(CollectionUtils.isEmpty(userIds)){
return;
}
userIds = userIds.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
if(CollectionUtils.isEmpty(userIds)){
return;
}
try {
String pcMessageUrl = message.getQWMessageUrl(qywxUrl1, dingCorpId, requestMap);
String messageUrl = message.getQWMessageUrl(qywxUrl2, dingCorpId, requestMap);
log.info("pcMessageUrl:{}", pcMessageUrl);
log.info("messageUrl:{}", messageUrl);
if(StringUtils.isBlank(messageUrl)){
log.info("获取通知url为空");
return;
}
if (StringUtils.isEmpty(requestMap.get("eid"))) {
requestMap.put("eid", enterpriseId);
}
SendMessageDTO messageDTO = new SendMessageDTO();
messageDTO.setCorpId(dingCorpId);
messageDTO.setUserIds(String.join(Constants.COMMA, userIds));
messageDTO.setOutBusinessId(UUIDUtils.get32UUID());
messageDTO.setAppType("qw_private_zx");
JSONObject map = new JSONObject();
map.put("pcMessageUrl", pcMessageUrl);
map.put("message_url", messageUrl);
log.info("【sendMessage】pcMessageUrl:【{}】message_url【{}】",pcMessageUrl,messageUrl);
JSONObject headJson = new JSONObject();
headJson.put("bgcolor", "FFBBBBBB");
map.put("head", headJson);
JSONObject body = new JSONObject();
body.put("title", message.getTitle());
body.put("content", message.getContent(requestMap));
map.put("body",body);
messageDTO.setOaJson(map);
simpleMessageService.send(JSONObject.toJSONString(messageDTO), RocketMqTagEnum.STORE_DING_QUEUE);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -104,10 +104,10 @@ public class JoinIntentionServiceImpl extends LineFlowService implements JoinInt
// requestMap.put("lineId", String.valueOf(lineInfoParam.getId()));
// HyOpenAreaInfoDO openAreaInfoDO = openAreaInfoMapper.selectById(lineInfoParam.getWantShopAreaId());
// requestMap.put("regionName", openAreaInfoDO.getAreaName());
//工作通知后面对接企业微信
// commonService.sendMessage(Collections.singletonList(lineInfoParam.getInvestmentManager()),
// MessageEnum.MESSAGE_29,
// requestMap);
commonService.sendQWMessage(Collections.singletonList(lineInfoParam.getInvestmentManager()),
QWMessageEnum.MESSAGE_1,
null);
return Boolean.TRUE;
}

View File

@@ -79,3 +79,6 @@ aliyun.sms.signName=酷店掌
mybatis.configuration.variables.enterpriseId=214ac5a3a517472a87268e02a2e6410a
enterprise.dingCorpId=wpayJeDAAAklx_q1jGhyGUd4yEh8vV_g
qywx.task.notice.url1=https://t3store-h5.coolstore.cn/notice?corpId=%s&appType=%s&target=%s
qywx.task.notice.url2=https://t3store-h5.coolstore.cn/?corpId=%s&appType=%s#/notice?target=%s

View File

@@ -79,3 +79,6 @@ aliyun.sms.signName=酷店掌
mybatis.configuration.variables.enterpriseId=5558ce7a3aa84e3590392fcaa8697ffb
enterprise.dingCorpId=wpayJeDAAAhGIFgUJpJN-zg39JuNbYhg
qywx.task.notice.url1=https://t3store-h5.coolstore.cn/notice?corpId=%s&appType=%s&target=%s
qywx.task.notice.url2=https://t3store-h5.coolstore.cn/?corpId=%s&appType=%s#/notice?target=%s