|
@@ -3,6 +3,7 @@ package com.management.platform.controller;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
import com.management.platform.constant.Constant;
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.entity.vo.UserVO;
|
|
@@ -77,8 +78,7 @@ public class WeiXinCorpController {
|
|
|
|
|
|
public static final String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET";
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ public static final String GET_REGISTER_CODE = "https://qyapi.weixin.qq.com/cgi-bin/service/get_register_code?provider_access_token=PROVIDER_ACCESS_TOKEN";
|
|
|
@Value("${suitId}")
|
|
|
private String suitId;
|
|
|
@Value("${suitSecret}")
|
|
@@ -181,6 +181,123 @@ public class WeiXinCorpController {
|
|
|
CorpwxJobResultMapper corpwxJobResultMapper;
|
|
|
@Resource
|
|
|
private AuditWorkflowTimeSettingMapper auditWorkflowTimeSettingMapper;
|
|
|
+ @Resource
|
|
|
+ private CorpwxPreAuthCodeMapper corpwxPreAuthCodeMapper;
|
|
|
+ @Resource
|
|
|
+ private CorpwxRegisterCodeMapper corpwxRegisterCodeMapper;
|
|
|
+
|
|
|
+ @CrossOrigin
|
|
|
+ @RequestMapping("/getPreAuthCode")
|
|
|
+ public HttpRespMsg getPreAuthCode() {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ List<CorpwxPreAuthCode> corpwxPreAuthCodes = corpwxPreAuthCodeMapper.selectList(new QueryWrapper<CorpwxPreAuthCode>());
|
|
|
+ boolean shouldRefresh = false;
|
|
|
+ CorpwxPreAuthCode oldItem = null;
|
|
|
+ if (corpwxPreAuthCodes.size() == 0) {
|
|
|
+ //调接口获取
|
|
|
+ shouldRefresh = true;
|
|
|
+ } else {
|
|
|
+ oldItem = corpwxPreAuthCodes.get(0);
|
|
|
+ if (oldItem.getExpireTime().isBefore(LocalDateTime.now())) {
|
|
|
+ shouldRefresh = true;
|
|
|
+ } else {
|
|
|
+ msg.data = oldItem;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (shouldRefresh) {
|
|
|
+ try {
|
|
|
+ String url = GET_PREAUTH_CODE_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken());
|
|
|
+ String forObject = this.restTemplate.getForObject(url, String.class);
|
|
|
+ JSONObject json = JSONObject.parseObject(forObject);
|
|
|
+ log.info("返回:"+json.toJSONString());
|
|
|
+ if (json.getIntValue("errcode") == 0) {
|
|
|
+ String code = json.getString("pre_auth_code");
|
|
|
+ CorpwxPreAuthCode item = new CorpwxPreAuthCode();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ item.setCode(code);
|
|
|
+ item.setIndate(now);
|
|
|
+ LocalDateTime expireTime = now.plusSeconds(json.getInteger("expires_in"));
|
|
|
+ item.setExpireTime(expireTime);
|
|
|
+ if (oldItem != null) {
|
|
|
+ item.setId(oldItem.getId());
|
|
|
+ corpwxPreAuthCodeMapper.updateById(item);
|
|
|
+ } else {
|
|
|
+ corpwxPreAuthCodeMapper.insert(item);
|
|
|
+ }
|
|
|
+ msg.data = item;
|
|
|
+ } else {
|
|
|
+ msg.setError(json.toString());
|
|
|
+ }
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ msg.setError(exception.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @CrossOrigin
|
|
|
+ @RequestMapping("/getRegisterCode")
|
|
|
+ public HttpRespMsg getRegisterCode() {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ List<CorpwxRegisterCode> list = corpwxRegisterCodeMapper.selectList(new QueryWrapper<CorpwxRegisterCode>());
|
|
|
+ boolean shouldRefresh = false;
|
|
|
+ CorpwxRegisterCode oldItem = null;
|
|
|
+ if (list.size() == 0) {
|
|
|
+ //调接口获取
|
|
|
+ shouldRefresh = true;
|
|
|
+ } else {
|
|
|
+ oldItem = list.get(0);
|
|
|
+ if (oldItem.getExpireTime().isBefore(LocalDateTime.now())) {
|
|
|
+ shouldRefresh = true;
|
|
|
+ } else {
|
|
|
+ msg.data = oldItem;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (shouldRefresh) {
|
|
|
+ try {
|
|
|
+ String url = GET_REGISTER_CODE.replace("PROVIDER_ACCESS_TOKEN", wxCorpInfoService.getProviderAccessToken());
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
+ //注册模板 -- 推广包ID
|
|
|
+ reqParam.put("template_id", "tpl42135b6584b8e5c0");
|
|
|
+// reqParam.put("corp_name", "南京火石闪信网络科技有限公司");
|
|
|
+// reqParam.put("admin_name", "南京火石闪信网络科技有限公司");
|
|
|
+// reqParam.put("admin_mobile", "南京火石闪信网络科技有限公司");
|
|
|
+// reqParam.put("state", "南京火石闪信网络科技有限公司");
|
|
|
+ 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) {
|
|
|
+ JSONObject json = JSONObject.parseObject(responseEntity.getBody());
|
|
|
+ log.info("返回:"+json.toJSONString());
|
|
|
+ if (json.getIntValue("errcode") == 0) {
|
|
|
+ String code = json.getString("register_code");
|
|
|
+ CorpwxRegisterCode item = new CorpwxRegisterCode();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ item.setCode(code);
|
|
|
+ item.setIndate(now);
|
|
|
+ LocalDateTime expireTime = now.plusSeconds(json.getInteger("expires_in"));
|
|
|
+ item.setExpireTime(expireTime);
|
|
|
+ if (oldItem != null) {
|
|
|
+ item.setId(oldItem.getId());
|
|
|
+ corpwxRegisterCodeMapper.updateById(item);
|
|
|
+ } else {
|
|
|
+ corpwxRegisterCodeMapper.insert(item);
|
|
|
+ }
|
|
|
+ msg.data = item;
|
|
|
+ } else {
|
|
|
+ msg.setError(json.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ msg.setError(exception.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
|
|
|
//"获取企业微信jssdk初始化配置参数"
|
|
|
@RequestMapping("/getCorpWXConfig")
|
|
@@ -3123,4 +3240,19 @@ public class WeiXinCorpController {
|
|
|
System.out.println("++++++++++++++++++++++"+"版本变更失败!"+"++++++++++++++++++++++++");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/installFromWebsite")
|
|
|
+ public ModelAndView installFromWebsite(@RequestParam String auth_code, @RequestParam Integer expires_in, @RequestParam String state){
|
|
|
+ System.out.println("installFromWebsite接收到请求:auth_code="+auth_code+", expires_in="+expires_in+",state="+state);
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String url = "https://www.ttkuaiban.com";
|
|
|
+ ModelAndView view = new ModelAndView("redirect:"+url);
|
|
|
+ try {
|
|
|
+ handleCorpAuth(auth_code);
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ msg.setError(exception.getMessage());
|
|
|
+ }
|
|
|
+ return view;
|
|
|
+ }
|
|
|
}
|