package mobvista.dmp.datasource.joypac;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import org.apache.hadoop.hive.ql.exec.UDF;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import sun.misc.BASE64Decoder;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 刘凯 2018-01-18 16:20 adn_sdk 工具类
 */
public class JoypcSdkTools extends UDF implements Serializable{
	public static void mainss(String[] args) {
		// TODO Auto-generated method stub
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		String password ="";
		try{
		password = buf.readLine();
		JSONObject json=getEtlJSON(password);
		System.out.println(json.toString());
		System.out.println(json.get("apps_info"));
		
		String business_name = json.getString("business_name");
		System.out.println(business_name);
        String business_pass = json.getString("business_pass");
        System.out.println(business_pass);
		boolean   result = business_name.equals("joypac_ios") && business_pass.equals("joypac_ios-sdk0121");
		System.out.println(result);
		}catch(IOException e)

		
		{

		System.out.println(e);

		System.exit(0);

		}
	}
	
	/**
	 * 
	 * @param log
	 * @return
	 */
	public static JSONObject getEtlJSON(String log) {
		String id = "";
		String idfa = "";
		String app_version = "";
		String brand = "";
		String network_type = "";
		String package_name = "";
		String platform = "";
		String language = "";
		String business_name = "";
		String apps_info = "";
		String business_pass = "";
		String os_version = "";
		String app_version_code = "";
		String model = "";
		String time_zone = "";
		String time = "";
			JSONObject json = null;
			try {
				json = JSON.parseObject(log);
			} catch (Exception e) {
				e.printStackTrace();
				json=new JSONObject();
			}
			
			if(json.get("id")==null){
				json.put("id", "");
			}
			
			if(json.get("idfa")==null){
				json.put("idfa", "");
			}
			
			if(json.get("app_version")==null){
				json.put("app_version", "");
			}
			
			if(json.get("brand")==null){
				json.put("brand", "");
			}
			if(json.get("network_type")==null){
				json.put("network_type", "");
			}
			if(json.get("package_name")==null){
				json.put("package_name", "");
			}
			if(json.get("platform")==null){
				json.put("platform", "");
			}
			if(json.get("language")==null){
				json.put("language", "");
			}
			if(json.get("business_name")==null){
				json.put("business_name", "");
			}
			if(json.get("business_pass")==null){
				json.put("business_pass", "");
			}
			
			if(json.get("apps_info")==null){
				json.put("apps_info", "");
			}
			
			if(json.get("os_version")==null){
				json.put("os_version", "");
			}
			if(json.get("app_version_code")==null){
				json.put("app_version_code", "");
			}
			if(json.get("model")==null){
				json.put("model", "");
			}
			if(json.get("time_zone")==null){
				json.put("time_zone", "");
			}
			if(json.get("time")==null){
				json.put("time", "");
			}
		return json;
	}

}
