public IDictionary <string, string> GetParameters()
        {
            ParamDictionary parameters = new ParamDictionary();

            parameters.Add("biz_content", this.Biz_Content);
            return(parameters);
        }
Ejemplo n.º 2
0
 public void RouteValue(RouteValueDictionary routeValue)
 {
     if (routeValue != null)
     {
         routeValue.ToList().ForEach(item =>
         {
             ParamDictionary.Add(item.Key, item.Value.ToString());
         });
     }
 }
Ejemplo n.º 3
0
        private ParamDictionary SerializeBizModel <T>(ParamDictionary requestParams, IRequest <T> request) where T : IResponse
        {
            ParamDictionary result            = requestParams;
            Boolean         isBizContentEmpty = !requestParams.ContainsKey(BIZ_CONTENT) || string.IsNullOrEmpty(requestParams[BIZ_CONTENT]);

            if (isBizContentEmpty && request.GetBizModel() != null)
            {
                IObject bizModel = request.GetBizModel();
                string  content  = Newtonsoft.Json.JsonConvert.SerializeObject(bizModel);
                result.Add(BIZ_CONTENT, content);
            }
            return(result);
        }
Ejemplo n.º 4
0
        private ParamDictionary buildRequestParams <T>(IRequest <T> request, string accessToken, string appAuthToken) where T : IResponse
        {
            // 默认参数
            ParamDictionary oriParams = new ParamDictionary(request.GetParameters());
            // 序列化BizModel
            ParamDictionary result = SerializeBizModel(oriParams, request);

            // 获取参数
            string charset = string.IsNullOrEmpty(this.charset) ? "utf-8" : this.charset;
            string version = string.IsNullOrEmpty(request.Version) ? this.Version : request.Version;

            // 添加协议级请求参数,为空的参数后面会自动过滤,这里不做处理。
            result.Add(METHOD, request.GetApiName());
            result.Add(VERSION, version);
            result.Add(APP_ID, appId);
            result.Add(FORMAT, format);
            result.Add(TIMESTAMP, DateTime.Now);
            result.Add(ACCESS_TOKEN, accessToken);
            result.Add(SIGN_TYPE, signType);
            result.Add(CHARSET, charset);
            result.Add(APP_AUTH_TOKEN, appAuthToken);

            if (request.GetNeedEncrypt())
            {
                if (string.IsNullOrEmpty(result[BIZ_CONTENT]))
                {
                    throw new ApiException("api request Fail ! The reason: encrypt request is not supported!");
                }

                if (string.IsNullOrEmpty(this.encyptKey) || string.IsNullOrEmpty(this.encyptType))
                {
                    throw new ApiException("encryptType or encryptKey must not null!");
                }

                if (!"AES".Equals(this.encyptType))
                {
                    throw new ApiException("api only support Aes!");
                }

                string encryptContent = EncryptUtils.AesEncrypt(this.encyptKey, result[BIZ_CONTENT], this.charset);
                result.Remove(BIZ_CONTENT);
                result.Add(BIZ_CONTENT, encryptContent);
                result.Add(ENCRYPT_TYPE, this.encyptType);
            }

            return(result);
        }