package com.yutou.jianr_mg.Tools;

import com.alibaba.fastjson.JSON;
import com.yutou.jianr_mg.Application;
import com.yutou.jianr_mg.Data.AppData;
import com.yutou.jianr_mg.Data.UUserdata;
import com.yutou.jianr_mg.Interfaces.HttpInterface;
import com.yutou.jianr_mg.Network.HttpApi;
import com.yutou.jianr_mg.Network.HttpUtils;

import org.json.JSONObject;

public class AdTools {
    public static int req=0,show=1,click=2;
    public static int Open=1,Inter=2,Banner=3,Native=4;
    public static void upload(int adType,int uType){
        try {
            JSONObject json=new JSONObject();
            json.put("adtype",adType);
            json.put("utype",uType);
            json.put("imei",Utils.getIMEI());
            HttpUtils.post(HttpApi.HOME_URL + HttpApi.AD_LOG, json, new HttpInterface() {
                @Override
                public void httpGetData(String string, int code) {
                    try{
                        JSONObject json=new JSONObject(string);
                        if(json.getInt("code")==100){
                            JSONObject data=json.getJSONObject("data");
                            if(data.getInt("code")==100){
                                Utils.toast(null,data.getString("msg"));
                            }
                            if(!data.isNull("user")){
                                AppData.userdata= JSON.parseObject(data.getJSONObject("user").getJSONObject("data").getJSONObject("userdata").toString(), UUserdata.class);
                            }
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }

                @Override
                public void httpError(Exception e) {

                }
            });
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
