package com.zhiwei.weixin.card;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSON;
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: GetCardList
 * @Description: TODO(查看所有卡劵列表)
 * @author 志伟
 * @date 2015-3-28 下午7:26:57
 */
public class GetCardList {
	//查询卡劵集合
	private static String card_list_url = "https://api.weixin.qq.com/card/batchget?access_token=TOKEN";
	 //修改卡劵信息
//	private static String update_card_url = "";
	
	  // 调用接口获取access_token  
    //获取ticket
    //卡劵id
    private static String card_id = "p_Vmbjs0WI73ZfC7PuKFg8Y_8qvs";
	//记录日志
	private static Logger log = LoggerFactory.getLogger(WeixinUtil.class);
	
	
	private static String token;
    
	public GetCardList() 
	{
		token = new CreatAccessToken().getAccessToken();
	}
	
	/**
	 * 获取卡劵id
	 * 
	 * */
	public List getCardList()
	{
		List list = new ArrayList();
		
		String url = card_list_url.replace("TOKEN", token);
		
		JSONObject josn = new JSONObject();
		josn.put("offset",0);
		josn.put("count",30);
		
		
		JSONObject jsonObject = HttpRequest.httpRequest(url, "POST", josn.toString());
		
		System.out.println(jsonObject);
		if(jsonObject!=null)
		{
			List alist = (List)jsonObject.get("card_id_list");
			
			System.out.println(alist.size());
			
			for(int i = 0;i<alist.size();i++)
			{
				System.out.println(alist.get(i));
			}
		}
		
		return list;
	}
	
	
	
	/***/
	
	
	
	public static void main(String[] args)
	{
		new GetCardList().getCardList();
		
		
		//p_VmbjmyRWFIpiixBEwLslPPUnqw
	}
}
