Ejemplo n.º 1
0
        public static bool VerifyNotify(SortedDictionary <string, string> inputPara, string notify_id, string sign, string _key, string _input_charset, string _partner)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            bool   flag = Verify(CreateLinkString(FilterPara(inputPara)), sign, _key, _input_charset);
            string str2 = "true";

            if ((notify_id != null) && (notify_id != ""))
            {
                string str3 = "https://mapi.alipay.com/gateway.do?service=notify_verify&";
                str2 = new HttpHelp().DoGet(str3 + "partner=" + _partner + "&notify_id=" + notify_id, null);
            }
            return((str2 == "true") && flag);
        }
Ejemplo n.º 2
0
        public string DoPost(string url, IDictionary <string, string> parameters)
        {
            HttpWebRequest webRequest = this.GetWebRequest(url, "POST", null, null);

            webRequest.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
            byte[] bytes         = Encoding.UTF8.GetBytes(HttpHelp.BuildQuery(parameters));
            Stream requestStream = webRequest.GetRequestStream();

            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();
            HttpWebResponse rsp = (HttpWebResponse)webRequest.GetResponse();

            return(this.GetResponseAsString(rsp, Encoding.UTF8));
        }
Ejemplo n.º 3
0
 public string BuildGetUrl(string url, IDictionary <string, string> parameters)
 {
     if (parameters != null && parameters.Count > 0)
     {
         if (url.Contains("?"))
         {
             url = url + "&" + HttpHelp.BuildQuery(parameters);
         }
         else
         {
             url = url + "?" + HttpHelp.BuildQuery(parameters);
         }
     }
     return(url);
 }
Ejemplo n.º 4
0
        public static bool VerifyNotify(SortedDictionary <string, string> inputPara, string notify_id, string sign, string _key, string _input_charset, string _partner)
        {
            Dictionary <string, string> strs = new Dictionary <string, string>();
            string str  = OutPayHelp.CreateLinkString(OutPayHelp.FilterPara(inputPara));
            bool   flag = OutPayHelp.Verify(str, sign, _key, _input_charset);
            string str1 = "true";

            if ((notify_id == null ? false : notify_id != ""))
            {
                string   str2      = "https://mapi.alipay.com/gateway.do?service=notify_verify&";
                HttpHelp httpHelp  = new HttpHelp();
                string[] strArrays = new string[] { str2, "partner=", _partner, "&notify_id=", notify_id };
                str1 = httpHelp.DoGet(string.Concat(strArrays), null);
            }
            return((str1 != "true" ? true : !flag) ? false : true);
        }
Ejemplo n.º 5
0
        public string DoGet(string url, IDictionary <string, string> parameters)
        {
            if (parameters != null && parameters.Count > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&" + HttpHelp.BuildQuery(parameters);
                }
                else
                {
                    url = url + "?" + HttpHelp.BuildQuery(parameters);
                }
            }
            HttpWebRequest webRequest = this.GetWebRequest(url, "GET", null, null);

            webRequest.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
            HttpWebResponse rsp = (HttpWebResponse)webRequest.GetResponse();

            return(this.GetResponseAsString(rsp, Encoding.UTF8));
        }
Ejemplo n.º 6
0
        public static bool VerifyNotify(SortedDictionary <string, string> inputPara, string notify_id, string sign, string _key, string _input_charset, string _partner)
        {
            Dictionary <string, string> dicArray = new Dictionary <string, string>();

            dicArray = OutPayHelp.FilterPara(inputPara);
            string prestr = OutPayHelp.CreateLinkString(dicArray);
            bool   flag   = OutPayHelp.Verify(prestr, sign, _key, _input_charset);
            string a      = "true";

            if (notify_id != null && notify_id != "")
            {
                string text = "https://mapi.alipay.com/gateway.do?service=notify_verify&";
                a = new HttpHelp().DoGet(string.Concat(new string[]
                {
                    text,
                    "partner=",
                    _partner,
                    "&notify_id=",
                    notify_id
                }), null);
            }
            return(a == "true" && flag);
        }
