ClientSecretHelper.java 994 Bytes
/**
 * 
 */
package com.yoho.unions.helper;

import com.yoho.unions.interceptor.SecurityInterceptor;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
 * 描述:
 * 
 * @author ping.huang
 * 2016年4月1日
 */
@Component
public class ClientSecretHelper {

	@Resource
	SecurityInterceptor securityInterceptor;
	
	/**
	 * 生产client_secret
	 * @param map
	 */
	public String createClientSecret(Map<String, String> map) {
		if (MapUtils.isEmpty(map)) {
			return null;
		}
		map.put("v", "7");
		map.put("client_secret", securityInterceptor.getSign(map));
		List<String> list = new ArrayList<String>();
		for (Entry<String, String> entry : map.entrySet()) {
			list.add(entry.getKey() + "=" + entry.getValue());
		}
		return StringUtils.join(list, "&");
	}
}