Example #1
0
        public ActionResult Recevie()
        {
            LogHelper.Error("回调");

            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            Dictionary <string, string> sArray = GetRequestPost();

            LogHelper.Error("回调" + sArray.Count);
            if (sArray.Count != 0)
            {
                bool flag = AlipaySignature.RSACheckV1(sArray, Common.Alipay.Config.alipay_public_key, Common.Alipay.Config.charset, Common.Alipay.Config.sign_type, false);
                LogHelper.Error("回调" + flag);
                if (flag)
                {
                    //交易状态
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
                    //如果有做过处理,不执行商户的业务程序

                    //注意:
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知


                    string trade_status = Request.Form["trade_status"];

                    string code = Request.Form["out_trade_no"];
                    LogHelper.Error("回调3" + code);


                    var order = DB.ShopOrder.Where(a => a.OrderCode == code).FirstOrDefault();
                    LogHelper.Error("回调4" + trade_status);
                    if (order.State == 1 && (trade_status == "TRADE_SUCCESS" || trade_status == "TRADE_FINISHED"))
                    {
                        order.PayState = ShopEnum.OrderPayState.Pay.GetHashCode();
                        order.PayTime  = DateTime.Now;
                        order.State    = ShopEnum.OrderState.Pay.GetHashCode();
                        DB.ShopOrder.Update(order);
                        var member = DB.Member_Info.FindEntity(order.MemberID);
                        DB.Jiang.GiveJiang(DB.Member_Info.FindEntity(order.MemberID), order);
                    }
                    Response.Write("<script language='JavaScript'>location.href='http://www.jst1314.cn/mobile/mobilecenter/bill';</script>");
                }
                else
                {
                    Response.Write("<script language='JavaScript'>window.open('http://www.jst1314.cn/mobile/mobilecenter/bill');</script>");
                }
            }
            return(View());
        }
Example #2
0
        /// <summary>
        /// 支付成功回调
        /// </summary>
        /// <param name="request"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static AlipayNotifyResponse Notify(AlipayData request, AlipayConfig config)
        {
            var response = request.ToObject <AlipayNotifyResponse>();

            //签名校验
            if (!AlipaySignature.RSACheckV1(request.GetValues(), config.AliPublicKey, response.Charset, response.SignType, config.KeyFromFile))
            {
                throw new Exception("签名校验失败");
            }
            return(response);
        }
Example #3
0
 /// 验证签名
 /// </summary>
 /// <param name="content">需要验证的内容</param>
 /// <param name="signedString">签名结果</param>
 /// <param name="publicKey">公钥</param>
 /// <param name="input_charset">编码格式</param>
 /// <returns></returns>
 public static bool verify2(IDictionary <string, string> parameters, string publicKeyPem, string charset, string signType, bool keyFromFile)
 {
     try
     {
         bool result = AlipaySignature.RSACheckV1(parameters, publicKeyPem, charset, signType, keyFromFile);
         return(result);
     }
     catch
     {
         return(false);
     }
 }
Example #4
0
        public static AlipayReturnData GetNotifyData(string Query)
        {
            AlipayReturnData data = new AlipayReturnData();
            //string Query = HttpContext.Current.Request.Url.Query;
            //Query = HttpUtility.UrlDecode(Query);
            //LogHelper.Info("Post过来的参数:" + Query);
            Dictionary <string, string> paras = new Dictionary <string, string>();
            var coll = BuildParams(Query);

            String[] requestItem = coll.AllKeys;
            for (int i = 0; i < requestItem.Length; i++)
            {
                paras.Add(requestItem[i], coll[requestItem[i]]);
            }
            //验证签名
            if (paras.Keys.Count > 0)
            {
                bool aSignature = AlipaySignature.RSACheckV1(paras, ALI_PUBLIC_KEY, "utf-8");
                if (aSignature)
                {
                    data.app_id       = paras.ContainsKey("app_id") ? paras["app_id"] : string.Empty;
                    data.body         = paras.ContainsKey("body") ? paras["body"] : string.Empty;
                    data.buyer_id     = paras.ContainsKey("buyer_id") ? paras["buyer_id"] : string.Empty;
                    data.gmt_create   = paras.ContainsKey("gmt_create") ? paras["gmt_create"] : string.Empty;
                    data.notify_id    = paras.ContainsKey("notify_id") ? paras["notify_id"] : string.Empty;
                    data.notify_time  = paras.ContainsKey("notify_time") ? paras["notify_time"] : string.Empty;
                    data.notify_type  = paras.ContainsKey("notify_type") ? paras["notify_type"] : string.Empty;
                    data.gmt_payment  = paras.ContainsKey("gmt_payment") ? paras["gmt_payment"] : string.Empty;
                    data.out_trade_no = paras.ContainsKey("out_trade_no") ? paras["out_trade_no"] : string.Empty;
                    data.seller_id    = paras.ContainsKey("seller_id") ? paras["seller_id"] : string.Empty;
                    data.subject      = paras.ContainsKey("subject") ? paras["subject"] : string.Empty;
                    data.total_amount = paras.ContainsKey("total_amount") ? paras["total_amount"] : string.Empty;
                    data.trade_no     = paras.ContainsKey("trade_no") ? paras["trade_no"] : string.Empty;
                    data.trade_status = paras.ContainsKey("trade_status") ? paras["trade_status"] : string.Empty;
                    data.sign         = paras.ContainsKey("sign") ? paras["sign"] : string.Empty;
                    data.sign_type    = paras.ContainsKey("sign_type") ? paras["sign_type"] : string.Empty;
                    LogHelper.Info("异步通知验证签名成功");
                }
                else
                {
                    LogHelper.Info("异步通知验证签名失败");
                }
            }
            else
            {
                LogHelper.Info("异步通知的参数为空");
            }

            return(data);
        }
Example #5
0
        public void Notify()
        {
            var sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                bool flag = AlipaySignature.RSACheckV1(sPara, Config.alipay_public_key, "utf-8", "RSA2", false);

                if (flag) //验签成功 && 关键业务参数校验成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

                    //商户订单号
                    string out_trade_no = Request.Form["out_trade_no"];


                    //支付宝交易号
                    string trade_no = Request.Form["trade_no"];

                    //交易状态
                    //在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,才是买家付款成功。
                    string trade_status = Request.Form["trade_status"];


                    //判断是否在商户网站中已经做过了这次通知返回的处理
                    //如果没有做过处理,那么执行商户的业务程序
                    //如果有做过处理,那么不执行商户的业务程序

                    Response.Write("success");  //请不要修改或删除

                    //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }
Example #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            Dictionary <string, string> sArray = GetRequestPost();

            if (sArray.Count != 0)
            {
                bool flag = AlipaySignature.RSACheckV1(sArray, config.alipay_public_key, config.charset, config.sign_type, false);
                if (flag)
                {
                    int orderid = 0;
                    if (sArray.ContainsKey("out_trade_no"))
                    {
                        orderid = int.Parse(sArray["out_trade_no"]);
                    }

                    DB     db  = new DB();
                    string sql = "update [Order] set State='待发货' where OrderID=" + orderid;
                    db.exsql(sql);



                    //交易状态
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
                    //如果有做过处理,不执行商户的业务程序

                    //注意:
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知

                    string trade_status = Request.Form["trade_status"];



                    Response.Write("success");
                }
                else
                {
                    Response.Write("fail");
                }
            }
        }
