Skip to content

Commit e66ca97

Browse files
committed
Merge branch 'feature-request-options' into 'master'
Feature request options See merge request api-team/pingpp-java!21
2 parents 786e2d4 + ad5fc6a commit e66ca97

111 files changed

Lines changed: 4016 additions & 3307 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# ChangeLog
22

3+
## 2.4.0
4+
5+
> 本次更新有较多与旧版本不兼容的地方。
6+
7+
- 修改: 支持 JDK 8 及以上;
8+
- 修改: 异常抛出修改,统一声明为 `PingppException`,实际使用可以再做具体判断;
9+
- 废弃: 原接口,支持传 `apiKey` 参数的方法,全部删除,可以用 `RequestOptions` 代替;
10+
- 新增: 每个接口最后一个参数支持 `RequestOptions`;
11+
- 新增: `PingppException` 增加 `type``code``statusCode`;
12+
- 新增: 对象增加 `getLastResponse()` 方法,可以用于获取当前这次请求的 `response` 对象,包含 `HTTP Status Code``Headers``Response Body` 等;
13+
- 废弃: 取消对 `PKCS1` 格式私钥的支持,请转成 `PKCS8` 再使用;
14+
15+
---
16+
317
## 2.3.14
418

519
- 新增:settle_account.recipient extra 字段

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99

1010
## 版本要求
1111

12-
Java SDK 要求 JDK 版本 1.7 及以上
12+
Java 要求 JDK 8 及以上
1313

1414
## 安装
1515

16-
#### 手动安装
16+
### 手动安装
1717

