diff --git a/pom.xml b/pom.xml
index 3eb6bd8..032771c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,12 +127,12 @@
spring-boot-starter-data-redis
2.4.0
-
- junit
- junit
- 4.13.2
- test
-
+
+
+
+
+
+
io.springfox
@@ -144,6 +144,18 @@
springfox-swagger2
2.9.2
+
+ org.jetbrains
+ annotations
+ RELEASE
+ compile
+
+
+ org.jetbrains
+ annotations
+ RELEASE
+ compile
+
diff --git a/src/main/java/com/gitlink/softbot/utils/GitLinkApi.java b/src/main/java/com/gitlink/softbot/utils/GitLinkApi.java
new file mode 100644
index 0000000..1e7d619
--- /dev/null
+++ b/src/main/java/com/gitlink/softbot/utils/GitLinkApi.java
@@ -0,0 +1,119 @@
+package com.gitlink.softbot.utils;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.gitlink.softbot.global.vo.Response;
+import com.gitlink.softbot.vo.Webhook;
+import org.mapstruct.BeforeMapping;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;
+import org.springframework.http.HttpMethod;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class GitLinkApi {
+
+ @Value("${gitlink.url}")
+ private String URL;
+
+ @Value("${gitlink.token}")
+ private String TOKEN;
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ private Map headParams;
+
+ public Map getHeader(){
+ Map headParams = new HashMap<>();
+ headParams.put("Authorization", "Bearer "+TOKEN);
+ return headParams;
+ }
+
+
+ public Response getUserByUid(Integer uid){
+ Map inputParams = new HashMap<>();
+ inputParams.put("uid", uid.toString());
+ Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.GET, URL+"/api", null, "/users/get_user_info.json", inputParams, null ,getHeader());
+ return response;
+ }
+
+ public Response getWebhookById(Integer uid, Object[] params,Integer webhookId) throws JsonProcessingException {
+ Map inputParams = new HashMap<>();
+ inputParams.put("uid", uid.toString());
+ ObjectMapper mapper = new ObjectMapper();
+ Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.GET, URL+"/api/v1", params, "/webhooks/"+webhookId+".json", inputParams, null,getHeader());
+ return response;
+ }
+
+ public Response addWebhook(Integer uid, Object[] params, Webhook webhook) throws JsonProcessingException {
+ Map inputParams = new HashMap<>();
+ inputParams.put("uid", uid.toString());
+ ObjectMapper mapper = new ObjectMapper();
+ Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.POST, URL+"/api/v1", params, "/webhooks.json", inputParams, mapper.writeValueAsString(webhook) ,getHeader());
+ return response;
+ }
+
+ public Response updateWebhook(Integer uid, Object[] params, Integer webhookId, Webhook webhook) throws JsonProcessingException {
+ Map inputParams = new HashMap<>();
+ inputParams.put("uid", uid.toString());
+ ObjectMapper mapper = new ObjectMapper();
+ Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.PATCH, URL+"/api/v1", params, "/webhooks/"+webhookId+".json", inputParams, mapper.writeValueAsString(webhook) ,getHeader());
+ return response;
+ }
+
+ public Response deleteWebhook(Integer uid, Object[] params, Integer webhookId) {
+ Map inputParams = new HashMap<>();
+ inputParams.put("uid", uid.toString());
+ ObjectMapper mapper = new ObjectMapper();
+ Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.DELETE, URL+"/api/v1", params, "/webhooks/"+webhookId+".json", inputParams,null, getHeader());
+ return response;
+ }
+
+ /**
+ * 调用平台中与bot 身份认证相关的接口,auth_active, update_secret, update_private_key
+ *
+ * @param uid bot拥有者用户的uid
+ * @param botId bot主键id
+ * @param suffix 方法类别 auth_active, update_secret, update_private_key
+ * @return Response 统一响应对象
+ */
+ public Response activeBotAuth(Integer uid, Integer botId, String suffix){
+ Map inputParams = new HashMap<>();
+ inputParams.put("uid", uid.toString());
+ Object[] params = new Object[]{botId.toString()};
+ Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.POST, URL+"/app", params, "/"+suffix, inputParams, null ,getHeader());
+ return response;
+ }
+
+// public Response activeBotAuth(Integer uid, Integer botId){
+// Map inputParams = new HashMap<>();
+// inputParams.put("uid", uid.toString());
+// Object[] params = new Object[]{botId.toString()};
+// Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.POST, URL+"/app", params, "/auth_active", inputParams, null ,getHeader());
+// return response;
+// }
+//
+// public Response updateSecet(Integer uid, Integer botId){
+// Map inputParams = new HashMap<>();
+// inputParams.put("uid", uid.toString());
+// Object[] params = new Object[]{botId.toString()};
+// Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.POST, URL+"/app", params, "/update_secret", inputParams, null ,getHeader());
+// return response;
+// }
+//
+// public Response updatePrivateKey(Integer uid, Integer botId){
+// Map inputParams = new HashMap<>();
+// inputParams.put("uid", uid.toString());
+// Object[] params = new Object[]{botId.toString()};
+// Response response = RestTemplateUtil.httpRequest(restTemplate, HttpMethod.POST, URL+"/app", params, "/update_private_key", inputParams, null ,getHeader());
+// return response;
+// }
+
+
+}
diff --git a/src/main/java/com/gitlink/softbot/utils/RestTemplateUtil.java b/src/main/java/com/gitlink/softbot/utils/RestTemplateUtil.java
index 930e889..3b3c776 100644
--- a/src/main/java/com/gitlink/softbot/utils/RestTemplateUtil.java
+++ b/src/main/java/com/gitlink/softbot/utils/RestTemplateUtil.java
@@ -2,6 +2,8 @@ package com.gitlink.softbot.utils;
import com.gitlink.softbot.global.vo.Response;
+import org.apache.logging.log4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
@@ -17,6 +19,7 @@ import java.util.Objects;
public class RestTemplateUtil {
+ //private static Logger logger = (Logger) LoggerFactory.getLogger(RestTemplateUtil.class);
/**
* @Description 私有构造函数
*/
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 5e8ef5a..7866537 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -58,3 +58,8 @@ logging:
mapper : debug
elasticsearch:
url: localhost:9200
+
+gitlink:
+ url: https://testforgeplus.trustie.net
+ token: eyJraWQiOiJUaEVSLVl3Ukg4TWYwOHM0UnJLUDYzXzZLWmVET2NZckZXcmdzN2VUVWdrIiwiYWxnIjoiSFM1MTIifQ.eyJpc3MiOiJHaXRMaW5rIiwiaWF0IjoxNjc1NzYyMDkwLCJqdGkiOiI0MzA1ZDUwZC01ZGRkLTQ0MzUtODMyNS1iZDczYmVhMWMxYjciLCJ1c2VyIjp7ImlkIjpudWxsLCJsb2dpbiI6bnVsbCwibWFpbCI6bnVsbH19.hpHCJeU4Jyz-DM2NBUdB-tQW_E0-tu9H3LoGhsJ7kPHkSsdXJCII0jxhyPb9gwDsgd8SnlRZF8tZDDjnZSoztQ
+
diff --git a/src/test/java/com/gitlink/softbot/service/market/GitLinkApiTest.java b/src/test/java/com/gitlink/softbot/service/market/GitLinkApiTest.java
new file mode 100644
index 0000000..10d87d9
--- /dev/null
+++ b/src/test/java/com/gitlink/softbot/service/market/GitLinkApiTest.java
@@ -0,0 +1,77 @@
+package com.gitlink.softbot.service.market;
+
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.gitlink.softbot.global.vo.Response;
+import com.gitlink.softbot.utils.GitLinkApi;
+import com.gitlink.softbot.vo.Webhook;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@SpringBootTest
+public class GitLinkApiTest {
+
+ @Autowired
+ private GitLinkApi api;
+
+ private Integer uid = 85175;
+
+ private Webhook webhooks;
+
+ @Test
+ public void getUserTest(){
+ Response response = api.getUserByUid(uid);
+ System.out.println(response.getData());
+ }
+
+ @Test
+ public void activeBotAuthTest(){
+ Response response = api.activeBotAuth(84993,800,"auth_active");
+ System.out.println(response.getData());
+ }
+
+ @Test
+ public void updateSecretTest(){
+ Response response = api.activeBotAuth(84993,800,"update_secret");
+ System.out.println(response.getData());
+ }
+
+ @Test
+ public void updatePrivateKeyTest(){
+ Response response = api.activeBotAuth(84993,800,"update_private_key");
+ System.out.println(response.getData());
+ }
+
+ @Test
+ public void addWebhook() throws JsonProcessingException {
+ webhooks = new Webhook(true, "json", "GET", "123456", "http://localhost:10000", "*", new Object[]{"push"});
+ Object[] params = new Object[]{"xxq250", "ruoyi-vue-pro"};
+ Response response = api.addWebhook(85175,params,webhooks);
+ System.out.println(response.getData());
+ }
+
+ @Test
+ public void updateWebhook() throws JsonProcessingException {
+ webhooks = new Webhook(false, "json", "GET", "123456", "http://localhost:10000", "*", new Object[]{"push"});
+ Object[] params = new Object[]{"xxq250", "ruoyi-vue-pro"};
+ Response response = api.updateWebhook(85175,params,1082,webhooks);
+ System.out.println(response.getData());
+ }
+
+ @Test
+ public void deleteWebhook() throws JsonProcessingException {
+ Object[] params = new Object[]{"xxq250", "ruoyi-vue-pro"};
+ Response response = api.deleteWebhook(85175,params,1082);
+ System.out.println(response.getData());
+ }
+
+ @Test
+ public void getWebhook() throws JsonProcessingException {
+ Object[] params = new Object[]{"xxq250", "ruoyi-vue-pro"};
+ Response response = api.getWebhookById(85175,params,983);
+ System.out.println(response.getData());
+ }
+}
diff --git a/target/classes/application.yml b/target/classes/application.yml
index 5e8ef5a..7866537 100644
--- a/target/classes/application.yml
+++ b/target/classes/application.yml
@@ -58,3 +58,8 @@ logging:
mapper : debug
elasticsearch:
url: localhost:9200
+
+gitlink:
+ url: https://testforgeplus.trustie.net
+ token: eyJraWQiOiJUaEVSLVl3Ukg4TWYwOHM0UnJLUDYzXzZLWmVET2NZckZXcmdzN2VUVWdrIiwiYWxnIjoiSFM1MTIifQ.eyJpc3MiOiJHaXRMaW5rIiwiaWF0IjoxNjc1NzYyMDkwLCJqdGkiOiI0MzA1ZDUwZC01ZGRkLTQ0MzUtODMyNS1iZDczYmVhMWMxYjciLCJ1c2VyIjp7ImlkIjpudWxsLCJsb2dpbiI6bnVsbCwibWFpbCI6bnVsbH19.hpHCJeU4Jyz-DM2NBUdB-tQW_E0-tu9H3LoGhsJ7kPHkSsdXJCII0jxhyPb9gwDsgd8SnlRZF8tZDDjnZSoztQ
+
diff --git a/target/classes/com/gitlink/softbot/utils/GitLinkApi.class b/target/classes/com/gitlink/softbot/utils/GitLinkApi.class
new file mode 100644
index 0000000..c49f79a
Binary files /dev/null and b/target/classes/com/gitlink/softbot/utils/GitLinkApi.class differ
diff --git a/target/classes/com/gitlink/softbot/utils/RestTemplateUtil.class b/target/classes/com/gitlink/softbot/utils/RestTemplateUtil.class
index 1a0c55b..77ef41d 100644
Binary files a/target/classes/com/gitlink/softbot/utils/RestTemplateUtil.class and b/target/classes/com/gitlink/softbot/utils/RestTemplateUtil.class differ
diff --git a/target/test-classes/com/gitlink/softbot/service/market/GitLinkApiTest.class b/target/test-classes/com/gitlink/softbot/service/market/GitLinkApiTest.class
new file mode 100644
index 0000000..1b10392
Binary files /dev/null and b/target/test-classes/com/gitlink/softbot/service/market/GitLinkApiTest.class differ