Skip to content

Commit 8845aa7

Browse files
authored
Merge pull request #27 from alipay/using_lombok
Using lombok
2 parents c991468 + f8fcf6b commit 8845aa7

File tree

140 files changed

+1382
-4547
lines changed

Some content is hidden

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

140 files changed

+1382
-4547
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ https://mvnrepository.com/artifact/com.alipay.global.sdk/global-open-sdk-java
1212
<dependency>
1313
<groupId>com.alipay.global.sdk</groupId>
1414
<artifactId>global-open-sdk-java</artifactId>
15-
<version>2.0.23</version>
15+
<version>2.0.25</version>
1616
</dependency>
1717
```
1818

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.alipay.global.sdk</groupId>
55
<artifactId>global-open-sdk-java</artifactId>
66
<packaging>jar</packaging>
7-
<version>2.0.23</version>
7+
<version>2.0.25</version>
88
<name>global-open-sdk-java</name>
99
<url>https://github.com/alipay/global-open-sdk-java</url>
1010
<description>
@@ -69,6 +69,13 @@
6969
<artifactId>fastjson</artifactId>
7070
<version>1.2.83</version>
7171
</dependency>
72+
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
73+
<dependency>
74+
<groupId>org.projectlombok</groupId>
75+
<artifactId>lombok</artifactId>
76+
<version>1.18.30</version>
77+
<scope>provided</scope>
78+
</dependency>
7279
</dependencies>
7380

7481
<build>

src/main/java/com/alipay/global/api/BaseAlipayClient.java

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
import com.alipay.global.api.request.AlipayRequest;
88
import com.alipay.global.api.response.AlipayResponse;
99
import com.alipay.global.api.tools.Constants;
10-
import com.alipay.global.api.tools.SignatureTool;
1110
import com.alipay.global.api.tools.DateTool;
11+
import com.alipay.global.api.tools.SignatureTool;
1212
import org.apache.commons.lang3.StringUtils;
1313

1414
import java.util.HashMap;
1515
import java.util.Map;
1616

17-
public abstract class BaseAlipayClient implements AlipayClient{
17+
public abstract class BaseAlipayClient implements AlipayClient {
1818

1919
private static final Integer DEFAULT_KEY_VERSION = 1;
2020
/**
21-
* eg:https://open-na.alipay.com
21+
* eg: https://open-na.alipay.com
2222
*/
23-
private String gatewayUrl;
23+
private String gatewayUrl;
2424
/**
2525
* merchants private key
2626
*/
@@ -30,10 +30,10 @@ public abstract class BaseAlipayClient implements AlipayClient{
3030
*/
3131
private String alipayPublicKey;
3232

33-
public BaseAlipayClient(){
33+
public BaseAlipayClient() {
3434
}
3535

36-
public BaseAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey ){
36+
public BaseAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey) {
3737
this.gatewayUrl = gatewayUrl;
3838
this.merchantPrivateKey = merchantPrivateKey;
3939
this.alipayPublicKey = alipayPublicKey;
@@ -43,12 +43,12 @@ public <T extends AlipayResponse> T execute(AlipayRequest<T> alipayRequest) thro
4343

4444
checkRequestParam(alipayRequest);
4545

46-
String clientId = alipayRequest.getClientId();
47-
String httpMethod = alipayRequest.getHttpMethod();
48-
String path = alipayRequest.getPath();
49-
Integer keyVersion = alipayRequest.getKeyVersion();
50-
String reqTime = DateTool.getCurrentTimeMillis();
51-
String reqBody = JSON.toJSONString(alipayRequest);
46+
String clientId = alipayRequest.getClientId();
47+
String httpMethod = alipayRequest.getHttpMethod();
48+
String path = alipayRequest.getPath();
49+
Integer keyVersion = alipayRequest.getKeyVersion();
50+
String reqTime = DateTool.getCurrentTimeMillis();
51+
String reqBody = JSON.toJSONString(alipayRequest);
5252

5353
/**
5454
* 对内容加签(Sign the content)
@@ -58,9 +58,9 @@ public <T extends AlipayResponse> T execute(AlipayRequest<T> alipayRequest) thro
5858
/**
5959
* 生成必要header(Generate required headers)
6060
*/
61-
Map<String, String> header = buildBaseHeader(reqTime, clientId, keyVersion, signValue);
61+
Map<String, String> header = buildBaseHeader(reqTime, clientId, keyVersion, signValue);
6262
Map<String, String> customHeader = buildCustomHeader();
63-
if(customHeader != null && customHeader.size() > 0){
63+
if (customHeader != null && !customHeader.isEmpty()) {
6464
header.putAll(customHeader);
6565
}
6666

@@ -70,33 +70,33 @@ public <T extends AlipayResponse> T execute(AlipayRequest<T> alipayRequest) thro
7070
*/
7171
HttpRpcResult rsp = sendRequest(requestUrl, httpMethod, header, reqBody);
7272

73-
if(rsp == null){
73+
if (rsp == null) {
7474
throw new AlipayApiException("HttpRpcResult is null.");
7575
}
7676

77-
int httpRespCode = rsp.getRspCode();
78-
String rspBody = rsp.getRspBody();
79-
if(httpRespCode != Constants.HTTP_SUCCESS_CODE){
77+
int httpRespCode = rsp.getRspCode();
78+
String rspBody = rsp.getRspBody();
79+
if (httpRespCode != Constants.HTTP_SUCCESS_CODE) {
8080
throw new AlipayApiException("Response data error, rspBody:" + rspBody);
8181
}
82-
Class<T> responseClass = alipayRequest.getResponseClass();
83-
T alipayResponse = JSON.parseObject(rspBody, responseClass);
84-
Result result = alipayResponse.getResult();
85-
if(result == null){
82+
Class<T> responseClass = alipayRequest.getResponseClass();
83+
T alipayResponse = JSON.parseObject(rspBody, responseClass);
84+
Result result = alipayResponse.getResult();
85+
if (result == null) {
8686
throw new AlipayApiException("Response data error, result field is null, rspBody:" + rspBody);
8787
}
8888

8989
String rspSignValue = rsp.getRspSign();
90-
String rspTime = rsp.getResponseTime();
91-
if(null == rspSignValue || rspSignValue.isEmpty() || null == rspTime || rspTime.isEmpty()){
90+
String rspTime = rsp.getResponseTime();
91+
if (null == rspSignValue || rspSignValue.isEmpty() || null == rspTime || rspTime.isEmpty()) {
9292
return alipayResponse;
9393
}
9494

9595
/**
9696
* 对返回结果验签(Verify the result signature)
9797
*/
9898
boolean isVerifySuccess = checkRspSign(httpMethod, path, clientId, rspTime, rspBody, rspSignValue);
99-
if(!isVerifySuccess){
99+
if (!isVerifySuccess) {
100100
throw new AlipayApiException("Response signature verify fail.");
101101
}
102102

@@ -113,84 +113,83 @@ private String genSignValue(String httpMethod, String path, String clientId, Str
113113
return signatureValue;
114114
}
115115

116-
private boolean checkRspSign(String httpMethod, String path, String clientId, String responseTime, String rspBody, String rspSignValue) throws AlipayApiException{
117-
try{
116+
private boolean checkRspSign(String httpMethod, String path, String clientId, String responseTime, String rspBody, String rspSignValue) throws AlipayApiException {
117+
try {
118118
boolean isVerify = SignatureTool.verify(httpMethod, path, clientId, responseTime, rspBody, rspSignValue, alipayPublicKey);
119119
return isVerify;
120-
} catch(Exception e){
120+
} catch (Exception e) {
121121
throw new AlipayApiException(e);
122122
}
123123

124124
}
125125

126-
private void checkRequestParam(AlipayRequest alipayRequest) throws AlipayApiException{
127-
if(alipayRequest == null){
126+
private void checkRequestParam(AlipayRequest alipayRequest) throws AlipayApiException {
127+
if (alipayRequest == null) {
128128
throw new AlipayApiException("alipayRequest can't null");
129129
}
130130

131131
String clientId = alipayRequest.getClientId();
132-
String httpMehod = alipayRequest.getHttpMethod();
132+
String httpMethod = alipayRequest.getHttpMethod();
133133
String path = alipayRequest.getPath();
134134

135-
if(StringUtils.isBlank(gatewayUrl)){
135+
if (StringUtils.isBlank(gatewayUrl)) {
136136
throw new AlipayApiException("gatewayUrl can't null");
137137
}
138138

139-
if(StringUtils.isBlank(clientId)){
139+
if (StringUtils.isBlank(clientId)) {
140140
throw new AlipayApiException("clientId can't null");
141141
}
142142

143-
if(StringUtils.isBlank(httpMehod)){
143+
if (StringUtils.isBlank(httpMethod)) {
144144
throw new AlipayApiException("httpMehod can't null");
145145
}
146146

147-
if(StringUtils.isBlank(path)){
147+
if (StringUtils.isBlank(path)) {
148148
throw new AlipayApiException("path can't null");
149149
}
150150

151-
if(!path.startsWith("/")){
151+
if (!path.startsWith("/")) {
152152
throw new AlipayApiException("path must start with /");
153153
}
154154

155155
}
156156

157-
private String genRequestUrl(String path){
158-
if(!gatewayUrl.startsWith("http://") && !gatewayUrl.startsWith("https://")){
157+
private String genRequestUrl(String path) {
158+
if (!gatewayUrl.startsWith("http://") && !gatewayUrl.startsWith("https://")) {
159159
gatewayUrl = "https://" + gatewayUrl;
160160
}
161-
if(gatewayUrl.endsWith("/")){
161+
if (gatewayUrl.endsWith("/")) {
162162
int len = gatewayUrl.length();
163163
gatewayUrl = gatewayUrl.substring(0, len - 1);
164164
}
165-
String requestUrl = gatewayUrl + path;
166-
return requestUrl;
165+
return gatewayUrl + path;
167166

168167
}
169168

170169
/**
171170
* Generate required headers
171+
*
172172
* @param requestTime
173173
* @param clientId
174174
* @param keyVersion
175175
* @param signatureValue
176176
* @return
177177
*/
178-
private Map<String,String> buildBaseHeader(String requestTime, String clientId, Integer keyVersion, String signatureValue){
178+
private Map<String, String> buildBaseHeader(String requestTime, String clientId, Integer keyVersion, String signatureValue) {
179179
Map<String, String> header = new HashMap<String, String>();
180180
header.put(Constants.CONTENT_TYPE_HEADER, "application/json; charset=UTF-8");
181181
header.put(Constants.REQ_TIME_HEADER, requestTime);
182182
header.put(Constants.CLIENT_ID_HEADER, clientId);
183-
if(keyVersion == null){
183+
if (keyVersion == null) {
184184
keyVersion = DEFAULT_KEY_VERSION;
185185
}
186186
String signatureHeader = "algorithm=RSA256,keyVersion=" + keyVersion + ",signature=" + signatureValue;
187187
header.put(Constants.REQ_SIGN_HEADER, signatureHeader);
188188
return header;
189189
}
190190

191-
public abstract Map<String,String> buildCustomHeader();
192-
193-
public abstract HttpRpcResult sendRequest(String requestUrl, String httpMethod, Map<String, String> header, String reqBody)throws AlipayApiException;
191+
public abstract Map<String, String> buildCustomHeader();
194192

193+
public abstract HttpRpcResult sendRequest(String requestUrl, String httpMethod, Map<String, String> header, String reqBody) throws AlipayApiException;
195194

196195
}

src/main/java/com/alipay/global/api/DefaultAlipayClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.alipay.global.api;
22

3-
import java.util.Map;
4-
53
import com.alipay.global.api.exception.AlipayApiException;
64
import com.alipay.global.api.net.DefaultHttpRPC;
75
import com.alipay.global.api.net.HttpRpcResult;
86

7+
import java.util.Map;
8+
99
public class DefaultAlipayClient extends BaseAlipayClient {
1010

1111
public DefaultAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey) {

src/main/java/com/alipay/global/api/example/PayNotifyListener.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@
1111

1212
public class PayNotifyListener {
1313

14-
public void acceptNotify(HttpRequest request, HttpResponse response){
14+
public void acceptNotify(HttpRequest request, HttpResponse response) {
1515

1616
InputStream inputStream = request.getInputStream();
17-
String reqBody = read(inputStream);
17+
String reqBody = read(inputStream);
1818

1919
PayNotifyRequest payNotifyRequest = JSON.parseObject(reqBody, PayNotifyRequest.class);
2020

21-
if(!PaymentNotifyType.PAYMENT_RESULT.equals(payNotifyRequest.getNotifyType())){
21+
if (!PaymentNotifyType.PAYMENT_RESULT.equals(payNotifyRequest.getNotifyType())) {
2222
return;
2323
}
24-
Result resultInfo = payNotifyRequest.getResultInfo();
24+
Result resultInfo = payNotifyRequest.getResultInfo();
2525
String paymentRequestId = payNotifyRequest.getPaymentRequestId();
2626
ResultStatusType resultStatus = resultInfo.getResultStatus();
2727

2828
boolean isAcceptSuccess = false;
29-
if(ResultStatusType.S.equals(resultStatus)){
29+
if (ResultStatusType.S.equals(resultStatus)) {
3030
// TODO Update the record status to success by paymentRequestId
3131
isAcceptSuccess = true;
32-
} else if(ResultStatusType.F.equals(resultStatus)){
32+
} else if (ResultStatusType.F.equals(resultStatus)) {
3333
// TODO Update the record status to fail by paymentRequestId
3434
isAcceptSuccess = true;
3535
} else {
3636
// TODO Notify exception, contact tech support
37-
return ;
37+
return;
3838
}
3939

40-
Result result = new Result("SUCCESS", "success", ResultStatusType.S);
41-
if(!isAcceptSuccess){
42-
result = new Result("PROCESS_FAIL", "failure", ResultStatusType.F);
40+
Result result = new Result("SUCCESS", ResultStatusType.S, "success");
41+
if (!isAcceptSuccess) {
42+
result = new Result("PROCESS_FAIL", ResultStatusType.F, "failure");
4343
}
4444
try {
4545
PayNotifyResponse payNotifyResponse = new PayNotifyResponse();
@@ -50,7 +50,7 @@ public void acceptNotify(HttpRequest request, HttpResponse response){
5050

5151
}
5252

53-
public String read(InputStream inputStream){
53+
public String read(InputStream inputStream) {
5454

5555
return null;
5656
}

src/main/java/com/alipay/global/api/example/RiskDecideDemoCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public static void buildRiskDecideRequest(RiskDecideRequest request) {
196196
buyer.setReferenceBuyerId("test12345678");
197197
buyer.setBuyerPhoneNo("12345678912");
198198
buyer.setBuyerEmail("[email protected]");
199-
buyer.setAccountVerified(true);
199+
buyer.setIsAccountVerified(true);
200200
buyer.setSuccessfulOrderCount(100);
201201
UserName buyerName = new UserName();
202202
buyerName.setFirstName("Dehua");

src/main/java/com/alipay/global/api/example/excutable/CashierExecutableDemoCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private static void cashierPay(){
9595

9696
// set auth capture payment mode
9797
PaymentFactor paymentFactor = new PaymentFactor();
98-
paymentFactor.setAuthorization(true);
98+
paymentFactor.setIsAuthorization(true);
9999
alipayPayRequest.setPaymentFactor(paymentFactor);
100100

101101
// replace to your notify url

src/main/java/com/alipay/global/api/example/excutable/CashierPayExecutableDemoCode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static void executePayWithCard() {
143143

144144
// set auth capture payment mode
145145
PaymentFactor paymentFactor = new PaymentFactor();
146-
paymentFactor.setAuthorization(true);
146+
paymentFactor.setIsAuthorization(true);
147147
alipayPayRequest.setPaymentFactor(paymentFactor);
148148

149149
// replace to your notify url
@@ -216,7 +216,7 @@ public static void executePayWithBlik() {
216216

217217
// set auth capture payment mode
218218
PaymentFactor paymentFactor = new PaymentFactor();
219-
paymentFactor.setAuthorization(true);
219+
paymentFactor.setIsAuthorization(true);
220220
alipayPayRequest.setPaymentFactor(paymentFactor);
221221

222222
// replace to your notify url
@@ -268,7 +268,7 @@ public static void executePaymentSessionCreateWithCard(){
268268

269269
// set auth capture payment mode
270270
PaymentFactor paymentFactor = new PaymentFactor();
271-
paymentFactor.setAuthorization(true);
271+
paymentFactor.setIsAuthorization(true);
272272
alipayPaymentSessionRequest.setPaymentFactor(paymentFactor);
273273

274274
// replace to your orderId

0 commit comments

Comments
 (0)