18-
将 libs/ 下面的 jar 包导入工程
18+
JAR 下载地址: [pingpp-java](https://jcenter.bintray.com/Pingplusplus/pingpp-java/)
1919

20-
#### maven 安装
20+
请根据版本号下载相应的 JAR 文件并导入至工程。
21+
22+
#### 依赖库
23+
24+
- com.google.code.gson:gson
25+
- commons-codec:commons-codec
26+
27+
### maven 安装
2128

2229
maven 远程仓库
2330

@@ -28,45 +35,47 @@ maven 远程仓库
2835
</snapshots>
2936
<id>central</id>
3037
<name>bintray</name>
31-
<url>http://jcenter.bintray.com</url>
38+
<url>https://jcenter.bintray.com</url>
3239
</repository>
3340
```
3441

3542
安装 Ping++ SDK
43+
3644
``` xml
3745
<dependency>
3846
<groupId>Pingplusplus</groupId>
3947
<artifactId>pingpp-java</artifactId>
40-
<version>2.3.14</version>
48+
<version>2.4.0</version>
4149
<type>jar</type>
4250
</dependency>
4351
```
4452

45-
#### gradle 安装
53+
### gradle 安装
4654

4755
gradle 远程仓库
4856

4957
```
5058
repositories {
5159
maven {
52-
url "http://jcenter.bintray.com"
60+
url "https://jcenter.bintray.com"
5361
}
5462
}
5563
```
5664

5765
安装 Ping++ SDK
5866

5967
```
60-
compile 'Pingplusplus:pingpp-java:2.3.14'
68+
compile 'Pingplusplus:pingpp-java:2.4.0'
6169
```
6270

63-
### 初始化
71+
## 初始化
6472

6573
```
6674
Pingpp.apiKey = "YOUR_API_KEY";
6775
```
6876

69-
### 使用示例
77+
## 使用示例
7078

7179
- 参考 [example](/example) 示例项目工程。该工程提供了付款、退款、微信公共号付款相关的 demo。
7280
- 以及 [test](/src/test/java/com/pingplusplus) 目录下的示例。
81+
- 原有旧版本的用户请查看[升级文档](/docs/update/)进行相应调整。

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.14
1+
2.4.0

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ allprojects {
1717
apply plugin: 'java'
1818
}
1919

20-
sourceCompatibility = 1.7
21-
targetCompatibility = 1.7
20+
sourceCompatibility = 1.8
21+
targetCompatibility = 1.8
2222

2323
dependencies {
2424
compile 'com.google.code.gson:gson:2.8.5'

docs/update/2.3-to-2.4.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# Upgrading to 2.4.* from 2.3.*
2+
3+
## Guidelines
4+
5+
### 1. RequestOptions
6+
7+
每个独立的请求可以使用特定的 API Key、App ID、私钥等配置。
8+
9+
#### 使用方法
10+
11+
初始化 `RequestOptions`
12+
13+
```java
14+
RequestOptions options = new RequestOptionsBuilder()
15+
.setApiKey("sk_test_ibbTe5jLGCi5rzfH4OqPW9KC")
16+
.setAppId("app_1Gqj58ynP0mHeX1q")
17+
.setPrivateKey("-----BEGIN PRIVATE KEY-----\n......\n-----END PRIVATE KEY-----")
18+
.setConnectTimeout(5000)
19+
.setReadTimeout(20000)
20+
.setAcceptLanguage("zh-CN")
21+
.setMaxNetworkRetries(2)
22+
.build();
23+
```
24+
25+
使用 `RequestOptions`
26+
27+
```java
28+
Map<String, Object> params = new HashMap<String, Object>();
29+
// 填充 params...
30+
Order order = Order.create(params, options);
31+
```
32+
33+
```java
34+
User user = User.retrieve("USER_ID", options);
35+
```
36+
37+
具体使用示例参考 [RequestOptionsTest.java](/src/test/java/com/pingplusplus/RequestOptionsTest.java)
38+
39+
### 2. API Key in method
40+
41+
原有方法中传 `API Key` 的方式都已经废弃,不能使用,请使用 `RequestOptions` 的方式。
42+
43+
涉及到以下方法:
44+
45+
```java
46+
Agreement.create(Map<String, Object> params, String apiKey)
47+
Agreement.retrieve(String id, String apiKey)
48+
Agreement.list(Map<String, Object> params, String apiKey)
49+
Agreement.cancel(String id, String apiKey)
50+
51+
BatchRefund.create(String apiKey, Map<String, Object>params)
52+
BatchRefund.retrieve(String id, String apiKey)
53+
BatchRefund.list(String apiKey, Map<String, Object> params)
54+
55+
BatchTransfer.create(String apiKey, Map<String, Object>params)
56+
BatchTransfer.retrieve(String id, String apiKey)
57+
BatchTransfer.list(String apiKey, Map<String, Object> params)
58+
BatchTransfer.update(String id, String apiKey, Map<String, Object> params)
59+
60+
CardInfo.query(Map<String, Object> params, String apiKey)
61+
62+
Charge.create(String apiKey, Map<String, Object> params)
63+
Charge.retrieve(String id, String apiKey)
64+
Charge.retrieve(String id, String apiKey, Map<String, Object> params)
65+
Charge.list(String apiKey, Map<String, Object> params)
66+
Charge.reverse(String id, String apiKey, Map<String, Object> params)
67+
Charge.reverse(String id, String apiKey)
68+
69+
charge.refunds.list(String apiKey, Map<String, Object> params)
70+
charge.refunds.retrieve(String id, String apiKey)
71+
charge.refunds.create(String apiKey, Map<String, Object> params)
72+
73+
Contact.create(Map<String, Object> params, String apiKey)
74+
75+
Customs.create(String apiKey, Map<String, Object> params)
76+
Customs.retrieve(String id, String apiKey)
77+
Customs.list(String apiKey, Map<String, Object> params)
78+
79+
Event.retrieve(String id, String apiKey)
80+
Event.retrieve(String id, String apiKey, Map<String, Object> params)
81+
82+
Identification.identify(String apiKey, Map<String, Object> params)
83+
84+
ProfitTransaction.retrieve(String id, String apiKey)
85+
ProfitTransaction.list(Map<String, Object> params, String apiKey)
86+
87+
RedEnvelope.create(String apiKey, Map<String, Object> params)
88+
RedEnvelope.retrieve(String id, String apiKey)
89+
RedEnvelope.retrieve(String id, String apiKey, Map<String, Object> params)
90+
RedEnvelope.list(String apiKey, Map<String, Object> params)
91+
92+
Refund.create(String charge, String apiKey, Map<String, Object> params)
93+
Refund.retrieve(String charge, String id, String apiKey)
94+
Refund.list(String charge, String apiKey, Map<String, Object>params)
95+
96+
Royalty.createData(String orderId, Map<String, Object> params, String apiKey)
97+
98+
SplitProfit.create(Map<String, Object> params, String apiKey)
99+
SplitProfit.retrieve(String id, String apiKey)
100+
SplitProfit.list(Map<String, Object> params, String apiKey)
101+
SplitReceiver.create(Map<String, Object> params, String apiKey)
102+
SplitReceiver.retrieve(String id, String apiKey)
103+
SplitReceiver.list(Map<String, Object> params, String apiKey)
104+
SplitReceiver.delete(String id, String apiKey)
105+
106+
SubBank.query(Map<String, Object> params, String apiKey)
107+
108+
Transfer.create(String apiKey, Map<String, Object> params)
109+
Transfer.retrieve(String id, String apiKey)
110+
Transfer.retrieve(String id, String apiKey, Map<String, Object> params)
111+
Transfer.list(String apiKey, Map<String, Object> params)
112+
113+
UserPic.upload(Map<String, Object> params, String apiKey)
114+
```
115+
116+
#### 替换示例
117+
118+
##### 示例 1
119+
120+
```java
121+
String apiKey = "YOUR_API_KEY";
122+
Agreement.create(params, apiKey);
123+
124+
// 替换成
125+
126+
String apiKey = "YOUR_API_KEY";
127+
RequestOptions options = new RequestOptionsBuilder().setApiKey(apiKey).build();
128+
Agreement.create(params, options);
129+
```
130+
131+
##### 示例 2
132+
133+
```java
134+
String apiKey = "YOUR_API_KEY";
135+
Charge.create(apiKey, params)
136+
137+
// 替换成
138+
139+
String apiKey = "YOUR_API_KEY";
140+
RequestOptions options = new RequestOptionsBuilder().setApiKey(apiKey).build();
141+
Charge.create(params, options);
142+
```
143+
144+
### 3. Exceptions
145+
146+
```java
147+
try {
148+
Charge.create(params);
149+
} catch (AuthenticationException e) {
150+
} catch (InvalidRequestException e) {
151+
} catch (APIConnectionException e) {
152+
} catch (APIException e) {
153+
} catch (ChannelException e) {
154+
} catch (RateLimitException e) {
155+
}
156+
```
157+
158+
改成
159+
160+
```java
161+
try {
162+
Charge.create(params);
163+
} catch (PingppException e) {
164+
// 如果要具体分是哪个 exception
165+
if (e instanceof InvalidRequestException) {
166+
InvalidRequestException ex = (InvalidRequestException) e;
167+
// 获取 error.code 字段(部分报错有)
168+
System.out.println(ex.getCode());
169+
// 获取请求的 HTTP Status Code
170+
System.out.println(ex.getStatusCode());
171+
// 获取 error.type 字段
172+
System.out.println(ex.getType));
173+
}
174+
// ...
175+
}
176+
```
177+
178+
### 4. Accept-Language
179+
180+
`Pingpp.AcceptLanguage` 改为 `Pingpp.acceptLanguage`
181+
182+
### 5. Private Key
183+
184+
废弃 `PKCS#1` 编码的私钥支持。
185+
186+
请使用 `PKCS#8` 编码的私钥。openssl 转换命令如下:
187+
188+
```shell
189+
openssl pkcs8 -topk8 -inform PEM -in pkcs1.pem -outform PEM -nocrypt -out pkcs8.pem
190+
```
191+
192+
### 6. getLastResponse
193+
194+
可以获取当前请求的 `response` 对象。
195+
196+
```java
197+
Charge charge = Charge.create(params);
198+
PingppResponse response = charge.getLastResponse();
199+
200+
// 获取响应的 HTTP Status Code
201+
int statusCode = response.getResponseCode();
202+
203+
// 获取响应的 Headers
204+
HttpHeaders headers = response.getResponseHeaders();
205+
206+
// 获取响应体
207+
String responseBody = response.getResponseBody()
208+
```