Example #7
0
 /// <summary>
 ///     支付回调通知处理
 /// </summary>
 /// <param name="dic"></param>
 /// <returns></returns>
 public bool PayNotifyHandler(Dictionary <string, string> dic)
 {
     try
     {
         var alipaySignPublicKey = _alipaySettings.AlipaySignPublicKey;
         var charset             = _alipaySettings.CharSet;
         var signtype            = _alipaySettings.SignType;
         var flag = AlipaySignature.RSACheckV1(dic, alipaySignPublicKey, charset, signtype, false);
         return(flag);
     }
     catch (Exception e)
     {
         LoggerAction?.Invoke("Error", e.Message);
         return(false);
     }
 }
Example #8
0
        public ActionResult AliPayNotify()
        {
            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            Dictionary <string, string> sArray = GetRequestPost();
            //本地业务处理
            string         number  = sArray["out_trade_no"];
            pay_order      order   = entity.pay_order.FirstOrDefault(p => p.number == number);
            module_product product = entity.module_product.FirstOrDefault(p => p.id == order.product_id);

            if (order.state_pay != true)
            {
                order.pay_time  = DateTime.Now;
                order.state_pay = true;
                int result = entity.SaveChanges();
                MessageTool.SendMessage(order.member_id.Value, "购买通知", "您已成功购买【" + product.name + "】!");
            }
            //本地业务处理 结束
            if (sArray.Count != 0)
            {
                bool flag = AlipaySignature.RSACheckV1(sArray, Config.alipay_public_key, Config.charset, Config.sign_type, false);
                if (flag)
                {
                    //交易状态
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
                    //如果有做过处理,不执行商户的业务程序

                    //注意:
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
                    string trade_status = Request.Form["trade_status"];

                    Response.Write("success");
                }
                else
                {
                    Response.Write("fail");
                }
            }
            return(null);
        }
        private void Notify()
        {
            //切记alipaypublickey是支付宝的公钥,请去open.alipay.com对应应用下查看。
            //bool RSACheckV1(IDictionary<string, string> parameters, string alipaypublicKey, string charset, string signType, bool keyFromFile)
            var flag = AlipaySignature.RSACheckV1(GetRequestPost(), AlipayPublicKey, Charset, SignType, false);

            LogHelper.Logger.Debug("Notify-" + flag);
            if (flag)
            {
                const string serviceUrl = "{0}/api/services/app/{1}/{2}";
                var          url        = string.Format(serviceUrl, ServerPath, "AppAlipayService", "PayNotify");
                LogHelper.Logger.Debug("Notify-url-" + url);
                var param = GetParams();
                LogHelper.Logger.Debug("Notify-param-" + param);
                var post = ApiCallingHelper.Post(url, param);
                LogHelper.Logger.Debug("Notify-data-" + post);
            }
        }
Example #10
0
        public string refund(string d)
        {
            Program.tool.输出log记录("refund.aspx页面 Page_Load被执行");
            //支付宝的公钥
            string alipaypublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApEdd7cyctmuuuiXrerHQTt6Qng0swOgP7+BzZxik3cHdEYvDmApFkTs95/HYuvOdM2rIFKJJ1jV/6ZnLO6PqReHbczQ/zwlJh7ytxNA63Uy9+eELTdxRhF7d3ZbljBO/jzwkIFLoGjDU/VVmw5BSi4RVrfvR4l6B1bJ9yFlKu7W3YfjJ0W+D5vntvo7KlUCIaZ13OsC71Fwy/4HcMkUQy4aUIr21tCb+o8gLVKuBFAN1kO2SIwscJmVlSgzJshO+nL2dpOUNQcYfJqLmxJBMo92EjAYqwxP+1th06k4n/W5jSS1mM5AMXevWKzzvGCt7gflk9dmPyT9STHJocQa75wIDAQAB";
            string charset         = "UTF-8";

            if (Request.Form["out_trade_no"] != "")
            {
            }
            else
            {
                Program.tool.输出log记录(" Request.Form[out_trade_no] == null  error!");
                return("error");
            }
            IFormCollection coll = Request.Form;
            bool            flag = AlipaySignature.RSACheckV1(GetRequestPost(coll), alipaypublicKey, charset, "RSA2", false);

            if (flag)
            {
                Program.tool.输出log记录("flag 通过");
                string out_trade_no = Request.Form["out_trade_no"];                 //商户订单号
                Program.tool.输出log记录("out_trade_no=" + out_trade_no);
                string trade_no = Request.Form["trade_no"];                         //支付宝交易号
                Program.tool.输出log记录("trade_no=" + trade_no);
                decimal refund_fee = Convert.ToDecimal(Request.Form["refund_fee"]); //退款总金额
                Program.tool.输出log记录("refund_fee=" + refund_fee);
                string gmt_refund_pay = Request.Form["gmt_refund_pay"];             //退款支付时间
                Program.tool.输出log记录("gmt_refund_pay=" + gmt_refund_pay);
                return("success");
            }
            else
            {
                //验签失败

                Program.tool.输出log记录("flag 失败输出 failure");
                return("failure");
            }

            //string 订单号 = c["out_trade_no"].ToString();
            //string 买家支付宝账号 = c["buyer_logon_id"].ToString();
            //string 实际收到的款 = c["receipt_amount"].ToString();
            //string 交易状态 = c["trade_status"].ToString();//TRADE_SUCCESS	TRADE_FINISHED 交易支付成功
        }
Example #11
0
        public static bool RSACheckV1(string companyId, IDictionary <string, string> paramsMap)
        {
            try
            {
                AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId);
                if (config == null)
                {
                    throw new MyException("获取支付宝配置失败");
                }

                string signType = config.AliPaySignType == 0 ? "RSA" : "RSA2";
                return(AlipaySignature.RSACheckV1(paramsMap, config.PublicKey, AliPayParam.charset, signType, false));
            }
            catch (Exception ex)
            {
                TxtLogServices.WriteTxtLogEx("AliPayApiServices", "验签报错:" + ex.StackTrace);
                return(false);
            }
        }
Example #12
0
        /// <summary>
        /// 页面跳转同步通知页面
        /// </summary>
        /// <returns></returns>
        public ActionResult ReturnUrl()
        {
            Pay.Log Log = new Pay.Log(Pay.AliPay.AliPayConfig.LogPath);
            Log.Info("ReturnUrl", "支付页面同步回调");
            //将同步通知中收到的所有参数都存放到map中
            IDictionary <string, string> map = GetRequestGet();

            if (map.Count > 0) //判断是否有带返回参数
            {
                try
                {
                    //支付宝的公钥
                    string alipayPublicKey = AliPayConfig.payKey;
                    string signType        = AliPayConfig.signType;
                    string charset         = AliPayConfig.charset;
                    bool   keyFromFile     = false;
                    // 获取支付宝GET过来反馈信息
                    bool verify_result = AlipaySignature.RSACheckV1(map, alipayPublicKey, charset, signType, keyFromFile);
                    if (verify_result)
                    {
                        // 验证成功
                        return(Json(new { Result = true, msg = "验证成功" }));
                    }
                    else
                    {
                        Log.Error("AliPayNotifyUrl", "支付验证失败");
                        return(Json(new { Result = false, msg = "验证失败" }));
                    }
                }
                catch (Exception e)
                {
                    //throw new Exception(e.Message);
                    return(Json(new { Result = false, msg = "验证失败" }));

                    Log.Error("AliPayNotifyUrl", "支付验证失败");
                }
            }
            else
            {
                return(Json(new { Result = false, msg = "无返回参数" }));
            }
        }
