mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨 优化部分代码
This commit is contained in:
parent
8467852c17
commit
0f8361e558
@ -25,11 +25,10 @@ import java.util.*;
|
||||
*/
|
||||
@Slf4j
|
||||
public class SignUtils {
|
||||
|
||||
/**
|
||||
* 签名的时候不携带的参数
|
||||
*/
|
||||
private static List<String> NO_SIGN_PARAMS = Lists.newArrayList("sign", "key", "xmlString", "xmlDoc", "couponList");
|
||||
private static final List<String> NO_SIGN_PARAMS = Lists.newArrayList("sign", "key", "xmlString", "xmlDoc", "couponList");
|
||||
|
||||
/**
|
||||
* 请参考并使用 {@link #createSign(Object, String, String, String[])}.
|
||||
@ -89,10 +88,8 @@ public class SignUtils {
|
||||
* @return 签名字符串 string
|
||||
*/
|
||||
public static String createSign(Map<String, String> params, String signType, String signKey, String[] ignoredParams) {
|
||||
SortedMap<String, String> sortedMap = new TreeMap<>(params);
|
||||
|
||||
StringBuilder toSign = new StringBuilder();
|
||||
for (String key : sortedMap.keySet()) {
|
||||
for (String key : new TreeMap<>(params).keySet()) {
|
||||
String value = params.get(key);
|
||||
boolean shouldSign = false;
|
||||
if (StringUtils.isNotEmpty(value) && !ArrayUtils.contains(ignoredParams, key)
|
||||
@ -121,7 +118,7 @@ public class SignUtils {
|
||||
public static String createEntSign(String actName, String mchBillNo, String mchId, String nonceStr,
|
||||
String reOpenid, Integer totalAmount, String wxAppId, String signKey,
|
||||
String signType) {
|
||||
Map<String, String> sortedMap = new HashMap<>();
|
||||
Map<String, String> sortedMap = new HashMap<>(8);
|
||||
sortedMap.put("act_name", actName);
|
||||
sortedMap.put("mch_billno", mchBillNo);
|
||||
sortedMap.put("mch_id", mchId);
|
||||
@ -130,21 +127,18 @@ public class SignUtils {
|
||||
sortedMap.put("total_amount", totalAmount + "");
|
||||
sortedMap.put("wxappid", wxAppId);
|
||||
|
||||
Map<String, String> sortParams = new TreeMap<>(sortedMap);
|
||||
Set<Map.Entry<String, String>> entries = sortParams.entrySet();
|
||||
Iterator<Map.Entry<String, String>> iterator = entries.iterator();
|
||||
Iterator<Map.Entry<String, String>> iterator = new TreeMap<>(sortedMap).entrySet().iterator();
|
||||
StringBuilder toSign = new StringBuilder();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry entry = iterator.next();
|
||||
String key = String.valueOf(entry.getKey());
|
||||
String value = String.valueOf(entry.getValue());
|
||||
Map.Entry<String, String> entry = iterator.next();
|
||||
String value = entry.getValue();
|
||||
boolean shouldSign = false;
|
||||
if (StringUtils.isNotEmpty(value)) {
|
||||
shouldSign = true;
|
||||
}
|
||||
|
||||
if (shouldSign) {
|
||||
toSign.append(key).append("=").append(value).append("&");
|
||||
toSign.append(entry.getKey()).append("=").append(value).append("&");
|
||||
}
|
||||
}
|
||||
//企业微信这里字段名不一样
|
||||
|
Loading…
Reference in New Issue
Block a user