MD5签名问题

签名传入的参数中包含数组类型的参数,String[] xy = new String[]{”116.288418”, “39.832535”}; 加密过程中需要转换为字符串Arrays.toString(xy)

 public static Map<String, Object> addCommonParams(Map<String, Object> reqMap,Object object){
        if(object instanceof PXOrderInfoDTO){
            PXOrderInfoDTO vo = (PXOrderInfoDTO)object;
            reqMap.put("imei", vo.getImei());
            reqMap.put("version", vo.getVersion());
            reqMap.put("platform", vo.getPlatform());
            reqMap.put("ch", vo.getCh());
            reqMap.put("app_id", vo.getApp_id());
            reqMap.put("client_id", vo.getClient_id());
            reqMap.put("timestamp", vo.getTimestamp());
            reqMap.put("token", vo.getToken1());
        }else if(object instanceof PXRequestVO){
            PXRequestVO vo = (PXRequestVO)object;
            reqMap.put("imei", vo.getImei());
            reqMap.put("version", vo.getVersion());
            reqMap.put("platform", vo.getPlatform());
            reqMap.put("ch", vo.getCh());
            reqMap.put("app_id", vo.getApp_id());
            reqMap.put("client_id", vo.getClient_id());
            reqMap.put("timestamp", vo.getTimestamp());
            reqMap.put("token", vo.getToken1());
        }
        return reqMap;
    }
    
    /**
     * 验证码验证签名
     * @param paramsMap
     * @return
     */
    public static String sign (Map<String, Object> paramsMap){
        paramsMap.put("clinetSecret", "54e4b395976c872d65ce71216fc0fefb");
        paramsMap.remove("sign");
        List<String> keys = new ArrayList<String>(paramsMap.keySet());
        Collections.sort(keys);
        List<String> keyValueList = new ArrayList<String>();
        for (String key : keys) {
            Object value = paramsMap.get(key);
            if (value != null) {
                keyValueList.add(key + "=" + value);
            }
        }
        String queryString="";
        for(String obj :keyValueList){
            queryString+=obj+"&";
        }
        log.info("加密参数串:"+queryString.substring(0,queryString.length()-1));
        String sign = PxMD5Util.getMD5Str(queryString.substring(0,queryString.length()-1));
        return sign;
    }

 

posted @ 2018-08-01 12:31  华格瑞沙  阅读(709)  评论(0编辑  收藏  举报