package com.wechat.pay;

import java.sql.Timestamp;

import com.library.util.ClientInternet;
import com.library.util.Tools;


/**
 * 发送信息通知给用户
 * @author Administrator
 *
 */
public class SendMessageTool {
	
	public static void main(String[] args) {
		//SendToAdminByOrders();
	}
	

	
	/**
	 * 订单进度提醒-发送用户
	 */
	public static void SendToUser(String touser_OPENID,String title,String order_number,String id,String time,String shopName,String price,String shoppingInfo){
		String access_token=WeChatManager.GetAccess_token();
		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="P2ZzKfn-6c_FgOEcdvmmfnjEX08lwXgqpsvdYxY181k";//模板ID
//		String url="http://sziit.cn.com/FirstService/wechatpublic/my.html";//点击后跳转的地址
		String url=Tools.getAddress("go5_"+id);
		//		String first="新英雄出场了";//
//		String order_number="乐享英雄推送";//
//		String order_content="瑞雯已死，取代它的是谁呢！";//
//		String order_State="2015-08-21 11：00";//
		String remark="感谢您的使用。";//
		String json=SendToUser_CreatJSON(touser_OPENID, template_id, url, title, order_number, time, shopName, price,shoppingInfo,remark);
		String res=ClientInternet.OpearConnect(urlConnect, null, json);
		System.out.println(res);
	}
	

	/**
	 * 订单进度提醒-发送用户
	 */
	public static void TestSendToUser(){
		String access_token=WeChatManager.GetAccess_token();
		String urlConnect="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
		String touser_OPENID="oaccFxAXlQWqGOFwflx9jWGVqxlU";//用户的ID
		String template_id="P2ZzKfn-6c_FgOEcdvmmfnjEX08lwXgqpsvdYxY181k";//模板ID
		String url="http://sziit.cn.com/FirstService/wechatpublic/my.html";//点击后跳转的地址
		String first="尊敬的客户，您已成功下单。";//
		String keyword1="订单号";//
		String keyword2="2017-01-01";//
		String keyword3="上海市虹梅路店";//
		String keyword4="68元";//
		String keyword5="精洗";//
		String remark="感谢您的使用。";//
		String json=SendToUser_CreatJSON(touser_OPENID, template_id, url, first, keyword1, keyword2, keyword3,keyword4, keyword5, remark);
		String res=ClientInternet.OpearConnect(urlConnect, null, json);
		System.out.println(res);
	}

	/**
	 * 组成模板的JSON数据-订单进度提醒
	 */
	public static String SendToUser_CreatJSON(String touser_OPENID,String template_id,String url,String first,String keyword1,String keyword2,String keyword3
			,String keyword4,String keyword5,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\"},\"keyword5\": {\"value\":\""+keyword5+"\",\"color\":\"#173177\"},"+
	                "\"remark\":{\"value\":\""+remark+"\",\"color\":\"#173177\"}}}";
	}
	
	

	/**
	 * 用户支付成功	---客户订单已付款通知
	 */
	public static void SendToShop(String touser_OPENID,String title,int order_id,String username,String phone,double price,String price_type,String out_trade_no){
		String access_token=WeChatManager.GetAccess_token();
		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="hK55EsrRY1ArMeOVkBJYZqaI-q85vAMrwulMqywcI1Q";//模板ID
//		String url="http://sziit.cn.com/FirstService/wechatpublic/my.html";//点击后跳转的地址
		String url=Tools.getAddress("go11_"+order_id);
		String remark="请相关部门人员及时处理！";//
		String json=SendToShop_CreatJSON(touser_OPENID, template_id, url, title, username, phone, price,price_type,out_trade_no,remark);
		String res=ClientInternet.OpearConnect(urlConnect, null, json);
		System.out.println("++++++++++++++++"+res);
	}
	

	
	/**
	 * 组成模板的JSON数据-订单进度提醒
	 */
	public static String SendToShop_CreatJSON(String touser_OPENID,String template_id,String url,String first,String keyword1,String keyword2,double keyword3
			,String keyword4,String keyword5,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\"},\"keyword5\": {\"value\":\""+keyword5+"\",\"color\":\"#173177\"},"+
	                "\"remark\":{\"value\":\""+remark+"\",\"color\":\"#173177\"}}}";
	}
	
	
	
	
	
