package com.iamberry.wechat.tools;

import java.util.TreeMap;

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.appId);
		signatureParams.put("timestamp", timestamp);
		signatureParams.put("url", url);//当前页面链接
		signatureParams.put("accesstoken", access_token);//网页授权得到
		String s1 = TenpayUtil.getKeyValue(signatureParams);
		
		System.out.println(s1);
		
		String addrSign = Sha1Util.getSha2(s1);
		String json = "{\"nonceStr\":\"%s\",\"appId\":\"%s\",\"timeStamp\":\"%s\",\"addrSign\":\"%s\"}";
		json = String.format(json, nonceStr, NameUtils.appId, timestamp, addrSign);
		return json;
	}
	
	public static void main(String[] args) {
		TreeMap<String, String> signatureParams = new TreeMap<String, String>();
		signatureParams.put("noncestr", "123456");
		signatureParams.put("appid", "wx17ef1eaef46752cb");
		signatureParams.put("timestamp", "1384841012");
		signatureParams.put("url", "http://open.weixin.qq.com/");//当前页面链接
		signatureParams.put("accesstoken", "OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA");//网页授权得到
		String s1 = TenpayUtil.getKeyValue(signatureParams);
		System.out.println(s1);
		String addrSign = Sha1Util.getSha1(s1);
		String json = "{\"nonceStr\":\"%s\",\"appId\":\"%s\",\"timeStamp\":\"%s\",\"addrSign\":\"%s\"}";
		json = String.format(json, "123456", "wx17ef1eaef46752cb", "1384841012", addrSign);
		System.out.println(json);
	}
}
