Skip to content

Commit 1af2286

Browse files
Merge branch 'master' into constant_design
# Conflicts: # README.md # pom.xml # src/main/java/com/alipay/global/api/model/constants/ProductSceneConstants.java
2 parents 9bb33bd + d6db45d commit 1af2286

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

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

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

3+
import java.util.Map;
4+
35
import com.alipay.global.api.exception.AlipayApiException;
46
import com.alipay.global.api.net.DefaultHttpRPC;
57
import com.alipay.global.api.net.HttpRpcResult;
68

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

11-
public DefaultAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey ){
11+
public DefaultAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey) {
1212
super(gatewayUrl, merchantPrivateKey, alipayPublicKey);
1313
}
1414

@@ -17,11 +17,11 @@ public Map<String, String> buildCustomHeader() {
1717
return null;
1818
}
1919

20-
public HttpRpcResult sendRequest(String requestUrl, String httpMethod, Map<String, String> header, String reqBody)throws AlipayApiException {
20+
public HttpRpcResult sendRequest(String requestUrl, String httpMethod, Map<String, String> header, String reqBody) throws AlipayApiException {
2121
HttpRpcResult httpRpcResult;
2222
try {
2323
httpRpcResult = DefaultHttpRPC.doPost(requestUrl, header, reqBody);
24-
} catch (Exception e){
24+
} catch (Exception e) {
2525
throw new AlipayApiException(e);
2626
}
2727
return httpRpcResult;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.alipay.global.api.tools;
2+
3+
import com.alipay.global.api.exception.AlipayApiException;
4+
5+
public class WebhookTool {
6+
7+
/**
8+
* Check webhook signature
9+
*
10+
* @param requestUri your webhook endpoint, domain part excluded, sample: /payNotify
11+
* @param httpMethod http method
12+
* @param clientId your clientId, sample: SANDBOX_5X00000000000000
13+
* @param requestTime requestTime from http header, sample: 2019-01-01T01:01:01Z
14+
* @param signature signature from http header, sample: algorithm=RSA256,keyVersion=1,signature=xxx
15+
* @param notifyBody notify body
16+
* @param alipayPublicKey alipay public key
17+
* @return
18+
* @throws AlipayApiException
19+
*/
20+
public static boolean checkSignature(String requestUri, String httpMethod, String clientId, String requestTime,
21+
String signature, String notifyBody, String alipayPublicKey) throws AlipayApiException {
22+
String realSignature = "";
23+
24+
// get valid part from raw signature
25+
if (signature == null || signature.isEmpty()) {
26+
throw new RuntimeException("empty notify signature");
27+
} else {
28+
String[] parts = signature.split("signature=");
29+
if (parts.length > 1) {
30+
realSignature = parts[1];
31+
}
32+
}
33+
34+
try {
35+
// verify signature
36+
return SignatureTool.verify(httpMethod, requestUri, clientId, requestTime, notifyBody, realSignature, alipayPublicKey);
37+
} catch (Exception e) {
38+
throw new AlipayApiException(e);
39+
}
40+
41+
}
42+
43+
}

0 commit comments

Comments
 (0)