From 8945b94fc922fc6598f7558b318dc7674f525b70 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期四, 17 八月 2023 10:11:35 +0800
Subject: [PATCH] bug修改

---
 ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java                 |   18 ++++----
 ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java          |   12 +++---
 ycl-platform/src/main/resources/application-dev.yml                        |    8 ++++
 ycl-platform/src/main/resources/application.yml                            |    2 +
 ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java |   76 ++++++++++++++++++++++++++++++++++++-
 5 files changed, 98 insertions(+), 18 deletions(-)

diff --git a/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java b/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
index 2110dbf..f8f7622 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
@@ -1,8 +1,14 @@
 package com.ycl.controller.dingding;
 
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
+import com.alibaba.xxpt.gateway.shared.client.http.GetClient;
+import com.alibaba.xxpt.gateway.shared.client.http.PostClient;
 import com.ycl.api.CommonResult;
 import com.ycl.bo.AdminUserDetails;
 import com.ycl.common.dingding.DingCommon;
+import com.ycl.config.DingConfig;
 import com.ycl.controller.BaseController;
 import com.ycl.entity.dingding.DingUserInfo;
 import com.ycl.service.auth.AuthService;
@@ -12,18 +18,24 @@
 import com.ycl.vo.NewAddressBookVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static com.ycl.common.constant.DingConst.GET_TIKER;
+import static com.ycl.common.constant.DingConst.GET_TOKEN;
+
 @RestController
 @RequestMapping("/ding")
 @Api(tags = "閽夐拤")
+@Slf4j
 public class DingController extends BaseController {
 
     @Autowired
@@ -46,6 +58,13 @@
     @Autowired
     private BookRemarkService bookRemarkService;
 
+    @Resource
+    private ExecutableClient executableClient;
+
+    @Resource
+    private DingConfig dingConfig;
+
+
     @ApiOperation(value = "鏍规嵁閽夐拤鎺堟潈鐮佽幏鍙杢oken")
     @GetMapping("/dingLogin")
     public CommonResult<Map> dingLogin(@RequestParam String code) {
@@ -58,6 +77,60 @@
         map.put("tokenHead", tokenHead);
         map.put("accountId", dingUser.getAccountId());
         return CommonResult.success(map);
+    }
+
+    @ApiOperation(value = "鏍规嵁閽夐拤鎺堟潈鐮佽幏鍙杍sapiToken")
+    @GetMapping("/dingTicker")
+    public CommonResult<Map> dingTicker() {
+        String accessToken = getToken();
+        String ticket = getTiker(accessToken);
+        HashMap<String, Object> map = new HashMap<>();
+
+        map.put("accessToken", accessToken);
+
+        map.put("ticket", ticket);
+        return CommonResult.success(map);
+    }
+
+    private String getToken() {
+        //璋冪敤API
+        GetClient getTokenClient = executableClient.newGetClient(GET_TOKEN);
+        //璁剧疆鍙傛暟
+        getTokenClient.addParameter("appkey", dingConfig.getAppKey());
+        getTokenClient.addParameter("appsecret", dingConfig.getAppSecret());
+        String apiResult = getTokenClient.get();
+        return parsingResult(apiResult);
+    }
+
+    private String getTiker(String accToken) {
+        //璋冪敤API
+        PostClient postClient = executableClient.newPostClient(GET_TIKER);
+        //璁剧疆鍙傛暟
+        if (ObjectUtil.isNotNull(accToken)) {
+            postClient.addParameter("accessToken", accToken);
+            postClient.addParameter("appkey", dingConfig.getAppKey());
+            postClient.addParameter("appsecret", dingConfig.getAppSecret());
+            String apiResult = postClient.post();
+            return parsingResult(apiResult);
+        }
+        return null;
+    }
+
+    private String parsingResult(String apiResult) {
+        if (ObjectUtil.isNotNull(apiResult)) {
+            JSONObject resJson = JSONObject.parseObject(apiResult);
+            if (resJson.getBoolean("success")) {
+                JSONObject content = resJson.getJSONObject("content");
+                if (content.getBoolean("success")) {
+                    JSONObject dataObj = content.getJSONObject("data");
+                    String accessToken = dataObj.getString("accessToken");
+                    return accessToken;
+                }
+            } else {
+                log.error(resJson.toJSONString());
+            }
+        }
+        return null;
     }
 
     @ApiOperation(value = "閫氳褰�")
@@ -77,15 +150,12 @@
     }
 
 
