-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from buession/development
Release 2.3.1
- Loading branch information
Showing
31 changed files
with
384 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
* +-------------------------------------------------------------------------------------------------------+ | ||
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt | | ||
* | Author: Yong.Teng <[email protected]> | | ||
* | Copyright @ 2013-2022 Buession.com Inc. | | ||
* | Copyright @ 2013-2023 Buession.com Inc. | | ||
* +-------------------------------------------------------------------------------------------------------+ | ||
*/ | ||
package com.buession.security.captcha.aliyun; | ||
|
@@ -35,8 +35,6 @@ | |
import java.io.UnsupportedEncodingException; | ||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
|
@@ -69,15 +67,15 @@ class AliyunParametersBuilder implements ParametersBuilder<AliYunRequestData> { | |
private final AliYunCaptchaClient client; | ||
|
||
AliyunParametersBuilder(final String accessKeyId, final String accessKeySecret, final String appKey, | ||
final AliYunCaptchaClient client){ | ||
final AliYunCaptchaClient client) { | ||
this.accessKeyId = accessKeyId; | ||
this.accessKeySecret = accessKeySecret; | ||
this.appKey = appKey; | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public Map<String, String> build(final AliYunRequestData requestData){ | ||
public Map<String, String> build(final AliYunRequestData requestData) { | ||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); | ||
Date date = new Date(); | ||
|
||
|
@@ -89,11 +87,8 @@ public Map<String, String> build(final AliYunRequestData requestData){ | |
.put("SignatureVersion", SIGNATURE_VERSION).put("AccessKeyId", accessKeyId) | ||
.put("AppKey", appKey).put("Timestamp", sdf.format(date)).put("Token", requestData.getToken()) | ||
.put("Sig", requestData.getSig()).put("SessionId", requestData.getSessionId()) | ||
.put("Scene", requestData.getScene()); | ||
|
||
if(requestData.getClientIp() != null){ | ||
builder.put("RemoteIp", requestData.getClientIp()); | ||
} | ||
.put("Scene", requestData.getScene()) | ||
.putIfPresent("RemoteIp", requestData.getClientIp()); | ||
|
||
Map<String, String> parameters = builder.build(); | ||
|
||
|
@@ -102,15 +97,11 @@ public Map<String, String> build(final AliYunRequestData requestData){ | |
return parameters; | ||
} | ||
|
||
protected static String randomStr(final Date date){ | ||
final StringBuilder sb = new StringBuilder(20); | ||
|
||
sb.append(StringUtils.random(7)).append('_').append(date.getTime()); | ||
|
||
return sb.toString(); | ||
protected static String randomStr(final Date date) { | ||
return StringUtils.random(7) + '_' + date.getTime(); | ||
} | ||
|
||
protected static String percentEncode(final String value){ | ||
protected static String percentEncode(final String value) { | ||
try{ | ||
return value != null ? URLEncoder.encode(value, "UTF-8").replace("+", "%20").replace("*", "%2A") | ||
.replace("%7E", "~") : null; | ||
|
@@ -119,7 +110,7 @@ protected static String percentEncode(final String value){ | |
} | ||
} | ||
|
||
protected static String signature(final String signKey, final Map<String, String> parameters){ | ||
protected static String signature(final String signKey, final Map<String, String> parameters) { | ||
String[] sortedKeys = parameters.keySet().toArray(new String[0]); | ||
Arrays.sort(sortedKeys); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
* +-------------------------------------------------------------------------------------------------------+ | ||
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt | | ||
* | Author: Yong.Teng <[email protected]> | | ||
* | Copyright @ 2013-2022 Buession.com Inc. | | ||
* | Copyright @ 2013-2023 Buession.com Inc. | | ||
* +-------------------------------------------------------------------------------------------------------+ | ||
*/ | ||
package com.buession.security.captcha.geetest.api.v3; | ||
|
@@ -41,34 +41,28 @@ class GeetestV3ParametersBuilder implements ParametersBuilder<GeetestV3RequestDa | |
|
||
private final String sdkName; | ||
|
||
GeetestV3ParametersBuilder(final String appId, final String secretKey, final String sdkName){ | ||
GeetestV3ParametersBuilder(final String appId, final String secretKey, final String sdkName) { | ||
this.appId = appId; | ||
this.secretKey = secretKey; | ||
this.sdkName = sdkName; | ||
} | ||
|
||
@Override | ||
public Map<String, String> build(final GeetestV3RequestData requestData){ | ||
public Map<String, String> build(final GeetestV3RequestData requestData) { | ||
MapBuilder<String, String> builder = MapBuilder.<String, String>create(9) | ||
.put("captchaid", appId) | ||
.put("challenge", requestData.getChallenge()) | ||
.put("validate", requestData.getValidate()) | ||
.put("seccode", requestData.getSeccode()) | ||
.put("json_format", "1") | ||
.put("sdk", sdkName); | ||
|
||
if(requestData.getUserId() != null){ | ||
builder.put("user_id", requestData.getUserId()); | ||
} | ||
.put("sdk", sdkName) | ||
.putIfPresent("user_id", requestData.getUserId()) | ||
.putIfPresent("ip_address", requestData.getIpAddress()); | ||
|
||
if(requestData.getClientType() != null){ | ||
builder.put("client_type", requestData.getClientType().getValue()); | ||
} | ||
|
||
if(requestData.getIpAddress() != null){ | ||
builder.put("ip_address", requestData.getIpAddress()); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
* +-------------------------------------------------------------------------------------------------------+ | ||
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt | | ||
* | Author: Yong.Teng <[email protected]> | | ||
* | Copyright @ 2013-2022 Buession.com Inc. | | ||
* | Copyright @ 2013-2023 Buession.com Inc. | | ||
* +-------------------------------------------------------------------------------------------------------+ | ||
*/ | ||
package com.buession.security.captcha.tencent; | ||
|
@@ -39,22 +39,19 @@ class TencentParametersBuilder implements ParametersBuilder<TencentRequestData> | |
|
||
private final String secretKey; | ||
|
||
TencentParametersBuilder(final String secretId, final String secretKey){ | ||
TencentParametersBuilder(final String secretId, final String secretKey) { | ||
this.secretId = secretId; | ||
this.secretKey = secretKey; | ||
} | ||
|
||
@Override | ||
public Map<String, String> build(final TencentRequestData requestData){ | ||
public Map<String, String> build(final TencentRequestData requestData) { | ||
MapBuilder<String, String> builder = MapBuilder.<String, String>create(5) | ||
.put("aid", secretId) | ||
.put("AppSecretKey", secretKey) | ||
.put("Ticket", requestData.getTicket()) | ||
.put("Randstr", requestData.getRandstr()); | ||
|
||
if(requestData.getClientIp() != null){ | ||
builder.put("UserIP", requestData.getClientIp()); | ||
} | ||
.put("Randstr", requestData.getRandstr()) | ||
.putIfPresent("UserIP", requestData.getClientIp()); | ||
|
||
return builder.build(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.