Skip to content

Commit c11fba6

Browse files
authored
Merge pull request #1 from xelloss00x/main
[feature] v1.0.0.0
2 parents 31b721b + 68471cf commit c11fba6

28 files changed

+1900
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[1.0.0.0] - 2021-01-04
2+
3+
### 新增
4+
5+
* OPPO、XM icon和图片上传接口实现

README.md

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,95 @@
1-
# getui-3rd-push-utils
1+
# GT SDK Libraries for Java
2+
该SDK是多厂商推送工具集,目前包装的功能有:icon上传。支持的厂商模块有OPPO、XM。
3+
4+
需要的jdk版本:
5+
- JDK 1.8 or higher.
6+
7+
## Adding dependency to your build
8+
使用maven添加依赖如下
9+
10+
```xml
11+
<dependency>
12+
<groupId>com.getui.push</groupId>
13+
<artifactId>getui-3rd-push-utils</artifactId>
14+
<version>1.0.0.0</version>
15+
</dependency>
16+
```
17+
18+
## Usage
19+
### sdk初始化
20+
在应用配置类中初始化执行一次如下代码
21+
```java
22+
// 配置文件的路径是运行程序所在的相对路径
23+
GtSDKStarter.getInstance().loadPropertyFile("/src/main/resources/application.properties").init();
24+
```
25+
26+
### 配置说明
27+
请在上一步指定的配置文件内添加以下参数,
28+
29+
```properties
30+
## 是否需要初始化厂商服务实例(主要包含各厂商服务类实例化、鉴权)。默认是true
31+
GtSDK.manufacturerInitSwitch=true
32+
## 需要执行的厂商模块(不区分大小写),目前支持oppo和xm。不启用配置就默认执行所有厂商模块,启用配置单不填值就所有厂商模块都不执行。
33+
GtSDK.moduleSet=oppo,xm
34+
## 判断文件是否相同的方式,支持sha1和fileName。如不配置默认使用fileName。(为了避免文件重复上传,文件上传后sdk会将厂商返回的链接缓存起来,下次从缓存里取。
35+
## 这里就是决定使用什么方式来判断文件是否重复。缓存的时效使用各厂商icon最大存储时效,由于目前使用的本地缓存,应用重启也会导致缓存清空)
36+
GtSDK.judgeFile=sha1
37+
## 接口调用超时等待时间,单位毫秒,默认500毫秒
38+
GtSDK.callTimeout=500
39+
## 以下是各厂商配置参数
40+
GtSDK.XM.AppId=
41+
GtSDK.XM.AppKey=
42+
GtSDK.XM.AppSecret=
43+
GtSDK.XM.MasterSecret=
44+
GtSDK.OPPO.AppId=
45+
GtSDK.OPPO.AppKey=
46+
GtSDK.OPPO.AppSecret=
47+
GtSDK.OPPO.MasterSecret=
48+
```
49+
50+
### 服务调用
51+
目前提供了四个服务:
52+
53+
1. 多厂商上传同一个icon文件。完成上两步后,只需要在需要上传icon的代码处编写以下代码即可得到各厂商上传结果。
54+
55+
```java
56+
// 配置文件的路径是运行程序所在的相对路径
57+
Map<String, Result> result = ManufacturerFactory.uploadIcon(new File("/xxx/xxx/xxx.png"));
58+
```
59+
60+
2. 多厂商上传不同的icon文件。代码如下:
61+
62+
```java
63+
// 配置文件的路径是运行程序所在的相对路径
64+
ManufacturerFile file1 = new ManufacturerFile(ManufacturerConstants.ManufacturerName.OPPO, "/xxx/xxx/xxx/xxx1.png");
65+
ManufacturerFile file2 = new ManufacturerFile(ManufacturerConstants.ManufacturerName.XM, "/xxx/xxx/xxx2.png");
66+
ManufacturerFile[] manufacturerFiles = new ManufacturerFile[]{file1, file2};
67+
Map<String, Result> result = ManufacturerFactory.uploadIcon(manufacturerFiles);
68+
```
69+
70+
3. 多厂商上传同一个图片文件。代码如下:
71+
72+
```java
73+
// 配置文件的路径是运行程序所在的相对路径
74+
Map<String, Result> result = ManufacturerFactory.uploadPic(new File("/xxx/xxx/xxx.png"));
75+
```
76+
77+
4. 多厂商上传不同的图片文件。代码如下:
78+
79+
```java
80+
// 配置文件的路径是运行程序所在的相对路径
81+
ManufacturerFile file1 = new ManufacturerFile(ManufacturerConstants.ManufacturerName.OPPO, "/xxx/xxx/xxx/xxx1.png");
82+
ManufacturerFile file2 = new ManufacturerFile(ManufacturerConstants.ManufacturerName.XM, "/xxx/xxx/xxx2.png");
83+
ManufacturerFile[] manufacturerFiles = new ManufacturerFile[]{file1, file2};
84+
Map<String, Result> result = ManufacturerFactory.uploadPic(manufacturerFiles);
85+
```
86+
87+
### 服务结果解析
88+
上一步可以看出上传接口返回的都是个Map,Map的key是厂商名(OPPO、XM),value是一个Result对象。Result包含以下三个属性:
89+
- code:结果码,0成功、1失败、2超时失败、3没有厂商实例(正常情况是配置没配这个厂商,但代码里却想使用这个厂商的服务)、4鉴权失败
90+
- message:success、fail、timeout、has no manufacturer instance、auth fail
91+
- data:成功时,值为icon在各厂商的上传url结果(或者picId);失败时,值是失败原因。
92+
93+
## 其他说明
94+
由于该sdk本质只是各厂商api的包装,所以对于一些接口限制和返回处理,需要遵循各厂商的api文档。下面放出
95+
[OPPO](https://open.oppomobile.com/wiki/doc#id=10693)[XM](https://dev.mi.com/console/doc/detail?pId=1163#_10_1) 的API在线文档供参考。

config/application.properties

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## 是否需要初始化厂商服务实例(主要包含各厂商服务类实例化、鉴权)。默认是true
2+
GtSDK.manufacturerInitSwitch=true
3+
## 需要执行的厂商模块(不区分大小写),目前支持oppo和xm。不启用配置就默认执行所有厂商模块,启用配置单不填值就所有厂商模块都不执行。
4+
GtSDK.moduleSet=oppo,xm
5+
## 判断文件是否相同的方式,支持sha1和fileName。如不配置默认使用fileName。(为了避免文件重复上传,文件上传后sdk会将厂商返回的链接缓存起来,下次从缓存里取。
6+
## 这里就是决定使用什么方式来判断文件是否重复。缓存的时效使用各厂商icon最大存储时效,由于目前使用的本地缓存,应用重启也会导致缓存清空)
7+
GtSDK.judgeFile=sha1
8+
## 接口调用超时等待时间,单位毫秒,默认500毫秒
9+
GtSDK.callTimeout=5000
10+
## 以下是各厂商配置参数
11+
GtSDK.XM.AppId=
12+
GtSDK.XM.AppKey=
13+
GtSDK.XM.AppSecret=
14+
GtSDK.XM.MasterSecret=
15+
GtSDK.OPPO.AppId=
16+
GtSDK.OPPO.AppKey=
17+
GtSDK.OPPO.AppSecret=
18+
GtSDK.OPPO.MasterSecret=

image/icon.png

3.64 KB
Loading

image/pic.jpeg

93.2 KB
Loading

pom.xml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.getui.push</groupId>
8+
<artifactId>getui-3rd-push-utils</artifactId>
9+
<version>1.0.0.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>${project.groupId}:${project.artifactId}</name>
13+
<description>A multi manufacturer push toolset implemented by GeTui</description>
14+
<url>https://github.com/GetuiLaboratory/getui-3rd-push-utils</url>
15+
16+
<licenses>
17+
<license>
18+
<name>Apache License, Version 2.0</name>
19+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
<distribution>repo</distribution>
21+
</license>
22+
</licenses>
23+
24+
<developers>
25+
<developer>
26+
<name>GeTui</name>
27+
<email>developer@getui.com</email>
28+
<organization>GeTui</organization>
29+
<organizationUrl>https://www.getui.com/</organizationUrl>
30+
</developer>
31+
</developers>
32+
33+
<scm>
34+
<connection>scm:git@github.com:GetuiLaboratory/getui-3rd-push-utils.git</connection>
35+
<developerConnection>scm:git:ssh://git@github.com:GetuiLaboratory/getui-3rd-push-utils.git</developerConnection>
36+
<url>https://github.com/GetuiLaboratory/getui-3rd-push-utils</url>
37+
</scm>
38+
39+
<distributionManagement>
40+
<snapshotRepository>
41+
<id>sonatype-nexus-snapshots</id>
42+
<name>Sonatype Nexus Snapshots</name>
43+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
44+
</snapshotRepository>
45+
<repository>
46+
<id>sonatype-nexus-staging</id>
47+
<name>Nexus Release Repository</name>
48+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
49+
</repository>
50+
</distributionManagement>
51+
52+
<properties>
53+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
54+
<javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
55+
</properties>
56+
57+
<dependencies>
58+
<dependency>
59+
<groupId>ch.qos.logback</groupId>
60+
<artifactId>logback-classic</artifactId>
61+
<version>1.1.7</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.reflections</groupId>
65+
<artifactId>reflections</artifactId>
66+
<version>0.9.11</version>
67+
</dependency>
68+
<!-- https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine -->
69+
<dependency>
70+
<groupId>com.github.ben-manes.caffeine</groupId>
71+
<artifactId>caffeine</artifactId>
72+
<version>2.8.8</version>
73+
</dependency>
74+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
75+
<dependency>
76+
<groupId>com.fasterxml.jackson.core</groupId>
77+
<artifactId>jackson-databind</artifactId>
78+
<version>2.12.0</version>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>junit</groupId>
83+
<artifactId>junit</artifactId>
84+
<version>4.12</version>
85+
</dependency>
86+
</dependencies>
87+
88+
89+
90+
<build>
91+
<plugins>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-compiler-plugin</artifactId>
95+
<configuration>
96+
<source>8</source>
97+
<target>8</target>
98+
</configuration>
99+
</plugin>
100+
<plugin>
101+
<groupId>org.apache.maven.plugins</groupId>
102+
<artifactId>maven-source-plugin</artifactId>
103+
<version>2.2.1</version>
104+
<executions>
105+
<execution>
106+
<id>attach-sources</id>
107+
<goals>
108+
<goal>jar-no-fork</goal>
109+
</goals>
110+
</execution>
111+
</executions>
112+
</plugin>
113+
<plugin>
114+
<groupId>org.apache.maven.plugins</groupId>
115+
<artifactId>maven-javadoc-plugin</artifactId>
116+
<version>2.9.1</version>
117+
<executions>
118+
<execution>
119+
<id>attach-javadocs</id>
120+
<goals>
121+
<goal>jar</goal>
122+
</goals>
123+
</execution>
124+
</executions>
125+
</plugin>
126+
<plugin>
127+
<groupId>org.apache.maven.plugins</groupId>
128+
<artifactId>maven-gpg-plugin</artifactId>
129+
<version>1.5</version>
130+
<configuration>
131+
<skip>true</skip>
132+
</configuration>
133+
<executions>
134+
<execution>
135+
<id>sign-artifacts</id>
136+
<phase>verify</phase>
137+
<goals>
138+
<goal>sign</goal>
139+
</goals>
140+
</execution>
141+
</executions>
142+
</plugin>
143+
</plugins>
144+
</build>
145+
146+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.getui.gtps;
2+
3+
4+
import com.getui.gtps.config.CommonConfig;
5+
import com.getui.gtps.manufacturer.ManufacturerFactory;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.io.IOException;
10+
11+
/**
12+
* @author wangxu
13+
* date: 2020/12/25
14+
*/
15+
public class GtSDKStarter {
16+
17+
private static final Logger LOGGER = LoggerFactory.getLogger(GtSDKStarter.class);
18+
19+
private GtSDKStarter() {
20+
21+
}
22+
23+
private static class SingletonHolder {
24+
private final static GtSDKStarter instance = new GtSDKStarter();
25+
}
26+
27+
public static GtSDKStarter getInstance() {
28+
return SingletonHolder.instance;
29+
}
30+
31+
/**
32+
* 加载配置文件
33+
*
34+
* @param fileName 配置文件名,用户目录下的相对路径
35+
* @return GtSDKStarter
36+
* @throws IOException 加载配置文件时可能会有IOException
37+
*/
38+
public GtSDKStarter loadPropertyFile(String fileName) throws IOException {
39+
CommonConfig.manufacturerProperties.load(new java.io.FileInputStream(System.getProperty("user.dir") + fileName));
40+
return this;
41+
}
42+
43+
/**
44+
* sdk初始化,包括配置初始化和厂商实例初始化
45+
*/
46+
public void init() {
47+
LOGGER.info("GT SDKInit start.");
48+
// 从启动参数或配置文件中进行参数初始化
49+
CommonConfig.init();
50+
// 如果参数配置开启了厂商初始就进行厂商初始化:包括厂商服务类实例化和鉴权
51+
if (CommonConfig.manufacturerInitSwitch) {
52+
ManufacturerFactory.init();
53+
}
54+
LOGGER.info("GT SDKInit finish.");
55+
}
56+
57+
58+
}

0 commit comments

Comments
 (0)