public string GetURL(OneNetContext context) { var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public String GetURL(OneNetContext context) { context.setContext(DEVICE_ID, DeviceID); var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public String GetURL(OneNetContext context) { otherParameters.Add(Register_Code, RegisterCode); var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public String GetURL(OneNetContext context) { context.setContext(CMD_UUID, CmdUuid); var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public string GetURL(OneNetContext context) { otherParameters.Add(DEVICE_ID, DeviceID.ToString()); otherParameters.Add(DATASTREAM_ID, DatastreamId); var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public string GetURL(OneNetContext context) { otherParameters.Add("title", Title); otherParameters.Add("page", Page.ToString()); otherParameters.Add("per_page", Per_Page.ToString()); var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public T Execute <T>(IParamsRequest request, DateTime timestamp) where T : TopResponse { try { request.Validate(); } catch (TopException e) { return(createErrorResponse <T>(e.ErrorCode, e.ErrorMsg)); } string url = this.ServerUrl; var txtParams = new TopDictionary(request.GetParameters()); txtParams.Add(METHOD, request.GetApiName()); txtParams.Add(API_KEY, apiKey); txtParams.Add(TIMESTAMP, TopUtils.GetUnixTimestamp(timestamp).ToString()); //if (expires.HasValue) txtParams.Add(EXPIRES, PushUtils.GetUnixTimestamp(expires.Value).ToString()); txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret)); string body; if (request is ITopUploadRequest) { var fileParams = (request as ITopUploadRequest).GetFileParameters(); body = webUtils.DoPost(url, txtParams, fileParams); } else { body = webUtils.DoPost(url, txtParams); } // 解释响应结果 T rsp = this.DisableParser ? Activator.CreateInstance <T>() : TopUtils.JsonParser <T>(body); rsp.Body = body; // 追踪错误的请求 if (!DisableTrace) { txtParams.Remove(SIGN); txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret)); rsp.ReqUrl = WebUtils.BuildGetUrl(url, txtParams); if (rsp.IsError) { topLogger.Warn(rsp.ReqUrl + "\r\n" + rsp.Body); } } return(rsp); }
public string GetURL(OneNetContext context) { var url = URIUtils.fmtURI(URI, context); otherParameters.Add("page", Page.ToString()); otherParameters.Add("per_page", PerPage.ToString()); otherParameters.Add("dev_id", DeviceId); otherParameters.Add("key", Key); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public String GetURL(OneNetContext context) { context.setContext(DEVICE_ID, DeviceID); otherParameters.Add(DatastreamID, DataStreamId); otherParameters.Add(START, StartTimeTxt); otherParameters.Add(END, EndTimeTxt); otherParameters.Add(LIMIT, Limit); otherParameters.Add(CURSOR, Cursor); otherParameters.Add(INTERVAL, Interval); otherParameters.Add(METHOD, Method); otherParameters.Add(FIRST, First); var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public String GetURL(OneNetContext context) { otherParameters.Add("start", Start.ToString("s")); otherParameters.Add("device_id", DeviceID); otherParameters.Add("datastream_id", DataStreamId); if (End.HasValue) { otherParameters.Add("end", End.Value.ToString("s")); } otherParameters.Add("limit", Limit.ToString()); otherParameters.Add("cursor", Cursor); if (Duration.HasValue) { otherParameters.Add("duration", Duration.ToString()); } otherParameters.Add("page", Page.ToString()); var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
public String GetURL(OneNetContext context) { otherParameters.Add(Key_WORDS, Keywords); if (OnLine.HasValue) { otherParameters.Add(ONLINE, OnLine.ToString()); } if (Private.HasValue) { otherParameters.Add(PRIVATE, Private.ToString()); } otherParameters.Add(PAGE, Page.ToString()); otherParameters.Add(PER_PAGE, PageSize.ToString()); otherParameters.Add(TAG, Tag); context.setContext(DEVICE_ID, DeviceIds); var url = URIUtils.fmtURI(URI, context); var webUtils = new WebUtils(); return(webUtils.BuildGetUrl(url, otherParameters)); }
private T DoExecute <T>(ITopRequest <T> request, string session, DateTime timestamp) where T : TopResponse { // 提前检查业务参数 try { request.Validate(); } catch (TopException e) { return(createErrorResponse <T>(e.ErrorCode, e.ErrorMsg)); } string sip_timestamp = timestamp.ToString("yyyy-MM-dd HH:mm:ss.000"); // 添加协议级请求参数 TopDictionary txtParams = new TopDictionary(); PortalRestRequest portalRestRequest = request.GetParameters(); //Jayrock.Json.JsonTextWriter writer = new Jayrock.Json.JsonTextWriter(); //Jayrock.Json.Conversion.JsonConvert.Export(paramDict, writer); //txtParams.Add(PORTALTRANSACTION, "[" + Jayrock.Json.Conversion.JsonConvert.ExportToString(portalRestRequest) + "]"); txtParams.Add(PORTALTRANSACTION, "[" + Newtonsoft.Json.JsonConvert.SerializeObject(portalRestRequest) + "]"); txtParams.Add(APP_KEY, appKey); txtParams.Add(TIMESTAMP, sip_timestamp); txtParams.AddAll(this.systemParameters); // 添加签名参数 txtParams.Add(SIGN, TopUtils.SignBurgeonPortalRequest(appKey, appSecret, sip_timestamp)); // 是否需要上传文件 string body; if (request is ITopUploadRequest <T> ) { ITopUploadRequest <T> uRequest = (ITopUploadRequest <T>)request; IDictionary <string, FileItem> fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters()); body = webUtils.DoPost(this.serverUrl, txtParams, fileParams); } else { body = webUtils.DoPost(this.serverUrl, txtParams); } // 解释响应结果 T rsp; if (disableParser) { rsp = Activator.CreateInstance <T>(); rsp.Body = body; } else { ITopParser tp = new TopJsonParser(); //去掉body[] body = body.Substring(1, body.LastIndexOf(']') - 1); rsp = tp.Parse <T>(body); } // 追踪错误的请求 if (!disableTrace) { rsp.Body = body; rsp.ReqUrl = webUtils.BuildGetUrl(this.serverUrl, txtParams); if (rsp.IsError) { topLogger.Warn(rsp.ReqUrl + "\r\n" + rsp.Body); } } return(rsp); }
private T DoExecute <T>(ITopRequest <T> request, string session, DateTime timestamp) where T : TopResponse { // 提前检查业务参数 try { request.Validate(); } catch (TopException e) { return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg)); } // 添加协议级请求参数 TopDictionary txtParams = new TopDictionary(request.GetParameters()); txtParams.Add(METHOD, request.GetApiName()); txtParams.Add(VERSION, "2.0"); txtParams.Add(SIGN_METHOD, Constants.SIGN_METHOD_MD5); txtParams.Add(APP_KEY, appKey); txtParams.Add(FORMAT, format); txtParams.Add(PARTNER_ID, GetSdkVersion()); txtParams.Add(TIMESTAMP, timestamp); txtParams.Add(TARGET_APP_KEY, request.GetTargetAppKey()); txtParams.Add(SESSION, session); txtParams.AddAll(this.systemParameters); if (this.useSimplifyJson) { txtParams.Add(SIMPLIFY, "true"); } // 添加签名参数 txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret, true)); // 添加头部参数 if (this.useGzipEncoding) { request.GetHeaderParameters()[Constants.ACCEPT_ENCODING] = Constants.CONTENT_ENCODING_GZIP; } string realServerUrl = GetServerUrl(this.serverUrl, request.GetApiName(), session); string reqUrl = webUtils.BuildGetUrl(realServerUrl, txtParams); try { string body; if (request is ITopUploadRequest <T> ) // 是否需要上传文件 { ITopUploadRequest <T> uRequest = (ITopUploadRequest <T>)request; IDictionary <string, FileItem> fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters()); body = webUtils.DoPost(realServerUrl, txtParams, fileParams, request.GetHeaderParameters()); } else { body = webUtils.DoPost(realServerUrl, txtParams, request.GetHeaderParameters()); } // 解释响应结果 T rsp; if (disableParser) { rsp = Activator.CreateInstance <T>(); rsp.Body = body; } else { if (FORMAT_XML.Equals(format)) { ITopParser tp = new TopXmlParser(); rsp = tp.Parse <T>(body); } else { ITopParser tp; if (useSimplifyJson) { tp = new TopJsonSimplifyParser(); } else { tp = new TopJsonParser(); } rsp = tp.Parse <T>(body); } } // 追踪错误的请求 if (!disableTrace && rsp.IsError) { StringBuilder sb = new StringBuilder(reqUrl).Append(" response error!\r\n").Append(rsp.Body); topLogger.Warn(sb.ToString()); } return(rsp); } catch (Exception e) { if (!disableTrace) { StringBuilder sb = new StringBuilder(reqUrl).Append(" request error!\r\n").Append(e.StackTrace); topLogger.Error(sb.ToString()); } throw e; } }
private T DoExecute <T> (IJdRequest <T> request, string access_token, DateTime timestamp) where T : JdResponse { // 提前检查业务参数 try { request.Validate(); } catch (JdException e) { return(createErrorResponse <T> (e.ErrorCode, e.ErrorMsg)); } // 添加协议级请求参数 JdDictionary txtParams = new JdDictionary(); txtParams.Add(METHOD, request.GetApiName()); txtParams.Add(VERSION, "2.0"); txtParams.Add(APP_KEY, appKey); txtParams.Add(TIMESTAMP, timestamp); if (access_token != null) { txtParams.Add(ACCESS_TOKEN, access_token); } txtParams.Add(PARAM_JSON, JsonConvert.ExportToString(request.GetParameters())); // 添加签名参数 txtParams.Add(SIGN, JdUtils.SignJdRequest(txtParams, appSecret, true)); string reqUrl = webUtils.BuildGetUrl(this.serverUrl, txtParams); try { string body; if (request is IJdUploadRequest <T> ) // 是否需要上传文件 { IJdUploadRequest <T> uRequest = (IJdUploadRequest <T>)request; IDictionary <string, FileItem> fileParams = JdUtils.CleanupDictionary(uRequest.GetFileParameters()); body = webUtils.DoPost(this.serverUrl, txtParams, fileParams); } else { body = webUtils.DoPost(this.serverUrl, txtParams); } // 解释响应结果 T rsp; if (disableParser) { rsp = Activator.CreateInstance <T> (); rsp.Body = body; } else { if (FORMAT_XML.Equals(format)) { IJdParser tp = new JdXmlParser(); rsp = tp.Parse <T> (body); } else { IJdParser tp = new JdJsonParser(); rsp = tp.Parse <T> (body); } } // 追踪错误的请求 if (!disableTrace && rsp.IsError) { StringBuilder sb = new StringBuilder(reqUrl).Append(" response error!\r\n").Append(rsp.Body); JdLogger.Warn(sb.ToString()); } return(rsp); } catch (Exception e) { if (!disableTrace) { StringBuilder sb = new StringBuilder(reqUrl).Append(" request error!\r\n").Append(e.StackTrace); JdLogger.Error(sb.ToString()); } throw e; } }
private T DoExecute <T>(ITopRequest <T> request, string session, long timestamp) where T : YunResponse { // 提前检查业务参数 try { request.Validate(); } catch (YunException e) { return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg)); } // 添加协议级请求参数 var txtParams = new YunDictionary(request.GetParameters()) { { METHOD, request.GetApiName() }, { VERSION, "1.0" }, { APP_KEY, appKey }, { FORMAT, format }, { TIMESTAMP, timestamp }, { SESSION, session } }; txtParams.AddAll(this.systemParameters); // 添加签名参数 txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret, "UTF-8")); var reqUrl = webUtils.BuildGetUrl(this.serverUrl, txtParams); try { string body; if (request is ITopUploadRequest <T> ) // 是否需要上传文件 { var uRequest = (ITopUploadRequest <T>)request; var fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters()); body = webUtils.DoPost(this.serverUrl, txtParams, fileParams); } else { body = webUtils.DoPost(this.serverUrl, txtParams); } // 解释响应结果 T rsp; if (disableParser) { rsp = Activator.CreateInstance <T>(); rsp.Body = body; } else { if (FORMAT_XML.Equals(format)) { ITopParser tp = new TopXmlParser(); rsp = tp.Parse <T>(body); } else { ITopParser tp = new TopJsonParser(); rsp = tp.Parse <T>(body); //rsp = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(body); //rsp = JsonDeserialize<T>(body); } } rsp.ReqUrl = reqUrl; // 追踪错误的请求 if (!disableTrace && rsp.IsError) { var sb = new StringBuilder(reqUrl).Append(" response error!\r\n").Append(rsp.Body); topLogger.Warn(sb.ToString()); } return(rsp); } catch (Exception e) { if (!disableTrace) { var sb = new StringBuilder(reqUrl).Append(" request error!\r\n").Append(e.StackTrace); topLogger.Error(sb.ToString()); } throw e; } }
private T DoExecute <T>(IOneNETRequest <T> request, string session, DateTime timestamp) where T : OneNETResponse { // 提前检查业务参数 try { request.Validate(); } catch (OneNETException e) { return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg)); } // 添加协议级请求参数 var txtParams = new OneNETDictionary(request.GetParameters()); txtParams.Add(VERSION, "2.0"); txtParams.Add(FORMAT, format); txtParams.Add(TIMESTAMP, timestamp); txtParams.Add(SESSION, session); txtParams.AddAll(this.systemParameters); // 添加签名参数 (目前不需要) //txtParams.Add(SIGN, OneNETUtils.SignOneNETRequest(txtParams, appSecret)); var paramStr = txtParams.Where(x => x.Value is string) .ToDictionary(k => k.Key, v => v.Value.ToString()); var requestUrl = request.GetURL(context); var reqUrl = webUtils.BuildGetUrl(requestUrl, paramStr); try { var httpHeader = API_KEY + ":" + appKey; string body; byte[] bytesBody = null; switch (request.RequestMethod()) { case HttpRequestMethod.Get: { if (request.IsRequestForByte()) { body = ""; bytesBody = webUtils.DoGetBytes(reqUrl, paramStr, httpHeader); } else { body = webUtils.DoGet(reqUrl, paramStr, httpHeader); } break; } case HttpRequestMethod.Post: body = webUtils.DoPost(reqUrl, request.GetPostContent(), httpHeader); break; case HttpRequestMethod.Put: body = webUtils.DoPut(reqUrl, request.GetPostContent(), httpHeader); break; case HttpRequestMethod.Delete: body = webUtils.DoDelete(reqUrl, httpHeader); break; default: body = webUtils.DoGet(reqUrl, paramStr, httpHeader); break; } // 解释响应结果 T rsp; if (disableParser) { rsp = Activator.CreateInstance <T>(); rsp.Body = body; } else { if (FORMAT_XML.Equals(format)) { var tp = new OneNETXmlParser(); rsp = tp.Parse <T>(body); } else { rsp = request.IsRequestForByte() ? Activator.CreateInstance <T>() : JsonConvert.DeserializeObject <T>(body); if (bytesBody != null) { rsp.BinDataBody = bytesBody; } rsp.Body = body; } } // 追踪错误的请求 if (disableTrace || !rsp.IsError) { return(rsp); } var sb = new StringBuilder(reqUrl).Append(" response error!\r\n").Append(rsp.Body); OneNETLogger.Warn(sb.ToString()); return(rsp); } catch (Exception e) { if (disableTrace) { throw; } var sb = new StringBuilder(reqUrl).Append(" request error!\r\n").Append(e.StackTrace); OneNETLogger.Error(sb.ToString()); throw; } }
private T DoExecute <T>(ITopRequest <T> request, string session, DateTime timestamp) where T : TopResponse { // 提前检查业务参数 try { request.Validate(); } catch (TopException e) { return(createErrorResponse <T>(e.ErrorCode, e.ErrorMsg)); } // 添加协议级请求参数 TopDictionary txtParams = new TopDictionary(request.GetParameters()); txtParams.Add(METHOD, request.GetApiName()); txtParams.Add(VERSION, "2.0"); txtParams.Add(APP_KEY, appKey); txtParams.Add(FORMAT, format); txtParams.Add(PARTNER_ID, "top-sdk-net-20130425"); txtParams.Add(TIMESTAMP, timestamp); txtParams.Add(SESSION, session); txtParams.AddAll(this.systemParameters); // 添加签名参数 txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret)); // 是否需要上传文件 string body; if (request is ITopUploadRequest <T> ) { ITopUploadRequest <T> uRequest = (ITopUploadRequest <T>)request; IDictionary <string, FileItem> fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters()); body = webUtils.DoPost(this.serverUrl, txtParams, fileParams); } else { body = webUtils.DoPost(this.serverUrl, txtParams); } // 解释响应结果 T rsp; if (disableParser) { rsp = Activator.CreateInstance <T>(); rsp.Body = body; } else { if (FORMAT_XML.Equals(format)) { ITopParser tp = new TopXmlParser(); rsp = tp.Parse <T>(body); } else { ITopParser tp = new TopJsonParser(); rsp = tp.Parse <T>(body); } } // 追踪错误的请求 if (!disableTrace) { rsp.ReqUrl = webUtils.BuildGetUrl(this.serverUrl, txtParams); if (rsp.IsError) { topLogger.Warn(rsp.ReqUrl + "\r\n" + rsp.Body); } } return(rsp); }