|
|
@@ -4,14 +4,19 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
+import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
+import com.cyksj.common.util.IoKit;
|
|
|
+import com.cyksj.common.util.J11HttpC;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.config.corp.WeChatCorpFactory;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.corp.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.request.corp.Attachments;
|
|
|
import com.cyksj.model.request.corp.CorpXmlMessage;
|
|
|
import com.cyksj.model.request.corp.CorpXmlOutMessage;
|
|
|
import com.cyksj.model.response.CorpExternalContactInfo;
|
|
|
@@ -28,6 +33,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.net.http.HttpRequest;
|
|
|
+import java.net.http.HttpResponse;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
@@ -67,6 +74,12 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
|
|
|
private final MarketFrontService marketFrontService;
|
|
|
|
|
|
+ private final CorpNewUserWelcomeMsgMapper corpNewUserWelcomeMsgMapper;
|
|
|
+
|
|
|
+ private final GlobalThreadPoolTaskExecutor THREAD_POOL;
|
|
|
+
|
|
|
+ private static final String DEFAULT_MSG = "您好,欢迎加入银河录像局";
|
|
|
+
|
|
|
/**
|
|
|
* 客户添加成员
|
|
|
*/
|
|
|
@@ -127,7 +140,8 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
followedUsers.stream()
|
|
|
.filter((followedUser) -> !relationFollowUserIds.contains(followedUser.getUserId()))
|
|
|
.forEach(followedUser -> updateUserFollowRelation(followedUser, corpUserInfo.getExternalUserId(), wxCorpApp.getId()));
|
|
|
-
|
|
|
+ //发送自定义欢迎语
|
|
|
+ sendDesignWelcomeMsg(corpId, welcomeCode, userId, corpUserInfo.getCorpName());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -318,4 +332,47 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ public void sendDesignWelcomeMsg(String corpId, String welcomeCode, String followId, String corpUserName) {
|
|
|
+ //新用户欢迎语
|
|
|
+ if (StrUtil.isNotEmpty(welcomeCode)) {
|
|
|
+ THREAD_POOL.execute(() -> {
|
|
|
+ SysConfig corpConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.CORP_POPULARIZE_CUSTOMER)
|
|
|
+ .eq(SysConfig::getSysValue, followId)
|
|
|
+ .last("limit 1"));
|
|
|
+ Optional.ofNullable(corpConfig).ifPresent(config -> {
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ CorpNewUserWelcomeMsg corpNewUserWelcomeMsg = Optional.ofNullable(corpNewUserWelcomeMsgMapper.selectOne(Wrappers.lambdaQuery(CorpNewUserWelcomeMsg.class).eq(CorpNewUserWelcomeMsg::getIsDefault, true).eq(CorpNewUserWelcomeMsg::getCorpId, corpId).eq(CorpNewUserWelcomeMsg::getFollowId, followId).last("limit 1"))).orElseGet(() -> new CorpNewUserWelcomeMsg(DEFAULT_MSG));
|
|
|
+ HashMap<String, Object> text = new HashMap<>(1);
|
|
|
+ text.put("content", corpNewUserWelcomeMsg.getText());
|
|
|
+ params.putOpt("welcome_code", welcomeCode);
|
|
|
+ params.putOpt("text", text);
|
|
|
+ if (corpNewUserWelcomeMsg.getIsLink()) {
|
|
|
+ List<Attachments> attachments = new ArrayList<>();
|
|
|
+ Attachments link = new Attachments("link", new Attachments.Link(corpNewUserWelcomeMsg.getLinkTitle(), corpNewUserWelcomeMsg.getLinkPicUrl(), corpNewUserWelcomeMsg.getLinkDesc(), corpNewUserWelcomeMsg.getLinkUrl()));
|
|
|
+ attachments.add(link);
|
|
|
+ params.putOpt("attachments", attachments);
|
|
|
+ }
|
|
|
+ HttpResponse<byte[]> res = null;
|
|
|
+ try {
|
|
|
+ res = J11HttpC.custom()
|
|
|
+ .ofPost()
|
|
|
+ .url(String.format("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token=%s", wxCorpOps.getAccessToken(corpId)))
|
|
|
+ .body(HttpRequest.BodyPublishers.ofString(params.toString(), IoKit.Charsets.UTF_8.getCharset()))
|
|
|
+ .headers(J11HttpC.ReqType.raw_json)
|
|
|
+ .send(HttpResponse.BodyHandlers.ofByteArray());
|
|
|
+ JSONObject jsonObject = Jsons.parseObject(res.body(), JSONObject.class);
|
|
|
+ if (jsonObject.getInt("errcode") != 0) {
|
|
|
+ log.info("{}成员,发送欢迎语至客户{}失败,msg:{}", followId, corpUserName, jsonObject.get("errmsg"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ log.info("{}成员,发送欢迎语至客户{}成功", followId, corpUserName);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("发送欢迎语过程异常,{}", e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|