Beispiel #1
0
        /// <summary>
        /// 调用API
        /// </summary>
        /// <typeparam name="TRequestParameter">接口参数类别</typeparam>
        /// <typeparam name="TResponseData">响应数据</typeparam>
        /// <param name="pType">接口类型</param>
        /// <param name="pAction">请求操作</param>
        /// <param name="pRequest">请求参数</param>
        /// <returns></returns>
        public static APIResponse <TResponseData> CallAPI <TRequestParameter, TResponseData>(APITypes pType, string pAction, APIRequest <TRequestParameter> pRequest)
            where TRequestParameter : IAPIRequestParameter, new()
            where TResponseData : IAPIResponseData
        {
            string queryString = string.Format("?type={0}&action={1}", pType.ToCode(), pAction);
            var    content     = string.Format("req={0}", HttpUtility.UrlEncode(pRequest.ToJSON()));
            var    strRsp      = APIClientProxy.CallAPI(queryString, content);

            if (!string.IsNullOrWhiteSpace(strRsp))
            {
                if (!string.IsNullOrWhiteSpace(pRequest.JSONP))
                {
                    strRsp = strRsp.Substring(pRequest.JSONP.Length + 1);
                    strRsp = strRsp.Substring(0, strRsp.Length - 1);
                }
                return(strRsp.DeserializeJSONTo <APIResponse <TResponseData> >());
            }
            //
            return(null);
        }
Beispiel #2
0
 /// <summary>
 /// 调用Demo接口
 /// </summary>
 /// <typeparam name="TRequestParameter">接口参数类别</typeparam>
 /// <typeparam name="TResponseData">响应数据</typeparam>
 /// <param name="pAction">请求操作</param>
 /// <param name="pRequest">请求参数</param>
 /// <returns></returns>
 public static APIResponse <TResponseData> CallDemoAPI <TRequestParameter, TResponseData>(string pAction, APIRequest <TRequestParameter> pRequest)
     where TRequestParameter : IAPIRequestParameter, new()
     where TResponseData : IAPIResponseData
 {
     return(APIClientProxy.CallAPI <TRequestParameter, TResponseData>(APITypes.Demo, pAction, pRequest));
 }