@@ -29,6 +29,10 @@ public abstract class BaseAlipayClient implements AlipayClient {
29
29
* alipay public key
30
30
*/
31
31
private String alipayPublicKey ;
32
+ /**
33
+ * client id
34
+ */
35
+ private String clientId ;
32
36
33
37
public BaseAlipayClient () {
34
38
}
@@ -39,11 +43,18 @@ public BaseAlipayClient(String gatewayUrl, String merchantPrivateKey, String ali
39
43
this .alipayPublicKey = alipayPublicKey ;
40
44
}
41
45
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
+
42
53
public <T extends AlipayResponse > T execute (AlipayRequest <T > alipayRequest ) throws AlipayApiException {
43
54
44
55
checkRequestParam (alipayRequest );
45
56
46
- String clientId = alipayRequest .getClientId ();
57
+ String clientId = alipayRequest .getClientId () == null ? this . clientId : alipayRequest . getClientId () ;
47
58
String httpMethod = alipayRequest .getHttpMethod ();
48
59
String path = alipayRequest .getPath ();
49
60
Integer keyVersion = alipayRequest .getKeyVersion ();
@@ -115,20 +126,18 @@ private String genSignValue(String httpMethod, String path, String clientId, Str
115
126
116
127
private boolean checkRspSign (String httpMethod , String path , String clientId , String responseTime , String rspBody , String rspSignValue ) throws AlipayApiException {
117
128
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 );
120
130
} catch (Exception e ) {
121
131
throw new AlipayApiException (e );
122
132
}
123
-
124
133
}
125
134
126
135
private void checkRequestParam (AlipayRequest alipayRequest ) throws AlipayApiException {
127
136
if (alipayRequest == null ) {
128
137
throw new AlipayApiException ("alipayRequest can't null" );
129
138
}
130
139
131
- String clientId = alipayRequest .getClientId ();
140
+ String clientId = alipayRequest .getClientId () == null ? this . clientId : alipayRequest . getClientId () ;
132
141
String httpMethod = alipayRequest .getHttpMethod ();
133
142
String path = alipayRequest .getPath ();
134
143
@@ -141,7 +150,7 @@ private void checkRequestParam(AlipayRequest alipayRequest) throws AlipayApiExce
141
150
}
142
151
143
152
if (StringUtils .isBlank (httpMethod )) {
144
- throw new AlipayApiException ("httpMehod can't null" );
153
+ throw new AlipayApiException ("httpMethod can't null" );
145
154
}
146
155
147
156
if (StringUtils .isBlank (path )) {
0 commit comments