Ejemplo n.º 7
0
        public static WeiPayResult WeiXinPayOut(OutPayWeiInfo payinfos, string Mch_appid, string Mchid, string Check_Name, string _key)
        {
            WeiPayResult weiPayResult;
            SortedDictionary <string, string> strs = new SortedDictionary <string, string>()
            {
                { "mch_appid", Mch_appid },
                { "mchid", Mchid },
                { "nonce_str", payinfos.Nonce_Str },
                { "partner_trade_no", payinfos.Partner_Trade_No },
                { "openid", payinfos.Openid },
                { "check_name", Check_Name },
                { "amount", payinfos.Amount.ToString() },
                { "desc", payinfos.Desc },
                { "spbill_create_ip", Globals.ServerIP() },
                { "re_user_name", payinfos.Re_User_Name },
                { "device_info", "" }
            };
            string        str           = _key;
            string        mD5           = "";
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<xml>");
            foreach (string key in strs.Keys)
            {
                if (strs[key] != "")
                {
                    string   str1 = mD5;
                    string[] item = new string[] { str1, "&", key, "=", strs[key] };
                    mD5  = string.Concat(item);
                    item = new string[] { "<", key, ">", strs[key], "</", key, ">" };
                    stringBuilder.AppendLine(string.Concat(item));
                }
            }
            mD5 = mD5.Remove(0, 1);
            mD5 = string.Concat(mD5, "&key=", str);
            mD5 = OutPayHelp.GetMD5(mD5, "utf-8");
            mD5 = mD5.ToUpper();
            stringBuilder.AppendLine(string.Concat("<sign>", mD5, "</sign>"));
            stringBuilder.AppendLine("</xml>");
            HttpHelp     httpHelp  = new HttpHelp();
            string       str2      = httpHelp.DoPost(OutPayHelp.WeiPayUrl, stringBuilder.ToString(), OutPayHelp.WeixinCertPassword, OutPayHelp.WeiXinCertPath);
            WeiPayResult innerText = new WeiPayResult()
            {
                return_code      = "FAIL",
                return_msg       = "访问服务器出错了!",
                err_code         = "SERVERERR",
                UserId           = payinfos.UserId,
                Amount           = payinfos.Amount,
                partner_trade_no = payinfos.Partner_Trade_No
            };

            if (!(httpHelp.errstr != ""))
            {
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(str2);
                    innerText.return_code = xmlDocument.SelectSingleNode("/xml/return_code").InnerText;
                    innerText.return_msg  = xmlDocument.SelectSingleNode("/xml/return_msg").InnerText;
                    if (!(innerText.return_code.ToUpper() == "SUCCESS"))
                    {
                        innerText.err_code = "FAIL";
                    }
                    else
                    {
                        innerText.result_code = xmlDocument.SelectSingleNode("/xml/result_code").InnerText;
                        if (!(innerText.result_code.ToUpper() == "SUCCESS"))
                        {
                            innerText.err_code = xmlDocument.SelectSingleNode("/xml/err_code").InnerText;
                        }
                        else
                        {
                            innerText.mch_appid        = xmlDocument.SelectSingleNode("/xml/mch_appid").InnerText;
                            innerText.mchid            = xmlDocument.SelectSingleNode("/xml/mchid").InnerText;
                            innerText.device_info      = xmlDocument.SelectSingleNode("/xml/device_info").InnerText;
                            innerText.nonce_str        = xmlDocument.SelectSingleNode("/xml/nonce_str").InnerText;
                            innerText.result_code      = xmlDocument.SelectSingleNode("/xml/result_code").InnerText;
                            innerText.partner_trade_no = xmlDocument.SelectSingleNode("/xml/partner_trade_no").InnerText;
                            innerText.payment_no       = xmlDocument.SelectSingleNode("/xml/payment_no").InnerText;
                            innerText.payment_time     = xmlDocument.SelectSingleNode("/xml/payment_time").InnerText;
                        }
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    Globals.Debuglog(str2, "_DebuglogBatchPayment.txt");
                    innerText.return_code = "FAIL";
                    innerText.return_msg  = exception.Message.ToString();
                }
                weiPayResult = innerText;
            }
            else
            {
                innerText.return_msg = httpHelp.errstr;
                weiPayResult         = innerText;
            }
            return(weiPayResult);
        }