Example #13
0
        /// <summary>
        /// 支付异步回调通知 需配置域名 因为是支付宝主动post请求这个action 所以要通过域名访问或者公网ip
        /// </summary>
        public ActionResult Notify()
        {
            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            Dictionary <string, string> sArray = GetRequestPost(Request);

            if (sArray.Count != 0)
            {
                bool flag = AlipaySignature.RSACheckV1(sArray, AlipayPublicKey, CharSet, SignType, false);
                if (flag)
                {
                    AlipayTradeQueryResponseViewModel traceState = GetTraceMsg(sArray["out_trade_no"], sArray["trade_no"]);
                    if (traceState.alipay_trade_query_response.code != "10000")
                    {
                        Console.WriteLine($"获取订单失败,失败原因:{traceState.alipay_trade_query_response.msg}");
                    }

                    //交易状态
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
                    //如果有做过处理,不执行商户的业务程序

                    //注意:
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
                    Console.WriteLine(Request.Form["trade_status"]);

                    return(View("Success"));
                }
                else
                {
                    return(View("Fail"));
                }
            }

            return(View("Fail"));
        }
Example #14
0
        /// <summary>
        /// 异步验签(验签成功后将改变支付状态,并通知支付宝)
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public static string AsynchronousYanQian(Dictionary <string, string> result)
        {
            //这里可以取出相关的值
            string buyer_pay_amount = result["buyer_pay_amount"]; //用户在交易中支付的金额
            string out_trade_no     = result["out_trade_no"];     //原支付请求的商户订单号(订单id)

            //从pem文件中读取支付宝公钥
            ALIPAY_PUBLIC_KEY = GetCurrentPathByAbs() + "rsa_alipay_public_key.pem";

            bool flag;

            try
            {
                flag = AlipaySignature.RSACheckV1(result, ALIPAY_PUBLIC_KEY, CHARSET, sign_type, true);

                WriteLog("支付宝异步验签结果为:" + flag + "\n");
            }
            catch (Exception e)
            {
                return(e.ToString());
            }


            if (flag)
            {
                //验签成功,将数据库中订单的支付状态改变
                if (ChangePayState())
                {
                    //如果数据库插入成功,通知支付宝已收到通知
                    return("success");
                }
                else
                {
                    return("fail");
                }
            }
            else
            {
                return("fail");
            }
        }
Example #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            Dictionary <string, string> sArray  = GetRequestGet();
            Dictionary <string, string> sArrayp = GetRequestPost();

            if (sArray.Count != 0)
            {
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(sArray);
                //Log.Info("支付宝同步返回内容", json);
                string jsonp = Newtonsoft.Json.JsonConvert.SerializeObject(sArrayp);
                //Log.Info("支付宝同步返回内容ppp", jsonp);

                bool flag = AlipaySignature.RSACheckV1(sArray, config.alipay_public_key, config.charset, config.sign_type, false);
                if (flag)
                {
                    Response.Write("同步验证通过");
                }
                else
                {
                    Response.Write("同步验证失败");
                    //total_amount=0.01&
                    //timestamp=2018-08-14+09%3a12%3a42&
                    //sign=d230qm+AkwuGMz9lfEn0pdcPgGxii7%2fGd%2f8gBMHjVvaS8fcAXI1Iv0ktH29yXq0OWYNQte69xV0fUjc1t1jsrIDp6J6uZ5X5YhVKf1hRQCR31M7i5PMAPf7yyDBIImjesaYSAp+udGPJImnpbxNziAOn53sxQHgv2EkZEYcBzQp6jRGinmZoPX7WYTpx+uzRpSlQxtFM080aB3S%2fHCHujbVq+GQbW%2fC6OAUFTe2IzVRHOLfOd0WSgojMqU9d6cq0Jci+oZN7RB5PLCTSY5sJosPKONqzpizqbIl81vicQnp7OM+1WFB3cMZdUr1BUXbJw2Wuf6IcJtI649klWbHUyQ%3d%3d&
                    //trade_no=2018081421001004740535762277&
                    //sign_type=RSA2&
                    //auth_app_id=2018080860963479&
                    //charset=UTF-8&
                    //seller_id=2088002326374601&
                    //method=alipay.trade.page.pay.return&
                    //app_id=2018080860963479&
                    //out_trade_no=YXF201808140911579066&
                    //version=1.0
                }
            }
        }
Example #16
0
        // GET
        public IActionResult Index()
        {
            /* 实际验证过程建议商户添加以下校验。
             *         1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             *         2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             *         3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             *         4、验证app_id是否为该商户本身。
             */
            var sArray = GetRequestPost();
            var msg    = string.Empty;

            if (sArray.Count != 0)
            {
                var flag = AlipaySignature.RSACheckV1(sArray, _settings.Value.alipay_public_key,
                                                      _settings.Value.charset, _settings.Value.sign_type, false);
                if (flag)
                {
                    //交易状态
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
                    //如果有做过处理,不执行商户的业务程序

                    //注意:
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
                    string trade_status = Request.Form["trade_status"];


                    msg = "success";
                }
                else
                {
                    msg = "fail";
                }
            }
            System.IO.File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "result.txt"), msg);
            return(Content(msg));
        }
Example #17
0
        public PayResult GetOrderPaidStatus(string xmlParamter)
        {
            Dictionary <string, string> aliPayResponse = new Dictionary <string, string>();
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlParamter);
            XmlNode     xmlNode = xmlDoc.FirstChild;
            XmlNodeList nodes   = xmlNode.ChildNodes;

            foreach (XmlNode xn in nodes)
            {
                XmlElement xe = (XmlElement)xn;
                aliPayResponse[xe.Name] = xe.InnerText;
            }
            var result = new PayResult();

            if (aliPayResponse.Count == 0)
            {
                return(result);
            }
            if (aliPayResponse.ContainsKey(Common.AliPayInfo.TradeNo) == false)
            {
                return(result);
            }
            if (aliPayResponse.ContainsKey(Common.AliPayInfo.OutTradeNo) == false)
            {
                return(result);
            }
            bool isPaid = string.CompareOrdinal(aliPayResponse[Common.AliPayInfo.TradeStatus], Common.AliPayInfo.TradeSuccess) == 0 ||
                          string.CompareOrdinal(aliPayResponse[Common.AliPayInfo.TradeStatus], Common.AliPayInfo.TradeFinished) == 0;

            result.IsSuccess  = isPaid;
            result.OrderRef   = aliPayResponse[Common.AliPayInfo.OutTradeNo];
            result.GatewayRef = aliPayResponse[Common.AliPayInfo.TradeNo];
            result.IsSuccess  =
                AlipaySignature.RSACheckV1(aliPayResponse, AliPayInfo.AliPayPublicKey, "utf-8", "RSA2", false);
            return(result);
        }
        /// <summary>
        /// 验证请求签名
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool ValidateRequest(HttpRequest request)
        {
            bool flag = false;

            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            this.sArray = this.GetRequestGet(request);
            if (sArray.Count > 0)
            {
                var alipayConfig = ConfigHelper.GetConfigSection <AlipayConfigSection>(AlipayConfigSection.SectionName);
                //注意:这里一定要使用支付宝公钥,不用应用的公钥
                flag = AlipaySignature.RSACheckV1(sArray, alipayConfig.AlipayPublicKey, alipayConfig.CharSet, alipayConfig.SignType, false);
            }
            if (true == flag)
            {
                this.ParseToBizModel();
            }
            return(flag);
        }
        /// <summary>
        /// 同步回调
        /// </summary>
        public void SyncNotify()
        {
            Dictionary <string, string> sArray = GetRequestGet();

            if (sArray.Count != 0)
            {
                bool flag = AlipaySignature.RSACheckV1(sArray, config.alipay_public_key, config.charset, config.sign_type, false);
                if (flag)
                {
                    Response.Write("同步验证通过");
                    log.Info("同步回调,验证通过");
                }
                else
                {
                    Response.Write("同步验证失败");
                    log.Info("同步回调,验证失败");
                }
            }
            else
            {
                log.Info("同步回调,获取到的参数为空");
            }
        }
