// #region 订单及退款 // /// <summary> // /// 订单查询 // /// </summary> // /// <returns></returns> // public ActionResult OrderQuery() // { // string nonceStr = TenPayV3Util.GetNoncestr(); // RequestHandler packageReqHandler = new RequestHandler(null); // //设置package订单参数 // packageReqHandler.SetParameter("appid", TenPayV3Info.AppId); //公众账号ID // packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId); //商户号 // packageReqHandler.SetParameter("transaction_id", ""); //填入微信订单号 // packageReqHandler.SetParameter("out_trade_no", ""); //填入商家订单号 // packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 // string sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key); // packageReqHandler.SetParameter("sign", sign); //签名 // string data = packageReqHandler.ParseXML(); // var result = TenPayV3.OrderQuery(data); // var res = XDocument.Parse(result); // string openid = res.Element("xml").Element("sign").Value; // return Content(openid); // } // /// <summary> // /// 关闭订单接口 // /// </summary> // /// <returns></returns> // public ActionResult CloseOrder() // { // string nonceStr = TenPayV3Util.GetNoncestr(); // RequestHandler packageReqHandler = new RequestHandler(null); // //设置package订单参数 // packageReqHandler.SetParameter("appid", TenPayV3Info.AppId); //公众账号ID // packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId); //商户号 // packageReqHandler.SetParameter("out_trade_no", ""); //填入商家订单号 // packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 // string sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key); // packageReqHandler.SetParameter("sign", sign); //签名 // string data = packageReqHandler.ParseXML(); // var result = TenPayV3.CloseOrder(data); // var res = XDocument.Parse(result); // string openid = res.Element("xml").Element("openid").Value; // return Content(openid); // } // /// <summary> // /// 退款申请接口 // /// </summary> // /// <returns></returns> // public ActionResult Refund() // { // try // { // WeixinTrace.SendCustomLog("进入退款流程", "1"); // string nonceStr = TenPayV3Util.GetNoncestr(); // string outTradeNo = HttpContext.Session.GetString("BillNo"); // WeixinTrace.SendCustomLog("进入退款流程", "2 outTradeNo:" + outTradeNo); // string outRefundNo = "OutRefunNo-" + SystemTime.Now.Ticks; // int totalFee = int.Parse(HttpContext.Session.GetString("BillFee")); // int refundFee = totalFee; // string opUserId = TenPayV3Info.MchId; // var notifyUrl = $"{_siteUrl}/TenPayV3/RefundNotifyUrl"; // var dataInfo = new TenPayV3RefundRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, TenPayV3Info.Key, // null, nonceStr, null, outTradeNo, outRefundNo, totalFee, refundFee, opUserId, null, notifyUrl: notifyUrl); // #region 旧方法 // //var cert = @"D:\cert\apiclient_cert_SenparcRobot.p12";//根据自己的证书位置修改 // //var password = TenPayV3Info.MchId;//默认为商户号,建议修改 // //var result = TenPayV3.Refund(dataInfo, cert, password); // #endregion // #region 新方法(Senparc.Weixin v6.4.4+) // var result = TenPayV3.Refund(dataInfo);//证书地址、密码,在配置文件中设置,并在注册微信支付信息时自动记录 // #endregion // WeixinTrace.SendCustomLog("进入退款流程", "3 Result:" + result.ToJson()); // return Content(string.Format("退款结果:{0} {1}。您可以刷新当前页面查看最新结果。", result.result_code, result.err_code_des)); // //return Json(result, JsonRequestBehavior.AllowGet); // } // catch (Exception ex) // { // WeixinTrace.WeixinExceptionLog(new WeixinException(ex.Message, ex)); // throw; // } // #region 原始方法 // //RequestHandler packageReqHandler = new RequestHandler(null); // //设置package订单参数 // //packageReqHandler.SetParameter("appid", TenPayV3Info.AppId); //公众账号ID // //packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId); //商户号 // //packageReqHandler.SetParameter("out_trade_no", "124138540220170502163706139412"); //填入商家订单号 // ////packageReqHandler.SetParameter("out_refund_no", ""); //填入退款订单号 // //packageReqHandler.SetParameter("total_fee", ""); //填入总金额 // //packageReqHandler.SetParameter("refund_fee", "100"); //填入退款金额 // //packageReqHandler.SetParameter("op_user_id", TenPayV3Info.MchId); //操作员Id,默认就是商户号 // //packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 // //string sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key); // //packageReqHandler.SetParameter("sign", sign); //签名 // ////退款需要post的数据 // //string data = packageReqHandler.ParseXML(); // ////退款接口地址 // //string url = "http://api.mch.weixin.qq.com/secapi/pay/refund"; // ////本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中) // //string cert = @"D:\cert\apiclient_cert_SenparcRobot.p12"; // ////私钥(在安装证书时设置) // //string password = TenPayV3Info.MchId; // //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); // ////调用证书 // //X509Certificate2 cer = new X509Certificate2(cert, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); // //#region 发起post请求 // //HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); // //webrequest.ClientCertificates.Add(cer); // //webrequest.Method = "post"; // //byte[] postdatabyte = Encoding.UTF8.GetBytes(data); // //webrequest.ContentLength = postdatabyte.Length; // //Stream stream; // //stream = webrequest.GetRequestStream(); // //stream.Write(postdatabyte, 0, postdatabyte.Length); // //stream.Close(); // //HttpWebResponse httpWebResponse = (HttpWebResponse)webrequest.GetResponse(); // //StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()); // //string responseContent = streamReader.ReadToEnd(); // //#endregion // //// var res = XDocument.Parse(responseContent); // ////string openid = res.Element("xml").Element("out_refund_no").Value; // //return Content("申请成功:<br>" + HttpUtility.RequestUtility.HtmlEncode(responseContent)); // #endregion // } // /// <summary> // /// 退款通知地址 // /// </summary> // /// <returns></returns> // public ActionResult RefundNotifyUrl() // { // WeixinTrace.SendCustomLog("RefundNotifyUrl被访问", "IP" + HttpContext.UserHostAddress()?.ToString()); // string responseCode = "FAIL"; // string responseMsg = "FAIL"; // try // { // ResponseHandler resHandler = new ResponseHandler(null); // string return_code = resHandler.GetParameter("return_code"); // string return_msg = resHandler.GetParameter("return_msg"); // WeixinTrace.SendCustomLog("跟踪RefundNotifyUrl信息", resHandler.ParseXML()); // if (return_code == "SUCCESS") // { // responseCode = "SUCCESS"; // responseMsg = "OK"; // string appId = resHandler.GetParameter("appid"); // string mch_id = resHandler.GetParameter("mch_id"); // string nonce_str = resHandler.GetParameter("nonce_str"); // string req_info = resHandler.GetParameter("req_info"); // var decodeReqInfo = TenPayV3Util.DecodeRefundReqInfo(req_info, TenPayV3Info.Key); // var decodeDoc = XDocument.Parse(decodeReqInfo); // //获取接口中需要用到的信息 // string transaction_id = decodeDoc.Root.Element("transaction_id").Value; // string out_trade_no = decodeDoc.Root.Element("out_trade_no").Value; // string refund_id = decodeDoc.Root.Element("refund_id").Value; // string out_refund_no = decodeDoc.Root.Element("out_refund_no").Value; // int total_fee = int.Parse(decodeDoc.Root.Element("total_fee").Value); // int? settlement_total_fee = decodeDoc.Root.Element("settlement_total_fee") != null // ? int.Parse(decodeDoc.Root.Element("settlement_total_fee").Value) // : null as int?; // int refund_fee = int.Parse(decodeDoc.Root.Element("refund_fee").Value); // int tosettlement_refund_feetal_fee = int.Parse(decodeDoc.Root.Element("settlement_refund_fee").Value); // string refund_status = decodeDoc.Root.Element("refund_status").Value; // string success_time = decodeDoc.Root.Element("success_time").Value; // string refund_recv_accout = decodeDoc.Root.Element("refund_recv_accout").Value; // string refund_account = decodeDoc.Root.Element("refund_account").Value; // string refund_request_source = decodeDoc.Root.Element("refund_request_source").Value; // //进行业务处理 // } // } // catch (Exception ex) // { // responseMsg = ex.Message; // WeixinTrace.WeixinExceptionLog(new WeixinException(ex.Message, ex)); // } // string xml = string.Format(@"<xml> // <return_code><![CDATA[{0}]]></return_code> // <return_msg><![CDATA[{1}]]></return_msg> // </xml>", responseCode, responseMsg); // return Content(xml, "text/xml"); // } // #endregion public IActionResult Card() { try { JsSdkUiPackage jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(TenPayV3Info.AppId, TenPayV3Info.AppSecret, Request.AbsoluteUri()); var api_ticket = WxCardApiTicketContainer.TryGetWxCardApiTicket(TenPayV3Info.AppId, TenPayV3Info.AppSecret); // var openId = HttpContext.Session.GetString("OpenId"); var timeStamp = TenPayV3Util.GetTimestamp(); var nonceStr = TenPayV3Util.GetNoncestr(); var sign = JSSDKHelper.GetcardExtSign(api_ticket, timeStamp, "pukHe541WmaHEBgW3gACiBCD4EbY", nonceStr); var cardExt = new { timestamp = timeStamp, signature = sign, nonce_str = nonceStr }; ViewData["cardExt"] = JsonConvert.SerializeObject(cardExt); return(View(jssdkUiPackage)); } catch (Exception ex) { var msg = ex.Message; msg += "<br>" + ex.StackTrace; msg += "<br>==Source==<br>" + ex.Source; if (ex.InnerException != null) { msg += "<br>===InnerException===<br>" + ex.InnerException.Message; } return(Content(msg)); } }
public ActionResult JsSdkConfig() { //构造url地址,注意是包含域名的 string url = $"{Domin}{Request.RawUrl}"; JsSdkUiPackage jssdkuipackage = JSSDKHelper.GetJsSdkUiPackage(appID, appsecret, url); return(PartialView(jssdkuipackage)); }
//配置 js-sdk public ActionResult JsSdkConfig() { string url = $"http://wx.lingnian.xin{Request.RawUrl}"; //方法中的参数就是每一个需要使用接口的页面地址 JsSdkUiPackage jssdkpackge = JSSDKHelper.GetJsSdkUiPackage(appID, appsecret, url); return(PartialView(jssdkpackge)); }
//配置js-sdk public ActionResult JsSdkConfig() { //方法中的参数就是每一个需要使用的页面地址 string url = $"{Domin}{Request.RawUrl}"; JsSdkUiPackage jssdkpackage = JSSDKHelper.GetJsSdkUiPackage(appID, appsecret, url); return(PartialView(jssdkpackage)); }
public ActionResult ForBuy(int id) { JsSdkUiPackage package = JSSDKHelper.GetJsSdkUiPackage(TF.QR.Config.AppId, TF.QR.Config.AppSecret, base.Request.Url.AbsoluteUri); base.ViewData["jssdk"] = package; var buy = Config.Helper.SingleById <DbBuy>(id); return(View(buy)); }
public ActionResult Index(int id) { JsSdkUiPackage package = JSSDKHelper.GetJsSdkUiPackage(TF.QR.Config.AppId, TF.QR.Config.AppSecret, base.Request.Url.AbsoluteUri); base.ViewData["jssdk"] = package; var product = Config.Helper.SingleById <DbProduct>(id); return(View(product)); }
public async Task <JsonResult> GetJsTicketParameters() { string appId = await SettingManager.GetSettingValueForTenantAsync(WechatSettings.General.AppId, InfrastructureSession.TenantId.Value); string appSecret = await SettingManager.GetSettingValueForTenantAsync(WechatSettings.General.Secret, InfrastructureSession.TenantId.Value); JsSdkUiPackage jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(appId, appSecret, Request.UrlReferrer.ToString()); return(Json(jssdkUiPackage)); }
/// <summary> /// 重写虚方法,此方法将在Init事件前执行 /// </summary> protected override void ShowPage() { int weixinId = DTRequest.GetQueryInt("wxid"); string url = "http://" + DTRequest.GetHost() + HttpContext.Current.Request.RawUrl; BLL.weixin_account wxBll = new BLL.weixin_account(); Model.weixin_account modelt = wxBll.GetModel(weixinId); if (modelt != null) { string ticket = JsApiTicketContainer.TryGetJsApiTicket(modelt.appid, modelt.appsecret); jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(modelt.appid, modelt.appsecret, url); } this.Init += new EventHandler(article_show_Init); }
public ActionResult Edit(string code) { try { string openid = base.Request.Cookies["openid"].Value; DbQRInfo model = TF.QR.Config.Helper.CreateWhere <DbQRInfo>().Where(o => o.Code == code).Where(o => o.OpenID == openid).FirstOrDefault(null); if (model == null) { return(base.RedirectError("对不起,无权修改此编码信息")); } JsSdkUiPackage package = JSSDKHelper.GetJsSdkUiPackage(TF.QR.Config.AppId, TF.QR.Config.AppSecret, base.Request.Url.AbsoluteUri); base.ViewData["jssdk"] = package; return(base.View(model)); } catch (Exception exception) { return(base.RedirectError(exception.Message)); } }
public static JsSdkUiPackage GetJsSdkUiPackage(string url) { long timestamp = JSSDKHelper.GetTimestamp(); string nonceStr = JSSDKHelper.GetNoncestr(); JsApiTicketResult ticket = new JsApiTicketResult(); if (CacheFactory.Cache().GetCache <JsApiTicketResult>("jsapi_ticket") == null) { ticket = CommonApi.GetTicket(CORPID, _JsCorpSecret); CacheFactory.Cache().WriteCache(ticket, "jsapi_ticket", System.DateTime.Now.AddSeconds(3600)); } else { ticket = CacheFactory.Cache().GetCache <JsApiTicketResult>("jsapi_ticket"); } string signature = JSSDKHelper.GetSignature(ticket.ticket, nonceStr, timestamp, url); JsSdkUiPackage result = new JsSdkUiPackage(CORPID, timestamp.ToString(), nonceStr, signature); return(result); }
public int InitViewBag(SessionInfo sessionInfo, out string strError) { strError = ""; ViewBag.AppName = sessionInfo.gzh.appNameCN; ViewBag.weixinId = sessionInfo.WeixinId; if (sessionInfo.Active != null) { // 取出上次记住的图书推荐栏目 if (Request.Path == "/Library/Book") { ViewBag.remeberBookSubject = sessionInfo.Active.bookSubject; } //设到ViewBag里 string userName = ""; string userNameInfo = ""; if (sessionInfo.Active.type == WxUserDatabase.C_Type_Worker) { userName = sessionInfo.Active.userName; userNameInfo = userName; ViewBag.isPatron = 0; } else { userName = sessionInfo.Active.readerBarcode; userNameInfo = sessionInfo.Active.readerName;// +"["+sessionInfo.Active.readerBarcode+"]"; ViewBag.isPatron = 1; } ViewBag.userName = userName; ViewBag.userNameInfo = userNameInfo; ViewBag.userId = sessionInfo.Active.id; string libName = sessionInfo.Active.libName;//sessionInfo.CurrentLib.Entity.libName; if (string.IsNullOrEmpty(sessionInfo.Active.bindLibraryCode) == false) { libName = sessionInfo.Active.bindLibraryCode; } string libId = sessionInfo.Active.libId; ViewBag.LibName = "[" + libName + "]"; ViewBag.PureLibName = libName; ViewBag.LibId = libId; ViewBag.LibraryCode = sessionInfo.Active.bindLibraryCode; //这里用绑定的图书馆 20180313 LibEntity libEntity = sessionInfo.CurrentLib.Entity; //dp2WeiXinService.Instance.GetLibById(libId); if (libEntity != null && libEntity.state == "到期" && Request.Path.Contains("/Patron/SelectLib") == false) //选择图书馆界面除外 { strError = "服务已到期,请联系图书馆工作人员。"; return(-1); } ViewBag.showPhoto = sessionInfo.Active.showPhoto; ViewBag.showCover = sessionInfo.Active.showCover; ViewBag.LibState = sessionInfo.CurrentLib.State; if (sessionInfo.CurrentLib.State == LibraryManager.C_State_Hangup) //checkLibState == true && { string warn = LibraryManager.GetLibHungWarn(sessionInfo.CurrentLib); if (string.IsNullOrEmpty(warn) == false) { strError = warn; return(-1); } } } // 书目查询 与 借还 使用 JSSDK try { if (Request.Path.Contains("/Biblio/Index") == true || Request.Path.Contains("/Library/Charge2") == true) { GzhCfg gzh = sessionInfo.gzh; bool bJsReg = JsApiTicketContainer.CheckRegistered(gzh.appId); // 注意这里有时异常 JsSdkUiPackage package = JSSDKHelper.GetJsSdkUiPackage(gzh.appId, gzh.secret, Request.Url.AbsoluteUri);//http://localhost:15794/Library/Charge //http://www.dp2003.com/dp2weixin/Library/Charge ViewData["AppId"] = gzh.appId; ViewData["Timestamp"] = package.Timestamp; ViewData["NonceStr"] = package.NonceStr; ViewData["Signature"] = package.Signature; } } catch (Exception ex) { } return(0); }
/// <summary> /// 根据session信息初始化界面信息 /// </summary> /// <param name="sessionInfo"></param> /// <param name="strError"></param> /// <returns> /// -1 出错 /// 0 成功 /// </returns> private int InitViewBag(SessionInfo sessionInfo, bool isCheckLibState, out string strError) { strError = ""; // 书目查询 与 借还 使用 JSSDK try { //if (Request.Path.Contains("/Biblio/Index") == true // || Request.Path.Contains("/Library/Charge2") == true // || Request.Path.Contains("/Account/ScanQRCodeBind") == true) //{ GzhCfg gzh = sessionInfo.gzh; bool bJsReg = JsApiTicketContainer.CheckRegistered(gzh.appId); // 注意这里有时异常 JsSdkUiPackage package = JSSDKHelper.GetJsSdkUiPackage(gzh.appId, gzh.secret, Request.Url.AbsoluteUri);//http://localhost:15794/Library/Charge //http://www.dp2003.com/dp2weixin/Library/Charge ViewData["AppId"] = gzh.appId; ViewData["Timestamp"] = package.Timestamp; ViewData["NonceStr"] = package.NonceStr; ViewData["Signature"] = package.Signature; //} } catch (Exception ex) { } ViewBag.AppName = sessionInfo.gzh.appNameCN; ViewBag.weixinId = sessionInfo.WeixinId; // 没有当前帐户时,直接返回 if (sessionInfo.ActiveUser == null) { return(0); } //===== // 取出上次记住的图书推荐栏目 if (Request.Path == "/Library/Book") { ViewBag.remeberBookSubject = sessionInfo.ActiveUser.bookSubject; } //设到ViewBag里,当前帐户信息 string userName = ""; string userNameInfo = ""; if (sessionInfo.ActiveUser.type == WxUserDatabase.C_Type_Worker) { userName = sessionInfo.ActiveUser.userName; userNameInfo = userName; ViewBag.isPatron = 0; } else { userName = sessionInfo.ActiveUser.readerBarcode; userNameInfo = sessionInfo.ActiveUser.readerName;// +"["+sessionInfo.Active.readerBarcode+"]"; ViewBag.isPatron = 1; } ViewBag.userName = userName; ViewBag.userNameInfo = userNameInfo; ViewBag.userId = sessionInfo.ActiveUser.id; // 2020-2-29 在配置文件中增加读者库配置 string patronDbName = ""; string libName = sessionInfo.ActiveUser.libName;//sessionInfo.CurrentLib.Entity.libName; // 2019/05/06 显示的名称依据libcfg.xml的配置 LibModel libCfg = dp2WeiXinService.Instance._areaMgr.GetLibCfg(sessionInfo.ActiveUser.libId, sessionInfo.ActiveUser.bindLibraryCode); if (libCfg != null) { libName = libCfg.name; patronDbName = libCfg.patronDbName; } ViewBag.PatronDbName = patronDbName; ViewBag.LibName = "[" + libName + "]"; ViewBag.PureLibName = libName; ViewBag.LibId = sessionInfo.ActiveUser.libId; ViewBag.LibraryCode = sessionInfo.ActiveUser.bindLibraryCode; //这里用绑定的图书馆 20180313 // 到期的图书馆应该不会显示出来,所以这一段后面可以删除 2020-2-29 { LibEntity libEntity = sessionInfo.CurrentLib.Entity; //dp2WeiXinService.Instance.GetLibById(libId); if (libEntity != null && libEntity.state == "到期" && Request.Path.Contains("/Patron/SelectOwnerLib") == false) //选择图书馆界面除外 { strError = "服务已到期,请联系图书馆工作人员。"; return(-1); } } ViewBag.LibState = sessionInfo.CurrentLib.IsHangup.ToString(); if (isCheckLibState == true && sessionInfo.CurrentLib.IsHangup == true) { // 获取服务器不通文字描述 string warn = LibraryManager.GetLibHungWarn(sessionInfo.CurrentLib, true); if (string.IsNullOrEmpty(warn) == false) { strError = warn; return(-1); } } return(0); }