package com.ssj.api.request;

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

import com.alibaba.fastjson.JSONObject;
import com.ssj.framework.core.util.HttpRemote;
import com.ssj.framework.core.util.PropertiesUtil;
import com.ssj.framework.weixin.pay.util.MD5Util;

public class RequestOpenApiUtils {
	
	private static Logger logger = LoggerFactory.getLogger(RequestOpenApiUtils.class);
	
	private static String appid="zhidian";
	
	private static String accessKey="Zhidian@34889_";
	
	
	//生成第三方接口的请求token
	public static String createOpenToken(String appid, String accessKey) {
		long time = System.currentTimeMillis() / 60000;
		return MD5Util.MD5Encode(appid + accessKey + time, "utf-8");
	}
	
	//调用第三方的删除校区学生服务。
	public static void openApiServiceCRM(Integer type,String libId,Integer signType,Integer mealType,Integer num,String startActiveTime,String computeTime,String endTime) {
		try {
			
			String host=PropertiesUtil.getValue("API_OPEN_URL");
			String accessToken=createOpenToken(appid, accessKey);
			String url=host+"/api/parents/share/dealServiceCRM?appid="+appid+"&accessToken="+accessToken;
			
			JSONObject json=new JSONObject();
			json.put("type", type);
			json.put("libId", libId);
			json.put("signType", signType);
			json.put("mealType", mealType);
			json.put("num", num);
			json.put("activateTime", startActiveTime);
			json.put("beginTime", computeTime);
			json.put("endTime", endTime);
		
			logger.info("调用第三方接口【dealServiceCRM】，请求URL："+url);
			logger.info("调用第三方接口【dealServiceCRM】，请求参数："+json);
			String text=HttpRemote.POSTMethod(url, json.toJSONString());
			logger.info("调用第三方接口【dealServiceCRM】，返回结果："+text);
		} catch (Exception e) {
			logger.info("调用第三方接口【dealServiceCRM】，异常");
			e.printStackTrace();
		}
	}
	

	
	

}
