package com.sino.rrs.entity;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sino.weixin.oauth.util.AdvancedUtil;
import com.sino.weixin.oauth.util.Constants;
import com.sino.weixin.oauth.util.HttpsUtil;
import common.Logger;

public class DeleteOrderMessage {
	Logger log=Logger.getLogger(SendOrderMessage.class);
	private AdvancedUtil util=new AdvancedUtil();
	/**
	 * appID 公众号ID
	 * appsecret 公众号密钥
	 * openid
	 */
	public int delete_template_message(String appID,String appsecret,String openId,String orderCode,String supplyRemark){
		   String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+Constants.ACCESS_TOKEN;		 
		
		 WXplate plate=new WXplate();
		 
	//	 plate.setTemplate_id("1-kQlbOcRhmnkLZSiu5h3KeFwUKU5kXhJ-Th3_A_i9w"); //正式
	//	 plate.setTemplate_id("UfCEkcVJXoHvP6xy32h7UqmsHzbhbmyp6Fmdhc1F50w"); //测试
		 plate.setTemplate_id("rciW09p6ITTZ6eL2fcZ5uR1LsLwNsdz1n-O3xxI6ejs");  //本地
		 plate.setTouser(openId);
		 
		 Map<String,TemplateData> data=new HashMap<String, TemplateData>();
		 TemplateData first=new TemplateData();
		 first.setValue("您好！您当前订单已被取消！请知晓！");
		 first.setColor("#173177");
		 data.put("first", first);
		 
		//订单编号
		 TemplateData order=new TemplateData();
		 order.setValue(orderCode);
		 order.setColor("#173177");
		 data.put("keyword1", order);
		 
		 //取消原因
		 TemplateData reason=new TemplateData();
		 if(supplyRemark.equals("")){
			 reason.setValue("无"); 
		 }else{
			 reason.setValue(supplyRemark);
		 }
		 reason.setColor("#173177");
		 data.put("keyword2", reason);
		 
		 TemplateData remark=new TemplateData();
		 remark.setValue("如有疑问请咨询。。。。");
		 remark.setColor("#173177");
		 data.put("remark", remark); 
		 plate.setData(data);
	   String objectString=JSON.toJSONString(plate);
	   
	   String jsonObject=HttpsUtil.sendPost(url, objectString);
	   int result = 0;
	   if (null != jsonObject) {  
		   JSONObject jsonobj = JSON.parseObject(jsonObject);
           if (0 != jsonobj.getIntValue("errcode")) {  
               result = jsonobj.getIntValue("errcode");
               log.error("错误 errcode:{} errmsg:{}"+jsonobj.getIntValue("errcode")+jsonobj.getString("errmsg"));  
           }  
       }
	   log.error("模板消息发送结果："+result);
	   return result;
	}
}



