/// <summary> /// 请求云通信接口 /// 作者:郭明 /// 日期:2016年8月20日 /// </summary> /// <param name="obj"></param> /// <param name="method"></param> /// <returns></returns> string Post(dynamic obj, string method, Func <int, bool> match = null, string url = "https://console.tim.qq.com/v4/") { var requestParamters = JsonHelper.ToJson(obj); var requestBeginTime = DateTime.Now; var response = ""; try { var userSig = Tencent.TSLHelper.GetSig(uint.Parse(Configuration.IMConfig.sdkAppID), Configuration.IMConfig.adminAccount, uint.Parse(Configuration.IMConfig.accountType)); int random = GlobalRandom; url = string.Format(url + "/{4}?usersig={0}&identifier={1}&sdkappid={2}&random={3}&contenttype=json", userSig, Configuration.IMConfig.adminAccount, Configuration.IMConfig.sdkAppID, random, method); //请求腾讯云接口 return(WebAPIHelper.HttpPost(url, requestParamters)); } catch (Exception E) { LogHelper.DefaultLogger.Error(E.Message, E); throw E; } finally { //WriteTrackLog(url, method, requestParamters, requestBeginTime, response); } return(""); }
public static ApiResult <T> Post <T>(string path, string param) { var requestTime = DateTime.Now; var response = ""; try { response = WebAPIHelper.HttpPost(path, param); return(JsonDeserialize <ApiResult <T> >(response)); } catch (Exception ex) { response = JsonSerialize(ex.GetDetailException()); return(new ApiResult <T>() { resultCode = 1, resultData = default(T), msg = ex.Message }); } finally { WriteTrackLog(path, "", param, requestTime, response); } }
public bool UploadInspect(List <RequestUserInspectResultDTO> inspects) { var config = SysConfigRepository.Get <Inspect>(); var storeConfig = SysConfigRepository.Get <IMGStore>(); var apiConfig = SysConfigRepository.Get <Common.Config.Consultation>(); System.Collections.Generic.SortedList <string, string> list = new SortedList <string, string>(); list.Add("appid", config.AppId); list.Add("appkey", config.AppKey); list.Add("noncestr", Guid.NewGuid().ToString("N")); string sign = WebAPIHelper.GetSign(list); list.Remove("appkey"); list.Add("sign", sign); try { inspects.ForEach(x => { string param = JsonHelper.ToJson(new { fileId = x.InspectResultID, filePath = storeConfig.UrlPrefix.TrimEnd('/') + "/" + x.FileUploadName.TrimStart('/'), callBackUrl = apiConfig.ConsultationApiUrl.TrimEnd('/') + "/UploadInspectCallback" }); string result = WebAPIHelper.HttpPost(config.UploadFileUrl, param, list); var obj = JsonHelper.FromJson <dynamic>(result); if (obj.error_code != 100) { LogHelper.DefaultLogger.Error(string.Format("影像上传接口:{0},参数:{1},调用异常:{2}", config.UploadFileUrl, param, obj.message)); } }); return(true); } catch (Exception e) { LogHelper.DefaultLogger.Error(e.Message, e); return(false); } }
protected override bool Run() { string extras = "[{\"StrKey\":\"OrderId\",\"StrValue\":\"" + OrderID + "\"}]"; var data = new { Title = "", Content = Content, FromAccountID = FromAccountId, Alias = ToAlias, ExtrasIOS = extras, ExtrasAndroid = extras }; var ds = JsonHelper.ToJson(data); var apiUrl = Configuration.Config.JPushUrl.TrimEnd('/') + "/MessagePush/SendToAliasNetHospital"; var model = WebAPIHelper.HttpPost(apiUrl, ds); return(true); }
/// <summary> /// 请求云通信接口 /// 作者:郭明 /// 日期:2016年8月20日 /// </summary> /// <param name="obj"></param> /// <param name="method"></param> /// <returns></returns> bool Request(dynamic obj, string method, Func <int, bool> match = null, string url = "https://console.tim.qq.com/v4/") { var requestParamters = JsonHelper.ToJson(obj); var requestBeginTime = DateTime.Now; var response = ""; try { var userSig = Tencent.TSLHelper.GetSig(uint.Parse(Configuration.IMConfig.sdkAppID), Configuration.IMConfig.adminAccount, uint.Parse(Configuration.IMConfig.accountType)); int random = GlobalRandom; url = string.Format(url + "/{4}?usersig={0}&identifier={1}&sdkappid={2}&random={3}&contenttype=json", userSig, Configuration.IMConfig.adminAccount, Configuration.IMConfig.sdkAppID, random, method); //请求腾讯云接口 response = WebAPIHelper.HttpPost(url, requestParamters); var result = JsonHelper.FromJson <ResponseIMResultDTO>(response); if (result != null && result.ErrorCode == 0) { return(true); } else { LogHelper.DefaultLogger.Warn($" Request {url},Params:{requestParamters} 失败,Response ErrorCode={result.ErrorCode},ErrorInfo={result.ErrorInfo}"); if (match != null) { if (match(result.ErrorCode)) { return(true); } } if (result.ErrorCode == 10015) { return(true); //throw new InvalidGroupException(); } //all identifiers you want to add are invalid if (result.ErrorCode == 10019) { return(true); //throw new InvalidToAccountException(); } if (result.ErrorCode == 90012) { return(true); //throw new InvalidToAccountException(); } } } catch (Exception E) { LogHelper.DefaultLogger.Error(E.Message, E); throw E; } finally { //WriteTrackLog(url, method, requestParamters, requestBeginTime, response); } return(false); }