package com.iamberry.wechat.tools;

import java.util.TreeMap;
/**
 * 微信1.0网页地址授权工具类
 * @company	深圳爱贝源科技有限公司
 * @website www.iamberry.com
 * @author 	献
 * @tel		18271840547
 * @date	2017年2月22日
 */
public class AddrUtil {

	public static String getAddress(String url, String access_token){
		String nonceStr = Sha1Util.getNonceStr(); 
		String timestamp = Sha1Util.getTimeStamp();
		TreeMap<String, String> signatureParams = new TreeMap<String, String>();
		signatureParams.put("noncestr", nonceStr);
		signatureParams.put("appid", NameUtils.getConfig("appId"));
		signatureParams.put("timestamp", timestamp);
		signatureParams.put("url", url);//当前页面链接
		signatureParams.put("accesstoken", access_token);//网页授权得到
		String s1 = TenpayUtil.getKeyValue(signatureParams);
		String addrSign = Sha1Util.getSha1(s1);
		String json = "{\"nonceStr\":\"%s\",\"appId\":\"%s\",\"timeStamp\":\"%s\",\"addrSign\":\"%s\"}";
		json = String.format(json, nonceStr, NameUtils.getConfig("appId"), timestamp, addrSign);
		return json;
	}
}