Example #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        /* 实际验证过程建议商户添加以下校验。
         * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
         * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
         * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
         * 4、验证app_id是否为该商户本身。
         */
        Dictionary <string, string> sArray = GetRequestGet();

        if (sArray.Count != 0)
        {
            bool flag = AlipaySignature.RSACheckV1(sArray, Config.alipay_public_key, Config.charset, Config.sign_type, false);
            if (flag)
            {
                Response.Write("同步验证通过");
            }
            else
            {
                Response.Write("同步验证失败");
            }
        }
    }
Example #21
0
        //支付宝功能
        public JsonResult ReturnView()
        {
            //// 应用ID,您的APPID
            //string app_id = "2016110200785876";
            //// 支付宝网关
            //string gatewayUrl = "https://openapi.alipaydev.com/gateway.do";
            //// 商户私钥,您的原始格式RSA私钥
            //string private_key = "MIIEogIBAAKCAQEAnqbiWEAmoSSeKSZXg2v+okxekGyRRUoDcIMrZxUoagY2UCW9u1gfOIODKtXXssBHJZxtFXEu0t0WPaVRr8RgHgFm1XIPqc93iBtU+4xfpV7U0YsOBUJVz1/3edBYp2yN9ca5MHcePDuXCIgq948bV9wpQN6GgYMXOksxLxIKnxo5F5HNNF5pAshKR5eJXuWMQVfUCNiYHlrubJaSS9eKw3CLpGARdFf/cpypDvfTkgQl5dLVNmNXSmiacBb/lnoE2Kb+2c/5xcV4XoblMC43jlBKFOQsOqLnvki/6o5u9wC+zixoPHEOkZn04DejpkakYL+kiBTJ22LRE2Oc6s+VlwIDAQABAoIBAGi2zX5iGR0TBjEy1WAwz4hfz6qTfe61wz9n1CXdmSchooeT4X7d0v2CD/kd25hnwI3aiUU1xyn2Ms/NZfUVMDudwTnwZtY10TdMkvLU2+xSgzUrCr394pVVSgpksZ8Pz0MBPwn2FUa8Lhu7hGCRXALJlZDzTuP8mkAnkPb4eXo40k5/t0/4f1wqIfaUpEHi0tDYZxxJDWKRDKJHlEQT9TRHckB8B/q93vZnkQ4L2HHGPV+QCHxrqr5IJ+nhaLQsxE0P1l5FUMTt2VyzRmFDtSKmZ+fbUrM5HgzbSagacMDHDNnbqZWu30jrncMeeHgn3q3hhUgu+YWxh1IpExGxw4ECgYEA03CPYdLEHIYKT0Nl9dlpK1heYZkkyA7ONXagYC0e/ZiJA0V20D132txIH7DmC/JXp/skNKNDzqY/4pNKTvfo30gYmyrk1krKYe4RKKc5eHY2yMYH5SXhyqK/En+bssJ16ye/KWExoYLuhknw80CEo2gRXFmo81HNf8QMihQ3vQ8CgYEAwBZa+DCyBeoCByH7iaKDsHoeSFFmZF/bmxDUTfw0Tm7FZ6exMb1NvSh/AlnHgLak+Aj/uw/nGiviCpBgEBVTZ5oAPH3w34aKmoUHKk22u42LT1In06j44ToRbWLHyYmr74gTLEnwqP+kz7OCzBphhPxHJMGkaA0v64qdcjlgLvkCgYATrHuK7KOWy9oVuf24vHwOrnBJwIgtnUMOsnUFve0OR60oAsSlZ7LJSInleP5OykPhu3qI81AR4GI9YNsfMe4XKIwxk/IrBlaCejZahATS8pzyXYrKhZXW1wHUZM9F+NYkBVTCMur9TkOHd0XWPICa+8nxv936lff7FXDdQDhXfQKBgHkg38aodmpyUUsMK+F0ANUVfOkfo5DiPcqAB1ESHC3lfkhKH9v8wvvogIcL9Fl/U3IxwonEkngXehgtSNZ7jDfFjiaXSIC8B8U+4/DSRsvoixO+++xmHmNwybKP2uqFDU4kIesIyWDYrKZpTa7FZ/+DUp2kGreesTw4EecItVWJAoGAWk5N7I1rxLcdaPgc6oyAsQ0e6MDyyzk9tppHO5h2hIEyLXa19ewfCts/hyIU9+9MfUokKUiLueiaQMdei08cAXWKjFmkZ/1YT9jSoPrF+moptSStrwwmOSWfkFjUrC0ez7mueDO9GfYN5/fo+GoDv0CLOmVo2ZE4WONDZXivzRo=";
            //// 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
            string alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIOTX12zAnMQ9nLQfEJgV2iRXR47XNLOhAo4+eZZHxQW67eSmUdDK99DEmLpxTueRaIeJQ4fGfuMBUZm8wl5LatJv0yty3gcyFS+LjfILvJsZ8MumkgiG97X0scGDJ62kaPG+s4cp+ydnYJfWceld0h3nLWFrjosnhAEP58JiKE1/Floc51ZBrhdjAssMPc+kdbD6rFhji+NIV5IAbHeBPT/L6xwsPrg0eRX7F39pD+zTvQdOFBrf1z8TWArjPPgDE7nU6lrjuCuxBT/bXIPyC9smgi6evUcn7TaAN0Dq4Jw+RMfR9UsldRo+3BSv9uuo6V1wtMvGrwSsjFdmF+m7QIDAQAB";
            // 签名方式
            string sign_type = "RSA2";
            // 编码格式
            string charset = "UTF-8";

            var req = Request.QueryString;
            Dictionary <string, string> sArray = GetRequestGet();

            if (sArray.Count != 0)
            {
                bool flag = AlipaySignature.RSACheckV1(sArray, alipay_public_key, charset, sign_type, false);
                if (flag)
                {
                    //Response.Write("同步验证通过");
                    return(Json(new { msg = "1" }));
                }
                else
                {
                    // Response.Write("同步验证失败");
                    return(Json(new { msg = "0" }));
                }
            }
            else
            {
                return(Json(new { msg = "0" }));
            }
        }
