提交 | 用户 | age
|
5c5945
|
1 |
package com.hx.mp.util; |
E |
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
import java.util.Map; |
|
5 |
import java.util.Set; |
|
6 |
import java.util.SortedMap; |
|
7 |
|
|
8 |
public class WXSignUtils { |
|
9 |
/** |
|
10 |
* 微信支付签名算法sign |
|
11 |
* @param characterEncoding |
|
12 |
* @param parameters |
|
13 |
* @return |
|
14 |
*/ |
|
15 |
@SuppressWarnings("rawtypes") |
|
16 |
public static String createSign(String characterEncoding, SortedMap<Object,Object> parameters, String key){ |
|
17 |
StringBuffer sb = new StringBuffer(); |
|
18 |
Set es = parameters.entrySet();//所有参与传参的参数按照accsii排序(升序) |
|
19 |
Iterator it = es.iterator(); |
|
20 |
while(it.hasNext()) { |
|
21 |
Map.Entry entry = (Map.Entry)it.next(); |
|
22 |
String k = (String)entry.getKey(); |
|
23 |
Object v = entry.getValue(); |
|
24 |
if(null != v && !"".equals(v) |
|
25 |
&& !"sign".equals(k) && !"key".equals(k)) { |
|
26 |
sb.append(k + "=" + v + "&"); |
|
27 |
} |
|
28 |
} |
|
29 |
sb.append("key=" + key); |
|
30 |
String sign = MD5Util.MD5Encode(sb.toString(), characterEncoding).toUpperCase(); |
|
31 |
return sign; |
|
32 |
} |
|
33 |
} |