	/**
	 * 接单人员支付保证金
	 */
	public static void SendToAdmin(String touser_OPENID,String title,String state,String name,String phone,double price,String price_type,String out_trade_no){
		String access_token=WeChatManager.GetAccess_token();
		String urlConnect="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
		//String touser_OPENID="oaccFxLdCl5wXqAa3h9pzEIfFS5Y";//用户的ID
		String template_id="iBhH0qpOqmUce9JdQGu793VmhQcoHMsCfm1GjqnSssA";//模板ID
		//String url="http://sziit.cn.com/FirstService/wechatpublic/my.html";//点击后跳转的地址
		String URL=Tools.getAddress(state);
		String first=title;//
		/*String name="蔡永勇";//
		String phone="13543185677";//
		double price=500;//
		String price_type="微信支付";
		String order_number="11123123";*/
		String remark="请相关部门人员及时处理！";//
	
		String json=SendToAdmin_CreatJSON(touser_OPENID, template_id, URL, first, name, phone, price,price_type,out_trade_no,remark);
		String res=ClientInternet.OpearConnect(urlConnect, null, json);
		System.out.println(res);
	}
	
	/**
	 * 组成模板的JSON数据-商家保证金支付提醒
	 */
	public static String SendToAdmin_CreatJSON(String touser_OPENID,String template_id,String url,String first,String keyword1,String keyword2,double keyword3
			,String keyword4,String keyword5,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\"},\"keyword5\": {\"value\":\""+keyword5+"\",\"color\":\"#173177\"},"+
	                "\"remark\":{\"value\":\""+remark+"\",\"color\":\"#173177\"}}}";
	}
	
	
	
	
	/**
	 * 用户扫码转账支付
	 */
	public static void SendToShop2(String touser_OPENID,String title,String state,double price,String out_trade_no){
		String access_token=WeChatManager.GetAccess_token();
		String urlConnect="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
		//String touser_OPENID="oaccFxLdCl5wXqAa3h9pzEIfFS5Y";//用户的ID
		String template_id="llbg83HVvza7-dvrVPRYJL-v_DKsTF6IKLTmEkHSLG8";//模板ID
		//String url="http://sziit.cn.com/FirstService/wechatpublic/my.html";//点击后跳转的地址
		
		String URL=Tools.getAddress(state);
		String first=title;//
		/*String name="蔡永勇";//
		String phone="13543185677";//
		double price=500;//
		String price_type="微信支付";
		String order_number="11123123";*/
		String remark="欢迎您再次使用我们的服务！";//
	
		String json=SendToShop2_CreatJSON(touser_OPENID, template_id, URL, first,out_trade_no,price,remark);
		String res=ClientInternet.OpearConnect(urlConnect, null, json);
		System.out.println(res);
	}
	
	
	
	/**
	 * 组成模板的JSON数据-用户扫码转账支付
	 */
	public static String SendToShop2_CreatJSON(String touser_OPENID,String template_id,String url,String first,String keyword1,double keyword2,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\"},"+
	                "\"remark\":{\"value\":\""+remark+"\",\"color\":\"#173177\"}}}";
	}
	
	
	
	
	

