package com.izouma.agpay.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class MessageUtil {

	public static String getSignStr(String body) {
		JSONObject jsonObject = JSON.parseObject(body);
		Set<Map.Entry<String, Object>> entries = jsonObject.entrySet();
		TreeMap<String, Object> map = new TreeMap<String, Object>();
		for (Map.Entry<String, Object> entry : entries) {
			map.put(entry.getKey(), entry.getValue());
		}
		if (map.size() == 0) {
			//这个……，比较蛋疼等有在优化吧，如果有时间的话
			map.put("emptybody", "emptybodysignvalue");
		}
		StringBuffer buf = new StringBuffer();
		for (String key : map.keySet()) {
			buf.append(key).append("=").append((String) map.get(key)).append("&");
		}
		return buf.toString();
	}
}
