Esempio n. 1
0
        public static object ConvertToParam(ParamType paramType, object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            object param;

            switch (paramType)
            {
            case ParamType.Md5:
                param = HashingUtil.Md5(obj.ToString(), false);
                break;

            case ParamType.Object:
                param = obj.ToString();
                break;

            case ParamType.Json:
                param = JsonConvert.SerializeObject(obj, ApiConstants.JsonSerializerSettings);
                break;

            default:
            {
                param = obj.GetType().IsPrimitive ? obj : obj.ToString();
                break;
            }
            }

            return(param);
        }
Esempio n. 2
0
        public static SignatureBody GetSign(List <KeyValuePair <string, object> > paramList, BaseStringPreprocessingDelegate baseStringPreprocessing = null)
        {
            if (paramList == null)
            {
                return(SignatureBody.Nil);
            }

            var baseString = GetBaseString(paramList, false, baseStringPreprocessing);
            // 获得签名
            var body = new SignatureBody
            {
                Signature  = HashingUtil.Md5(baseString),
                BaseString = baseString
            };

            return(body);
        }