Search in sources :

Example 1 with JUtilString

use of j.util.JUtilString in project JFramework by gugumall.

the class Sample method createSign.

/**
 * @param key
 * @param parameters
 * @return
 */
public static String createSign(String key, ConcurrentMap parameters) {
    // 所有参数名
    List keys = parameters.listKeys();
    JUtilString sorter = new JUtilString();
    // 将参数名按字母排序,如  aac,aad,cac,f2v...
    keys = sorter.bubble(keys, JUtilSorter.ASC);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < keys.size(); i++) {
        // 按参数名的字母顺序拼接字符串
        String k = (String) keys.get(i);
        String v = (String) parameters.get(k);
        if (!"v".equals(k)) {
            // 不包括签名本身和无关参数
            sb.append(k + "=" + v + "&");
        }
    }
    // 通信秘钥
    sb.append("k=" + key);
    System.out.println(sb.toString());
    String sign = JUtilMD5.MD5EncodeToHex(sb.toString());
    return sign;
}
Also used : List(java.util.List) JUtilString(j.util.JUtilString) JUtilString(j.util.JUtilString)

Example 2 with JUtilString

use of j.util.JUtilString in project JFramework by gugumall.

the class DateUtil method createSign.

/**
 * @param key
 * @param parameters
 * @return
 */
public static String createSign(String key, ConcurrentMap parameters) {
    // 所有参数名
    List keys = parameters.listKeys();
    JUtilString sorter = new JUtilString();
    // 将参数名按字母排序,如  aac,aad,cac,f2v...
    keys = sorter.bubble(keys, JUtilSorter.ASC);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < keys.size(); i++) {
        // 按参数名的字母顺序拼接字符串
        String k = (String) keys.get(i);
        String v = (String) parameters.get(k);
        if (!"v".equals(k)) {
            // 不包括签名本身和无关参数
            sb.append(k + "=" + v + "&");
        }
    }
    // 通信秘钥
    sb.append("k=" + key);
    System.out.println(sb.toString());
    String sign = JUtilMD5.MD5EncodeToHex(sb.toString());
    return sign;
}
Also used : List(java.util.List) JUtilString(j.util.JUtilString) JUtilString(j.util.JUtilString)

Aggregations

JUtilString (j.util.JUtilString)2 List (java.util.List)2