Skip to content

Commit

Permalink
初始化提交工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
刘志永 committed Aug 3, 2021
1 parent 9315b56 commit 83e4b8d
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
*/target
*/idea
104 changes: 104 additions & 0 deletions kernel/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.aliyun</groupId>
<artifactId>anubis-openapi-kernel</artifactId>
<version>1.0.0-SNAPSHOT</version>

<name>anubis-openapi-kernel</name>
<!-- FIXME change it to the project's website -->

<description>eleme anubis kernel SDK for Java
</description>
<url>https://github.com/eleme/anubis-openapi-third</url>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<id>aliyunproducts</id>
<name>Aliyun SDK</name>
<email>aliyunsdk@aliyun.com</email>
</developer>
</developers>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<scm>
<connection/>
<developerConnection/>
<url/>
</scm>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea</artifactId>
<version>[1.0.3, 2.0.0)</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<encoding>UTF-8</encoding>
<doclint>none</doclint>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
</project>
82 changes: 82 additions & 0 deletions kernel/src/main/java/me/eleme/anubis/sdk/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package me.eleme.anubis.sdk;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

public class Client {
/**
* 构造成本较高的一些参数缓存在上下文中
*/
private final Context context;

/**
* 注入的可选额外文本参数集合
*/
private final Map<String, String> optionalTextParams = new HashMap<>();

/**
* 注入的可选业务参数集合
*/
private final Map<String, Object> optionalBizParams = new HashMap<>();

/**
* 构造函数
*
* @param context 上下文对象
*/
public Client(Context context) {
this.context = context;
}


/**
* 注入额外文本参数
*
* @param key 参数名称
* @param value 参数的值
* @return 本客户端本身,便于链路调用
*/
public Client injectTextParam(String key, String value) {
optionalTextParams.put(key, value);
return this;
}

/**
* 注入额外业务参数
*
* @param key 业务参数名称
* @param value 业务参数的值
* @return 本客户端本身,便于链式调用
*/
public Client injectBizParam(String key, Object value) {
optionalBizParams.put(key, value);
return this;
}

/**
* 获取时间戳,格式yyyy-MM-dd HH:mm:ss
*
* @return 当前时间戳
*/
public String getTimestamp() throws Exception {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("GMT+8"));
return df.format(new Date());
}

/**
* 获取Config中的配置项
*
* @param key 配置项的名称
* @return 配置项的值
*/
public String getConfig(String key) throws Exception {
return context.getConfig(key);
}


}
62 changes: 62 additions & 0 deletions kernel/src/main/java/me/eleme/anubis/sdk/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package me.eleme.anubis.sdk;

import com.aliyun.tea.NameInMap;
import com.aliyun.tea.TeaModel;
import com.aliyun.tea.Validation;

public class Config extends TeaModel {

/**
* 通信协议,通常填写https
*/
@NameInMap("protocol")
@Validation(required = true)
public String protocol;

/**
* 网关域名
* 线上为:openapi.alipay.com
* 沙箱为:openapi.alipaydev.com
*/
@NameInMap("gatewayHost")
@Validation(required = true)
public String gatewayHost;

/**
* AppId
*/
@NameInMap("appId")
@Validation(required = true)
public String appId;

/**
* AppId
*/
@NameInMap("merchantId")
@Validation(required = true)
public String merchantId;

/**
* AppId
*/
@NameInMap("secretKey")
@Validation(required = true)
public String secretKey;


/**
* 代理地址(可选)
* 例如:http://127.0.0.1:8080
*/
@NameInMap("httpProxy")
public String httpProxy;


/**
* 忽略证书校验(可选)
*/
@NameInMap("ignoreSSL")
public boolean ignoreSSL;


}
25 changes: 25 additions & 0 deletions kernel/src/main/java/me/eleme/anubis/sdk/Context.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.eleme.anubis.sdk;

import com.aliyun.tea.TeaModel;

import java.util.Map;

public class Context {
/**
* 客户端配置参数
*/
private final Map<String, Object> config;

public Context(Config options) throws Exception {
config = TeaModel.buildMap(options);
}

public String getConfig(String key) {
if (String.valueOf(config.get(key)) == "null") {
return null;
} else {
return String.valueOf(config.get(key));
}
}

}

0 comments on commit 83e4b8d

Please sign in to comment.