public override BaseResponse Execute()
        {
            logger.Info("Executing...");
            ParamsVerification();
            BaseResponse response = null;
            SortedDictionary <string, string> paras = new SortedDictionary <string, string>();
            Type type = this.GetType();

            PropertyInfo[] properties = type.GetProperties();
            if (properties != null)
            {
                for (int i = 0; i < properties.Length; i++)
                {
                    string key = properties[i].Name;
                    if (key == "appid")
                    {
                        key = "mch_appid";
                    }
                    if (key == "mch_id")
                    {
                        key = "mchid";
                    }
                    if (key == "body" || key == "sign_type")
                    {
                        continue;
                    }
                    object value = properties[i].GetValue(this);

                    paras.Add(key, (value != null ? value.ToString() : ""));
                }
            }
            string sign = null;

            sign = HashWrapper.MD5_Hash(paras, this.shop_secret);
            logger.Info("sign:" + sign);
            paras.Add("sign", sign);
            NameValueCollection col = new NameValueCollection();

            foreach (KeyValuePair <string, string> param in paras)
            {
                if (param.Value != null && !string.IsNullOrEmpty(param.Value.ToString()))
                {
                    col.Add(param.Key, param.Value);
                }
            }
            string str = null;

            if (needCert)
            {
                str = HttpSercice.PostHttpRequest(this.url, col, RequestType.POST, "text/xml", true, config);
            }
            else
            {
                str = HttpSercice.PostHttpRequest(this.url, col, RequestType.POST, "text/xml");
            }
            logger.Info("response:" + str);
            response = ParseXML(str);
            logger.Info("Done.");
            return(response);
        }
예제 #2
0
        public override BaseResponse Execute()
        {
            PayOrderQueryResponse             response = null;
            SortedDictionary <string, object> paras    = new SortedDictionary <string, object>();
            Type type = this.GetType();

            PropertyInfo[] properties = type.GetProperties();
            if (properties != null)
            {
                for (int i = 0; i < properties.Length; i++)
                {
                    string key   = properties[i].Name;
                    object value = properties[i].GetValue(this);
                    paras.Add(key, value);
                }
            }
            string paraUrl = string.Empty;

            foreach (KeyValuePair <string, object> param in paras)
            {
                if (paraUrl == string.Empty)
                {
                    paraUrl = param.Key + "=" + (param.Value != null ? param.Value.ToString() : "");
                }
                else
                {
                    paraUrl += "&" + param.Key + "=" + (param.Value != null ? param.Value.ToString() : "");
                }
            }
            paraUrl += "&key=" + this.secret;
            string sign = null;

            if (signType.Trim().ToLower() == "md5")
            {
                sign = HashWrapper.MD5_Hash(paraUrl);
            }
            paras.Add("sign", sign);
            NameValueCollection col = new NameValueCollection();

            foreach (KeyValuePair <string, object> param in paras)
            {
                col.Add(param.Key, param.Value != null ? param.Value.ToString() : "");
            }
            string str = HttpSercice.PostHttpRequest(this.url, col, RequestType.POST, "xml");

            response = ParseXML(str);
            return(response);
        }
예제 #3
0
        public ComparisonResults Compare(IUniquelyIdentifiable identifiable)
        {
            bool selfNull  = this.Self == null;
            bool otherNull = identifiable == null;

            if (selfNull && otherNull)
            {
                return(ComparisonResults.Invalidating);
            }
            else if (selfNull ^ otherNull)
            {
                return(ComparisonResults.Invalidating);
            }
            else
            {
                IUniqueIdentifier otherIdentifier = identifiable.GetIdentifier();
                HashWrapper       selfIdentifier  = this.hashWrapper.Value;
                if (otherIdentifier is HashWrapper wrapper)
                {
                    bool hashMatch     = wrapper.Hash == selfIdentifier.Hash;
                    bool instanceMatch = wrapper.Instance == selfIdentifier.Instance;

                    if (hashMatch && instanceMatch)
                    {
                        return(ComparisonResults.Match);
                    }
                    else if (hashMatch)
                    {
                        return(ComparisonResults.DifferentButEquivalent);
                    }
                    else if (instanceMatch)
                    {
                        return(ComparisonResults.Different | ComparisonResults.Invalidating);
                    }
                    else
                    {
                        return(ComparisonResults.Different);
                    }
                }
                else
                {
                    // Since the other instance wasn't a wrapper, it's (probably) not a match. Also, since we have no
                    // idea what the type we contain is, assume we need to invalidate the cache.
                    return(ComparisonResults.Different | ComparisonResults.Invalidating);
                }
            }
        }
예제 #4
0
        public void HighRiskCode_CheckSumTest(string file, string checksum)
        {
            string actual = HashWrapper.GetChecksum(file);

            actual.Should().Be(checksum);
        }
예제 #5
0
        public override BaseResponse Execute()
        {
            logger.Info(this.GetType().FullName + "................");
            logger.Info("url:" + this.url);
            if (string.IsNullOrEmpty(out_trade_no))
            {
                logger.Info("out_trade_no cannot be empty");
                throw new Exception("out_trade_no cannot be empty");
            }
            if (string.IsNullOrEmpty(notify_url))
            {
                logger.Info("notify_url cannot be empty");
                throw new Exception("notify_url cannot be empty");
            }
            if (string.IsNullOrEmpty(spbill_create_ip))
            {
                logger.Info("spbill_create_ip cannot be empty");
                throw new Exception("spbill_create_ip cannot be empty");
            }
            PreOrderResponse response = null;
            SortedDictionary <string, object> paras = new SortedDictionary <string, object>();
            Type type = this.GetType();

            PropertyInfo[] properties = type.GetProperties();
            if (properties != null)
            {
                for (int i = 0; i < properties.Length; i++)
                {
                    string key   = properties[i].Name;
                    object value = properties[i].GetValue(this);
                    paras.Add(key, value);
                }
            }
            string paraUrl = string.Empty;

            foreach (KeyValuePair <string, object> param in paras)
            {
                if (param.Value != null && !string.IsNullOrEmpty(param.Value.ToString()))
                {
                    if (paraUrl == string.Empty)
                    {
                        paraUrl = param.Key + "=" + (param.Value != null ? param.Value.ToString() : "");
                    }
                    else
                    {
                        paraUrl += "&" + param.Key + "=" + (param.Value != null ? param.Value.ToString() : "");
                    }
                }
            }
            paraUrl += "&key=" + this.shop_secret;
            logger.Info("parameters:" + paraUrl);
            string sign = null;

            if (sign_type.Trim().ToLower() == "md5")
            {
                sign = HashWrapper.MD5_Hash(paraUrl);
            }
            sign = sign.ToUpper();
            logger.Info("sign:" + sign);
            paras.Add("sign", sign);
            NameValueCollection col = new NameValueCollection();

            foreach (KeyValuePair <string, object> param in paras)
            {
                if (param.Value != null && !string.IsNullOrEmpty(param.Value.ToString()))
                {
                    col.Add(param.Key, param.Value.ToString());
                }
            }
            string str = HttpSercice.PostHttpRequest(this.url, col, RequestType.POST, "text/xml");

            logger.Info("response:" + str);
            response = ParseXML(str);
            logger.Info("Done.");
            return(response);
        }