package com.zhiwei.weixin.card;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zhiwei.weixin.accesstoken.CreatAccessToken;
import com.zhiwei.weixin.http.HttpRequest;
import com.zhiwei.weixin.pojo.AccessToken;
import com.zhiwei.weixin.util.WeixinUtil;

/** 
 * @Package com.zhiwei.weixin.card
 * @ClassName: HeXiaoCard
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author 志伟
 * @date 2015-3-28 下午8:16:11
 */
public class HeXiaoCard {

	//查询卡劵集合
		private static String consume_card_url = "https://api.weixin.qq.com/card/code/consume?access_token=TOKEN";
		 //修改卡劵信息
//		private static String update_card_url = "";
	    //获取ticket
	    //卡劵id
	    private static String card_id = "p_Vmbjs0WI73ZfC7PuKFg8Y_8qvs";
		//记录日志
		private static Logger log = LoggerFactory.getLogger(WeixinUtil.class);

		private static String token;
		    
		public HeXiaoCard() 
		{
			token = new CreatAccessToken().getAccessToken();
		}
		
		public int hexiaoCard(String code)
		{
			String url = consume_card_url.replace("TOKEN", token);
			JSONObject json = new JSONObject();
			json.put("code", code);
			
			JSONObject jsonObject = HttpRequest.httpRequest(url, "POST", json.toString());
			if(jsonObject!=null)
			{
				int errcode = jsonObject.getInt("errcode");
				if(errcode == 0)
				{
					return 0;
				}
			}
			
			return 1;
		}
		
		
		public static void main(String[] args)
		{
			String code = "";
			new HeXiaoCard().hexiaoCard(code);
		}

}
