|
@@ -74,6 +74,8 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
//获取日程
|
|
|
public static final String ADD_SCHEDULE = " https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/add?access_token=ACCESS_TOKEN";
|
|
|
|
|
|
+ public static final String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET";
|
|
|
+
|
|
|
|
|
|
public static final int TEXT_CARD_MSG_BUSTRIP_WAITING_AUDIT = 0;//出差待审核
|
|
|
public static final int TEXT_CARD_MSG_BUSTRIP_AGREE = 1;//出差审核通过
|
|
@@ -250,7 +252,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
if (isDev) return;
|
|
|
log.info("发送企业微信消息===" + corpUserid);
|
|
|
System.out.println("发送企业微信消息===" + corpUserid);
|
|
|
- String accessToken = getCorpAccessToken(corpInfo);
|
|
|
+ String accessToken = getAppConcactAccessToken(corpInfo);
|
|
|
String url = URL_SEND_WXCORP_MSG.replaceAll("ACCESS_TOKEN", accessToken);
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
@@ -267,15 +269,17 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
}else {
|
|
|
jumpUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww4e237fd6abb635af&redirect_uri=http://worktime.ttkuaiban.com/api/corpWXAuth&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
|
|
|
}
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(pageRouter)) {
|
|
|
- title = "消息通知";
|
|
|
- jumpUrl = jumpUrl.replace("STATE", "0");
|
|
|
- if (msgType.equals(TEXT_CARD_MSG_REPORT_DENY)) {
|
|
|
- title = "日报驳回";
|
|
|
- } else if (msgType.equals(TEXT_CARD_MSG_REPORT_AGREE)) {
|
|
|
- title = "日报审核通过";
|
|
|
- }
|
|
|
+ jumpUrl = jumpUrl.replace("STATE", pageRouter);
|
|
|
+ if ("plan/today".equals(pageRouter)) {
|
|
|
+ //出差
|
|
|
+ title = "收到新的今日计划";
|
|
|
+ } else if ("plan/tomorrow".equals(pageRouter)) {
|
|
|
+ //费用报销
|
|
|
+ title = "收到新的明日计划";
|
|
|
+ }
|
|
|
+ else if ("plan/orderInsert".equals(pageRouter)) {
|
|
|
+ //费用报销
|
|
|
+ title = "收到新的插单计划";
|
|
|
}
|
|
|
cardJson.put("title", title);
|
|
|
cardJson.put("description", msg);
|
|
@@ -505,6 +509,30 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
return userOpenIdList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取应用的AccessToken
|
|
|
+ * @param corpInfo
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private String getAppConcactAccessToken(WxCorpInfo corpInfo) throws Exception {
|
|
|
+ String url = GET_CORP_TOKEN.replace("ID", corpInfo.getCorpid()).replace("SECRET", corpInfo.getAgentSecret());
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
|
+ HttpMethod.GET, null, String.class);
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ JSONObject json = JSONObject.parseObject(resp);
|
|
|
+ if (json.getIntValue("errcode") == 0) {
|
|
|
+ String access_token = json.getString("access_token");
|
|
|
+ System.out.println("获取到access_token=="+access_token);
|
|
|
+ corpInfo.setAccessToken(access_token);
|
|
|
+ } else {
|
|
|
+ throw new Exception(json.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return corpInfo.getAccessToken();
|
|
|
+ }
|
|
|
+
|
|
|
//获取企业AccessToken
|
|
|
private String getCorpAccessToken(WxCorpInfo corpInfo) throws Exception {
|
|
|
if (corpInfo.getExpireTime().isBefore(LocalDateTime.now())) {
|