-
-
     @ApiOperation(value = "閫氳褰曢�掑綊")
     @GetMapping("/getDddressBook")
     public CommonResult<NewAddressBookVO> getNewAddressBook(@RequestParam("id") Long id) {
         AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
         return CommonResult.success(dingService.getAddressBookById(id, user.getUserId()));
     }
-
 
 
     @ApiOperation(value = "淇敼閫氳褰曞娉�")
diff --git a/ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java b/ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java
index b33b59d..2c163f9 100644
--- a/ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java
+++ b/ycl-platform/src/main/java/com/ycl/timer/GetDingToken.java
@@ -93,14 +93,14 @@
     }
     @Scheduled(cron ="0 0/2 * * * ? ")
     public void runAction() {
-        // //gettoken
-        // String getToken = getToken();
-        // //jsApi
-        // String jsapiToken = getTiker(getToken);
-        // //瀛樺偍鍒皉edis
-        // JSONObject dingObj = new JSONObject();
-        // dingObj.put("token", getToken);
-        // dingObj.put("jsApiTiker", jsapiToken);
-        // redisTemplate.opsForValue().set("ding", dingObj.toJSONString(), 2L, TimeUnit.HOURS);
+         //gettoken
+         String getToken = getToken();
+         //jsApi
+         String jsapiToken = getTiker(getToken);
+         //瀛樺偍鍒皉edis
+         JSONObject dingObj = new JSONObject();
+         dingObj.put("token", getToken);
+         dingObj.put("jsApiTiker", jsapiToken);
+         redisTemplate.opsForValue().set("ding", dingObj.toJSONString(), 2L, TimeUnit.HOURS);
     }
 }
diff --git a/ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java b/ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java
index 92d2be9..86e4f07 100644
--- a/ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java
+++ b/ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java
@@ -52,11 +52,11 @@
 
     @Override
     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
-        // if (contextRefreshedEvent.getApplicationContext().getParent() == null) {
-        //     Thread thread = new Thread(this::run);
-        //     thread.setUncaughtExceptionHandler(handler);
-        //     thread.start();
-        // }
+         if (contextRefreshedEvent.getApplicationContext().getParent() == null) {
+             Thread thread = new Thread(this::run);
+             thread.setUncaughtExceptionHandler(handler);
+             thread.start();
+         }
     }
 
     @Autowired
@@ -204,6 +204,6 @@
 
     @Override
     public void run(ApplicationArguments args) throws Exception {
-        // run();
+         run();
     }
 }
diff --git a/ycl-platform/src/main/resources/application-dev.yml b/ycl-platform/src/main/resources/application-dev.yml
index f3a1029..bd06cc6 100644
--- a/ycl-platform/src/main/resources/application-dev.yml
+++ b/ycl-platform/src/main/resources/application-dev.yml
@@ -79,3 +79,11 @@
     keyId: LTAI5tRpMjypcziJ2WAWEKsV
     keySecret: U7CPi1JqOWvTbdLR99duJ8ev3tcjRp
     bucketName: upload-bzh-new
+
+#涓撴湁閽夐拤鍙傛暟
+zzding :
+  app-key : SC_ZHZF-IC5g2YiRDW8tug1DfAfiui
+  app-secret : 39RIHFOKd8fUeeW9T7CdBcwEqA6dMKx5d3686B6P
+  domain-name : openplatform.dg-work.cn
+  protocal : https
+  tenant-id : 50645661
\ No newline at end of file
diff --git a/ycl-platform/src/main/resources/application.yml b/ycl-platform/src/main/resources/application.yml
index a5c6f78..75ab11b 100644
--- a/ycl-platform/src/main/resources/application.yml
+++ b/ycl-platform/src/main/resources/application.yml
@@ -90,3 +90,5 @@
       - /**/api/**
       - /**/text/**
       - /**/API/**
+      - /**/ding/**
+      - /**/sccg_region/**

--
Gitblit v1.8.0