|
@@ -3,6 +3,7 @@ package com.management.platform.service.impl;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.controller.WeiXinCorpController;
|
|
|
import com.management.platform.entity.SysConfig;
|
|
|
import com.management.platform.entity.User;
|
|
@@ -13,7 +14,6 @@ import com.management.platform.mapper.UserCorpwxTimeMapper;
|
|
|
import com.management.platform.mapper.UserMapper;
|
|
|
import com.management.platform.mapper.WxCorpInfoMapper;
|
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.util.DateTimeUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -32,8 +32,6 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import static org.mockito.ArgumentMatchers.startsWith;
|
|
|
-
|
|
|
/**
|
|
|
* <p>
|
|
|
* 服务实现类
|
|
@@ -115,6 +113,48 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void sendWXCorpTemplateMsg(WxCorpInfo corpInfo, String corpUserid, JSONObject msg) {
|
|
|
+ try {
|
|
|
+ log.info("发送企业微信模板消息==="+corpUserid);
|
|
|
+ System.out.println("发送企业微信模板消息==="+corpUserid);
|
|
|
+ String accessToken = getCorpAccessToken(corpInfo);
|
|
|
+ String url = URL_SEND_WXCORP_MSG.replaceAll("ACCESS_TOKEN", accessToken);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
+ reqParam.put("touser", corpUserid);
|
|
|
+ reqParam.put("toparty", "");
|
|
|
+ reqParam.put("totag", "");
|
|
|
+ reqParam.put("msgtype", "template_msg");
|
|
|
+ reqParam.put("agentid", corpInfo.getAgentid());
|
|
|
+ reqParam.put("template_msg",msg);
|
|
|
+
|
|
|
+ HttpEntity<String> requestEntity = new HttpEntity<String>(reqParam.toJSONString(), headers);
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
|
+ HttpMethod.POST, requestEntity, String.class);
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ log.info("发送企业微信模板消息返回结果=="+resp);
|
|
|
+ System.out.println("发送企业微信模板消息返回结果=="+resp);
|
|
|
+ JSONObject json = JSONObject.parseObject(resp);
|
|
|
+ if (json.getIntValue("errcode") == 0) {
|
|
|
+ //发送成功
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new Exception(json.toJSONString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("发送失败:"+responseEntity.getStatusCode()+", "+responseEntity.getBody());
|
|
|
+ System.err.println("发送失败:"+responseEntity.getStatusCode()+", "+responseEntity.getBody());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String downloadFile(WxCorpInfo corpInfo, String mediaId) {
|
|
|
try {
|