wfansh há 6 meses atrás
pai
commit
f713c2ccce

+ 24 - 11
build.gradle

@@ -1,28 +1,41 @@
 plugins {
-	id 'java'
-	id 'org.springframework.boot' version '3.3.3'
-	id 'io.spring.dependency-management' version '1.1.6'
+    id 'java'
+    id 'org.springframework.boot' version '3.3.3'
+    id 'io.spring.dependency-management' version '1.1.6'
 }
 
 group = 'com.wechi.adweb'
 version = '0.0.1-SNAPSHOT'
 
 java {
-	toolchain {
-		languageVersion = JavaLanguageVersion.of(17)
-	}
+    toolchain {
+        languageVersion = JavaLanguageVersion.of(17)
+    }
 }
 
 repositories {
-	mavenCentral()
+    mavenCentral()
 }
 
 dependencies {
-	implementation 'org.springframework.boot:spring-boot-starter'
-	testImplementation 'org.springframework.boot:spring-boot-starter-test'
-	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
+    implementation 'org.springframework.boot:spring-boot-starter'
+
+    implementation 'org.springframework:spring-context'
+    implementation 'org.slf4j:slf4j-api'
+    implementation 'org.apache.commons:commons-lang3'
+    implementation 'com.google.guava:guava:33.0.0-jre'
+
+    compileOnly 'org.projectlombok:lombok'
+    annotationProcessor 'org.projectlombok:lombok'
+
+    // Google
+    implementation 'com.google.apis:google-api-services-tagmanager:v2-rev20240701-2.0.0'
+
+
+    testImplementation 'org.springframework.boot:spring-boot-starter-test'
+    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
 }
 
 tasks.named('test') {
-	useJUnitPlatform()
+    useJUnitPlatform()
 }

+ 3 - 4
src/main/java/com/wechi/adweb/bridge/DataBridgeApplication.java

@@ -6,8 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 @SpringBootApplication
 public class DataBridgeApplication {
 
-	public static void main(String[] args) {
-		SpringApplication.run(DataBridgeApplication.class, args);
-	}
-
+    public static void main(String[] args) {
+        SpringApplication.run(DataBridgeApplication.class, args);
+    }
 }

+ 41 - 0
src/main/java/com/wechi/adweb/bridge/google/gtm/GTMService.java

@@ -0,0 +1,41 @@
+package com.wechi.adweb.bridge.google.gtm;
+
+import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
+import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
+import com.google.api.client.http.HttpTransport;
+import com.google.api.client.json.gson.GsonFactory;
+import com.google.api.services.tagmanager.TagManager;
+import com.google.api.services.tagmanager.TagManagerScopes;
+
+import jakarta.annotation.PostConstruct;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+
+/**
+ * @author wfansh
+ */
+@Slf4j
+@Service
+public class GTMService {
+    private TagManager tagManager;
+
+    @PostConstruct
+    private TagManager init() throws GeneralSecurityException, IOException {
+        // Service account authorization;
+        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
+        GoogleCredential credential =
+                GoogleCredential.fromStream(
+                                this.getClass()
+                                        .getClassLoader()
+                                        .getResourceAsStream("google/service-account-key.json"))
+                        .createScoped(TagManagerScopes.all());
+
+        return new TagManager.Builder(httpTransport, GsonFactory.getDefaultInstance(), credential)
+                .build();
+    }
+}

+ 2 - 0
src/main/resources/application.properties

@@ -1 +1,3 @@
 spring.application.name=data-bridge
+## Spring Boot
+server.port=8090

+ 13 - 0
src/main/resources/google/service-account-key.json

@@ -0,0 +1,13 @@
+{
+  "type": "service_account",
+  "project_id": "admp-go",
+  "private_key_id": "0c2387f064cf7ebf52e4929b6a8fb6382096e2ae",
+  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDCYTgeHDTqHPKx\nNjDzDma9q9j/mINGtjXBU+Z99kIwTRo5/3+tUqHJij682qIiJ7CJiIM3mu2vjXKf\nPo+CkSvoOGZ6MswXd+efKYQYuEfjrOQuzCSVtD9+jFrcDwLCPzgRJMk14vX/lg1X\nm86Y8hmxBMZnFR0jrqlbu1QKK7byiISpadddYtJJUv+lS+T2mTAmoTkhQn55K9c3\n/K38JzTzE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TN2bnHzp2khnYhKDYIR3e6cKD\nQfO0e3nBSF3lpkCvWTIqrGrRhrjI9M89HxM+6wRy7emHrqylKAwqocHLGAcpmn+q\nKlQtX775LiaEoLE3nZzYQEJwlmukJnA4ypcOa8O5AoGAFun1JxbszICNBE7CG4JF\nT9IHWFtplD6fjHGXLY0gxsCWjsnwtRawMLsm/BZg3uMyIG9wZNNQAaXmu63Zdeew\nbZRfzKbr9MuGr+Gfi4LdbL9nlVkkctHDevYhKElnKvQF0yT26Hlwg5IJ9T+X1Ubm\nHg9spV4Qg7Wz4t6wcD8+/hk=\n-----END PRIVATE KEY-----\n",
+  "client_email": "admp-go@admp-go.iam.gserviceaccount.com",
+  "client_id": "102623520381386002228",
+  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
+  "token_uri": "https://oauth2.googleapis.com/token",
+  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
+  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/admp-go%40admp-go.iam.gserviceaccount.com",
+  "universe_domain": "googleapis.com"
+}