/// <summary> /// 发送web数据 /// </summary> /// <param name="url"></param> /// <param name="callBack"></param> /// <param name="isPost"></param> /// <param name="isGetData">是否获取字节数据</param> /// <param name="dic"></param> public void SendData(string url, HttpSendDataCallBack callBack, bool isPost = false, bool isGetData = false, Dictionary <string, object> dic = null) { if (IsBusy) { return; } IsBusy = true; m_CallBack = callBack; m_IsGetData = isGetData; if (!isPost) { GetUrl(url); } else { //web加密 if (dic != null) { //客户端标识符 dic["deviceIdentifier"] = DeviceUtil.DeviceIdentifier; //设备型号 dic["deviceModel"] = DeviceUtil.DeviceModel; long t = GameEntry.Data.SysDataManager.CurrServerTime; //签名 dic["sign"] = EncryptUtil.Md5(string.Format("{0}:{1}", t, DeviceUtil.DeviceIdentifier)); //时间戳 dic["t"] = t; } string json = string.Empty; if (dic != null) { json = JsonMapper.ToJson(dic); if (!m_IsGetData) { GameEntry.Log(LogCategory.Proto, "<color=#ffa200>发送消息:</color><color=#FFFB80>" + url + "</color>"); GameEntry.Log(LogCategory.Proto, "<color=#ffdeb3>==>>" + json + "</color>"); } GameEntry.Pool.EnqueueClassObject(dic); } PostUrl(url, json); } }
/// <summary> /// 请求服务器 /// </summary> /// <param name="data"></param> /// <returns></returns> private IEnumerator Request(UnityWebRequest data) { yield return(data.SendWebRequest()); IsBusy = false; if (data.isNetworkError || data.isHttpError) { if (m_CallBack != null) { m_CallBackArgs.HasError = true; m_CallBackArgs.Value = data.error; if (!m_IsGetData) { GameEntry.Log(LogCategory.Proto, "<color=#00eaff>接收消息:</color><color=#00ff9c>" + data.url + "</color>"); GameEntry.Log(LogCategory.Proto, "<color=#c5e1dc>==>>" + JsonUtility.ToJson(m_CallBackArgs) + "</color>"); } m_CallBack(m_CallBackArgs); } } else { if (m_CallBack != null) { m_CallBackArgs.HasError = false; m_CallBackArgs.Value = data.downloadHandler.text; if (!m_IsGetData) { GameEntry.Log(LogCategory.Proto, "<color=#00eaff>接收消息:</color><color=#00ff9c>" + data.url + "</color>"); GameEntry.Log(LogCategory.Proto, "<color=#c5e1dc>==>>" + JsonUtility.ToJson(m_CallBackArgs) + "</color>"); } m_CallBackArgs.Data = data.downloadHandler.data; m_CallBack(m_CallBackArgs); } } data.Dispose(); data = null; //Debug.Log("把http访问器回池"); GameEntry.Pool.EnqueueClassObject(this); }