Ejemplo n.º 8
0
        public static WeiPayResult WeiXinPayOut(OutPayWeiInfo payinfos, string Mch_appid, string Mchid, string Check_Name, string _key)
        {
            SortedDictionary <string, string> dictionary = new SortedDictionary <string, string>();

            dictionary.Add("mch_appid", Mch_appid);
            dictionary.Add("mchid", Mchid);
            dictionary.Add("nonce_str", payinfos.Nonce_Str);
            dictionary.Add("partner_trade_no", payinfos.Partner_Trade_No);
            dictionary.Add("openid", payinfos.Openid);
            dictionary.Add("check_name", Check_Name);
            dictionary.Add("amount", payinfos.Amount.ToString());
            dictionary.Add("desc", payinfos.Desc);
            dictionary.Add("spbill_create_ip", Globals.ServerIP());
            dictionary.Add("re_user_name", payinfos.Re_User_Name);
            dictionary.Add("device_info", "");
            string        str     = _key;
            string        str2    = "";
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("<xml>");
            foreach (string str3 in dictionary.Keys)
            {
                if (dictionary[str3] != "")
                {
                    string str5 = str2;
                    str2 = str5 + "&" + str3 + "=" + dictionary[str3];
                    builder.AppendLine("<" + str3 + ">" + dictionary[str3] + "</" + str3 + ">");
                }
            }
            builder.AppendLine("<sign>" + GetMD5(str2.Remove(0, 1) + "&key=" + str, "utf-8").ToUpper() + "</sign>");
            builder.AppendLine("</xml>");
            HttpHelp     help   = new HttpHelp();
            string       xml    = help.DoPost(WeiPayUrl, builder.ToString(), WeixinCertPassword, WeiXinCertPath);
            WeiPayResult result = new WeiPayResult {
                return_code      = "FAIL",
                return_msg       = "访问服务器出错了!",
                err_code         = "SERVERERR",
                UserId           = payinfos.UserId,
                Amount           = payinfos.Amount,
                partner_trade_no = payinfos.Partner_Trade_No
            };

            if (help.errstr != "")
            {
                result.return_msg = help.errstr;
                return(result);
            }
            try
            {
                XmlDocument document = new XmlDocument();
                document.LoadXml(xml);
                result.return_code = document.SelectSingleNode("/xml/return_code").InnerText;
                result.return_msg  = document.SelectSingleNode("/xml/return_msg").InnerText;
                if (result.return_code.ToUpper() == "SUCCESS")
                {
                    result.result_code = document.SelectSingleNode("/xml/result_code").InnerText;
                    if (result.result_code.ToUpper() == "SUCCESS")
                    {
                        result.mch_appid        = document.SelectSingleNode("/xml/mch_appid").InnerText;
                        result.mchid            = document.SelectSingleNode("/xml/mchid").InnerText;
                        result.device_info      = document.SelectSingleNode("/xml/device_info").InnerText;
                        result.nonce_str        = document.SelectSingleNode("/xml/nonce_str").InnerText;
                        result.result_code      = document.SelectSingleNode("/xml/result_code").InnerText;
                        result.partner_trade_no = document.SelectSingleNode("/xml/partner_trade_no").InnerText;
                        result.payment_no       = document.SelectSingleNode("/xml/payment_no").InnerText;
                        result.payment_time     = document.SelectSingleNode("/xml/payment_time").InnerText;
                        return(result);
                    }
                    result.err_code = document.SelectSingleNode("/xml/err_code").InnerText;
                    return(result);
                }
                result.err_code = "FAIL";
            }
            catch (Exception exception)
            {
                Globals.Debuglog(xml, "_DebuglogBatchPayment.txt");
                result.return_code = "FAIL";
                result.return_msg  = exception.Message.ToString();
            }
            return(result);
        }
