Skip to content

Commit a99188e

Browse files
authored
Merge pull request #31 from alipay/adding_url_to_request
为请求对象设置path;使用lombok改写ams接口对象;
2 parents 928e5c3 + c05c67e commit a99188e

File tree

101 files changed

+1732
-4151
lines changed

Some content is hidden

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

101 files changed

+1732
-4151
lines changed

CHANGE.log

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,7 @@ add subscription params and constants
9999
add lombok support
100100

101101
29、Version:2.0.27
102-
add Checkout Payment Page support
102+
add Checkout Payment Page support
103+
104+
30、Version:2.0.29
105+
adding path to request, using lombok for ams api, update sample code

README.md

Lines changed: 7 additions & 10 deletions
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.28</version>
15+
<version>2.0.29</version>
1616
</dependency>
1717
```
1818

@@ -38,11 +38,10 @@ public static boolean verify(String httpMethod, String path, String clientId, St
3838
AMS:
3939

4040
```
41-
AlipayClient defaultAlipayClient = new DefaultAlipayClient("https://open-na.alipay.com", merchantPrivateKey, alipayPublicKey);
41+
AlipayClient CLIENT = new DefaultAlipayClient("https://open-na.alipay.com", merchantPrivateKey, alipayPublicKey, clientid);
4242
4343
AlipayPayRequest alipayPayRequest = new AlipayPayRequest();
4444
alipayPayRequest.setClientId("clientId");
45-
alipayPayRequest.setPath("/ams/api/v1/payments/pay");
4645
alipayPayRequest.setProductCode(ProductCodeType.CASHIER_PAYMENT);
4746
alipayPayRequest.setPaymentRequestId("pay_test_99");
4847
@@ -92,34 +91,32 @@ SettlementStrategy settlementStrategy = new SettlementStrategy();
9291
settlementStrategy.setSettlementCurrency("USD");
9392
alipayPayRequest.setSettlementStrategy(settlementStrategy);
9493
95-
AlipayPayResponse alipayPayResponse = defaultAlipayClient.execute(alipayPayRequest);
94+
AlipayPayResponse alipayPayResponse = CLIENT.execute(alipayPayRequest);
9695
9796
```
9897

9998
APS:
10099

101100
```
102-
AlipayClient defaultAlipayClient = new DefaultAlipayClient("https://open-na.alipay.com", merchantPrivateKey, alipayPublicKey);
101+
AlipayClient CLIENT = new DefaultAlipayClient("https://open-na.alipay.com", merchantPrivateKey, alipayPublicKey, clientid);
103102
104103
AlipayApsInquiryPaymentRequest inquiryPaymentRequest = new AlipayApsInquiryPaymentRequest();
105104
106-
inquiryPaymentRequest.setPath("/aps/api/v1/payments/inquiryPayment");
107105
inquiryPaymentRequest.setClientId("clientId");
108106
inquiryPaymentRequest.setPaymentId("20210518190796060008A0001628707");
109107
inquiryPaymentRequest.setPaymentRequestId("rtanhU9au6F3VEbvbVWRz");
110108
111-
AlipayApsInquiryPaymentResponse alipayResponse = defaultAlipayClient.execute(inquiryPaymentRequest);
109+
AlipayApsInquiryPaymentResponse alipayResponse = CLIENT.execute(inquiryPaymentRequest);
112110
113111
```
114112

115113
RISK:
116114

117115
```
118-
AlipayClient defaultAlipayClient = new DefaultAlipayClient("https://open-sea-global.alipay.com", merchantPrivateKey, alipayPublicKey);
116+
AlipayClient CLIENT = new DefaultAlipayClient("https://open-sea-global.alipay.com", merchantPrivateKey, alipayPublicKey, clientid);
119117
120118
RiskDecideRequest riskDecideRequest = new RiskDecideRequest();
121119
riskDecideRequest.setClientId("clietId");
122-
riskDecideRequest.setPath("/ams/api/v1/risk/payments/decide");
123120
riskDecideRequest.setReferenceTransactionId("test_referenceTransactionId");
124121
riskDecideRequest.setAuthorizationPhase(AuthorizationPhase.PRE_AUTHORIZATION);
125122
@@ -171,7 +168,7 @@ env.setTerminalType(TerminalType.APP);
171168
env.setOsType(OsType.IOS);
172169
riskDecideRequest.setEnv(env);
173170
174-
RiskDecideResponse response = defaultAlipayClient.execute(riskDecideRequest);
171+
RiskDecideResponse response = CLIENT.execute(riskDecideRequest);
175172
```
176173

177174
The execute method contains the HTTP request to the gateway.

pom.xml

Lines changed: 1 addition & 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.28</version>
7+
<version>2.0.29</version>
88
<name>global-open-sdk-java</name>
99
<url>https://github.com/alipay/global-open-sdk-java</url>
1010
<description>

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

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

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.apache.commons.lang3.StringUtils;
7+
38
import com.alibaba.fastjson.JSON;
9+
import com.alibaba.fastjson.serializer.SerializerFeature;
410
import com.alipay.global.api.exception.AlipayApiException;
511
import com.alipay.global.api.model.Result;
612
import com.alipay.global.api.net.HttpRpcResult;
@@ -9,10 +15,6 @@
915
import com.alipay.global.api.tools.Constants;
1016
import com.alipay.global.api.tools.DateTool;
1117
import com.alipay.global.api.tools.SignatureTool;
12-
import org.apache.commons.lang3.StringUtils;
13-
14-
import java.util.HashMap;
15-
import java.util.Map;
1618

1719
public abstract class BaseAlipayClient implements AlipayClient {
1820

@@ -75,7 +77,7 @@ public <T extends AlipayResponse> T execute(AlipayRequest<T> alipayRequest) thro
7577
String path = alipayRequest.getPath();
7678
Integer keyVersion = alipayRequest.getKeyVersion();
7779
String reqTime = DateTool.getCurrentTimeMillis();
78-
String reqBody = JSON.toJSONString(alipayRequest);
80+
String reqBody = JSON.toJSONString(alipayRequest, SerializerFeature.DisableCircularReferenceDetect);
7981

8082
/**
8183
* 对内容加签(Sign the content)
@@ -197,7 +199,7 @@ private String genRequestUrl(String path) {
197199
* @param alipayRequest
198200
*/
199201
private void adjustSandboxUrl(AlipayRequest alipayRequest) {
200-
if (isSandboxMode) {
202+
if (isSandboxMode && alipayRequest.usingSandboxUrl()) {
201203
String originPath = alipayRequest.getPath();
202204
alipayRequest.setPath(originPath.replaceFirst("/ams/api", "/ams/sandbox/api"));
203205
}

0 commit comments

Comments
 (0)