Skip to content

Commit 8c7ed45

Browse files
committed
add clientId to AlipayClient
1 parent f8fcf6b commit 8c7ed45

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
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.25</version>
15+
<version>2.0.26</version>
1616
</dependency>
1717
```
1818

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.25</version>
7+
<version>2.0.26</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: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public abstract class BaseAlipayClient implements AlipayClient {
2929
* alipay public key
3030
*/
3131
private String alipayPublicKey;
32+
/**
33+
* client id
34+
*/
35+
private String clientId;
3236

3337
public BaseAlipayClient() {
3438
}
@@ -39,11 +43,18 @@ public BaseAlipayClient(String gatewayUrl, String merchantPrivateKey, String ali
3943
this.alipayPublicKey = alipayPublicKey;
4044
}
4145

46+
public BaseAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey, String clientId) {
47+
this.gatewayUrl = gatewayUrl;
48+
this.merchantPrivateKey = merchantPrivateKey;
49+
this.alipayPublicKey = alipayPublicKey;
50+
this.clientId = clientId;
51+
}
52+
4253
public <T extends AlipayResponse> T execute(AlipayRequest<T> alipayRequest) throws AlipayApiException {
4354

4455
checkRequestParam(alipayRequest);
4556

46-
String clientId = alipayRequest.getClientId();
57+
String clientId = alipayRequest.getClientId() == null ? this.clientId : alipayRequest.getClientId();
4758
String httpMethod = alipayRequest.getHttpMethod();
4859
String path = alipayRequest.getPath();
4960
Integer keyVersion = alipayRequest.getKeyVersion();
@@ -115,20 +126,18 @@ private String genSignValue(String httpMethod, String path, String clientId, Str
115126

116127
private boolean checkRspSign(String httpMethod, String path, String clientId, String responseTime, String rspBody, String rspSignValue) throws AlipayApiException {
117128
try {
118-
boolean isVerify = SignatureTool.verify(httpMethod, path, clientId, responseTime, rspBody, rspSignValue, alipayPublicKey);
119-
return isVerify;
129+
return SignatureTool.verify(httpMethod, path, clientId, responseTime, rspBody, rspSignValue, alipayPublicKey);
120130
} catch (Exception e) {
121131
throw new AlipayApiException(e);
122132
}
123-
124133
}
125134

126135
private void checkRequestParam(AlipayRequest alipayRequest) throws AlipayApiException {
127136
if (alipayRequest == null) {
128137
throw new AlipayApiException("alipayRequest can't null");
129138
}
130139

131-
String clientId = alipayRequest.getClientId();
140+
String clientId = alipayRequest.getClientId() == null ? this.clientId : alipayRequest.getClientId();
132141
String httpMethod = alipayRequest.getHttpMethod();
133142
String path = alipayRequest.getPath();
134143

@@ -141,7 +150,7 @@ private void checkRequestParam(AlipayRequest alipayRequest) throws AlipayApiExce
141150
}
142151

143152
if (StringUtils.isBlank(httpMethod)) {
144-
throw new AlipayApiException("httpMehod can't null");
153+
throw new AlipayApiException("httpMethod can't null");
145154
}
146155

147156
if (StringUtils.isBlank(path)) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public DefaultAlipayClient(String gatewayUrl, String merchantPrivateKey, String
1212
super(gatewayUrl, merchantPrivateKey, alipayPublicKey);
1313
}
1414

15+
public DefaultAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey, String clientId) {
16+
super(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId);
17+
}
18+
1519
@Override
1620
public Map<String, String> buildCustomHeader() {
1721
return null;

0 commit comments

Comments
 (0)