/// <summary> /// 退款按钮点击方法【不支持】 /// </summary> protected void RefundButton_Click(object sender, EventArgs e) { OrderInfo order = ButtoStart(); //余额处理 decimal money = order.Balance; int isCod = PayPlugins.ReadPayPlugins(order.PayKey).IsCod; if (order.OrderStatus == (int)OrderStatus.HasReturn && isCod == (int)BoolType.False) { money += OrderBLL.ReadNoPayMoney(order); } else if (order.OrderStatus == (int)OrderStatus.NoEffect && OrderActionBLL.ReadLast(order.Id, order.OrderStatus).StartOrderStatus == (int)OrderStatus.WaitCheck && isCod == (int)BoolType.False) { money += OrderBLL.ReadNoPayMoney(order); } if (money > 0) { var accountRecord = new UserAccountRecordInfo { RecordType = (int)AccountRecordType.Money, Money = money, Point = 0, Date = DateTime.Now, IP = ClientHelper.IP, Note = "退还订单:" + order.OrderNumber + "的金额", UserId = order.UserId, UserName = order.UserName }; UserAccountRecordBLL.Add(accountRecord); } //更新订单 int startOrderStatus = order.OrderStatus; order.OrderStatus = (int)order.OrderStatus; order.Balance = 0; order.CouponMoney = 0; order.IsRefund = (int)BoolType.True; ButtonEnd(order, Note.Text, OrderOperate.Refund, startOrderStatus); }
protected void Page_Load(object sender, EventArgs e) { string suchtml = "<meta content=\"China TENCENT\" name=\"TENCENT_ONLINE_PAYMENT\">\n" + "<script language=\"javascript\">\n" + "window.location.href='http://" + Request.ServerVariables["Http_Host"] + "/Plugins/Pay/TenPay/Show.aspx';\n" + "</script>"; string errmsg = ""; PayConfig payConfig = new PayConfig(); Md5Pay md5pay = new Md5Pay(); md5pay.Key = payConfig.BusinessKey; //卖家商户key md5pay.Bargainor_id = payConfig.BargainorID; //判断签名 if (md5pay.GetPayValueFromUrl(Request.QueryString, out errmsg)) { //认证签名成功 //支付判断 if (md5pay.Pay_Result == Md5Pay.PAYOK) { //支付成功,同定单号md5pay.Transaction_id可能会多次通知,请务必注意判断订单是否重复的逻辑 //跳转到成功页面,财付通收到<meta content=\"China TENCENT\" name=\"TENCENT_ONLINE_PAYMENT\">,认为通知成功 string orderNumber = md5pay.Sp_billno; OrderInfo order = OrderBLL.ReadOrderByNumber(orderNumber, 0); if (order.ID > 0) { if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.OrderStatus = (int)OrderStatus.WaitCheck; OrderBLL.UpdateOrder(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderID = order.ID; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户财付通在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.AddOrderAction(orderAction); } } else { UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0); if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False) { userRecharge.IsFinish = (int)BoolType.True; UserRechargeBLL.UpdateUserRecharge(userRecharge); //账户记录 string note = "财付通在线冲值:" + userRecharge.Number; UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName); } } //StreamWriter sw = File.AppendText(Server.MapPath("log.txt")); //sw.WriteLine(DateTime.Now.ToString() + orderNumber); //sw.Flush(); //sw.Close(); Response.Write(suchtml); } else { //支付失败,请不要按成功处理 Response.Write("支付失败" + errmsg); } } else { //认证签名失败 Response.Write("认证签名失败"); } }
/// <summary> /// 撤销按钮点击方法 /// </summary> protected void BackButton_Click(object sender, EventArgs e) { OrderInfo order = ButtoStart(); int startOrderStatus = order.OrderStatus; order.OrderStatus = OrderActionBLL.ReadLast(order.Id, order.OrderStatus).StartOrderStatus; //减去用户积分,积分为负数 int sendPoint = 0; if (startOrderStatus == (int)OrderStatus.ReceiveShipping && order.IsActivity == (int)BoolType.False) { //sendPoint = -OrderBLL.ReadOrderSendPoint(order.Id); //根据订单付款金额全额返还积分 sendPoint = -(int)Math.Floor(OrderBLL.ReadNoPayMoney(order)); } if (startOrderStatus == (int)OrderStatus.HasShipping && order.OrderStatus == (int)OrderStatus.ReceiveShipping && order.IsActivity == (int)BoolType.False)//相当于收货确认 { //sendPoint = OrderBLL.ReadOrderSendPoint(order.Id); //根据订单付款金额全额返还积分 sendPoint = -(int)Math.Floor(OrderBLL.ReadNoPayMoney(order)); } if (sendPoint != 0) { var accountRecord = new UserAccountRecordInfo { RecordType = (int)AccountRecordType.Point, Money = 0, Point = sendPoint, Date = DateTime.Now, IP = ClientHelper.IP, Note = ShopLanguage.ReadLanguage("OrderBack").Replace("$OrderNumber", order.OrderNumber), UserId = order.UserId, UserName = order.UserName }; UserAccountRecordBLL.Add(accountRecord); } //更新商品库存数量 switch (startOrderStatus) { case (int)OrderStatus.WaitPay: case (int)OrderStatus.WaitCheck: if (order.OrderStatus == (int)OrderStatus.NoEffect) //相当于取消操作 { ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Minus); } break; case (int)OrderStatus.NoEffect: ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Plus); break; case (int)OrderStatus.HasReturn: ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Plus); ProductBLL.ChangeSendCountByOrder(order.Id, ChangeAction.Plus); break; case (int)OrderStatus.Shipping: if (order.OrderStatus == (int)OrderStatus.HasShipping) { ProductBLL.ChangeSendCountByOrder(order.Id, ChangeAction.Plus); } break; case (int)OrderStatus.HasShipping: if (order.OrderStatus == (int)OrderStatus.Shipping) { ProductBLL.ChangeSendCountByOrder(order.Id, ChangeAction.Minus); } if (order.OrderStatus == (int)OrderStatus.HasReturn) //相当于退货确认操作 { ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Minus); ProductBLL.ChangeSendCountByOrder(order.Id, ChangeAction.Minus); } break; default: break; } //更新订单 ButtonEnd(order, Note.Text, OrderOperate.Back, startOrderStatus); }
protected void Page_Load(object sender, EventArgs e) { PayConfig payConfig = new PayConfig(); string alipayNotifyURL = "https://www.alipay.com/cooperate/gateway.do?"; string key = payConfig.SecurityKey; //partner 的对应交易安全校验码(必须填写) string _input_charset = "utf-8"; string partner = payConfig.Partner; //partner合作伙伴id(必须填写) alipayNotifyURL = alipayNotifyURL + "service=notify_verify" + "&partner=" + partner + "¬ify_id=" + Request.QueryString["notify_id"]; //获取支付宝ATN返回结果,true是正确的订单信息,false 是无效的 string responseTxt = Get_Http(alipayNotifyURL, 120000); int i; NameValueCollection coll = Request.QueryString; String[] requestarr = coll.AllKeys; //进行排序; string[] Sortedstr = BubbleSort(requestarr); //构造待md5摘要字符串 ; StringBuilder prestr = new StringBuilder(); for (i = 0; i < Sortedstr.Length; i++) { if (Request.Form[Sortedstr[i]] != "" && Sortedstr[i] != "sign" && Sortedstr[i] != "sign_type") { if (i == Sortedstr.Length - 1) { prestr.Append(Sortedstr[i] + "=" + Request.QueryString[Sortedstr[i]]); } else { prestr.Append(Sortedstr[i] + "=" + Request.QueryString[Sortedstr[i]] + "&"); } } } prestr.Append(key); //生成Md5摘要; string mysign = GetMD5(prestr.ToString(), _input_charset); string sign = Request.QueryString["sign"]; if (mysign == sign && responseTxt == "true") //验证支付发过来的消息,签名是否正确 { //更新数据库的订单语句 message = "成功付款"; string orderNumber = RequestHelper.GetQueryString <string>("out_trade_no"); OrderInfo order = OrderBLL.ReadOrderByNumber(orderNumber, 0); if (order.ID > 0) { if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.OrderStatus = (int)OrderStatus.WaitCheck; OrderBLL.UpdateOrder(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderID = order.ID; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户支付宝在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.AddOrderAction(orderAction); message = "您已经成功支付订单:" + orderNumber; } } else { UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0); if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False) { userRecharge.IsFinish = (int)BoolType.True; UserRechargeBLL.UpdateUserRecharge(userRecharge); //账户记录 string note = "支付宝在线冲值:" + userRecharge.Number; UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName); message = "您的冲值已经成功完成"; } } } else { message = "支付订单出现问题"; } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //检查待付款订单是否超时失效,超时则更新为失效状态 OrderBLL.CheckOrderPayTime(); int orderId = RequestHelper.GetQueryString <int>("Id"); sendPoint = OrderBLL.ReadOrderSendPoint(orderId); if (orderId != int.MinValue) { CheckAdminPower("ReadOrder", PowerCheckType.Single); order = OrderBLL.Read(orderId); order.UserName = System.Web.HttpUtility.UrlDecode(order.UserName, System.Text.Encoding.UTF8); int isCod = PayPlugins.ReadPayPlugins(order.PayKey).IsCod; if ((order.OrderStatus == (int)OrderStatus.WaitPay || order.OrderStatus == (int)OrderStatus.WaitCheck && isCod == (int)BoolType.True) && order.IsActivity == (int)BoolType.False) { canEdit = true; } orderActionList = OrderActionBLL.ReadList(orderId); ShowButton(order); #region 获取快递信息 if (order.OrderStatus == (int)OrderStatus.HasShipping) { ShippingInfo tempShipping = ShippingBLL.Read(order.ShippingId); string show = RequestHelper.GetQueryString <string>("show"); //string apiurl = "http://api.kuaidi100.com/api?id=2815b2d431fdfd26&com=" + typeCom + "&nu=" + nu + "&show=" + show + "&muti=1&order=asc"; string apiurl = "http://www.kuaidi100.com/applyurl?key=2815b2d431fdfd26&com=" + tempShipping.ShippingCode + "&nu=" + order.ShippingNumber + "&show=" + show + "&muti=1&order=desc"; //Response.Write (apiurl); WebRequest request = WebRequest.Create(@apiurl); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); Encoding encode = Encoding.UTF8; StreamReader reader = new StreamReader(stream, encode); shippingLink = reader.ReadToEnd(); } #endregion //正在处理中的退款订单或商品 orderRefundList = OrderRefundBLL.ReadListValid(orderId); //有正在处理中的退款订单或商品,禁用功能按钮 if (orderRefundList.Count(k => !OrderRefundBLL.HasReturn(k.Status)) > 0) { divOperate.Visible = false; divNotice.Visible = true; lblNotice.Text = "该订单有正在处理中的退款订单或商品..."; } } //如果付款操作,发送signalr消息 if (RequestHelper.GetQueryString <int>("paysuccess") == 1) { IHubContext chat = GlobalHost.ConnectionManager.GetHubContext <PushHub>(); chat.Clients.All.sendMessage(1); } } //不支持退货和退款操作,如果要退货退款,请线下操作 ReturnButton.Visible = false; }
public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); //检查支付结果中transaction_id是否存在 if (!notifyData.IsSet("transaction_id")) { //若transaction_id不存在,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "支付结果中微信订单号不存在"); Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml()); //page.Response.Write(res.ToXml()); //page.Response.End(); } else { string transaction_id = notifyData.GetValue("transaction_id").ToString(); //查询订单,判断订单真实性 if (!QueryOrder(transaction_id)) ////沙箱测试只能用out_trade_no //if (notifyData.IsSet("out_trade_no") && !QueryOrderByout_trade_no(notifyData.GetValue("out_trade_no").ToString())) { //若订单查询失败,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml()); //page.Response.Write(res.ToXml()); //page.Response.End(); } //查询订单成功 else { Log.Debug(this.GetType().ToString(), "订单查询成功 "); /************在这里加入商户自己的逻辑***********************************************************/ //attach:以逗号分开的订单Id字符串,与支付时提交的数据一致 if (notifyData.IsSet("attach")) { string attach = notifyData.GetValue("attach").ToString(); string[] orderIds = attach.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string orderId in orderIds) { var order = OrderBLL.Read(int.Parse(orderId)); if (order.Id > 0) { #region 正常流程 待付款--》待审核 if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.PayKey = "WxPay"; order.PayName = "微信支付"; order.WxPayTradeNo = transaction_id; //沙箱测试用out_trade_no //order.WxPayTradeNo = notifyData.GetValue("out_trade_no").ToString(); order.OrderStatus = (int)OrderStatus.WaitCheck; order.PayDate = RequestHelper.DateNow; OrderBLL.Update(order); #region 拼团订单付款:团长付款--开团+增加参团记录;成员付款--增加参团记录 if (order.IsActivity == (int)OrderKind.GroupBuy) { var orderDetail = OrderDetailBLL.ReadList(order.Id).FirstOrDefault() ?? new OrderDetailInfo(); if (orderDetail.Id > 0) { var product = ProductBLL.Read(orderDetail.ProductId); //团长付款 if (order.FavorableActivityId <= 0) { //开团 int groupId = GroupBuyBLL.Add(new GroupBuyInfo { Leader = order.UserId, ProductId = product.Id, StartTime = DateTime.Now, EndTime = DateTime.Now.AddDays(ShopConfig.ReadConfigInfo().GroupBuyDays), Quantity = product.GroupQuantity, //团购订单支付成功之后计数加1 SignCount = 1 }); //订单绑定团购Id Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("[FavorableActivityId]", groupId); OrderBLL.UpdatePart("[Order]", dict, order.Id); //增加参团记录 GroupSignBLL.Add(new GroupSignInfo { GroupId = groupId, UserId = order.UserId, OrderId = order.Id, SignTime = DateTime.Now }); } else//参团者付款--放到参团者checkout { ////增加参团记录 //GroupSignBLL.Add(new GroupSignInfo //{ // GroupId = order.FavorableActivityId, // UserId = order.UserId, // OrderId = order.Id, // SignTime = DateTime.Now //}); ////开团表signcount加1 //GroupBuyBLL.PlusSignCount(order.FavorableActivityId); } } } #endregion #region 自提订单 生成提货码 //避免重复数据,一个订单对应一个提货码,提货码没有有效期,使用过后失效 if (order.SelfPick == 1 && PickUpCodeBLL.ReadByOrderId(order.Id).Id <= 0) { PickUpCodeInfo pkCode = new PickUpCodeInfo(); pkCode.OrderId = order.Id; pkCode.Status = 0; pkCode.PickCode = PickUpCodeBLL.CreatePickUpCode(); int pickCodeId = PickUpCodeBLL.Add(pkCode); } #endregion #region 价订单 if (order.IsActivity == (int)OrderKind.Bargain) { BargainOrderBLL.HandleBargainOrderPay(order.FavorableActivityId); } #endregion //发送订单支付成功通知 SendPayOrderMsg(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderId = order.Id; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户微信在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.Add(orderAction); } #endregion #region 非正常流程 待付款超时已失效(未退款)--》待审核 if (order.OrderStatus == (int)OrderStatus.NoEffect && order.IsRefund == 0) { order.PayKey = "WxPay"; order.PayName = "微信支付"; order.WxPayTradeNo = transaction_id; order.OrderStatus = (int)OrderStatus.WaitCheck; order.PayDate = RequestHelper.DateNow; OrderBLL.Update(order); #region 拼团订单付款:团长付款--开团+增加参团记录;成员付款--增加参团记录 if (order.IsActivity == (int)OrderKind.GroupBuy) { var orderDetail = OrderDetailBLL.ReadList(order.Id).FirstOrDefault() ?? new OrderDetailInfo(); if (orderDetail.Id > 0) { var product = ProductBLL.Read(orderDetail.ProductId); //团长付款 if (order.FavorableActivityId <= 0) { //开团 int groupId = GroupBuyBLL.Add(new GroupBuyInfo { Leader = order.UserId, ProductId = product.Id, StartTime = DateTime.Now, EndTime = DateTime.Now.AddDays(ShopConfig.ReadConfigInfo().GroupBuyDays), Quantity = product.GroupQuantity, //团购订单支付成功之后计数加1 SignCount = 1 }); //订单绑定团购Id Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("[FavorableActivityId]", groupId); OrderBLL.UpdatePart("[Order]", dict, order.Id); //增加参团记录 GroupSignBLL.Add(new GroupSignInfo { GroupId = groupId, UserId = order.UserId, OrderId = order.Id, SignTime = DateTime.Now }); } else//参团者付款--放到参团者checkout { ////增加参团记录 //GroupSignBLL.Add(new GroupSignInfo //{ // GroupId = order.FavorableActivityId, // UserId = order.UserId, // OrderId = order.Id, // SignTime = DateTime.Now //}); ////开团表signcount加1 //GroupBuyBLL.PlusSignCount(order.FavorableActivityId); } } } #endregion #region 自提订单 生成提货码 //避免重复数据,一个订单对应一个提货码,提货码没有有效期,使用过后失效 if (order.SelfPick == 1 && PickUpCodeBLL.ReadByOrderId(order.Id).Id <= 0) { PickUpCodeInfo pkCode = new PickUpCodeInfo(); pkCode.OrderId = order.Id; pkCode.Status = 0; pkCode.PickCode = PickUpCodeBLL.CreatePickUpCode(); int pickCodeId = PickUpCodeBLL.Add(pkCode); } #endregion #region 价订单 if (order.IsActivity == (int)OrderKind.Bargain) { BargainOrderBLL.HandleBargainOrderPay(order.FavorableActivityId); } #endregion #region 扣除支付积分 if (order.Point > 0) { //减少积分 UserAccountRecordInfo uarInfo = new UserAccountRecordInfo(); uarInfo.RecordType = (int)AccountRecordType.Point; uarInfo.UserId = order.UserId; uarInfo.UserName = order.UserName; uarInfo.Note = "支付订单:" + order.OrderNumber; uarInfo.Point = -order.Point; uarInfo.Money = 0; uarInfo.Date = DateTime.Now; uarInfo.IP = ClientHelper.IP; UserAccountRecordBLL.Add(uarInfo); } #endregion #region 减少商品库存 ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Plus); #endregion //发送订单支付成功通知 SendPayOrderMsg(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderId = order.Id; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户微信在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.Add(orderAction); } #endregion //记录微信支付交易单号 if (order.OrderStatus == (int)OrderStatus.WaitCheck && string.IsNullOrEmpty(order.WxPayTradeNo)) { order.WxPayTradeNo = transaction_id; OrderBLL.Update(order); } notifyResult = true; } } } /************在这里加入商户自己的逻辑***********************************************************/ WxPayData res = new WxPayData(); res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml()); //page.Response.Write(res.ToXml()); //page.Response.End(); } } }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { AlipayNotify aliNotify = new AlipayNotify(); bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); if (verifyResult) //验证成功 { if (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS") // 判断支付状态TRADE_FINISHED(文档中有枚举表可以参考) { //更新数据库的订单语句 string orderNumber = RequestHelper.GetForm <string>("out_trade_no"); OrderInfo order = OrderBLL.ReadOrderByNumber(orderNumber, 0); if (order.ID > 0) { if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.OrderStatus = (int)OrderStatus.WaitCheck; OrderBLL.UpdateOrder(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderID = order.ID; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户支付宝在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.AddOrderAction(orderAction); } } //else //{ // UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0); // if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False) // { // userRecharge.IsFinish = (int)BoolType.True; // UserRechargeBLL.UpdateUserRecharge(userRecharge); // //账户记录 // string note = "支付宝在线冲值:" + userRecharge.Number; // UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName); // } //} } Response.Write("success"); //请不要修改或删除 } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sPara = GetRequestGet(); if (sPara.Count > 0)//判断是否有带返回参数 { AlipayNotify aliNotify = new AlipayNotify(); bool verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]); if (verifyResult)//验证成功 { if (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS") { //更新数据库的订单语句 message = "成功付款"; string orderNumber = RequestHelper.GetQueryString <string>("out_trade_no"); OrderInfo order = OrderBLL.ReadOrderByNumber(orderNumber, 0); if (order.ID > 0) { if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.OrderStatus = (int)OrderStatus.WaitCheck; OrderBLL.UpdateOrder(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderID = order.ID; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户支付宝在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.AddOrderAction(orderAction); message = "您已经成功支付订单:" + orderNumber; } } //else //{ // UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0); // if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False) // { // userRecharge.IsFinish = (int)BoolType.True; // UserRechargeBLL.UpdateUserRecharge(userRecharge); // //账户记录 // string note = "支付宝在线冲值:" + userRecharge.Number; // UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName); // message = "您的冲值已经成功完成"; // } //} ResponseHelper.Redirect("PrePaidCourse.aspx"); } else { Response.Write("trade_status=" + Request.QueryString["trade_status"]); } } else//验证失败 { Response.Write("验证失败"); } } else { Response.Write("无返回参数"); } }
public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); //检查支付结果中transaction_id是否存在 if (!notifyData.IsSet("transaction_id")) { //若transaction_id不存在,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "支付结果中微信订单号不存在"); Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } string transaction_id = notifyData.GetValue("transaction_id").ToString(); //查询订单,判断订单真实性 if (!QueryOrder(transaction_id)) { //若订单查询失败,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } //查询订单成功 else { //更新数据库的订单语句 string orderNumber = notifyData.GetValue("out_trade_no").ToString(); OrderInfo order = OrderBLL.ReadOrderByNumber(orderNumber, 0); if (order.ID > 0) { if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.OrderStatus = (int)OrderStatus.WaitCheck; OrderBLL.UpdateOrder(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderID = order.ID; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "微信支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.AddOrderAction(orderAction); } } WxPayData res = new WxPayData(); res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { PayConfig payConfig = new PayConfig(); string alipayNotifyURL = "https://www.alipay.com/cooperate/gateway.do?"; string key = payConfig.SecurityKey; //partner 的对应交易安全校验码(必须填写) string partner = payConfig.Partner; //partner合作伙伴id(必须填写) alipayNotifyURL = alipayNotifyURL + "service=notify_verify" + "&partner=" + partner + "¬ify_id=" + Request.Form["notify_id"]; //获取支付宝ATN返回结果,true是正确的订单信息,false 是无效的 string responseTxt = Get_Http(alipayNotifyURL, 120000000); int i; NameValueCollection coll = Request.Form; String[] requestarr = coll.AllKeys; //进行排序; string[] Sortedstr = BubbleSort(requestarr); //构造待md5摘要字符串 ; string prestr = ""; for (i = 0; i < Sortedstr.Length; i++) { if (Request.Form[Sortedstr[i]] != "" && Sortedstr[i] != "sign" && Sortedstr[i] != "sign_type") { if (i == Sortedstr.Length - 1) { prestr = prestr + Sortedstr[i] + "=" + Request.Form[Sortedstr[i]]; } else { prestr = prestr + Sortedstr[i] + "=" + Request.Form[Sortedstr[i]] + "&"; } } } prestr = prestr + key; //生成Md5摘要; string mysign = GetMD5(prestr); string sign = Request.Form["sign"]; //StreamWriter sw = File.AppendText(Server.MapPath("log.txt")); //sw.WriteLine(DateTime.Now.ToString() + "返回页面:" + RequestHelper.GetStringForm("out_trade_no") + ":" + Request.Form["trade_status"]); //sw.WriteLine("mysign:" + mysign + ";sign:" + sign + ";responseTxt:" + responseTxt); //sw.Flush(); //sw.Close(); if (mysign == sign && responseTxt == "true") //验证支付发过来的消息,签名是否正确 { //sw = File.AppendText(Server.MapPath("log.txt")); //sw.WriteLine(DateTime.Now.ToString() + "验证成功:" + RequestHelper.GetStringForm("out_trade_no") +":"+ Request.Form["trade_status"]); //sw.Flush(); //sw.Close(); if (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "WAIT_SELLER_SEND_GOODS")// 判断支付状态TRADE_FINISHED(文档中有枚举表可以参考) { //更新数据库的订单语句 string orderNumber = RequestHelper.GetForm <string>("out_trade_no"); OrderInfo order = OrderBLL.ReadOrderByNumber(orderNumber, 0); if (order.ID > 0) { if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.OrderStatus = (int)OrderStatus.WaitCheck; OrderBLL.UpdateOrder(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderID = order.ID; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户支付宝在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.AddOrderAction(orderAction); } } else { UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0); if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False) { userRecharge.IsFinish = (int)BoolType.True; UserRechargeBLL.UpdateUserRecharge(userRecharge); //账户记录 string note = "支付宝在线冲值:" + userRecharge.Number; UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName); } } Response.Write("success"); } else { Response.Write("fail"); } } else { Response.Write("fail"); } }
protected void Page_Load(object sender, EventArgs e) { string out_trade_no = RequestHelper.GetQueryString <string>("order_id"); string[] orderIds = out_trade_no.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string orderId in orderIds) { var order = OrderBLL.Read(int.Parse(orderId)); if (order.Id > 0) { #region 正常流程 待付款--》待审核 if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.PayKey = "WxPay"; order.PayName = "微信支付"; order.OrderStatus = (int)OrderStatus.WaitCheck; order.PayDate = RequestHelper.DateNow; OrderBLL.Update(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderId = order.Id; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户微信在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.Add(orderAction); } #endregion #region 非正常流程 待付款超时已失效--》待审核 if (order.OrderStatus == (int)OrderStatus.NoEffect) { order.PayKey = "WxPay"; order.PayName = "微信支付"; order.OrderStatus = (int)OrderStatus.WaitCheck; order.PayDate = RequestHelper.DateNow; OrderBLL.Update(order); #region 扣除支付积分 if (order.Point > 0) { //减少积分 UserAccountRecordInfo uarInfo = new UserAccountRecordInfo(); uarInfo.RecordType = (int)AccountRecordType.Point; uarInfo.UserId = order.UserId; uarInfo.UserName = order.UserName; uarInfo.Note = "支付订单:" + order.OrderNumber; uarInfo.Point = -order.Point; uarInfo.Money = 0; uarInfo.Date = DateTime.Now; uarInfo.IP = ClientHelper.IP; UserAccountRecordBLL.Add(uarInfo); } #endregion #region 减少商品库存 ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Plus); #endregion //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderId = order.Id; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户微信在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.Add(orderAction); } #endregion } } }
protected void Page_Load(object sender, EventArgs e) { PayConfig payConfig = new PayConfig(); string merchant_key = payConfig.MerchantKey; ///商户密钥 string merchant_id = Request["merchant_id"].ToString(); ///获取商户编号 string orderid = Request["orderid"].ToString(); ///获取订单编号 string amount = Request["amount"].ToString(); ///获取订单金额 string dealdate = Request["date"].ToString(); ///获取交易日期 string succeed = Request["succeed"].ToString(); ///获取交易结果,Y成功,N失败 string mac = Request["mac"].ToString(); ///获取安全加密串 string merchant_param = Request["merchant_param"].ToString(); ///获取商户私有参数 string couponid = Request["couponid"].ToString(); ///获取优惠券编码 string couponvalue = Request["couponvalue"].ToString(); ///获取优惠券面额 ///生成加密串,注意顺序 string SrctStr = "merchant_id=" + merchant_id + "&orderid=" + orderid + "&amount=" + amount + "&date=" + dealdate + "&succeed=" + succeed + "&merchant_key=" + merchant_key; string mymac = FormsAuthentication.HashPasswordForStoringInConfigFile(SrctStr, "MD5"); if (mac == mymac) { if (succeed == "Y") { //更新数据库的订单语句 message = "成功付款"; string orderNumber = orderid; OrderInfo order = OrderBLL.ReadOrderByNumber(orderNumber, 0); if (order.ID > 0) { if (order.OrderStatus == (int)OrderStatus.WaitPay) { order.OrderStatus = (int)OrderStatus.WaitCheck; OrderBLL.UpdateOrder(order); //增加操作记录 OrderActionInfo orderAction = new OrderActionInfo(); orderAction.OrderID = order.ID; orderAction.OrderOperate = (int)OrderOperate.Pay; orderAction.StartOrderStatus = (int)OrderStatus.WaitPay; orderAction.EndOrderStatus = (int)OrderStatus.WaitCheck; orderAction.Note = "客户快钱在线支付"; orderAction.IP = ClientHelper.IP; orderAction.Date = RequestHelper.DateNow; orderAction.AdminID = 0; orderAction.AdminName = string.Empty; OrderActionBLL.AddOrderAction(orderAction); message = "您已经成功支付订单:" + orderNumber; } } else { UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0); if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False) { userRecharge.IsFinish = (int)BoolType.True; UserRechargeBLL.UpdateUserRecharge(userRecharge); //账户记录 string note = "快钱在线冲值:" + userRecharge.Number; UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName); message = "您的冲值已经成功完成"; } } } else { message = "支付订单失败"; } } else { message = "签名错误"; } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //检查待付款订单是否超时失效,超时则更新为失效状态 OrderBLL.CheckOrderPayTime(); //订单自动收货 OrderBLL.CheckOrderRecieveTimeProg(); CheckAdminPower("ReadOrder", PowerCheckType.Single); OrderNumber.Text = RequestHelper.GetQueryString <string>("OrderNumber"); OrderStatus.Text = RequestHelper.GetQueryString <string>("OrderStatus"); Consignee.Text = RequestHelper.GetQueryString <string>("Consignee"); StartAddDate.Text = RequestHelper.GetQueryString <string>("StartAddDate"); EndAddDate.Text = RequestHelper.GetQueryString <string>("EndAddDate"); SelfPick.Text = RequestHelper.GetQueryString <string>("SelfPick"); OrderSearchInfo orderSearch = new OrderSearchInfo(); orderSearch.OrderNumber = RequestHelper.GetQueryString <string>("OrderNumber"); intOrderStatus = RequestHelper.GetQueryString <int>("OrderStatus"); //如果查找已删除订单 if (intOrderStatus == (int)Entity.OrderStatus.HasDelete) { orderSearch.IsDelete = (int)BoolType.True;//已删除 } else { orderSearch.OrderStatus = intOrderStatus; orderSearch.IsDelete = (int)BoolType.False;//未删除 } orderSearch.Consignee = RequestHelper.GetQueryString <string>("Consignee"); orderSearch.StartAddDate = RequestHelper.GetQueryString <DateTime>("StartAddDate"); orderSearch.EndAddDate = RequestHelper.GetQueryString <DateTime>("EndAddDate"); orderSearch.SelfPick = RequestHelper.GetQueryString <int>("SelfPick"); PageSize = Session["AdminPageSize"] == null ? 20 : Convert.ToInt32(Session["AdminPageSize"]); AdminPageSize.Text = Session["AdminPageSize"] == null ? "20" : Session["AdminPageSize"].ToString(); var orderList = OrderBLL.SearchList(CurrentPage, PageSize, orderSearch, ref Count); //取得订单最后一次操作的时间 var orderActinList = OrderActionBLL.ReadListLastDate(orderList.Select(k => k.Id).ToArray()); foreach (var order in orderList) { var orderAction = orderActinList.FirstOrDefault(k => k.OrderId == order.Id) ?? new OrderActionInfo(); //此处使用InvoiceTitle字段来临时存储 order.InvoiceTitle = orderAction.OrderId > 0 ? orderAction.Date.ToString() : ""; } BindControl(orderList, RecordList, MyPager); #region 除订单 if (RequestHelper.GetQueryString <string>("Action") == "delete") { CheckAdminPower("DeleteOrder", PowerCheckType.Single); int orderId = RequestHelper.GetQueryString <int>("orderId"); if (orderId > 0) { OrderInfo tmpOrder = OrderBLL.Read(orderId); if (tmpOrder.OrderStatus == (int)JWShop.Entity.OrderStatus.WaitPay) {//待付款直接删除退还积分库存 #region 退还积分 if (tmpOrder.Point > 0) { var accountRecord = new UserAccountRecordInfo { RecordType = (int)AccountRecordType.Point, Money = 0, Point = tmpOrder.Point, Date = DateTime.Now, IP = ClientHelper.IP, Note = "取消订单:" + tmpOrder.OrderNumber + ",退回用户积分", UserId = tmpOrder.UserId, UserName = tmpOrder.UserName, }; UserAccountRecordBLL.Add(accountRecord); } #endregion //更新商品库存数量 ProductBLL.ChangeOrderCountByOrder(tmpOrder.Id, ChangeAction.Minus); OrderBLL.Delete(orderId); AdminLogBLL.Add(ShopLanguage.ReadLanguage("DeleteRecordCompletely"), ShopLanguage.ReadLanguage("Order"), orderId); } else { //已付款逻辑删除可恢复 if (tmpOrder.IsDelete == (int)BoolType.False) { tmpOrder.IsDelete = (int)BoolType.True; OrderBLL.Update(tmpOrder); AdminLogBLL.Add(ShopLanguage.ReadLanguage("DeleteRecord"), ShopLanguage.ReadLanguage("Order"), orderId); } } } ScriptHelper.Alert(ShopLanguage.ReadLanguage("DeleteOK"), Request.UrlReferrer.ToString()); } #endregion } }
protected void ExportButton_Click(object sender, EventArgs e) { OrderSearchInfo orderSearch = new OrderSearchInfo(); orderSearch.OrderNumber = ShopCommon.ConvertToT <string>(OrderNumber.Text); orderSearch.OrderStatus = ShopCommon.ConvertToT <int>(OrderStatus.Text); orderSearch.Consignee = ShopCommon.ConvertToT <string>(Consignee.Text); orderSearch.StartAddDate = ShopCommon.ConvertToT <DateTime>(StartAddDate.Text); orderSearch.EndAddDate = ShopCommon.SearchEndDate(ShopCommon.ConvertToT <DateTime>(EndAddDate.Text)); var data = OrderBLL.SearchList(1, 1000, orderSearch, ref Count); NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); NPOI.SS.UserModel.ISheet sheet = book.CreateSheet("Sheet1"); sheet.DefaultColumnWidth = 18; sheet.CreateFreezePane(0, 1, 0, 1); NPOI.SS.UserModel.IRow row = sheet.CreateRow(0); row.Height = 20 * 20; row.CreateCell(0).SetCellValue("订单号"); row.CreateCell(1).SetCellValue("订单金额"); row.CreateCell(2).SetCellValue("类型"); row.CreateCell(3).SetCellValue("收货方式"); row.CreateCell(4).SetCellValue("收货人"); //row.CreateCell(3).SetCellValue("收货地址"); row.CreateCell(5).SetCellValue("订单状态"); row.CreateCell(6).SetCellValue("下单时间"); row.CreateCell(7).SetCellValue("最近操作时间"); //设置表头格式 var headFont = book.CreateFont(); headFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold; headFont.FontHeightInPoints = 10; var headStyle = book.CreateCellStyle(); headStyle.SetFont(headFont); headStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center; headStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; headStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; headStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; headStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; foreach (var cell in row.Cells) { cell.CellStyle = headStyle; } //取得订单最后一次操作的时间 var orderActinList = OrderActionBLL.ReadListLastDate(data.Select(k => k.Id).ToArray()); foreach (var entity in data) { NPOI.SS.UserModel.IRow dataRow = sheet.CreateRow(data.IndexOf(entity) + 1); dataRow.CreateCell(0).SetCellValue(entity.OrderNumber); dataRow.CreateCell(1).SetCellValue((entity.ProductMoney + entity.ShippingMoney + entity.OtherMoney).ToString()); dataRow.CreateCell(2).SetCellValue(EnumHelper.ReadEnumChineseName <OrderKind>(entity.IsActivity)); dataRow.CreateCell(3).SetCellValue(entity.SelfPick == 1 ? "自提" : "配送"); dataRow.CreateCell(4).SetCellValue(entity.Consignee); //dataRow.CreateCell(3).SetCellValue(entity.Address); dataRow.CreateCell(5).SetCellValue(OrderBLL.ReadOrderStatus(entity.OrderStatus, entity.IsDelete)); dataRow.CreateCell(6).SetCellValue(entity.AddDate.ToString()); var orderAction = orderActinList.FirstOrDefault(k => k.OrderId == entity.Id) ?? new OrderActionInfo(); dataRow.CreateCell(7).SetCellValue(orderAction.OrderId > 0 ? orderAction.Date.ToString() : ""); var style = book.CreateCellStyle(); style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; foreach (var cell in dataRow.Cells) { cell.CellStyle = style; } } System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xls", DateTime.Now.ToString("yyyyMMddHHmmssfff"))); Response.BinaryWrite(ms.ToArray()); book = null; ms.Close(); ms.Dispose(); Response.End(); }