package com.library.test;

import com.library.util.ClientInternet;
import com.library.util.Tools;
import com.wechat.pay.WeChatManager;


public class TTTTTTTTTT {
	public static void main(String[] args) {
//		SettingCatelog();
		
		String con=WeChatManager.ShortUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8fe9657eb40e99f&redirect_uri=http%3a%2f%2fsziit.cn.com%2fFirstService%2fUserController%2fwechat_LoginRegist.do&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect");
		//{"errcode":0,"errmsg":"ok","short_url":"http:\/\/w.url.cn\/s\/ATdm0Jn"}
		System.out.println(con);
		
	}
	

	
	
	/**
	 * 使用模板发送信息给用户
	 */
	public static void SendTemplate(){
		String access_token="nUiX4WS-A49aIBphYvi7ajOfaR5cg5WQbLBCIbkzA1wa2-lRRJMFF67WrFuCmN-LsB43GLdI2s2Oq9EUMzRcV_16hyEsFwyplqB9_AMx_boIOSdAJAQWA";
		String urlConnect="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
		String touser_OPENID="oFLvmwwNe0AqRF1T8vTCmrhzt_fk";//用户的ID
		String template_id="m1nvLL2f70mXksKY3-5EhG5oXfumno-_pyTtTHkO7hQ";//模板ID
		String url="https://www.baidu.com/";//点击后跳转的地址
		String first="新英雄出场了";//
		String keyword1="乐享英雄推送";//
		String keyword2="瑞雯已死，取代它的是谁呢！";//
		String keyword3="2015-08-21 11：00";//
		String keyword4="2015-08-21 11：00";//
		String remark="记得去看看喔！（取消本类型消息订阅，请到个人中心！）";//
		String json=CreatJSON(touser_OPENID, template_id, url, first, keyword1, keyword2, keyword3, keyword4,remark);
		String res=ClientInternet.OpearConnect(urlConnect, null, json);
		System.out.println(res);
	}

	/**
	 * 组成模板的JSON数据
	 */
	public static String CreatJSON(String touser_OPENID,String template_id,String url,String first,String keyword1,String keyword2,String keyword3,String keyword4,String remark){
		return "{\"touser\":\""+touser_OPENID+"\", \"template_id\":\""+template_id+"\",\"url\":\""+url+"\","+           
		           "\"data\":{\"first\": {\"value\":\""+first+"\",\"color\":\"#173177\"},\"keyword1\":{\"value\":\""+keyword1+"\", \"color\":\"#173177\"},"+
	               "\"keyword2\": {\"value\":\""+keyword2+"\",\"color\":\"#173177\"},\"keyword3\": {\"value\":\""+keyword3+"\",\"color\":\"#173177\"},"+
	               "\"keyword4\": {\"value\":\""+keyword4+"\",\"color\":\"#173177\"},"+
	                "\"remark\":{\"value\":\""+remark+"\",\"color\":\"#173177\"}}}";
	}
	
