Browse Source

DataForSEO API

wfansh 5 months ago
parent
commit
604f1f421e

+ 1 - 1
jeecg-module-system/jeecg-system-biz/pom.xml

@@ -66,7 +66,7 @@
 		<dependency>
 			<groupId>io.github.dataforseo</groupId>
 			<artifactId>dataforseo-client</artifactId>
-			<version>1.0.9</version>
+			<version>1.0.19</version>
 		</dependency>
 
     </dependencies>

+ 42 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/seo/service/dataforseo/DataForSEOConfig.java

@@ -0,0 +1,42 @@
+package org.jeecg.modules.adweb.seo.service.dataforseo;
+
+import io.github.dataforseo.client.ApiClient;
+import io.github.dataforseo.client.api.SerpApi;
+import io.github.dataforseo.client.auth.*;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * See https://docs.dataforseo.com/v3
+ *
+ * @author wfansh
+ */
+@Configuration
+public class DataForSEOConfig {
+
+    @Value("${dataforseo.username}")
+    private String username;
+
+    @Value("${dataforseo.password}")
+    private String password;
+
+    @Value("${dataforseo.api-path}")
+    private String apiPath;
+
+    @Bean
+    public SerpApi serpApi() {
+        ApiClient defaultClient = io.github.dataforseo.client.Configuration.getDefaultApiClient();
+        defaultClient.setBasePath(apiPath);
+        // HTTP超时 - 30秒
+        defaultClient.setConnectTimeout(30 * 1000);
+
+        // API认证方式 - basicAuth
+        HttpBasicAuth basicAuth = (HttpBasicAuth) defaultClient.getAuthentication("basicAuth");
+        basicAuth.setUsername(username);
+        basicAuth.setPassword(password);
+
+        return new SerpApi(defaultClient);
+    }
+}

+ 6 - 0
jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml

@@ -355,3 +355,9 @@ data-bridge:
   api:
     host: http://data-bridge.v3.adwebcloud.com:9002
     token: lgoXX9APqgPLGMPECiNoxaPx
+
+### dataforseo
+dataforseo:
+  username: advichdev@gmail.com
+  password: 0845d3de83295cca
+  api-path: https://api.dataforseo.com

+ 6 - 0
jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml

@@ -343,3 +343,9 @@ data-bridge:
   api:
     host: http://data-bridge.v3.adwebcloud.com:9002
     token: lgoXX9APqgPLGMPECiNoxaPx
+
+### dataforseo
+dataforseo:
+  username: advichdev@gmail.com
+  password: 0845d3de83295cca
+  api-path: https://api.dataforseo.com

+ 6 - 0
jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml

@@ -340,3 +340,9 @@ data-bridge:
   api:
     host: http://data-bridge.v3.adwebcloud.com:9002
     token: lgoXX9APqgPLGMPECiNoxaPx
+
+### dataforseo
+dataforseo:
+  username: advichdev@gmail.com
+  password: 0845d3de83295cca
+  api-path: https://api.dataforseo.com

+ 38 - 0
jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/adweb/seo/service/DataForSEOTest.java

@@ -0,0 +1,38 @@
+package org.jeecg.modules.adweb.seo.service;
+
+import io.github.dataforseo.client.api.SerpApi;
+import io.github.dataforseo.client.model.SerpGoogleOrganicLiveAdvancedRequestInfo;
+import io.github.dataforseo.client.model.SerpGoogleOrganicLiveAdvancedResponseInfo;
+
+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 java.util.ArrayList;
+import java.util.List;
+
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("dev")
+public class DataForSEOTest {
+
+    @Autowired private SerpApi serpApi;
+
+    @Test
+    public void testSerpGoogleOrganic() throws Exception {
+        SerpGoogleOrganicLiveAdvancedRequestInfo task =
+                new SerpGoogleOrganicLiveAdvancedRequestInfo();
+
+        task.setLocationCode(2840);
+        task.setLanguageCode("en");
+        task.setKeyword("Aluminum Plastic Composite Panel Extrusion Line");
+
+        List<SerpGoogleOrganicLiveAdvancedRequestInfo> serpTaskRequestInfo =
+                new ArrayList<SerpGoogleOrganicLiveAdvancedRequestInfo>();
+        serpTaskRequestInfo.add(task);
+
+        SerpGoogleOrganicLiveAdvancedResponseInfo result =
+                serpApi.googleOrganicLiveAdvanced(serpTaskRequestInfo);
+        System.out.println(result);
+    }
+}