Exemplo n.º 1
0
        /// <summary>
        /// 验签
        /// </summary>
        /// <param name="initStr"></param>
        /// <param name="sign"></param>
        /// <param name="pubKey"></param>
        /// <returns></returns>
        public static bool VerifySign(string initStr, string sign, string pubKey)
        {
            RSASig sig = new RSASig();

            sig.setPublicKey(pubKey);
            return(sig.verifySigature(sign, initStr));
        }
Exemplo n.º 2
0
        public void PayServicemethod()
        {
            try
            {
                string signString = Request.QueryString["SIGN"].Trim();

                //本地Key值
                string pubKey = ConfigurationManager.AppSettings["PublicKey"].ToString().Trim();

                //签名源串
                string initString = "POSID=" + Request.QueryString["POSID"].Trim()
                    + "&BRANCHID=" + Request.QueryString["BRANCHID"].Trim()
                    + "&ORDERID=" + Request.QueryString["ORDERID"].Trim()
                    + "&PAYMENT=" + Request.QueryString["PAYMENT"].Trim()
                    + "&CURCODE=" + Request.QueryString["CURCODE"].Trim()
                    + "&REMARK1=" + Request.QueryString["REMARK1"].Trim()
                    + "&REMARK2=" + Request.QueryString["REMARK2"].Trim()
                    + "&ACC_TYPE=" + Request.QueryString["ACC_TYPE"]
                    + "&SUCCESS=" + Request.QueryString["SUCCESS"].Trim()
                    + "&TYPE=" + Request.QueryString["TYPE"].Trim()
                    + "&REFERER=" + Request.QueryString["REFERER"].Trim()
                    + "&CLIENTIP=" + Request.QueryString["CLIENTIP"].Trim()
                    + "&ACCDATE=" + Request.QueryString["ACCDATE"].Trim();

                RSASig sign = new RSASig();
                sign.setPublicKey(pubKey);

                bool result = sign.verifySigature(signString, initString);
                if (true == result)//验证成功
                {

                    Console.WriteLine("RSA verified!");
                }
                else//验证失败
                {
                    Console.WriteLine("RSA not verified!");
                }

            }
            catch (Exception ex)
            {
                ////写文本,纪录中国建设银行返回消息,比对md5计算结果(如网站不支持写txt文件,可改成写数据库)
                string TOEXCELLR = Request.Url.ToString() + "   " + ex.Message.ToString() + Request.UserHostName.Trim();
                StreamWriter fs = new StreamWriter(Server.MapPath("Return_DATA/" + "m" + DateTime.Now.ToString().Replace(":", "")) + ".txt", false, System.Text.Encoding.Default);
                fs.Write(TOEXCELLR);
                fs.Close();
            }
        }
Exemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            string requestParmas = string.Empty;
            string content       = string.Empty;

            try
            {
                logger.Info("----------------建设银行龙支付回调开始---------------------");
                var requestDictionary = new Dictionary <string, object>();
                logger.Info(JsonConvert.SerializeObject(context.Request.QueryString));//打印参数顺序
                var SignString = new StringBuilder();
                foreach (string key in context.Request.QueryString.Keys)
                {
                    requestDictionary.Add(key, context.Request.QueryString[key]);
                }
                requestParmas = JsonConvert.SerializeObject(requestDictionary);//打印参数
                logger.Info("请求参数:" + requestParmas);
                //拼接签名字符串
                SignString.AppendFormat("POSID={0}&", context.Request.QueryString["POSID"]);
                SignString.AppendFormat("BRANCHID={0}&", context.Request.QueryString["BRANCHID"]);
                SignString.AppendFormat("ORDERID={0}&", context.Request.QueryString["ORDERID"]);
                SignString.AppendFormat("PAYMENT={0}&", context.Request.QueryString["PAYMENT"]);
                SignString.AppendFormat("CURCODE={0}&", context.Request.QueryString["CURCODE"]);
                SignString.AppendFormat("REMARK1={0}&", context.Request.QueryString["REMARK1"]);
                SignString.AppendFormat("REMARK2={0}&", context.Request.QueryString["REMARK2"]);
                if (context.Request.QueryString["ACC_TYPE"] != null)
                {
                    SignString.AppendFormat("ACC_TYPE={0}&", context.Request.QueryString["ACC_TYPE"]);
                }
                SignString.AppendFormat("SUCCESS={0}&", context.Request.QueryString["SUCCESS"]);
                SignString.AppendFormat("TYPE={0}&", context.Request.QueryString["TYPE"]);
                SignString.AppendFormat("REFERER={0}&", context.Request.QueryString["REFERER"]);
                SignString.AppendFormat("CLIENTIP={0}&", context.Request.QueryString["CLIENTIP"]);
                if (context.Request.QueryString["DISCOUNT"] != null)
                {
                    SignString.AppendFormat("DISCOUNT={0}&", context.Request.QueryString["DISCOUNT"]);
                }
                string signString = SignString.ToString().TrimEnd('&');

                logger.Info("参与数字签名的字符串:" + signString);
                string pubKey = GetPubkey().Trim();//获取pubKey
                logger.Info("pubKey:" + pubKey);
                string oldSign = context.Request.QueryString["SIGN"];
                logger.Info("原签名:" + oldSign);
                //开始签名
                RSASig sign = new RSASig();
                sign.setPublicKey(pubKey);
                bool result = sign.verifySigature(oldSign, signString);
                if (result)
                {
                    logger.Info("签名验证成功");
                    bool iState = false;
                    if (context.Request.QueryString["SUCCESS"] == "Y")
                    {//支付成功
                        logger.Info("支付成功");
                        iState = true;
                    }
                    else
                    {//支付失败
                        logger.Info("支付失败");
                        iState = false;
                    }
                    decimal total_amount = Convert.ToDecimal(requestDictionary["PAYMENT"]) * 100;
                    bool    res          = ApiHelper.WxPayNotifyHandle(requestDictionary["ORDERID"].ToString(), //商户订单号
                                                                       iState,                                  //支付状态
                                                                       string.Empty,                            //支付宝交易号
                                                                       total_amount.ToString(),                 //本次交易支付的订单金额
                                                                       string.Empty,
                                                                       logger);
                    if (res)
                    {
                        //返回处理成功页面
                        StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "JSYHServer\\html\\success.html", System.Text.Encoding.GetEncoding("utf-8"));
                        content = sr.ReadToEnd().ToString();
                        sr.Close();
                    }
                    else
                    {
                        //返回处理失败页面
                        StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "JSYHServer\\html\\error.html", System.Text.Encoding.GetEncoding("utf-8"));
                        content = sr.ReadToEnd().ToString();
                        sr.Close();
                    }
                }
                else
                {
                    logger.Info("签名验证失败");
                    //返回处理失败页面
                    StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "JSYHServer\\html\\error.html", System.Text.Encoding.GetEncoding("utf-8"));
                    content = sr.ReadToEnd().ToString();
                    sr.Close();
                }
                context.Response.Clear();
                context.Response.Write(content);
            }
            catch (Exception ex)
            {
                logger.Info("----------------龙支付回调异常---------------------");
                logger.Info("异常错误信息:" + ex.Message);
                logger.Fatal("异常错误信息:" + ex.Message, ex);
                //返回处理失败页面
                StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "JSYHServer\\html\\error.html", System.Text.Encoding.GetEncoding("utf-8"));
                content = sr.ReadToEnd().ToString();
                sr.Close();
                context.Response.Clear();
                context.Response.Write(content);
            }
        }