//public TenPay() //{ // string domain = HttpContext.Current.Request.Url.Host; // returnUrl = returnUrl.Replace("{0}", domain).Replace("{1}", chargeType.ToString()); // payOkUrl = payOkUrl.Replace("{0}", domain); // payErrorUrl = payErrorUrl.Replace("{0}", domain); //} /// <summary> /// 发送支付请求 /// </summary> /// <param name="orderno"></param> /// <param name="total"></param> /// <param name="remark"></param> public void Send(string orderno, string total, string remark) { Md5Pay p = new Md5Pay(); p.Paygateurl = payUrl; p.Desc = remark; p.Total_fee = (long)(decimal.Parse(total) * 100); p.Sp_billno = orderno; p.Attach = "1"; p.Return_url = returnUrl; p.Transaction_id = p.Bargainor_id + p.Date + p.UnixStamp(); p.Spbill_create_ip = HttpContext.Current.Request.UserHostAddress; string url = ""; if (!p.GetPayUrl(out url)) { HttpContext.Current.Response.Write("TenPay Error"); //labErrmsg.Text = Server.HtmlEncode(url); } else { /*在这里可以把 * 交易单号 md5pay.Transaction_id * 商户订单号 md5pay.Sp_billno * 订单金额 md5pay.Total_fee * 等信息记入数据库. * */ MPayLog payrecordinfo = new MPayLog(); payrecordinfo.PayUrl = url; payrecordinfo.OrderId = decimal.Parse(orderno); payrecordinfo.PayMoney = decimal.Parse(total); payrecordinfo.UserId = this.UserId; payrecordinfo.PayResult = "100"; payrecordinfo.PayWay = PayWay; payrecordinfo.TransactionId = p.Transaction_id; payrecordinfo.BackUrl = p.Return_url; payrecordinfo.CreateTime = DateTime.Now; TMM.Service.Bll.Order.MPayLogBLL pbll = new TMM.Service.Bll.Order.MPayLogBLL(); pbll.Insert(payrecordinfo); HttpContext.Current.Response.Redirect(url); } }
/// <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/>"); } }
//public TenPay() //{ // string domain = HttpContext.Current.Request.Url.Host; // returnUrl = returnUrl.Replace("{0}", domain).Replace("{1}", chargeType.ToString()); // payOkUrl = payOkUrl.Replace("{0}", domain); // payErrorUrl = payErrorUrl.Replace("{0}", domain); //} /// <summary> /// ����֧������ /// </summary> /// <param name="orderno"></param> /// <param name="total"></param> /// <param name="remark"></param> public void Send(string orderno, string total, string remark) { Md5Pay p = new Md5Pay(); p.Paygateurl = payUrl; p.Desc = remark; p.Total_fee = (long)(decimal.Parse(total)*100); p.Sp_billno = orderno; p.Attach = "1"; p.Return_url = returnUrl; p.Transaction_id = p.Bargainor_id + p.Date + p.UnixStamp(); p.Spbill_create_ip =HttpContext.Current.Request.UserHostAddress; string url = ""; if (!p.GetPayUrl(out url)) { HttpContext.Current.Response.Write("TenPay Error"); //labErrmsg.Text = Server.HtmlEncode(url); } else { /*��������� * ������ md5pay.Transaction_id * �̻������� md5pay.Sp_billno * ������� md5pay.Total_fee * ����Ϣ�������ݿ�. * */ MPayLog payrecordinfo = new MPayLog(); payrecordinfo.PayUrl = url; payrecordinfo.OrderId = decimal.Parse(orderno); payrecordinfo.PayMoney = decimal.Parse(total); payrecordinfo.UserId = this.UserId; payrecordinfo.PayResult = "100"; payrecordinfo.PayWay = PayWay; payrecordinfo.TransactionId = p.Transaction_id; payrecordinfo.BackUrl = p.Return_url; payrecordinfo.CreateTime = DateTime.Now; TMM.Service.Bll.Order.MPayLogBLL pbll = new TMM.Service.Bll.Order.MPayLogBLL(); pbll.Insert(payrecordinfo); HttpContext.Current.Response.Redirect(url); } }
/// <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/>"); } }