Ejemplo n.º 9
0
        public static WeiPayResult WeiXinPayOut(OutPayWeiInfo payinfos, string Mch_appid, string Mchid, string Check_Name, string _key)
        {
            SortedDictionary <string, string> sortedDictionary = new SortedDictionary <string, string>();

            sortedDictionary.Add("mch_appid", Mch_appid);
            sortedDictionary.Add("mchid", Mchid);
            sortedDictionary.Add("nonce_str", payinfos.Nonce_Str);
            sortedDictionary.Add("partner_trade_no", payinfos.Partner_Trade_No);
            sortedDictionary.Add("openid", payinfos.Openid);
            sortedDictionary.Add("check_name", Check_Name);
            sortedDictionary.Add("amount", payinfos.Amount.ToString());
            sortedDictionary.Add("desc", payinfos.Desc);
            sortedDictionary.Add("spbill_create_ip", Globals.ServerIP());
            sortedDictionary.Add("re_user_name", payinfos.Re_User_Name);
            sortedDictionary.Add("device_info", "");
            string        text          = "";
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<xml>");
            foreach (string current in sortedDictionary.Keys)
            {
                if (sortedDictionary[current] != "")
                {
                    string text2 = text;
                    text = string.Concat(new string[]
                    {
                        text2,
                        "&",
                        current,
                        "=",
                        sortedDictionary[current]
                    });
                    stringBuilder.AppendLine(string.Concat(new string[]
                    {
                        "<",
                        current,
                        ">",
                        sortedDictionary[current],
                        "</",
                        current,
                        ">"
                    }));
                }
            }
            text = text.Remove(0, 1);
            text = text + "&key=" + _key;
            text = OutPayHelp.GetMD5(text, "utf-8");
            text = text.ToUpper();
            stringBuilder.AppendLine("<sign>" + text + "</sign>");
            stringBuilder.AppendLine("</xml>");
            HttpHelp     httpHelp     = new HttpHelp();
            string       text3        = httpHelp.DoPost(OutPayHelp.WeiPayUrl, stringBuilder.ToString(), OutPayHelp.WeixinCertPassword, OutPayHelp.WeiXinCertPath);
            WeiPayResult weiPayResult = new WeiPayResult();

            weiPayResult.return_code      = "FAIL";
            weiPayResult.return_msg       = "访问服务器出错了!";
            weiPayResult.err_code         = "SERVERERR";
            weiPayResult.UserId           = payinfos.UserId;
            weiPayResult.Amount           = payinfos.Amount;
            weiPayResult.partner_trade_no = payinfos.Partner_Trade_No;
            WeiPayResult result;

            if (httpHelp.errstr != "")
            {
                weiPayResult.return_msg = httpHelp.errstr;
                result = weiPayResult;
            }
            else
            {
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(text3);
                    weiPayResult.return_code = xmlDocument.SelectSingleNode("/xml/return_code").InnerText;
                    weiPayResult.return_msg  = xmlDocument.SelectSingleNode("/xml/return_msg").InnerText;
                    if (weiPayResult.return_code.ToUpper() == "SUCCESS")
                    {
                        weiPayResult.result_code = xmlDocument.SelectSingleNode("/xml/result_code").InnerText;
                        if (weiPayResult.result_code.ToUpper() == "SUCCESS")
                        {
                            weiPayResult.mch_appid        = xmlDocument.SelectSingleNode("/xml/mch_appid").InnerText;
                            weiPayResult.mchid            = xmlDocument.SelectSingleNode("/xml/mchid").InnerText;
                            weiPayResult.device_info      = xmlDocument.SelectSingleNode("/xml/device_info").InnerText;
                            weiPayResult.nonce_str        = xmlDocument.SelectSingleNode("/xml/nonce_str").InnerText;
                            weiPayResult.result_code      = xmlDocument.SelectSingleNode("/xml/result_code").InnerText;
                            weiPayResult.partner_trade_no = xmlDocument.SelectSingleNode("/xml/partner_trade_no").InnerText;
                            weiPayResult.payment_no       = xmlDocument.SelectSingleNode("/xml/payment_no").InnerText;
                            weiPayResult.payment_time     = xmlDocument.SelectSingleNode("/xml/payment_time").InnerText;
                        }
                        else
                        {
                            weiPayResult.err_code = xmlDocument.SelectSingleNode("/xml/err_code").InnerText;
                        }
                    }
                    else
                    {
                        weiPayResult.err_code = "FAIL";
                    }
                }
                catch (Exception ex)
                {
                    Globals.Debuglog(text3, "_DebuglogBatchPayment.txt");
                    weiPayResult.return_code = "FAIL";
                    weiPayResult.return_msg  = ex.Message.ToString();
                }
                result = weiPayResult;
            }
            return(result);
        }