Example #22
0
        /// <summary>
        /// 服务器异步通知页面
        /// </summary>
        public ActionResult ReturnUrl()
        {
            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            Dictionary <string, string> sArray = GetRequestGet();

            if (sArray.Count != 0)
            {
                bool flag = AlipaySignature.RSACheckV1(sArray, WeixinConfig.payKey, WeixinConfig.charset, WeixinConfig.signType, false);//支付宝公钥
                //订单号
                OrdersEntity order = ordersbll.GetEntityByOrderSn(sArray["out_trade_no"]);
                if (flag)
                {
                    ViewBag.Result  = "支付成功";
                    ViewBag.icon    = "success";
                    ViewBag.display = "none";
                    ViewBag.Tel     = order.Tel;
                    LogHelper.AddLog("同步验证通过,订单号:" + order.Tel);
                }
                else
                {
                    ViewBag.Result     = "未支付";
                    ViewBag.icon       = "warn";
                    ViewBag.display    = "block";
                    ViewBag.Tel        = order.Tel;
                    ViewBag.TelphoneID = order.TelphoneID;
                    ViewBag.Price      = order.Price;
                    LogHelper.AddLog("同步验证失败,订单号:" + order.Tel);
                }
            }
            return(View());
        }
Example #23
0
        /// <summary>
        /// 服务器异步通知页面
        /// 调用接口,收到异步通知后,返回小写的success,告知支付宝已收到通知:每当交易状态改变时,服务器异步通知页面就会收到支付宝发来的处理结果通知,
        /// 程序执行完后必须打印输出success。如果商户反馈给支付宝的字符不是success这7个字符,支付宝服务器会不断重发通知,直到超过24小时22分钟。
        /// 一般情况下,25小时以内完成8次通知(通知的间隔频率一般是:4m,10m,10m,1h,2h,6h,15h)。  参考示例代码: JAVA版本:out.println("success"); PHP版本:echo "success";
        /// .NET版本:Response.Write("success"); 注:返回success是为了告知支付宝,商户已收到异步,避免重复发送异步通知,与该笔交易的交易状态无关。
        /// </summary>
        public void AliPayNotifyUrl()
        {
            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            Dictionary <string, string> sArray = GetRequestPost();
            string sArraysStr = JsonConvert.SerializeObject(sArray);

            LogHelper.AddLog("支付宝异步调用sArraysStr:" + sArraysStr);
            if (sArray.Count != 0)
            {
                bool   flag    = AlipaySignature.RSACheckV1(sArray, WeixinConfig.payKey, WeixinConfig.charset, WeixinConfig.signType, false);//支付宝公钥
                string orderSn = sArray["out_trade_no"];
                if (flag)
                {
                    //注意:
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
                    string trade_status = Request.Form["trade_status"];
                    if (trade_status == "TRADE_SUCCESS")
                    {
                        //交易状态
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
                        //如果有做过处理,不执行商户的业务程序
                        //订单号
                        if (orderSn.Contains("LX-"))
                        {
                            OrdersEntity order = ordersbll.GetEntityByOrderSn(orderSn);
                            if (order != null)
                            {
                                string total_amount = sArray["total_amount"];
                                if (Convert.ToDecimal(total_amount) == order.Price)
                                {
                                    LogHelper.AddLog("异步调用orderSn:" + orderSn + "total_amount:" + total_amount + "金额一致");
                                    order.PayDate   = DateTime.Now;
                                    order.PayStatus = (int)PayStatus.已支付;
                                    order.Status    = (int)OrderStatus.未发货;
                                    ordersbll.SaveForm(order.Id, order);

                                    //同步下架
                                    TelphoneLiangH5Entity tel = tlbll.GetEntity(order.TelphoneID);//根据靓号id获取靓号,修改售出状态
                                    if (tel != null)
                                    {
                                        tel.SellMark   = 1;
                                        tel.SellerName = order.Host;
                                    }
                                    tlbll.SaveForm(tel.TelphoneID, tel);
                                    LogHelper.AddLog("同步下架:" + tel.Telphone);

                                    //头条url回调
                                    if (!string.IsNullOrEmpty(order.TouUrl))
                                    {
                                        TouTiaoApi(order.TouUrl);
                                    }
                                }
                            }
                        }
                        else if (orderSn.Contains("JM-"))
                        {
                            LogHelper.AddLog("支付宝加盟订单JM-异步调用orderSn:" + orderSn);
                            var order = ordersJMbll.GetEntityByOrderSn(orderSn);
                            if (order != null)
                            {
                                //支付成功,修改加盟订单表
                                order.PayDate   = DateTime.Now;
                                order.PayStatus = (int)PayStatus.已支付;
                                ordersJMbll.SaveForm(order.Id, order);

                                //修改会员表级别
                                var agent = agentbll.GetEntityByOpenId(order.OpenId);//订单里面的OpenId,不是当前微信OpenId
                                if (agent != null)
                                {
                                    agent.LV = order.LV;
                                    agentbll.SaveForm(agent.Id, agent);

                                    decimal direct   = 0;
                                    decimal indirect = 0;

                                    //上级不等于本身,才进行返佣,如果上级就是自己则为顶级
                                    if (agent.Pid != agent.Id)
                                    {
                                        Wechat_AgentEntity agentPid = agentbll.GetEntity(agent.Pid);//上级
                                        if (agentPid != null)
                                        {
                                            Wechat_AgentEntity agentPid2 = agentbll.GetEntity(agentPid.Pid);//上上级
                                            if (agentPid2 != null)
                                            {
                                                //如果父级不等于上上级,则对上上级进行返佣
                                                if (agent.Pid != agentPid2.Id)
                                                {
                                                    //获取返佣规则金额
                                                    DirectHelper.getJMDirect(order.LV, agentPid.LV, agentPid2.LV, out direct, out indirect);
                                                    //上级返佣
                                                    agentPid.profit += direct;
                                                    agentbll.SaveForm(agentPid.Id, agentPid);

                                                    //直接返佣日志
                                                    ComissionLogEntity logEntity = new ComissionLogEntity()
                                                    {
                                                        agent_id         = agentPid.Id,
                                                        agent_name       = agentPid.nickname,
                                                        indirect         = 0,
                                                        invited_agent_id = order.AgentId,
                                                        phonenum         = order.LV,
                                                        profit           = direct,
                                                        status           = 2,//已入账
                                                        orderno          = order.OrderSn
                                                    };
                                                    comissionLogBll.SaveForm(null, logEntity);
                                                    LogHelper.AddLog("支付宝加盟直接返佣:" + direct);

                                                    //上上级返佣
                                                    agentPid2.profit += indirect;
                                                    agentbll.SaveForm(agentPid2.Id, agentPid2);

                                                    //间接返佣日志
                                                    ComissionLogEntity logEntity2 = new ComissionLogEntity()
                                                    {
                                                        agent_id         = agentPid2.Id,
                                                        agent_name       = agentPid2.nickname,
                                                        indirect         = 1,
                                                        invited_agent_id = order.AgentId,
                                                        phonenum         = order.LV,
                                                        profit           = indirect,
                                                        status           = 2,//已入账
                                                        orderno          = order.OrderSn
                                                    };
                                                    comissionLogBll.SaveForm(null, logEntity2);
                                                    LogHelper.AddLog("支付宝加盟直接间接:" + indirect);
                                                }
                                                else
                                                {
                                                    //获取返佣规则金额
                                                    DirectHelper.getJMDirect(order.LV, agentPid.LV, null, out direct, out indirect);
                                                    //上级返佣
                                                    agentPid.profit += direct;
                                                    agentbll.SaveForm(agentPid.Id, agentPid);

                                                    //直接返佣日志
                                                    ComissionLogEntity logEntity = new ComissionLogEntity()
                                                    {
                                                        agent_id         = agentPid.Id,
                                                        agent_name       = agentPid.nickname,
                                                        indirect         = 0,
                                                        invited_agent_id = order.AgentId,
                                                        phonenum         = order.LV,
                                                        profit           = direct,
                                                        status           = 2,//已入账
                                                        orderno          = order.OrderSn
                                                    };
                                                    comissionLogBll.SaveForm(null, logEntity);
                                                    LogHelper.AddLog("支付宝加盟上级和顶级同一人只直接返佣:" + direct);
                                                }
                                            }
                                            else
                                            {
                                                //获取返佣规则金额
                                                DirectHelper.getJMDirect(order.LV, agentPid.LV, null, out direct, out indirect);
                                                //上级返佣
                                                agentPid.profit += direct;
                                                agentbll.SaveForm(agentPid.Id, agentPid);

                                                //直接返佣日志
                                                ComissionLogEntity logEntity = new ComissionLogEntity()
                                                {
                                                    agent_id         = agentPid.Id,
                                                    agent_name       = agentPid.nickname,
                                                    indirect         = 0,
                                                    invited_agent_id = order.AgentId,
                                                    phonenum         = order.LV,
                                                    profit           = direct,
                                                    status           = 2,//已入账
                                                    orderno          = order.OrderSn
                                                };
                                                comissionLogBll.SaveForm(null, logEntity);
                                                LogHelper.AddLog("支付宝加盟上上级为空只返上级直接返佣:" + direct);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                LogHelper.AddLog("订单号不存在:" + orderSn);
                            }
                        }
                        else if (orderSn.Contains("FX-"))
                        {
                            OrdersEntity order = ordersbll.GetEntityByOrderSn(orderSn);
                            if (order != null)
                            {
                                string total_amount = sArray["total_amount"];
                                if (Convert.ToDecimal(total_amount) == order.Price)
                                {
                                    LogHelper.AddLog("支付宝分销订单FX-异步调用orderSn:" + orderSn + "total_amount:" + total_amount + "金额一致");
                                    order.PayDate   = DateTime.Now;
                                    order.PayStatus = (int)PayStatus.已支付;
                                    order.Status    = (int)OrderStatus.未发货;
                                    ordersbll.SaveForm(order.Id, order);

                                    //同步下架
                                    TelphoneLiangH5Entity tel = tlbll.GetEntity(order.TelphoneID);//根据靓号id获取靓号,修改售出状态
                                    if (tel != null)
                                    {
                                        tel.SellMark   = 1;
                                        tel.SellerName = order.Host;
                                    }
                                    tlbll.SaveForm(tel.TelphoneID, tel);
                                    LogHelper.AddLog("同步下架:" + tel.Telphone);


                                    var logList = comissionLogBll.GetList("{\"orderno\":\"" + orderSn + "\"}");
                                    if (logList.Count() > 0)
                                    {
                                        foreach (var item in logList)
                                        {
                                            //返佣?不能直接返佣,需要等到开卡之后再返佣
                                            item.status = 1;//已支付,不入账
                                            comissionLogBll.SaveForm(item.id, item);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    LogHelper.AddLog("异步调用success,订单号:" + orderSn);
                    Response.Write("success");
                }
                else
                {
                    LogHelper.AddLog("异步调用fail,订单号:" + orderSn);
                    Response.Write("fail");
                }
            }
        }
        //public Task<T> SdkExecuteAsync<T>(IAopRequest<T> request) where T : AopResponse
        //{
        //    throw new NotImplementedException();
        //}

        public bool RSACheckV1(Dictionary <string, string> data)
        {
            return(AlipaySignature.RSACheckV1(data, Options.AlipayPublicKey, Options.CharSet, Options.SignType, false));
        }
Example #25
0
        private string PayCallBack(Action <BXTOrder> callback, string requestParams = null)
        {
            string        result = "fail";
            StringBuilder sb     = new StringBuilder();
            PayCBLog      paylog = new PayCBLog();

            paylog.IsPay = 0;

            string out_trade_no   = string.Empty;
            string total_amount   = string.Empty;
            string receipt_amount = string.Empty;
            string trade_status   = string.Empty;

            try
            {
                sb.AppendLine("开始获取参数组:");
                //string requestParams = Request.Form.ToString().Replace("?", string.Empty);
                sb.AppendLine(requestParams);
                //获取所有get请求的参数
                var parms = AliPayBLL.Instance.GetRequestGet(requestParams);
                sb.AppendLine(JsonHelper.ToJson(parms));
                //签名校验对比
                bool isSign = AlipaySignature.RSACheckV1(parms, AliPayConfig.alipay_public_key, AliPayConfig.charset, AliPayConfig.sign_type, false);
                if (Convert.ToDateTime(parms["notify_time"]) <= DateTime.Now.AddMonths(-10))
                {
                    return(result);
                }
                if (isSign)
                {
                    sb.AppendLine("两者签名一致");
                    out_trade_no   = parms["out_trade_no"];   //获取商户订单号
                    total_amount   = parms["total_amount"];   //订单金额
                    receipt_amount = parms["receipt_amount"]; //实收金额
                    trade_status   = parms["trade_status"];   //交易状态:交易支付成功-TRADE_SUCCESS  交易结束,不可退款-TRADE_FINISHED
                    sb.AppendLine("支付宝返回交易结果:商品订单号:{0},商品订单金额:{1},商品实收金额{2},商品交易状态:{3}".FormatWith(out_trade_no, total_amount, receipt_amount, trade_status));

                    //根据商品订单号获取实体数据
                    BXTOrder order = BXTOrderBLL.Instance.Search(out_trade_no);
                    if (order.IsPay != 1)
                    {
                        if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                        {
                            result = "success";
                            //记录支付成功
                            order.IsPay  = 1;
                            paylog.IsPay = 1;
                            if (BXTOrderBLL.Instance.Update(order).Ok)
                            {
                                //回调
                                callback(order);
                            }
                        }
                    }
                    else
                    {
                        if (order.OrderType == 2 || order.OrderType == 4 || order.OrderType == 8)
                        {
                            result = "success";
                            callback(order);
                        }
                    }
                }
                else
                {
                    sb.AppendLine("两者签名不一致!");
                }
            }
            catch (Exception e)
            {
                sb.AppendLine("处理异常:" + e.ToString());
            }
            //防止多次回调插数据
            if (out_trade_no.IsNotNullOrEmpty() && PayCBLogBLL.Instance.Search(out_trade_no) == null)
            {
                paylog.CallBackTime = DateTime.Now;
                paylog.IsDelete     = 0;
                paylog.Memo         = sb.ToString();
                paylog.TradeNo      = out_trade_no;
                paylog.TradeStatus  = trade_status;
                PayCBLogBLL.Instance.Add(paylog);
            }
            return(result);
        }
Example #26
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */

            var sArray = GetRequestPost(context.Request.Form);

            if (sArray.Count == 0)
            {
                LogFactory.Warn("请求参数为空!请求参数字典:" + JsonConvert.SerializeObject(sArray));

                return;
            }

            if (!AlipaySignature.RSACheckV1(sArray, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type, false))
            {
                LogFactory.Warn("支付宝验签失败!请求参数字典:" + JsonConvert.SerializeObject(sArray));

                return;
            }

            var seller_id = context.Request.Form["seller_id"];

            var app_id = context.Request.Form["app_id"];

            var trade_status = context.Request.Form["trade_status"];

            var trade_no = context.Request.Form["trade_no"];

            var out_trade_no = context.Request.Form["out_trade_no"];

            var total_amount = context.Request.Form["total_amount"];

            if (seller_id != AlipayConfig.seller_id || app_id != AlipayConfig.app_id)
            {
                LogFactory.Warn("支付宝商户信息异常!请求参数字典:" + JsonConvert.SerializeObject(sArray));

                return;
            }

            //交易状态
            //判断该笔订单是否在商户网站中已经做过处理
            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
            //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
            //如果有做过处理,不执行商户的业务程序

            //注意:
            //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知

            if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
            {
                RequestFactory.QueryRequest($"https://plugin.{badoucaiHost}/api/plugin/reChargeNotify?orderid={out_trade_no}&tradeid={trade_no}&amount={total_amount}");

                LogFactory.Info("充值成功!请求参数字典:" + JsonConvert.SerializeObject(sArray));

                context.Response.Write("success");
            }
        }
Example #27
0
        public string UpdateOrder(string id)
        {
            LogHelper.WriteLog("支付返回:" + id, LogHelper.LogType.Debug);
            if (id != "wxpay")
            {
                NameValueCollection          collection  = HttpContext.Current.Request.Form;
                String[]                     requestItem = HttpContext.Current.Request.Form.AllKeys;
                IDictionary <string, string> sArray      = new Dictionary <string, string>();

                for (int i = 0; i < requestItem.Length; i++)
                {
                    sArray.Add(requestItem[i], collection[requestItem[i]]);
                }

                LogHelper.WriteLog("支付返回:" + JsonConvert.SerializeObject(sArray), LogHelper.LogType.Debug);

                var success = AlipaySignature.RSACheckV1(sArray, Ali_PUBLIC_KEY, CHARSET, "RSA2", false);
                if (!success)
                {
                    return("fail");
                }

                var orderno  = sArray["out_trade_no"];
                var trade_no = sArray["trade_no"];
                var sign     = bll.UpdateOrder(orderno, trade_no);

                return(sign.Success ? "success" : "fail");
            }
            else
            {
                HttpContextBase context      = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context
                HttpRequestBase request      = context.Request;                                       //定义传统request对象
                var             verifyResult = "false";
                var             requestXml   = WeiXinUtil.GetRequestXmlData(request);
                var             dic          = WeiXinUtil.FromXml(requestXml);

                LogHelper.WriteLog("支付返回:" + JsonConvert.SerializeObject(dic), LogHelper.LogType.Debug);

                var returnCode = WeiXinUtil.GetValueFromDic <string>(dic, "return_code");

                if (!string.IsNullOrEmpty(returnCode) && returnCode == "SUCCESS")//通讯成功
                {
                    var result = WeiXinUtil.WePayNotifyValidation(dic);
                    if (result)
                    {
                        var transactionid = WeiXinUtil.GetValueFromDic <string>(dic, "transaction_id");

                        if (!string.IsNullOrEmpty(transactionid))
                        {
                            var queryXml       = WeiXinUtil.BuildQueryRequest(transactionid, dic);
                            var queryResult    = WeiXinUtil.Post("https://api.mch.weixin.qq.com/pay/orderquery", queryXml);
                            var queryReturnDic = WeiXinUtil.FromXml(queryResult);

                            if (WeiXinUtil.ValidatonQueryResult(queryReturnDic))//查询成功
                            {
                                verifyResult = "true";
                                var status = WeiXinUtil.GetValueFromDic <string>(dic, "result_code");

                                if (!string.IsNullOrEmpty(status) && status == "SUCCESS")
                                {
                                    //var order = new Order()
                                    //{
                                    //    OrderNumber = WeiXinUtil.GetValueFromDic<string>(dic, "out_trade_no"),
                                    //    TransactionId = transactionid,
                                    //    ProductPrice = WeiXinUtil.GetValueFromDic<decimal>(dic, "total_fee") / 100,
                                    //    TradeType = WeiXinUtil.GetValueFromDic<string>(dic, "trade_type"),
                                    //    BankType = WeiXinUtil.GetValueFromDic<string>(dic, "bank_type"),
                                    //    PayDate = DateTime.Parse(WeiXinUtil.GetValueFromDic<string>(dic, "time_end")),
                                    //    StatusId = 1,
                                    //    IsPresent = false,
                                    //    AddDate = DateTime.Now,
                                    //    IsDelete = false
                                    //};
                                    //CURD.Add(order, ConfigHelper.WriteDB);
                                    var orderNo = WeiXinUtil.GetValueFromDic <string>(dic, "out_trade_no");
                                    var sign    = bll.UpdateOrder(orderNo, transactionid);

                                    return(WeiXinUtil.BuildReturnXml("SUCCESS", "成功"));
                                }
                            }
                            else
                            {
                                return(WeiXinUtil.BuildReturnXml("FAIL", "订单查询失败"));
                            }
                        }
                        else
                        {
                            return(WeiXinUtil.BuildReturnXml("FAIL", "支付结果中微信订单号不存在"));
                        }
                    }
                    else
                    {
                        return(WeiXinUtil.BuildReturnXml("FAIL", "签名失败"));
                    }
                }
                else
                {
                    string returnmsg;
                    dic.TryGetValue("return_msg", out returnmsg);
                    throw new Exception("异步通知错误:" + returnmsg);
                }

                return(WeiXinUtil.BuildReturnXml("FAIL", "签名失败"));;
            }
        }
Example #28
0
    protected void Page_Load(object sender, EventArgs e)
    {
        /* 实际验证过程建议商户添加以下校验。
         * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
         * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
         * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
         * 4、验证app_id是否为该商户本身。
         */
        Logger.Log("Notify_url::Call back from alipay...");
        Dictionary <string, string> sArray = GetRequestPost();

        if (sArray.Count != 0)
        {
            var seller_email    = Request.Form["seller_email"];
            var aliAccount      = Config.getAliAccount(seller_email);
            var alipayPublicKey = string.Format(Config.alipay_public_key, aliAccount.AppName);

            bool flag = AlipaySignature.RSACheckV1(sArray, alipayPublicKey, Config.charset, Config.sign_type, true);
            if (flag)
            {
                //交易状态
                //判断该笔订单是否在商户网站中已经做过处理
                //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
                //如果有做过处理,不执行商户的业务程序

                //注意:
                //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知

                string trade_status = Request.Form["trade_status"];
                string trade_no     = Request.Form["trade_no"];
                Logger.Log("Callback for '" + trade_no + "' with status " + trade_status);

                if (trade_status == "TRADE_SUCCESS" || trade_status == "TRADE_FINISHED")
                {
                    if (SucceedAnOrder())
                    {
                        Response.Write("success");//Don't delete this
                    }
                    else
                    {
                        Response.Write("fail");
                    }
                }
                else
                {
                    if (FailedAnOrder())
                    {
                        Response.Write("success");//Don't delete this
                    }
                    else
                    {
                        Response.Write("fail");
                    }
                }
            }
            else
            {
                Logger.Log("Notify_url::Verify Sign Fail");
                Response.Write("fail");
            }
        }
    }
Example #29
0
        /// <summary>
        /// 服务器异步通知页面
        /// 调用接口,收到异步通知后,返回小写的success,告知支付宝已收到通知:每当交易状态改变时,服务器异步通知页面就会收到支付宝发来的处理结果通知,
        /// 程序执行完后必须打印输出success。如果商户反馈给支付宝的字符不是success这7个字符,支付宝服务器会不断重发通知,直到超过24小时22分钟。
        /// 一般情况下,25小时以内完成8次通知(通知的间隔频率一般是:4m,10m,10m,1h,2h,6h,15h)。  参考示例代码: JAVA版本:out.println("success"); PHP版本:echo "success";
        /// .NET版本:Response.Write("success"); 注:返回success是为了告知支付宝,商户已收到异步,避免重复发送异步通知,与该笔交易的交易状态无关。
        /// </summary>
        public void AliPayNotifyUrl()
        {
            /* 实际验证过程建议商户添加以下校验。
             * 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
             * 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
             * 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
             * 4、验证app_id是否为该商户本身。
             */
            Dictionary <string, string> sArray = GetRequestPost();
            string sArraysStr = JsonConvert.SerializeObject(sArray);

            LogHelper.AddLog("异步调用sArraysStr:" + sArraysStr);
            if (sArray.Count != 0)
            {
                bool   flag    = AlipaySignature.RSACheckV1(sArray, WeixinConfig.payKey, WeixinConfig.charset, WeixinConfig.signType, false);//支付宝公钥
                string orderSn = sArray["out_trade_no"];
                if (flag)
                {
                    //注意:
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
                    string trade_status = Request.Form["trade_status"];
                    if (trade_status == "TRADE_SUCCESS")
                    {
                        //交易状态
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
                        //如果有做过处理,不执行商户的业务程序
                        //订单号
                        OrdersEntity order = ordersbll.GetEntityByOrderSn(orderSn);
                        if (order != null)
                        {
                            string total_amount = sArray["total_amount"];
                            if (Convert.ToDecimal(total_amount) == order.Price)
                            {
                                LogHelper.AddLog("异步调用orderSn:" + orderSn + "total_amount:" + total_amount + "金额一致");
                                order.PayDate   = DateTime.Now;
                                order.PayStatus = (int)PayStatus.已支付;
                                order.Status    = (int)OrderStatus.未发货;
                                ordersbll.SaveForm(order.Id, order);

                                //不同步
                                TelphoneLiangH5Entity tel = tlbll.GetEntity(order.TelphoneID);//根据靓号id获取靓号,修改售出状态
                                if (tel != null)
                                {
                                    tel.SellMark   = 1;
                                    tel.SellerName = order.Host;
                                }
                                tlbll.SaveForm(tel.TelphoneID, tel);

                                //头条url回调
                                if (!string.IsNullOrEmpty(order.TouUrl))
                                {
                                    TouTiaoApi(order.TouUrl);
                                }
                            }
                        }
                    }

                    LogHelper.AddLog("异步调用success,订单号:" + orderSn);
                    Response.Write("success");
                }
                else
                {
                    LogHelper.AddLog("异步调用fail,订单号:" + orderSn);
                    Response.Write("fail");
                }
            }
        }
Example #30
0
        /// <summary>
        /// 服务器异步通知页面
        /// </summary>
        public void AliPayNotifyUrl()
        {
            Pay.Log Log = new Pay.Log(AliPayConfig.LogPath);
            Log.Info("AliPayNotifyUrl", "支付页面异步回调");
            IDictionary <string, string> map = GetRequestPost();

            if (map.Count > 0)
            {
                try
                {
                    string alipayPublicKey = AliPayConfig.payKey;
                    string signType        = AliPayConfig.signType;
                    string charset         = AliPayConfig.charset;
                    bool   keyFromFile     = false;

                    bool verify_result = AlipaySignature.RSACheckV1(map, alipayPublicKey, charset, signType, keyFromFile);
                    Log.Info("AliPayNotifyUrl验签", verify_result + "");

                    //验签成功后,按照支付结果异步通知中的描述,对支付结果中的业务内容进行二次校验,校验成功后再response中返回success并继续商户自身业务处理,校验失败返回false
                    if (verify_result)
                    {
                        //商户订单号
                        string out_trade_no = map["out_trade_no"];
                        //支付宝交易号
                        string trade_no = map["trade_no"];
                        //交易创建时间
                        string gmt_create = map["gmt_create"];
                        //交易付款时间
                        string gmt_payment = map["gmt_payment"];
                        //通知时间
                        string notify_time = map["notify_time"];
                        //通知类型  trade_status_sync
                        string notify_type = map["notify_type"];
                        //通知校验ID
                        string notify_id = map["notify_id"];
                        //开发者的app_id
                        string app_id = map["app_id"];
                        //卖家支付宝用户号
                        string seller_id = map["seller_id"];
                        //买家支付宝用户号
                        string buyer_id = map["buyer_id"];
                        //实收金额
                        string receipt_amount = map["receipt_amount"];
                        //交易状态
                        string return_code = map["trade_status"];

                        //交易状态TRADE_FINISHED的通知触发条件是商户签约的产品不支持退款功能的前提下,买家付款成功;
                        //或者,商户签约的产品支持退款功能的前提下,交易已经成功并且已经超过可退款期限
                        //状态TRADE_SUCCESS的通知触发条件是商户签约的产品支持退款功能的前提下,买家付款成功
                        if (return_code == "TRADE_FINISHED" || return_code == "TRADE_SUCCESS")
                        {
                            string msg;

                            Log.Error("AliPayNotifyUrl", receipt_amount + "==" + trade_no + "==" + return_code + "==" + out_trade_no + "==" + gmt_payment);

                            //判断该笔订单是否在商户网站中已经做过处理
                            ///支付回调的业务处理
                            //bool res = OrderBll.Value.CompleteAliPay(receipt_amount, trade_no, return_code, out_trade_no, gmt_payment, out msg);
                            bool res = true;

                            if (res == false)
                            {
                                Response.Write("添加支付信息失败!");
                            }
                            Log.Error("AliPayNotifyUrl", "支付成功");
                            Response.Write("success");  //请不要修改或删除
                        }
                    }
                    else
                    {
                        //验证失败
                        Log.Error("AliPayNotifyUrl", "支付验证失败");
                        Response.Write("验证失败!");
                    }
                }
                catch (Exception e)
                {
                    Response.Write("添加支付信息失败!");
                    Log.Error("AliPayNotifyUrl", "添加支付信息失败");
                }
            }
            else
            {
                //无返回参数
                Response.Write("无返回参数!");
                Log.Error("AliPayNotifyUrl", "无返回参数");
            }
        }