	/**
	 * 微信公众号的菜单
	 */
	public static void SettingCatelog(){
		String ACCESS_TOKEN="lhwHmctlDHr0eRmK5FJKlWJBCTzXgxpM1_otJ6W6TZSsqcOyaEa83ttcj1s3RPe2UbKEzgDC3jWi2F1q8wJ7fX7HQlqs7Nb96dm3Sh1U6MWjHkQyrYAu5d2_Idh97yN4GYQfABAOGY";
		String address="https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+WeChatManager.GetAccess_token();
		
		
		String url=Tools.getAddress("go3");//我的
		String about=Tools.getAddress("go4");//关于我们
		
		String http2=Tools.getAddress("go1");//商家
		String store1=Tools.getAddress("go2");//地图查看
		String recovery1=Tools.getAddress("go6");//首页
		String post="{\"button\":[{\"name\":\"汽车服务\", \"sub_button\":["+
           "{\"type\":\"view\",\"name\":\"商家\",\"url\":\""+http2+"\" },"+
            "{\"type\":\"view\", \"name\":\"首页\",\"url\":\""+recovery1+"\" },"+
            "{\"type\":\"view\", \"name\":\"地图查看\",\"url\":\""+store1+"\" }] },"+
           
            
            "{ \"name\":\"菜单\", \"sub_button\":["+
           "{\"type\":\"view\",\"name\":\" 我的\",\"url\":\""+url+"\" },"+
            "{\"type\":\"view\", \"name\":\"关于我们\",\"url\":\""+about+"\" }]}]}";
		String ress2=ClientInternet.OpearConnect(address, null, post);
		System.out.println(ress2);
	}
	

	
	/**
	 * 获取用户的信息
	 * {"subscribe":1,"openid":"o5ZsSuBd4skx6-WWOptFnV_yAh0k","nickname":"自由人。","sex":2,"language":"zh_CN","city":"","province":"法兰克福","country":"德国","headimgurl":"http:\/\/wx.qlogo.cn\/mmopen\/PiajxSqBRaELpXUTV9kXUvRux4cqlkFARaibpqp3yfldea0EYaSqibOZrKica06NSsUxbyxEVV5bA5nzjWBIibAL4mQ\/0","subscribe_time":1441625404,"remark":"","groupid":0,"tagid_list":[]}

	 */
	public static void GetUserInfo(){
		String ACCESS_TOKEN="rIUQEOBP1f5Ho43CiC1yO8TPh7JVWFWLrkd9bH537mjc1tuew66s8A_YteHazuBi3xK5ZBS8KWTNa7LLZ1bJmeWWjCqMWOHp3Qo_QYPzHd3KNVKcNY80-m4XYLtf69ZyYMSjADAQEK";
		String address="https://api.weixin.qq.com/cgi-bin/user/info?access_token="+ACCESS_TOKEN+"&openid=o5ZsSuBd4skx6-WWOptFnV_yAh0k&lang=zh_CN";
		String ress2=ClientInternet.OpearConnect(address, null, "");
		System.out.println(ress2);
	}
	
	/**
	 * 批量获取用户openid
 		"o5ZsSuBd4skx6-WWOptFnV_yAh0k",
            "o5ZsSuDdf7qHr5pk7xaPwZpgIO_o",
            "o5ZsSuOGwaOLbIylotEJ5AmI7Yro",
            "o5ZsSuKrPff8Hz8SvUQEIHQ08sE8",
            "o5ZsSuMAI8j_l7h5XR5-VMsdeGa4",
	 */
	public static void GetUserID(){
		String access_token="rIUQEOBP1f5Ho43CiC1yO8TPh7JVWFWLrkd9bH537mjc1tuew66s8A_YteHazuBi3xK5ZBS8KWTNa7LLZ1bJmeWWjCqMWOHp3Qo_QYPzHd3KNVKcNY80-m4XYLtf69ZyYMSjADAQEK";
		String address="https://api.weixin.qq.com/cgi-bin/user/get?access_token="+access_token+"&next_openid=";
		String ress2=ClientInternet.OpearConnect(address, null, "");
		System.out.println(ress2);
	}
	
	/**
	 * 获得用户的access_token
	 *{"access_token":"olm2_doKsX5DYZkZaO9cEOu8Gd7JVkp2wLyPW47LHpHrjKIi0pTY1E2Ie14O2BGoXlku2eKw96pcykXYjOflk8VTHqPyeE0m1zPMtWmnD01JfPi8eNfQh0JtO6eHjyVjNHNcAJAVPV","expires_in":7200}
*/
	public static void GetAccess_token(){
		String address="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxb8fe9657eb40e99f&secret=cf17339fe2c09f8e92bfdcbfb5274042";
		String ress2=ClientInternet.OpearConnect(address, null, "");
		System.out.println(ress2);
	}
}
