/// <summary> /// 微信公众号支付 /// </summary> /// <param name="pi"></param> /// <param name="ma"></param> private void Weixinpubpay(Song.Entities.PayInterface pi, Song.Entities.MoneyAccount ma) { string host = System.Web.HttpContext.Current.Request.Url.Host + ":" + WeiSha.Common.Server.Port + "/"; if (!string.IsNullOrWhiteSpace(pi.Pai_Returl)) { host = pi.Pai_Returl; } if (!host.EndsWith("/")) { host += "/"; } //构造网页授权获取code的URL string path = "Pay/Weixin/PublicPay.aspx"; //System.Web.HttpContext.Current.Response.Write(host + path); string redirect_uri = HttpUtility.UrlEncode(host + path.ToLower()); WxPayAPI.WxPayData data = new WxPayAPI.WxPayData(); data.SetValue("appid", pi.Pai_ParterID); data.SetValue("redirect_uri", redirect_uri); data.SetValue("response_type", "code"); data.SetValue("scope", "snsapi_base"); //返回的状态值,接口id、流水号 string state = "pi:{0},serial:{1}"; state = string.Format(state, pi.Pai_ID, ma.Ma_Serial); data.SetValue("state", state + "#wechat_redirect"); string url = "https://open.weixin.qq.com/connect/oauth2/authorize?" + data.ToUrl(); System.Web.HttpContext.Current.Response.Redirect(url); }
protected void Page_Load(object sender, EventArgs e) { //此页面的ajax提交,全部采用了POST方式 if (Request.ServerVariables["REQUEST_METHOD"] == "GET") { //初始化数据 initData(); //学员头像 if (acc == null) { Response.Redirect("/student/index.ashx"); return; } if (!System.IO.File.Exists(WeiSha.Common.Upload.Get["Accounts"].Physics + acc.Ac_Photo)) { accphoto = WeiSha.Common.Upload.Get["Accounts"].Virtual + acc.Ac_Photo; } Song.Entities.MoneyAccount maccount = Business.Do <IAccounts>().MoneySingle(serial); if (maccount != null && maccount.Ma_IsSuccess) { return; } //开始生成二维码 NativePay nativePay = new NativePay(); //****生成扫码支付模式二url //付款方信息 string buyer = string.Empty; if (acc != null) { buyer = string.IsNullOrWhiteSpace(acc.Ac_MobiTel1) ? acc.Ac_AccName : acc.Ac_MobiTel1; } //平台名称,会显示在支付界面(微信扫码后,在手机中显示) Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent(); string url2 = nativePay.GetPayUrl(total_fee.ToString(), org.Org_PlatformName, serial, total_fee, appid, mchid, paykey, notify_url, buyer); //将url生成二维码图片 //Image1.ImageUrl = "MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(url1); Image2.ImageUrl = "MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(url2); } //此页面的ajax提交,全部采用了POST方式 if (Request.ServerVariables["REQUEST_METHOD"] == "POST") { //监听充值是否完成,通过商户订号判断 Song.Entities.MoneyAccount maccount = Business.Do <IAccounts>().MoneySingle(serial); int state = 0; Log.Info(this.GetType().ToString(), "商户流水号 : " + serial); if (maccount != null) { Log.Info(this.GetType().ToString(), "支付状态 : " + maccount.Ma_IsSuccess); if (maccount.Ma_IsSuccess) { state = 1; } } Response.Write(state); Response.End(); } }
/// <summary> /// 支付宝网页直付 /// </summary> /// <param name="pi"></param> private void Alipayweb(Song.Entities.PayInterface pi, Song.Entities.MoneyAccount ma) { ////////////////////////////////////////////请求参数//////////////////////////////////////////// //商户订单号,商户网站订单系统中唯一订单号,必填 string out_trade_no = ma.Ma_Serial; //订单名称,必填 string name = string.IsNullOrWhiteSpace(Extend.LoginState.Accounts.CurrentUser.Ac_Name) ? "" : Extend.LoginState.Accounts.CurrentUser.Ac_Name; string subject = name + "(" + Extend.LoginState.Accounts.CurrentUser.Ac_AccName + ")充值"; //付款金额,必填 string total_fee = money.ToString(); //商品描述,可空 string body = subject; //////////////////////////////////////////////////////////////////////////////////////////////// //服务器异步通知页面路径 string domain = "http://" + WeiSha.Common.Server.Domain + ":" + WeiSha.Common.Server.Port + "/"; domain = string.IsNullOrWhiteSpace(pi.Pai_Returl) ? domain : pi.Pai_Returl; if (!domain.EndsWith("/")) { domain += "/"; } string notify_url = domain + "Pay/Alipayweb/notify_url.aspx"; //需http://格式的完整路径,不能加?id=123这类自定义参数 //页面跳转同步通知页面路径 string return_url = domain + "Pay/Alipayweb/return_url.aspx"; //////////////////////////////////////////////////////////////////////////////////////////////// //把请求参数打包成数组 SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>(); Com.Alipayweb.Config config = new Com.Alipayweb.Config(pi); sParaTemp.Add("service", Config.service); sParaTemp.Add("partner", config.Partner); sParaTemp.Add("seller_id", config.Seller_id); sParaTemp.Add("_input_charset", config.Input_charset.ToLower()); sParaTemp.Add("payment_type", Config.payment_type); sParaTemp.Add("notify_url", notify_url); sParaTemp.Add("return_url", return_url); sParaTemp.Add("anti_phishing_key", Config.anti_phishing_key); sParaTemp.Add("exter_invoke_ip", Config.exter_invoke_ip); sParaTemp.Add("out_trade_no", out_trade_no); sParaTemp.Add("subject", subject); //不要用Url编码处理中文 sParaTemp.Add("total_fee", total_fee); sParaTemp.Add("body", body); //不要用Url编码处理中文 //其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1 //如sParaTemp.Add("参数名","参数值"); //建立请求 Submit submit = new Submit(config); string sHtmlText = submit.BuildRequest(sParaTemp, "get", "确认"); Response.Write(sHtmlText); }
/// <summary> /// 微信小程序支付 /// </summary> /// <param name="pi"></param> /// <param name="ma"></param> private void WeixinMiniProgramPay(Song.Entities.PayInterface pi, Song.Entities.MoneyAccount ma) { string url = "Weixin/miniProgramPay.aspx?piid={0}&serial={1}&money={2}&org={3}"; url = string.Format(url, pi.Pai_ID, ma.Ma_Serial, money * 100, ma.Org_ID); //调试 string msg = string.Format("小程序支付,第一步(启动):\r\n接口ID:{0},流水号:{1},金额:{2}元", pi.Pai_ID, ma.Ma_Serial, money); WxPayAPI.Log.Info(this.GetType().FullName, msg); System.Web.HttpContext.Current.Response.Redirect(url); }
void fill() { Song.Entities.MoneyAccount mm = Business.Do <IAccounts>().MoneySingle(id); this.EntityBind(mm); //学员 Song.Entities.Accounts student = Business.Do <IAccounts>().AccountsSingle(mm.Ac_ID); if (student != null) { Ac_ID.Text = student.Ac_Name; } //支出或充值 Ma_Type.Text = mm.Ma_Type == 1 ? "支出" : "充值"; type = mm.Ma_Type; //支付方式 if (mm.Ma_From == 1) { Ma_From.Text = "管理员操作"; } if (mm.Ma_From == 2) { Ma_From.Text = "充值码充值"; } if (mm.Ma_From == 3) { Ma_From.Text = "在线支付"; } if (mm.Ma_From == 4) { Ma_From.Text = "购买课程"; } //支付账号,收款账号 Ma_Buyer.Text = mm.Ma_Buyer; Ma_Seller.Text = mm.Ma_Seller; //状态 Ma_IsSuccess.Text = mm.Ma_IsSuccess ? "成功" : "失败"; //充值码 trCode.Visible = mm.Ma_From == 2; Rc_Code.Text = mm.Rc_Code; //支付平台 if (mm.Ma_From == 3) { trPayinterface.Visible = true; Song.Entities.PayInterface payi = Business.Do <IPayInterface>().PaySingle(mm.Pai_ID); if (payi != null) { Pai_ID.Text = payi.Pai_Name; } } }
/// <summary> /// 微信扫码支付 /// </summary> /// <param name="pi"></param> /// <param name="ma"></param> private void WeixinNativepay(Song.Entities.PayInterface pi, Song.Entities.MoneyAccount ma) { string host = System.Web.HttpContext.Current.Request.Url.Host + ":" + WeiSha.Common.Server.Port + "/"; if (!string.IsNullOrWhiteSpace(pi.Pai_Returl)) { host = pi.Pai_Returl; } if (!host.EndsWith("/")) { host += "/"; } //用于生成支付二维码的URL string url = "Pay/Weixin/NativePayPage.aspx?pi={0}&serial={1}"; url = host + string.Format(url.ToString(), pi.Pai_ID, ma.Ma_Serial); System.Web.HttpContext.Current.Response.Redirect(url); }
/// <summary> /// 初始化数据 /// </summary> private void initData() { this.payInterface = Business.Do <IPayInterface>().PaySingle(pi); this.moneyAccount = Business.Do <IAccounts>().MoneySingle(serial); total_fee = (int)(moneyAccount.Ma_Money * 100); orgid = moneyAccount.Org_ID; appid = payInterface.Pai_ParterID; //绑定支付的APPID(必须配置) secret = payInterface.Pai_Key; //公众帐号secert(仅JSAPI支付的时候需要配置) WeiSha.Common.CustomConfig config = CustomConfig.Load(payInterface.Pai_Config); mchid = config["MCHID"].Value.String; //商户id paykey = config["Paykey"].Value.String; //支付密钥 //回调地址 notify_url = this.payInterface.Pai_Returl; if (string.IsNullOrWhiteSpace(notify_url)) { notify_url = "http://" + WeiSha.Common.Server.Domain + "/"; } if (!notify_url.EndsWith("/")) { notify_url += "/"; } notify_url += "Pay/Weixin/NativeNotifyPage.aspx"; }
/// <summary> /// 初始化数据 /// </summary> private void initData(string state) { int pi = 0; foreach (string s in state.Split(',')) { string[] arr = s.Split(':'); if (arr[0] == "serial") { serial = arr[1]; } if (arr[0] == "pi") { int.TryParse(arr[1], out pi); } } this.payInterface = Business.Do <IPayInterface>().PaySingle(pi); this.moneyAccount = Business.Do <IAccounts>().MoneySingle(serial); total_fee = (int)(moneyAccount.Ma_Money * 100); orgid = moneyAccount.Org_ID; appid = payInterface.Pai_ParterID; //绑定支付的APPID(必须配置) secret = payInterface.Pai_Key; //公众帐号secert(仅JSAPI支付的时候需要配置) WeiSha.Common.CustomConfig config = CustomConfig.Load(payInterface.Pai_Config); mchid = config["MCHID"].Value.String; //商户id paykey = config["Paykey"].Value.String; //支付密钥 //回调地址 notify_url = this.payInterface.Pai_Returl; if (string.IsNullOrWhiteSpace(notify_url)) { notify_url = "http://" + WeiSha.Common.Server.Domain + "/"; } if (!notify_url.EndsWith("/")) { notify_url += "/"; } notify_url += "Pay/Weixin/ResultNotifyPage.aspx"; }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { //支付宝返回的商户订单号,通过它查询交易记录 string out_trade_no = Request.Form["out_trade_no"]; Song.Entities.MoneyAccount maccount = Business.Do <IAccounts>().MoneySingle(out_trade_no); Notify aliNotify = new Notify(maccount.Pai_ID); bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //支付宝交易号 string trade_no = Request.Form["trade_no"]; //交易状态 string trade_status = Request.Form["trade_status"]; if (Request.Form["trade_status"] == "TRADE_FINISHED") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的 //如果有做过处理,不执行商户的业务程序 //注意: //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知 } else if (Request.Form["trade_status"] == "TRADE_SUCCESS") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的 //如果有做过处理,不执行商户的业务程序 //注意: //付款完成后,支付宝系统发送该交易状态通知 } else { } //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— //付款方与收款方 maccount.Ma_Buyer = Request.Form["buyer_email"]; maccount.Ma_Seller = Request.Form["seller_email"]; Business.Do <IAccounts>().MoneyConfirm(maccount); Response.Write("success"); //请不要修改或删除 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }
protected void Page_Load(object sender, EventArgs e) { string return_url = "/default.ashx"; SortedDictionary <string, string> sPara = GetRequestGet(); if (sPara.Count > 0)//判断是否有带返回参数 { //商户订单号 string out_trade_no = Request.QueryString["out_trade_no"]; Song.Entities.MoneyAccount maccount = Business.Do <IAccounts>().MoneySingle(out_trade_no); if (maccount == null) { Response.Redirect(string.Format(return_url, false, "", "")); return; } Notify aliNotify = new Notify(maccount.Pai_ID); bool verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 //支付宝交易号 string trade_no = Request.QueryString["trade_no"]; //交易状态 string trade_status = Request.QueryString["trade_status"]; if (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 } else { Response.Write("trade_status=" + Request.QueryString["trade_status"]); } //付款方与收款方 maccount.Ma_Buyer = Request.QueryString["buyer_email"]; maccount.Ma_Seller = Request.QueryString["seller_email"]; Business.Do <IAccounts>().MoneyConfirm(maccount); Response.Redirect(string.Format(return_url, true, maccount.Ma_Money, maccount.Pai_ID)); //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("验证失败"); } } else { Response.Write("无返回参数"); } }