example/src/main/java/com/pingxx/example/BatchTransferExample.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,7 @@ public BatchTransfer create() {
8080
try {
8181
obj = BatchTransfer.create(params);
8282
System.out.println(obj);
83-
} catch (AuthenticationException e) {
84-
e.printStackTrace();
85-
} catch (InvalidRequestException e) {
86-
e.printStackTrace();
87-
} catch (APIConnectionException e) {
88-
e.printStackTrace();
89-
} catch (APIException e) {
90-
e.printStackTrace();
91-
} catch (ChannelException e) {
92-
e.printStackTrace();
93-
} catch (RateLimitException e) {
83+
} catch (PingppException e) {
9484
e.printStackTrace();
9585
}
9686
return obj;
@@ -107,17 +97,7 @@ public void retrieve(String id) {
10797
try {
10898
BatchTransfer obj = BatchTransfer.retrieve(id);
10999
System.out.println(obj);
110-
} catch (AuthenticationException e) {
111-
e.printStackTrace();
112-
} catch (InvalidRequestException e) {
113-
e.printStackTrace();
114-
} catch (APIConnectionException e) {
115-
e.printStackTrace();
116-
} catch (APIException e) {
117-
e.printStackTrace();
118-
} catch (ChannelException e) {
119-
e.printStackTrace();
120-
} catch (RateLimitException e) {
100+
} catch (PingppException e) {
121101
e.printStackTrace();
122102
}
123103
}
@@ -135,17 +115,7 @@ public void list() {
135115
try {
136116
BatchTransferCollection objs = BatchTransfer.list(param);
137117
System.out.println(objs);
138-
} catch (AuthenticationException e) {
139-
e.printStackTrace();
140-
} catch (InvalidRequestException e) {
141-
e.printStackTrace();
142-
} catch (APIConnectionException e) {
143-
e.printStackTrace();
144-
} catch (APIException e) {
145-
e.printStackTrace();
146-
} catch (ChannelException e) {
147-
e.printStackTrace();
148-
} catch (RateLimitException e) {
118+
} catch (PingppException e) {
149119
e.printStackTrace();
150120
}
151121
}

0 commit comments

Comments
 (0)