	/**
	 * 新订单通知
	 */
	public static void TestNewOrderInfo(){
		String access_token="m4nrBXxu78n57W24EJpOWNb3bSxPnvXUwZkXhyCaZFXuAtFWScLdplzzJz45sD7rrzvcY5Q_DpYUOhImz43ew_d5cSroFt5aRFoaZNzo5EicY19LAgkieAxkuPgymQdPHNVaAEAYEM";
		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://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8c21546968cefd4&redirect_uri=http%3a%2f%2fsziit.cn.com%2fuser%2fwechatloginTwo&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect";//点击后跳转的地址
		String first="新英雄出场了";//
		String keyword1="乐享英雄推送";//
		String keyword2="瑞雯已死，取代它的是谁呢！";//
		String keyword3="2015-08-21 11：00";//
		String keyword4="2015-08-21 11：00";//
		String remark="记得去看看喔！（取消本类型消息订阅，请到个人中心！）";//
		String json=NewOrderInfo_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 NewOrderInfo_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 SendToRward(String touser_OPENID,String title,String state,double price,String out_trade_no,Timestamp time){
		String access_token=WeChatManager.GetAccess_token();
		String urlConnect="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
		//String touser_OPENID="oaccFxLdCl5wXqAa3h9pzEIfFS5Y";//用户的ID
		String template_id="nFq8JG8glpGgk53PMJqLaFptOCpYyd8B15S-3lC4ViE";//模板ID
		//String url="http://sziit.cn.com/FirstService/wechatpublic/my.html";//点击后跳转的地址
		String URL=Tools.getAddress(state);
		String first=title;//
		/*String name="蔡永勇";//
		String phone="13543185677";//
		double price=500;//
		String price_type="微信支付";
		String order_number="11123123";*/
		String remark="感谢您对服众网的使用！";//
	
		String json=SendToRaward_CreatJSON(touser_OPENID, template_id, URL, first, price,time,out_trade_no,remark);
		String res=ClientInternet.OpearConnect(urlConnect, null, json);
		System.out.println(res);
	}
	
	/**
	 * 组成模板的JSON数据-打赏金提醒
	 */
	public static String SendToRaward_CreatJSON(String touser_OPENID,String template_id,String url,String first,double price,Timestamp time,String out_trade_no,String remark){
		return "{\"touser\":\""+touser_OPENID+"\", \"template_id\":\""+template_id+"\",\"url\":\""+url+"\","+           
		           "\"data\":{\"first\": {\"value\":\""+first+"\",\"color\":\"#173177\"},\"keyword1\":{\"value\":\""+time+"\", \"color\":\"#173177\"},"+
	               "\"keyword2\": {\"value\":\""+price+"\",\"color\":\"#173177\"},\"keyword3\": {\"value\":\""+out_trade_no+"\",\"color\":\"#173177\"},"+
	                "\"remark\":{\"value\":\""+remark+"\",\"color\":\"#173177\"}}}";
	}





/**
 * 用户订单退款失败
 */
public static void SendToUserRefound(String touser_OPENID,String url,String title,String out_trade_no,double price,String reason,String remark){
	String access_token=WeChatManager.GetAccess_token();
	String urlConnect="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
	String template_id="5TcQCYBjddT7mjKGOamNFLp90qItMjjubDTg5vS4K64";//模板ID
	

	String json=SendToRaward_CreatJSON(touser_OPENID,url, template_id, title,out_trade_no, price,reason,remark);
	String res=ClientInternet.OpearConnect(urlConnect, null, json);
	System.out.println(res);
}

/**
 * 组成模板的JSON数据-用户退款失败通知
 */
public static String SendToRaward_CreatJSON(String touser_OPENID,String url,String template_id,String title,String out_trade_no,double price,String reason,String remark){
	return "{\"touser\":\""+touser_OPENID+"\", \"template_id\":\""+template_id+"\",\"url\":\""+url+"\","+           
	           "\"data\":{\"first\": {\"value\":\""+title+"\",\"color\":\"#173177\"},\"keyword1\":{\"value\":\""+out_trade_no+"\", \"color\":\"#173177\"},"+
               "\"keyword2\": {\"value\":\""+price+"\",\"color\":\"#173177\"},\"keyword3\": {\"value\":\""+reason+"\",\"color\":\"#173177\"},"+
                "\"remark\":{\"value\":\""+remark+"\",\"color\":\"#173177\"}}}";
}



/**
 * 商家受理用户退款申请
 */
public static void SendToShopRefound(String touser_OPENID,String url,String title,String out_trade_no,double price,String reason,String remark){
	String access_token=WeChatManager.GetAccess_token();
	String urlConnect="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
	String template_id="1tkcfX_xvHlbNP3C7XxuNh3jAWt61vk2HEtVGH2wu9M";//模板ID
	

	String json=SendToShopRefound_CreatJSON(touser_OPENID,url, template_id, title,out_trade_no, price,reason,remark);
	String res=ClientInternet.OpearConnect(urlConnect, null, json);
	System.out.println(res);
}

/**
 * 组成模板的JSON数据-商家受理用户退款申请
 */
public static String SendToShopRefound_CreatJSON(String touser_OPENID,String url,String template_id,String title,String out_trade_no,double price,String reason,String remark){
	return "{\"touser\":\""+touser_OPENID+"\", \"template_id\":\""+template_id+"\",\"url\":\""+url+"\","+           
	           "\"data\":{\"first\": {\"value\":\""+title+"\",\"color\":\"#173177\"},\"keyword1\":{\"value\":\""+out_trade_no+"\", \"color\":\"#173177\"},"+
               "\"keyword2\": {\"value\":\""+reason+"\",\"color\":\"#173177\"},\"keyword3\": {\"value\":\""+price+"\",\"color\":\"#173177\"},"+
                "\"remark\":{\"value\":\""+remark+"\",\"color\":\"#173177\"}}}";
}




}










