public void Notify() { try { QueryNotifyURL = QueryNotifyURL + "&partner=" + partner + "¬ify_id=" + HttpContext.Current.Request["notify_id"].ToString(); //��ȡ֧����ATN���ؽ����true����ȷ�Ķ�����Ϣ��false ����Ч�� // alipayNotifyURL = alipayNotifyURL + "&partner=" + partner + "¬ify_id=" + HttpContext.Current.Request.QueryString["notify_id"]; //��ȡ֧����ATN���ؽ����true����ȷ�Ķ�����Ϣ��false ����Ч�� string responseTxt = AliPayPackage.Get_Http(QueryNotifyURL, 120000); //*******����ǩ������ʼ//******* int i; System.Collections.Specialized.NameValueCollection coll; //Load Form variables into NameValueCollection variable. coll = HttpContext.Current.Request.Form; // Get names of all forms into a string array. String[] requestarr = coll.AllKeys; //�������� string[] Sortedstr = AliPayPackage.BubbleSort(requestarr); //�����md5ժҪ�ַ��� �� StringBuilder prestr = new StringBuilder(); // string temp = ""; for (i = 0; i < Sortedstr.Length; i++) { if (RQ(Sortedstr[i]) != "" && Sortedstr[i] != "sign" && Sortedstr[i] != "sign_type") { if (i == Sortedstr.Length - 1) { prestr.Append(Sortedstr[i] + "=" + RQ(Sortedstr[i])); } else { prestr.Append(Sortedstr[i] + "=" + RQ(Sortedstr[i]) + "&"); } } // temp+=Sortedstr[i]; } // MamShare.Utils.Log4Net.Error(temp); prestr.Append(key); //����Md5ժҪ�� string mysign = AliPayPackage.GetMD5(prestr.ToString(), _input_charset); //*******����ǩ���������******* string sign = RQ("sign"); // Response.Write(prestr.ToString()); string trade_status = RQ("trade_status"); MPayLog payrecordinfo = new MPayLog(); payrecordinfo.PayUrl = QueryNotifyURL;//���ص�ַ payrecordinfo.OrderId = decimal.Parse(RQ("out_trade_no"));//HttpContext.Current.Request.QueryString["out_trade_no"]); if (responseTxt == "true") payrecordinfo.PayResult = "1"; else payrecordinfo.PayResult = "0"; payrecordinfo.PayMoney = decimal.Parse(RQ("total_fee")); //decimal.Parse(HttpContext.Current.Request.QueryString["total_fee"]); payrecordinfo.TransactionId = RQ("trade_no"); //HttpContext.Current.Request.QueryString["trade_no"]; payrecordinfo.PayWay = PayWay; payrecordinfo.BackUrl = HttpContext.Current.Request.Url.AbsoluteUri; payrecordinfo.CreateTime = DateTime.Now; TMM.Service.Bll.Order.MPayLogBLL pbll = new TMM.Service.Bll.Order.MPayLogBLL(); pbll.Insert(payrecordinfo); if (responseTxt == "true") //��֤֧������������Ϣ��ǩ���Ƿ���ȷ { //�����Լ����ݿ�Ķ�����䣬���Լ���дһ�� if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS") { Service.Bll.Order.TOrderBLL obll = new TMM.Service.Bll.Order.TOrderBLL(); Service.Bll.User.MAccountBLL abll = new TMM.Service.Bll.User.MAccountBLL(); TOrder o = obll.GetOrderAndDetail(payrecordinfo.OrderId); if (o.Status >= 0 && o.Status < 10) //�¶��� -- �Ѹ��� ֮��Ĺ��� { //��ֵ abll.AddAmount(payrecordinfo.OrderId, payrecordinfo.PayMoney, Utils.TmmUtils.IPAddress(), this.PayWay); bool expandResult = true; //docidС��0 �����Ϊ���ⶩ������ִ���˻������Ķ��� if (o.SingleDetail.DocId > 0) { expandResult = abll.AccountExpend(payrecordinfo.OrderId, Utils.TmmUtils.IPAddress()); } if (expandResult) { Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack(); oCallBack.UserId = o.UserId; oCallBack.OrderId = o.OrderId; oCallBack.PayWay = PayWay; oCallBack.Status = (int)OrderStatus.IsPaied; oCallBack.PayDetail = "�Ա�֧��"; oCallBack.ExecAfterPaid(); Utils.Log4Net.Error(string.Format("֧�����ӿ��첽���ûص������ɹ�����ת��URL��{0}", payOkUrl)); } else { payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "�˻����㣡"); } } } HttpContext.Current.Response.Write("success"); // Response.Write("success"); //���ظ�֧������Ϣ���ɹ� } else { //HttpContext.Current.Response.Write("------------------------------------------"); //HttpContext.Current.Response.Write("<br>Result:responseTxt=" + responseTxt); //HttpContext.Current.Response.Write("<br>Result:mysign=" + mysign); //HttpContext.Current.Response.Write("<br>Result:sign=" + sign); //HttpContext.Current.Response.Write("fail"); payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "У��ʧ��,֧��ʧ��" + responseTxt); HttpContext.Current.Response.Write("fail"); // HttpContext.Current.Response.Redirect(payErrorUrl); } } catch(Exception e) { Utils.Log4Net.Error(e); HttpContext.Current.Response.Write("fail"); } }
/// <summary> /// ����֧���ɹ����� /// </summary> public void Receive() { string suchtml = "<meta content=\"China TENCENT\" name=\"TENCENT_ONLINE_PAYMENT\">\n" + "<script language=\"javascript\">\n" + "window.location.href='" + payOkUrl + "';\n" + "</script>"; string errmsg = ""; //string key = "tenpaytesttenpaytesttenpaytest12"; // string bargainor_id = "1202437801"; Md5Pay md5pay = new Md5Pay(); //md5pay.Key = key; //md5pay.Bargainor_id = bargainorId; //�ж�ǩ�� if (md5pay.GetPayValueFromUrl(HttpContext.Current.Request.QueryString, out errmsg)) { Decimal orderid = 0; orderid = Decimal.Parse(md5pay.Sp_billno); MPayLog payrecordinfo = new MPayLog(); payrecordinfo.PayUrl = HttpContext.Current.Request.UrlReferrer+""; payrecordinfo.OrderId = orderid; payrecordinfo.PayResult = md5pay.Pay_Result.ToString(); payrecordinfo.PayMoney = decimal.Parse(md5pay.Total_fee.ToString())/100; payrecordinfo.PayWay = PayWay; payrecordinfo.TransactionId = md5pay.Transaction_id; payrecordinfo.BackUrl = HttpContext.Current.Request.Url.AbsoluteUri; payrecordinfo.CreateTime = DateTime.Now; TMM.Service.Bll.Order.MPayLogBLL pbll = new TMM.Service.Bll.Order.MPayLogBLL(); pbll.Insert(payrecordinfo); //��֤ǩ���ɹ� //֧���ж� if (md5pay.Pay_Result == Md5Pay.PAYOK) { Service.Bll.Order.TOrderBLL obll = new TMM.Service.Bll.Order.TOrderBLL(); Service.Bll.User.MAccountBLL abll = new TMM.Service.Bll.User.MAccountBLL(); TOrder o = obll.GetOrderAndDetail(payrecordinfo.OrderId); if (o.Status >= 0 && o.Status < 10) //�¶��� -- �Ѹ��� ֮��Ĺ��� { //��ֵ abll.AddAmount(payrecordinfo.OrderId, payrecordinfo.PayMoney, Utils.TmmUtils.IPAddress(),this.PayWay); bool expandResult = true; //docidС��0 �����Ϊ���ⶩ������ִ���˻������Ķ��� if (o.SingleDetail.DocId > 0) { expandResult = abll.AccountExpend(payrecordinfo.OrderId, Utils.TmmUtils.IPAddress()); } //�������ûص��ӿ� if (expandResult) { #region �����ص��ӿ� //obll.UpdateOrder2Paid(payrecordinfo.OrderId, PayWay, "�Ƹ�֧ͨ��", (int)Models.MOrderStateInfo.������); Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack(); oCallBack.UserId = o.UserId; oCallBack.OrderId = o.OrderId; oCallBack.PayWay = PayWay; oCallBack.Status = (int)OrderStatus.IsPaied; oCallBack.PayDetail = "�Ƹ�֧ͨ��"; oCallBack.ExecAfterPaid(); suchtml = suchtml.Replace("{1}", orderid.ToString()); //֧���ɹ���ͬ������md5pay.Transaction_id���ܻ���֪ͨ�������ע���ж϶����Ƿ��ظ����� //����ҵ����������db֮��� //errmsg = "֧���ɹ�"; //Response.Write(errmsg+"<br/>"); //Response.Write("�Ƹ�ͨ������:"+ md5pay.Transaction_id +"(���μǶ�����)"+"<br/>"); //��ת���ɹ�ҳ�棬�Ƹ�ͨ�յ�<meta content=\"China TENCENT\" name=\"TENCENT_ONLINE_PAYMENT\">����Ϊ֪ͨ�ɹ� payOkUrl = payOkUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); Utils.Log4Net.Error(string.Format("���Ƹ�ͨ��-��ͬ���ص���-���ɹ���-��{0}��", payOkUrl)); HttpContext.Current.Response.Write(suchtml); #endregion } else { Utils.Log4Net.Error(string.Format("���Ƹ�ͨ��-��ͬ���ص���-��ʧ��AccountExpend��-��{0}��", payOkUrl)); payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "�˻����㣡"); } } else { Utils.Log4Net.Error(string.Format("���Ƹ�ͨ��-��ͬ���ص���-��ʧ�ܡ�-��{0}��������״̬{1}��", payOkUrl,o.Status)); payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "��������"); } } else { //֧��ʧ�ܣ��벻Ҫ���ɹ����� // Response.Write(md5pay.Pay_Result+" "+Md5Pay.PAYOK); payErrorUrl = payErrorUrl.Replace("{1}", md5pay.Sp_billno); payErrorUrl = payErrorUrl.Replace("{2}", "֧��ʧ��" + errmsg); HttpContext.Current.Response.Redirect(payErrorUrl); //HttpContext.Current.Response.Write("֧��ʧ��" + errmsg + "<br/>"); } } else { //��֤ǩ��ʧ�� payErrorUrl = payErrorUrl.Replace("{1}", md5pay.Sp_billno); payErrorUrl = payErrorUrl.Replace("{2}", "��֤ǩ��ʧ��"); HttpContext.Current.Response.Redirect(payErrorUrl); // errmsg = "��֤ǩ��ʧ��"; // HttpContext.Current.Response.Write("��֤ǩ��ʧ��" + "<br/>"); } }
/// <summary> /// 链接接收 /// </summary> public void Receive() { v_oid = HttpContext.Current.Request["v_oid"]; v_pstatus = HttpContext.Current.Request["v_pstatus"]; v_pstring = HttpContext.Current.Request["v_pstring"]; v_pmode = HttpContext.Current.Request["v_pmode"]; v_md5str = HttpContext.Current.Request["v_md5str"]; v_amount = HttpContext.Current.Request["v_amount"]; v_moneytype = HttpContext.Current.Request["v_moneytype"]; remark1 = HttpContext.Current.Request["remark1"]; remark2 = HttpContext.Current.Request["remark2"]; string str = v_oid + v_pstatus + v_amount + v_moneytype + key; str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5").ToUpper(); MPayLog payrecordinfo = new MPayLog(); payrecordinfo.PayUrl = HttpContext.Current.Request.UrlReferrer + ""; payrecordinfo.OrderId = decimal.Parse(v_oid); payrecordinfo.PayResult = v_pstatus; payrecordinfo.PayMoney = decimal.Parse(v_amount); payrecordinfo.TransactionId = v_oid.ToString(); payrecordinfo.PayWay = PayWay; payrecordinfo.BackUrl = HttpContext.Current.Request.Url.ToString(); TMM.Service.Bll.Order.MPayLogBLL pbll = new TMM.Service.Bll.Order.MPayLogBLL(); pbll.Insert(payrecordinfo); if (str == v_md5str) { if (v_pstatus.Equals("20")) { Service.Bll.Order.TOrderBLL obll = new TMM.Service.Bll.Order.TOrderBLL(); Service.Bll.User.MAccountBLL abll = new TMM.Service.Bll.User.MAccountBLL(); TOrder o = obll.Get(payrecordinfo.OrderId); if (o.Status >= 0 && o.Status < 10) //新订单 -- 已付款 之间的过程 { abll.AddAmount(payrecordinfo.OrderId, payrecordinfo.PayMoney, Utils.TmmUtils.IPAddress(), this.PayWay); if (abll.AccountExpend(payrecordinfo.OrderId, Utils.TmmUtils.IPAddress())) { //Web.Common.OrderCallBack oCallBack = new MamShare.Mall.Web.Common.OrderCallBack( // o.UserId, o.OrderId, PayWay, (int)Models.MOrderStateInfo.己付款, "ChinaBank支付"); //oCallBack.Update2Paid(); //payOkUrl = payOkUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); //HttpContext.Current.Response.Redirect(payOkUrl); Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack(); oCallBack.UserId = o.UserId; oCallBack.OrderId = o.OrderId; oCallBack.PayWay = PayWay; oCallBack.Status = (int)OrderStatus.IsPaied; oCallBack.PayDetail = "ChinaBank支付"; oCallBack.ExecAfterPaid(); } else { payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "账户余额不足!"); } } else { Utils.Log4Net.Error(string.Format("支付接口直接调用回调方法【失败】,跳转到URL:{0}", payOkUrl)); payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "订单错误!"); } } } else { payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "校验失败,数据可疑"); HttpContext.Current.Response.Redirect(payErrorUrl); // HttpContext.Current.Response.Write("校验失败,数据可疑"); } }
/// <summary> /// �첽֪ͨ /// </summary> public void Notify() { v_oid = HttpContext.Current.Request["v_oid"]; v_pstatus = HttpContext.Current.Request["v_pstatus"]; v_pstring = HttpContext.Current.Request["v_pstring"]; v_pmode = HttpContext.Current.Request["v_pmode"]; v_md5str = HttpContext.Current.Request["v_md5str"]; v_amount = HttpContext.Current.Request["v_amount"]; v_moneytype = HttpContext.Current.Request["v_moneytype"]; remark1 = HttpContext.Current.Request["remark1"]; remark2 = HttpContext.Current.Request["remark2"]; string str = v_oid + v_pstatus + v_amount + v_moneytype + key; str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5").ToUpper(); MPayLog payrecordinfo = new MPayLog(); payrecordinfo.PayUrl = HttpContext.Current.Request.UrlReferrer + ""; payrecordinfo.OrderId = decimal.Parse(v_oid); payrecordinfo.PayResult = v_pstatus; payrecordinfo.PayMoney = decimal.Parse(v_amount); payrecordinfo.TransactionId = v_oid.ToString(); payrecordinfo.PayWay = PayWay; payrecordinfo.BackUrl = HttpContext.Current.Request.Url.ToString(); TMM.Service.Bll.Order.MPayLogBLL pbll = new TMM.Service.Bll.Order.MPayLogBLL(); pbll.Insert(payrecordinfo); if (str == v_md5str) { if (v_pstatus.Equals("20")) { string domain = HttpContext.Current.Request.Url.Host; //ȷ����m6go�µĶ��� if (remark2.ToLower().Contains(domain.ToLower()) == true) { Service.Bll.Order.TOrderBLL obll = new TMM.Service.Bll.Order.TOrderBLL(); Service.Bll.User.MAccountBLL abll = new TMM.Service.Bll.User.MAccountBLL(); TOrder o = obll.Get(payrecordinfo.OrderId); if (o.Status >= 0 && o.Status < 10) //�¶��� -- �Ѹ��� ֮��Ĺ��� { abll.AddAmount(payrecordinfo.OrderId, payrecordinfo.PayMoney,Utils.TmmUtils.IPAddress(),this.PayWay); if (abll.AccountExpend(payrecordinfo.OrderId,Utils.TmmUtils.IPAddress())) { //Web.Common.OrderCallBack oCallBack = new MamShare.Mall.Web.Common.OrderCallBack( // o.UserId, o.OrderId, PayWay, (int)Models.MOrderStateInfo.������, "ChinaBank֧��"); //oCallBack.Update2Paid(); //payOkUrl = payOkUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); //HttpContext.Current.Response.Redirect(payOkUrl); Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack(); oCallBack.UserId = o.UserId; oCallBack.OrderId = o.OrderId; oCallBack.PayWay = PayWay; oCallBack.Status = (int)OrderStatus.IsPaied; oCallBack.PayDetail = "ChinaBank֧��"; oCallBack.ExecAfterPaid(); } else { payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "�˻����㣡"); HttpContext.Current.Response.Redirect(payErrorUrl); } } } HttpContext.Current.Response.Write("ok"); } else HttpContext.Current.Response.Write("error"); } else { payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "У��ʧ��,���ݿ���"); HttpContext.Current.Response.Write("error"); // HttpContext.Current.Response.Redirect(payErrorUrl); // HttpContext.Current.Response.Write("У��ʧ��,���ݿ���"); } }
public void Notify() { try { QueryNotifyURL = QueryNotifyURL + "&partner=" + partner + "¬ify_id=" + HttpContext.Current.Request["notify_id"].ToString(); //获取支付宝ATN返回结果,true是正确的订单信息,false 是无效的 // alipayNotifyURL = alipayNotifyURL + "&partner=" + partner + "¬ify_id=" + HttpContext.Current.Request.QueryString["notify_id"]; //获取支付宝ATN返回结果,true是正确的订单信息,false 是无效的 string responseTxt = AliPayPackage.Get_Http(QueryNotifyURL, 120000); //*******加密签名程序开始//******* int i; System.Collections.Specialized.NameValueCollection coll; //Load Form variables into NameValueCollection variable. coll = HttpContext.Current.Request.Form; // Get names of all forms into a string array. String[] requestarr = coll.AllKeys; //进行排序; string[] Sortedstr = AliPayPackage.BubbleSort(requestarr); //构造待md5摘要字符串 ; StringBuilder prestr = new StringBuilder(); // string temp = ""; for (i = 0; i < Sortedstr.Length; i++) { if (RQ(Sortedstr[i]) != "" && Sortedstr[i] != "sign" && Sortedstr[i] != "sign_type") { if (i == Sortedstr.Length - 1) { prestr.Append(Sortedstr[i] + "=" + RQ(Sortedstr[i])); } else { prestr.Append(Sortedstr[i] + "=" + RQ(Sortedstr[i]) + "&"); } } // temp+=Sortedstr[i]; } // MamShare.Utils.Log4Net.Error(temp); prestr.Append(key); //生成Md5摘要; string mysign = AliPayPackage.GetMD5(prestr.ToString(), _input_charset); //*******加密签名程序结束******* string sign = RQ("sign"); // Response.Write(prestr.ToString()); string trade_status = RQ("trade_status"); MPayLog payrecordinfo = new MPayLog(); payrecordinfo.PayUrl = QueryNotifyURL; //返回地址 payrecordinfo.OrderId = decimal.Parse(RQ("out_trade_no")); //HttpContext.Current.Request.QueryString["out_trade_no"]); if (responseTxt == "true") { payrecordinfo.PayResult = "1"; } else { payrecordinfo.PayResult = "0"; } payrecordinfo.PayMoney = decimal.Parse(RQ("total_fee")); //decimal.Parse(HttpContext.Current.Request.QueryString["total_fee"]); payrecordinfo.TransactionId = RQ("trade_no"); //HttpContext.Current.Request.QueryString["trade_no"]; payrecordinfo.PayWay = PayWay; payrecordinfo.BackUrl = HttpContext.Current.Request.Url.AbsoluteUri; payrecordinfo.CreateTime = DateTime.Now; TMM.Service.Bll.Order.MPayLogBLL pbll = new TMM.Service.Bll.Order.MPayLogBLL(); pbll.Insert(payrecordinfo); if (responseTxt == "true") //验证支付发过来的消息,签名是否正确 { //更新自己数据库的订单语句,请自己填写一下 if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS") { Service.Bll.Order.TOrderBLL obll = new TMM.Service.Bll.Order.TOrderBLL(); Service.Bll.User.MAccountBLL abll = new TMM.Service.Bll.User.MAccountBLL(); TOrder o = obll.GetOrderAndDetail(payrecordinfo.OrderId); if (o.Status >= 0 && o.Status < 10) //新订单 -- 已付款 之间的过程 { //充值 abll.AddAmount(payrecordinfo.OrderId, payrecordinfo.PayMoney, Utils.TmmUtils.IPAddress(), this.PayWay); bool expandResult = true; //docid小于0 的情况为特殊订单,不执行账户花销的动作 if (o.SingleDetail.DocId > 0) { expandResult = abll.AccountExpend(payrecordinfo.OrderId, Utils.TmmUtils.IPAddress()); } if (expandResult) { Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack(); oCallBack.UserId = o.UserId; oCallBack.OrderId = o.OrderId; oCallBack.PayWay = PayWay; oCallBack.Status = (int)OrderStatus.IsPaied; oCallBack.PayDetail = "淘宝支付"; oCallBack.ExecAfterPaid(); Utils.Log4Net.Error(string.Format("支付宝接口异步调用回调方法成功,跳转到URL:{0}", payOkUrl)); } else { payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "账户余额不足!"); } } } HttpContext.Current.Response.Write("success"); // Response.Write("success"); //返回给支付宝消息,成功 } else { //HttpContext.Current.Response.Write("------------------------------------------"); //HttpContext.Current.Response.Write("<br>Result:responseTxt=" + responseTxt); //HttpContext.Current.Response.Write("<br>Result:mysign=" + mysign); //HttpContext.Current.Response.Write("<br>Result:sign=" + sign); //HttpContext.Current.Response.Write("fail"); payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "校验失败,支付失败" + responseTxt); HttpContext.Current.Response.Write("fail"); // HttpContext.Current.Response.Redirect(payErrorUrl); } } catch (Exception e) { Utils.Log4Net.Error(e); HttpContext.Current.Response.Write("fail"); } }
public void GotoPay(string PayWay, decimal total, string pname, int docId, int chargeType) { OrderService os = Context.GetService <OrderService>(); AccountService accs = Context.GetService <AccountService>(); U_UserInfo logonUser = base.GetUser(); decimal orderId = Utils.TmmUtils.GenOrderId(); DDocInfo doc = new DDocInfo(); TOrder order = new TOrder(); TOrderDetail detail = new TOrderDetail(); int orderType = 0; //订单类型 if (chargeType == 1) { doc = os.DDocInfoBll.Get(docId); orderType = (int)OrderType.DownDocOrder; } else if (chargeType == 0) { //如果是直接充值,这里虚拟一个doc对象,来作为订单的商品 doc = new DDocInfo() { DocId = -1, Title = "直接充值:" + total.ToString(), Price = total }; orderType = (int)OrderType.DirectCharge; } detail = new TOrderDetail() { DocId = doc.DocId, DocTitle = doc.Title, GoodsCount = 1, Price = doc.Price, OrderId = orderId }; order = new TOrder() { OrderType = orderType, OrderId = orderId, UserId = logonUser.UserId, Email = logonUser.Email, Total = detail.Price * detail.GoodsCount, Ip = Context.Request.UserHostAddress, Status = (int)OrderStatus.NewOrder, CreateTime = DateTime.Now, PayWay = Helper.FormatHelper.GetPayWay(PayWay), OrderDetails = new List <TOrderDetail>() { detail } }; os.TOrderBll.SaveOrder(order); TOrder o = os.TOrderBll.Get(orderId); decimal amount = 0;//除扣除账户余额外还需要支付金额 amount = total; //if (total > minfo.Amount) //{ // amount = total - minfo.Amount; //} //else { // //账户支付 //} #region 转至支付接口 if (PayWay.ToLower() == "tenpay") { TenPay pay = new TenPay(); pay.UserId = logonUser.UserId; pay.Send(orderId.ToString(), amount.ToString(), pname); } if (PayWay.ToLower() == "chinabank") { ChinaBankPay pay = new ChinaBankPay(); pay.Send(orderId.ToString(), amount.ToString(), pname); // Response.Write("ChinaBank"); } if (PayWay.ToLower() == "alipay") { AliPay pay = new AliPay(); pay.Send(orderId.ToString(), amount.ToString(), pname, logonUser.UserId); // Response.Write("ChinaBank"); } if (PayWay.ToLower() == "useraccount") { MAccount minfo = accs.MAccountBll.GetByUserId(logonUser.UserId); //账户 if (o.Total <= minfo.Amount && (o.Status == (int)OrderStatus.NewOrder)) { //ms.MAccount.AccountExpend(o.OrderId); ////ms.MOrder.UpdateOrder2Paid(o.OrderId, 0, "账户支付", (int)Models.MOrderStateInfo.己付款); //Web.Common.OrderCallBack oCallBack = new MamShare.Mall.Web.Common.OrderCallBack( // o.UserId, o.OrderId, 0, (int)Models.MOrderStateInfo.己付款, "账户支付"); //oCallBack.Update2Paid(); //Hashtable p = new Hashtable(); //p.Add("OrderId", o.OrderId); //RedirectToAction("payok.do", p); os.MAccountBll.AccountExpend(o.OrderId, Utils.TmmUtils.IPAddress()); //账户花销 Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack(); oCallBack.UserId = o.UserId; oCallBack.OrderId = o.OrderId; oCallBack.PayWay = 0; oCallBack.Status = (int)OrderStatus.IsPaied; oCallBack.PayDetail = "账户支付"; oCallBack.GotoUrl = "/my/purchase.do"; oCallBack.ExecAfterPaid(); } else { Redirect("NetPay.do?orderid=" + o.OrderId); } } #endregion RenderView("pay"); }
public void GotoPay(string PayWay, decimal total, string pname, int docId,int chargeType) { OrderService os = Context.GetService<OrderService>(); AccountService accs = Context.GetService<AccountService>(); U_UserInfo logonUser = base.GetUser(); decimal orderId = Utils.TmmUtils.GenOrderId(); DDocInfo doc = new DDocInfo(); TOrder order = new TOrder(); TOrderDetail detail = new TOrderDetail(); int orderType = 0; //订单类型 if (chargeType == 1) { doc = os.DDocInfoBll.Get(docId); orderType = (int)OrderType.DownDocOrder; } else if (chargeType == 0) { //如果是直接充值,这里虚拟一个doc对象,来作为订单的商品 doc = new DDocInfo() { DocId = -1, Title = "直接充值:" + total.ToString(), Price = total }; orderType = (int)OrderType.DirectCharge; } detail = new TOrderDetail() { DocId = doc.DocId, DocTitle = doc.Title, GoodsCount = 1, Price = doc.Price, OrderId = orderId }; order = new TOrder() { OrderType = orderType, OrderId = orderId, UserId = logonUser.UserId, Email = logonUser.Email, Total = detail.Price * detail.GoodsCount, Ip = Context.Request.UserHostAddress, Status = (int)OrderStatus.NewOrder, CreateTime = DateTime.Now, PayWay = Helper.FormatHelper.GetPayWay(PayWay), OrderDetails = new List<TOrderDetail>() { detail } }; os.TOrderBll.SaveOrder(order); TOrder o = os.TOrderBll.Get(orderId); decimal amount = 0;//除扣除账户余额外还需要支付金额 amount = total; //if (total > minfo.Amount) //{ // amount = total - minfo.Amount; //} //else { // //账户支付 //} #region 转至支付接口 if (PayWay.ToLower() == "tenpay") { TenPay pay = new TenPay(); pay.UserId = logonUser.UserId; pay.Send(orderId.ToString(), amount.ToString(), pname); } if (PayWay.ToLower() == "chinabank") { ChinaBankPay pay = new ChinaBankPay(); pay.Send(orderId.ToString(), amount.ToString(), pname); // Response.Write("ChinaBank"); } if (PayWay.ToLower() == "alipay") { AliPay pay = new AliPay(); pay.Send(orderId.ToString(), amount.ToString(), pname,logonUser.UserId); // Response.Write("ChinaBank"); } if (PayWay.ToLower() == "useraccount") { MAccount minfo = accs.MAccountBll.GetByUserId(logonUser.UserId); //账户 if (o.Total <= minfo.Amount && (o.Status == (int)OrderStatus.NewOrder)) { //ms.MAccount.AccountExpend(o.OrderId); ////ms.MOrder.UpdateOrder2Paid(o.OrderId, 0, "账户支付", (int)Models.MOrderStateInfo.己付款); //Web.Common.OrderCallBack oCallBack = new MamShare.Mall.Web.Common.OrderCallBack( // o.UserId, o.OrderId, 0, (int)Models.MOrderStateInfo.己付款, "账户支付"); //oCallBack.Update2Paid(); //Hashtable p = new Hashtable(); //p.Add("OrderId", o.OrderId); //RedirectToAction("payok.do", p); os.MAccountBll.AccountExpend(o.OrderId, Utils.TmmUtils.IPAddress()); //账户花销 Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack(); oCallBack.UserId = o.UserId; oCallBack.OrderId = o.OrderId; oCallBack.PayWay = 0; oCallBack.Status = (int)OrderStatus.IsPaied; oCallBack.PayDetail = "账户支付"; oCallBack.GotoUrl = "/my/purchase.do"; oCallBack.ExecAfterPaid(); } else { Redirect("NetPay.do?orderid=" + o.OrderId); } } #endregion RenderView("pay"); }
/// <summary> /// 接受支付成功返回 /// </summary> public void Receive() { string suchtml = "<meta content=\"China TENCENT\" name=\"TENCENT_ONLINE_PAYMENT\">\n" + "<script language=\"javascript\">\n" + "window.location.href='" + payOkUrl + "';\n" + "</script>"; string errmsg = ""; //string key = "tenpaytesttenpaytesttenpaytest12"; // string bargainor_id = "1202437801"; Md5Pay md5pay = new Md5Pay(); //md5pay.Key = key; //md5pay.Bargainor_id = bargainorId; //判断签名 if (md5pay.GetPayValueFromUrl(HttpContext.Current.Request.QueryString, out errmsg)) { Decimal orderid = 0; orderid = Decimal.Parse(md5pay.Sp_billno); MPayLog payrecordinfo = new MPayLog(); payrecordinfo.PayUrl = HttpContext.Current.Request.UrlReferrer + ""; payrecordinfo.OrderId = orderid; payrecordinfo.PayResult = md5pay.Pay_Result.ToString(); payrecordinfo.PayMoney = decimal.Parse(md5pay.Total_fee.ToString()) / 100; payrecordinfo.PayWay = PayWay; payrecordinfo.TransactionId = md5pay.Transaction_id; payrecordinfo.BackUrl = HttpContext.Current.Request.Url.AbsoluteUri; payrecordinfo.CreateTime = DateTime.Now; TMM.Service.Bll.Order.MPayLogBLL pbll = new TMM.Service.Bll.Order.MPayLogBLL(); pbll.Insert(payrecordinfo); //认证签名成功 //支付判断 if (md5pay.Pay_Result == Md5Pay.PAYOK) { Service.Bll.Order.TOrderBLL obll = new TMM.Service.Bll.Order.TOrderBLL(); Service.Bll.User.MAccountBLL abll = new TMM.Service.Bll.User.MAccountBLL(); TOrder o = obll.GetOrderAndDetail(payrecordinfo.OrderId); if (o.Status >= 0 && o.Status < 10) //新订单 -- 已付款 之间的过程 { //充值 abll.AddAmount(payrecordinfo.OrderId, payrecordinfo.PayMoney, Utils.TmmUtils.IPAddress(), this.PayWay); bool expandResult = true; //docid小于0 的情况为特殊订单,不执行账户花销的动作 if (o.SingleDetail.DocId > 0) { expandResult = abll.AccountExpend(payrecordinfo.OrderId, Utils.TmmUtils.IPAddress()); } //继续调用回调接口 if (expandResult) { #region 订单回调接口 //obll.UpdateOrder2Paid(payrecordinfo.OrderId, PayWay, "财付通支付", (int)Models.MOrderStateInfo.己付款); Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack(); oCallBack.UserId = o.UserId; oCallBack.OrderId = o.OrderId; oCallBack.PayWay = PayWay; oCallBack.Status = (int)OrderStatus.IsPaied; oCallBack.PayDetail = "财付通支付"; oCallBack.ExecAfterPaid(); suchtml = suchtml.Replace("{1}", orderid.ToString()); //支付成功,同定单号md5pay.Transaction_id可能会多次通知,请务必注意判断订单是否重复的逻辑 //处理业务逻辑,处理db之类的 //errmsg = "支付成功"; //Response.Write(errmsg+"<br/>"); //Response.Write("财付通定单号:"+ md5pay.Transaction_id +"(请牢记定单号)"+"<br/>"); //跳转到成功页面,财付通收到<meta content=\"China TENCENT\" name=\"TENCENT_ONLINE_PAYMENT\">,认为通知成功 payOkUrl = payOkUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); Utils.Log4Net.Error(string.Format("【财付通】-【同步回调】-【成功】-【{0}】", payOkUrl)); HttpContext.Current.Response.Write(suchtml); #endregion } else { Utils.Log4Net.Error(string.Format("【财付通】-【同步回调】-【失败AccountExpend】-【{0}】", payOkUrl)); payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "账户余额不足!"); } } else { Utils.Log4Net.Error(string.Format("【财付通】-【同步回调】-【失败】-【{0}】【订单状态{1}】", payOkUrl, o.Status)); payErrorUrl = payErrorUrl.Replace("{1}", payrecordinfo.OrderId.ToString()); payErrorUrl = payErrorUrl.Replace("{2}", "订单错误!"); } } else { //支付失败,请不要按成功处理 // Response.Write(md5pay.Pay_Result+" "+Md5Pay.PAYOK); payErrorUrl = payErrorUrl.Replace("{1}", md5pay.Sp_billno); payErrorUrl = payErrorUrl.Replace("{2}", "支付失败" + errmsg); HttpContext.Current.Response.Redirect(payErrorUrl); //HttpContext.Current.Response.Write("支付失败" + errmsg + "<br/>"); } } else { //认证签名失败 payErrorUrl = payErrorUrl.Replace("{1}", md5pay.Sp_billno); payErrorUrl = payErrorUrl.Replace("{2}", "认证签名失败"); HttpContext.Current.Response.Redirect(payErrorUrl); // errmsg = "认证签名失败"; // HttpContext.Current.Response.Write("认证签名失败" + "<br/>"); } }