package com.iamberry.wechat.sendMsg;

import java.util.HashMap;

import org.springframework.stereotype.Component;

import com.iamberry.wechat.tools.NameUtils;
import com.iamberry.wechat.tools.ResultInfo;
import com.iamberry.wechat.tools.WeixinUtil;

@Component
public class SendMessageUtil {
		
		//快递公司列表
		public static HashMap<String, String> hashmap = new HashMap<String, String>();
		//正式环境
		{
			hashmap.put("shentong", "申通快递"); 
			hashmap.put("yuantong", "圆通快递");
			hashmap.put("shunfeng", "顺丰快递");
			hashmap.put("longbanwuliu", "龙邦快递");	
		}
		
		/**
		 * 发送模板通知给用户
		 * @param date data 日期
		 * @param openId 接受的用户id
		 * @param url  点击打开的url
		 * @param type 发送类型 1，收益成功通知 2，发货提醒通知 3、收入提醒通知,4、订单未支付通知 5、试用进度提醒
		 * @return
		 */
		public boolean sendTemplateMessageToOpenid(String date,String openId, String url,Integer type) {
			boolean result = false;
			switch (type) {
			case 1:  //1，收益成功通知
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId,ResultInfo.rewards_template_id, date, url);
				break;
			case 2:  // 2，发货提醒通知 
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.Shipment_template_id, date, url);
				break;
			case 3:  //3、收入提醒通知
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.Income_template_id, date, url);
				break;
			case 4:  //4、订单未支付通知
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.Order_template_id, date, url);
				break;
			case 5:  //5、试用进度提醒
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.trial_progress_remind, date, url);
				break;
			case 6:  //6、试用申请通知
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_apply_notice, date, url);
				break;
			case 7:  //7、试用申请成功通知
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_apply_success, date, url);
				break;
			case 8:  //8、订单支付成功
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_pay_success, date, url);
				break;
			case 9:  //9、订单关闭成功
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_shut_down, date, url);
				break;
			case 10:  //10、奖品领取通知 
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.prize_receive_push, date, url);
				break;
			case 11:  //11、母亲节活动，推送模板
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.service_push, date, url);
				break;
			case 12:  //12、拼单活动
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_spell_success, date, url);
				break;
			default: 
				break;
			}
			result = true;
			return  result;
		}
		
		public static void main(String[] args) {
//			String date = "{'first':{'color':'#173177', 'value':'尊敬的客户您好~您的订单已发货~'}, 'order_id':{'color':'#173177','value':'1009145345B11792L'}, 'package_id':{'color':'#173177','value':'yuantong:34234234'}, 'remark':{'color':'#173177', 'value':'点击进入商城查看-->>'}}";
			String date = "{'first':{'color':'#173177','value':'亲爱的用户，'}, 'Good':{'color':'#173177','value':'母亲节'}, 'contentType':{'color':'#173177', 'value':'优惠券'},'remark':{'color':'#FF0000','value':'remarkValue'}}";
			String openId = "o3G6nww8FoM08HSbwpJqrhGu8V6Q";
			String appId = "wx27c9f825761a861b";// 应用ID
			String appSecret = "97b2f2991e4ff0f2567fbc625f858377";// 应用密钥
			
			WeixinUtil.sendTemplateMessage(appId, appSecret, openId, "5hWq6wd6W9HbMZ0ICSRTDyCKh_r_MjpQtWzkQRSKLio", date, "xx");
			System.out.println("发送成功");
		}
		
		/**
		 * 试用进度提醒推送
		 * @param first  标题
		 * @param keyword1	商品名称
		 * @param keyword2	订单编号
		 * @param keyword3	申请时间
		 * @param keyword4	截止时间
		 * @param remark	全部内容
		 * @param openId	用户openid
		 * @param url	地址
		 */
		public void probationPush(String first,String keyword1,String keyword2,String keyword3,String keyword4,String remark,String openId,String url){
			String temp = ResultInfo.PROBATIONPUSH;
			temp = temp.replaceFirst("firstValueIamberry", first)
					.replaceFirst("keyword1Value",keyword1)
					.replaceFirst("keyword2Value",keyword2)
					.replaceFirst("keyword3Value",keyword3)
					.replaceFirst("keyword4Value",keyword4)
					.replaceFirst("remarkValue",remark);
				sendTemplateMessageToOpenid(temp, openId, url,5);
				temp = ResultInfo.PROBATIONPUSH;
		}
		
		/**
		 * 试用开始通知
		 * @param first 标题
		 * @param keyword1	商品信息
		 * @param keyword2	申请时间
		 * @param remark	全部内容
		 * @param openId	用户openid
		 * @param url	地址
		 */
		public void probationApplyNotice(String first,String keyword1,String keyword2,String remark,String openId,String url){
			String temp = ResultInfo.PROBATIONAPPLYNOTICE;
			temp = temp.replaceFirst("firstValueIamberry", first)
					.replaceFirst("keyword1Value",keyword1)
					.replaceFirst("keyword2Value",keyword2)
					.replaceFirst("remarkValue",remark);
				sendTemplateMessageToOpenid(temp, openId, url,6);
		}
		/**
		 * 派送成功通知
		 * @param first  标题
		 * @param keyword1	申请单号
		 * @param keyword2	申请时间
		 * @param keyword3	应付金额
		 * @param keyword4	应付积分
		 * @param keyword5	支付方式
		 * @param remark	全部内容
		 * @param openId	用户openid
		 * @param url	地址
		 */
		public void probationApplySuccess(String first,String keyword1,String keyword2,String keyword3,String keyword4,String keyword5,String remark,String openId,String url){
			String temp = ResultInfo.PROBATIONAPPLYSUCCESS;
			temp = temp.replaceFirst("firstValueIamberry", first)
					.replaceFirst("keyword1Value",keyword1)
					.replaceFirst("keyword2Value",keyword2)
					.replaceFirst("keyword3Value",keyword3)
					.replaceFirst("keyword4Value",keyword4)
					.replaceFirst("keyword5Value",keyword5)
					.replaceFirst("remarkValue",remark);
				sendTemplateMessageToOpenid(temp, openId, url,7);
		}
		/**
		 * 试用订单支付成功
		 * @param first  标题
		 * @param keyword1	支付金额
		 * @param keyword2	商品信息
		 * @param remark	全部内容
		 * @param openId	用户openid
		 * @param url	地址
		 */
		public void probationPaySuccess(String first,String keyword1,String keyword2,String remark,String openId,String url){
			String temp = ResultInfo.PROBATIONPAYSUCCESS;
			temp = temp.replaceFirst("firstValueIamberry", first)
					.replaceFirst("orderMoneySumValue",keyword1)
					.replaceFirst("orderProductNameValue",keyword2)
					.replaceFirst("remarkValue",remark);
			sendTemplateMessageToOpenid(temp, openId, url,8);
		}
		/**
		 * 试用订单关闭成功
		 * @param first  标题
		 * @param keyword1	支付金额
		 * @param keyword2	商品信息
		 * @param remark	全部内容
		 * @param openId	用户openid
		 * @param url	地址
		 */
		public void probationShutDown(String first,String transid,String fee,String pay_time,String remark,String openId,String url){
			String temp = ResultInfo.PROBATIONSHUTDOWN;
			temp = temp.replaceFirst("firstValueIamberry", first)
					.replaceFirst("transidValue",transid)
					.replaceFirst("feeValue",fee)
					.replaceFirst("pay_timeValue",pay_time)
					.replaceFirst("remarkValue",remark);
			sendTemplateMessageToOpenid(temp, openId, url,9);
		}
		
		/**
		 * 推荐人领取通知
		 * @param first  标题
		 * @param keyword1	被推荐人
		 * @param keyword2	消费商家
		 * @param keyword3	消费金额
		 * @param keyword4	消费时间
		 * @param keyword4	推荐奖励
		 * @param remark	全部内容
		 * @param openId	用户openid
		 * @param url	跳转地址
		 */
		public void prizeReceivePush(String first,String keyword1,String keyword2,String keyword3,String keyword4,String keyword5,String remark,String openId,String url){
			String temp = ResultInfo.PRIZERECEIVEPUSH;
			temp = temp.replaceFirst("firstValueIamberry", first)
					.replaceFirst("keyword1Value",keyword1)
					.replaceFirst("keyword2Value",keyword2)
					.replaceFirst("keyword3Value",keyword3)
					.replaceFirst("keyword4Value",keyword4)
					.replaceFirst("keyword5Value",keyword5)
					.replaceFirst("remarkValue",remark);
				sendTemplateMessageToOpenid(temp, openId, url,10);
		}

	/**
	 * 服务推送
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param remark
	 * @param openId
	 * @param url
	 */
	 public void servicePush(String first,String keyword1,String keyword2,String remark,String openId,String url){
		String temp = ResultInfo.SERVICEPUSH;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("GoodValue",keyword1)
				.replaceFirst("contentTypeValue",keyword2)
				.replaceFirst("remarkValue",remark);
			sendTemplateMessageToOpenid(temp, openId, url,11);
	 }

	/**
	 * 拼单成功推送
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param remark
	 * @param openId
	 * @param url
	 */
	 public void spellPush(String first,String keyword1,String keyword2,String remark,String openId,String url){
		String temp = ResultInfo.PROBATIONSPELLSUCCESS;
		 temp = temp.replaceFirst("firstValueIamberry", first)
				 .replaceFirst("keyword1Value",keyword1)
				 .replaceFirst("keyword2Value",keyword2)
				 .replaceFirst("remarkValue",remark);
			sendTemplateMessageToOpenid(temp, openId, url,12);
	 }
}
