/** * 生成直接支付url,支付url有效期为2小时,模式二 * @param rId 订单ID加密 * @return 模式二URL */ public string GetPayUrl(string rId) { //Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing..."); rId = Rc.Common.DBUtility.DESEncrypt.Decrypt(rId); Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(rId); int total_fee = Convert.ToInt32(model.UserOrder_Amount * 100); WxPayData data = new WxPayData(); data.SetValue("body", Rc.Cloud.Web.Common.pfunction.GetSubstring(model.Book_Name, 20, false));//商品描述 示例值:腾讯充值中心-QQ会员充值 //data.SetValue("detail", model.Book_Name); // 商品详情 //data.SetValue("attach", "test");//附加数据 data.SetValue("out_trade_no", model.UserOrder_No); //订单号 //随机字符串WxPayApi.GenerateOutTradeNo() data.SetValue("total_fee", total_fee); //总金额 //data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));//交易起始时间 //data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));//交易结束时间 //data.SetValue("goods_tag", "jjj");//商品标记 data.SetValue("trade_type", "NATIVE"); //交易类型 data.SetValue("product_id", model.Book_Id); //商品ID data.SetValue("notify_url", string.Format("{0}/Payment/WxPayAPI/ResultNotifyPage.aspx", Rc.Cloud.Web.Common.pfunction.getHostPath())); //异步通知url WxPayData result = WxPayApi.UnifiedOrder(data); //调用统一下单接口 //Log.Info(this.GetType().ToString(), "调用统一下单接口返回数据 : " + result.ToXml()); string url = string.Empty; if (result.GetValue("return_code").ToString() == "SUCCESS" && result.GetValue("result_code").ToString() == "SUCCESS") { url = result.GetValue("code_url").ToString();//获得统一下单接口返回的二维码链接 } else { Log.Error("Get native pay mode 2 url ", result.ToXml()); } //Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url); return(url); }
public void ProcessRequest(HttpContext context) { try { string rid = context.Request.QueryString["rid"].Filter(); rid = Rc.Common.DBUtility.DESEncrypt.Decrypt(rid); Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(rid); if (model.UserOrder_Status == (int)UOrderStatus.完成 && !string.IsNullOrEmpty(model.trade_no) && !string.IsNullOrEmpty(model.trade_status)) { context.Response.Write("success"); } else { context.Response.Write("fail"); } } catch (Exception ex) { new Rc.Cloud.BLL.BLL_clsAuth().AddLogErrorFromBS("", string.Format("类:{0},方法{1},错误信息:{2}", ex.TargetSite.DeclaringType.ToString(), ex.TargetSite.Name.ToString(), ex.Message)); context.Response.Write("error"); } }
protected void Page_Load(object sender, EventArgs e) { try { string rid = Request.QueryString["rid"].Filter(); string key = Request.QueryString["key"].Filter(); string bankId = Request.QueryString["defaultbank"].Filter(); rid = Rc.Common.DBUtility.DESEncrypt.Decrypt(rid); Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(rid); string domain = Rc.Cloud.Web.Common.pfunction.getHostPath(); ////////////////////////////////////////////请求参数//////////////////////////////////////////// //支付类型 string payment_type = "1"; //必填,不能修改 //服务器异步通知页面路径 string notify_url = string.Format("{0}/Payment/notify_Alipay.aspx", domain); //需http://格式的完整路径,不能加?id=123这类自定义参数 //页面跳转同步通知页面路径 string return_url = string.Format("{0}/Payment/return_Alipay.aspx", domain); //商户订单号 string out_trade_no = model.UserOrder_No; //商户网站订单系统中唯一订单号,必填 //订单名称 string subject = model.Book_Name; //必填 //付款金额 string total_fee = model.UserOrder_Amount.ToString(); //必填 //订单描述 string body = model.Book_Name; //默认支付方式 string paymethod = "bankPay"; //必填 //默认网银 string defaultbank = bankId; //必填,银行简码请参考接口技术文档 //商品展示地址 string show_url = "";// string.Format("http://{0}/Show.aspx", domain); //需以http://开头的完整路径,例如:http://www.商户网址.com/myorder.html //防钓鱼时间戳 string anti_phishing_key = Submit.Query_timestamp(); //若要使用请调用类文件submit中的query_timestamp函数 //客户端的IP地址 string exter_invoke_ip = Rc.Cloud.Web.Common.pfunction.GetRealIP(); //非局域网的外网IP地址,如:221.0.0.1 //把请求参数打包成数组 SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>(); if (key == "platform") { #region 即时到账交易 sParaTemp.Add("service", "create_direct_pay_by_user"); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("notify_url", notify_url); sParaTemp.Add("return_url", return_url); //业务参数 sParaTemp.Add("out_trade_no", out_trade_no); sParaTemp.Add("subject", subject); sParaTemp.Add("payment_type", payment_type); sParaTemp.Add("total_fee", total_fee); sParaTemp.Add("seller_id", Config.Partner); sParaTemp.Add("seller_email", Config.Seller_email); sParaTemp.Add("body", body); sParaTemp.Add("show_url", show_url); sParaTemp.Add("anti_phishing_key", anti_phishing_key); sParaTemp.Add("exter_invoke_ip", exter_invoke_ip); sParaTemp.Add("qr_pay_mode", "4"); sParaTemp.Add("qrcode_width", "200"); #endregion } else if (key == "bank") { #region 网银支付 sParaTemp.Add("service", "create_direct_pay_by_user"); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("notify_url", notify_url); sParaTemp.Add("return_url", return_url); //业务参数 sParaTemp.Add("out_trade_no", out_trade_no); sParaTemp.Add("subject", subject); sParaTemp.Add("payment_type", payment_type); sParaTemp.Add("total_fee", total_fee); sParaTemp.Add("seller_id", Config.Partner); sParaTemp.Add("seller_email", Config.Seller_email); sParaTemp.Add("body", body); sParaTemp.Add("paymethod", paymethod); sParaTemp.Add("defaultbank", defaultbank); sParaTemp.Add("show_url", show_url); sParaTemp.Add("anti_phishing_key", anti_phishing_key); sParaTemp.Add("exter_invoke_ip", exter_invoke_ip); #endregion } //建立请求 string sHtmlText = Submit.BuildRequest(sParaTemp, "get", "确认"); Response.Write(sHtmlText); } catch (Exception) { Response.Write("<script language=\"javascript\">alert('请求失败,请返回重新操作');</script>"); } }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //商户订单号 string out_trade_no = Request.Form["out_trade_no"].Filter(); //支付宝交易号 string trade_no = Request.Form["trade_no"].Filter(); //交易状态 string trade_status = Request.Form["trade_status"].Filter(); //买家支付宝账号 string buyer_email = Request.Form["buyer_email"]; int orderStatus = 1;// (int)XHZ.Model.UOrderStatus.等待付款; if (trade_status.ToUpper() == "TRADE_FINISHED") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知 orderStatus = (int)UOrderStatus.付款成功; } else if (trade_status.ToUpper() == "TRADE_SUCCESS") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //付款完成后,支付宝系统发送该交易状态通知 orderStatus = (int)UOrderStatus.付款成功; } else { } //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— Rc.Web.Payment.Core.LogHandler.WriteLogForPay(out_trade_no, "付款成功", trade_no); #region 付款成功 异步更新订单表 author:Ethan Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(out_trade_no); if (orderStatus == (int)UOrderStatus.付款成功 && model.UserOrder_Status == (int)UOrderStatus.待付款) { model.UserOrder_Paytool = UserOrder_PaytoolEnum.ALIPAY.ToString(); model.UsreOrder_Buyeremail = buyer_email; model.trade_no = trade_no; model.trade_status = trade_status; model.UserOrder_Status = (int)UOrderStatus.完成; model.UserOrder_FinishTime = DateTime.Now; bool executeFlag = false; if (new BLL_UserBuyResources().GetRecordCount(string.Format("UserId='{0}' and Book_id='{1}' ", model.UserId, model.Book_Id)) == 0) { #region 用户购买资源表 Model_UserBuyResources buyModel = new Model_UserBuyResources(); buyModel.UserBuyResources_ID = Guid.NewGuid().ToString(); buyModel.UserId = model.UserId; buyModel.Book_id = model.Book_Id; buyModel.BookPrice = model.Book_Price; buyModel.BuyType = UserOrder_PaytoolEnum.ALIPAY.ToString(); buyModel.CreateTime = DateTime.Now; buyModel.CreateUser = "******"; #endregion executeFlag = bll.UpdateAndAddUserBuyResources(model, buyModel); } else { executeFlag = bll.Update(model); } if (executeFlag) { //try //{ // P_User userModel = new P_UserBLL().GetModel(model.user_id); // pfunction.SendSMS(userModel.moblie, "您的订单" + model.OrderNo + "已支付成功"); //} //catch //{ //} //if (new U_OrdersHandleBLL().GetRecordCount("OrderId='" + model.OrderId + "' and OperateUser='******'") == 0) //{ // pfunction.InsertOrderHandle(model.OrderId, "您已" + XHZ.Common.EnumService.GetDescription<UOrderStatus>(orderStatus), "支付接口异步回调"); //} new Rc.Cloud.BLL.BLL_clsAuth().AddLogFromBS(Request.Url.ToString(), string.Format("支付宝回调。购买资源成功,购买人:{0},资源标识:{1}" , model.UserId, model.Book_Id)); Response.Write("success"); //请不要修改或删除 } } #endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("fail"); } } 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 { Log.Info(this.GetType().ToString(), "订单支付成功,异步回调"); #region 支付成功,异步更新订单表2016-06-30TS Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(notifyData.GetValue("out_trade_no").ToString()); if (model.UserOrder_Status == (int)UOrderStatus.待付款 || string.IsNullOrEmpty(model.trade_no) || string.IsNullOrEmpty(model.trade_status)) { model.UserOrder_Paytool = UserOrder_PaytoolEnum.WXPAY.ToString(); model.UsreOrder_Buyeremail = notifyData.GetValue("openid").ToString(); model.trade_no = notifyData.GetValue("transaction_id").ToString(); model.trade_status = notifyData.GetValue("return_code").ToString(); model.UserOrder_Status = (int)UOrderStatus.完成; model.UserOrder_FinishTime = DateTime.Now; bool executeFlag = false; if (new BLL_UserBuyResources().GetRecordCount(string.Format("UserId='{0}' and Book_id='{1}' ", model.UserId, model.Book_Id)) == 0) { #region 用户购买资源表 Model_UserBuyResources buyModel = new Model_UserBuyResources(); buyModel.UserBuyResources_ID = Guid.NewGuid().ToString(); buyModel.UserId = model.UserId; buyModel.Book_id = model.Book_Id; buyModel.BookPrice = model.Book_Price; buyModel.BuyType = UserOrder_PaytoolEnum.WXPAY.ToString(); buyModel.CreateTime = DateTime.Now; buyModel.CreateUser = "******"; #endregion executeFlag = bll.UpdateAndAddUserBuyResources(model, buyModel); } else { executeFlag = bll.Update(model); } if (executeFlag) { new Rc.Cloud.BLL.BLL_clsAuth().AddLogFromBS(page.Request.Url.ToString(), string.Format("微信回调。购买资源成功,购买人:{0},资源标识:{1}" , model.UserId, model.Book_Id)); } } #endregion WxPayData res = new WxPayData(); res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); page.Response.Write(res.ToXml()); page.Response.End(); } }