示例#1
0
        public bool CheckCallbackInfo(PayCallbackInfo info)
        {
            var keys = info.Data.Keys;
            var dict = new Dictionary <string, string>();

            foreach (var key in keys)
            {
                if (key.Equals("sign"))
                {
                    continue;
                }
                dict[key] = info.Data[key];
            }

            //string[] keys = new string[] { "appid", "bank_type", "cash_fee", "fee_type", "is_subscribe", "mch_id", "nonce_str", "openid", "out_trade_no", "result_code", "return_code", "time_end", "total_fee", "trade_type", "transaction_id" };
            //foreach (var key in keys)
            //{
            //    dict[key] = info.Data[key];
            //}


            string sign = GetSignString(dict, config.MCH_KEY);

            if (sign.Equals(info.Data["sign"], StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            return(false);
        }
示例#2
0
        public PayCallbackInfo ParseCallbackInfo(string xmlString)
        {
            var xml = new XmlDocument();

            xml.LoadXml(xmlString);

            if (xml == null)
            {
                return(null);
            }

            var callbackInfo = new PayCallbackInfo();

            string return_code = xml.SelectSingleNode("/xml/return_code").InnerText;

            if (return_code == "SUCCESS")
            {
                callbackInfo.Status = "SUCC";

                var dict = new Dictionary <string, string>();

                var nodes = xml.DocumentElement.ChildNodes;
                for (int i = 0; i < nodes.Count; i++)
                {
                    var node = nodes[i];
                    dict[node.Name] = node.InnerText;
                }
                callbackInfo.Data = dict;
            }
            else if (return_code == "FAIL")
            {
                callbackInfo.Status = "FAIL";
                callbackInfo.Data   = null;
            }

            return(callbackInfo);
        }