public Rtn <object> jssdk(string origin) { #region v13.6.4之前的写法 ////获取时间戳 //var timestamp = JSSDKHelper.GetTimestamp(); ////获取随机码 //var nonceStr = JSSDKHelper.GetNoncestr(); //string ticket = JsApiTicketContainer.TryGetJsApiTicket(appId, secret); ////获取签名 //var signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, Request.Url.AbsoluteUri); //ViewData["AppId"] = appId; //ViewData["Timestamp"] = timestamp; //ViewData["NonceStr"] = nonceStr; //ViewData["Signature"] = signature; #endregion // var url = "http://" + HttpContext.Request.Host + HttpContext.Request.Path + HttpContext.Request.QueryString; Console.WriteLine("url:" + origin); System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); var jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(WechatConfig.AppId, WechatConfig.secret, origin); //ViewData["JsSdkUiPackage"] = jssdkUiPackage; //ViewData["AppId"] = appId; //ViewData["Timestamp"] = jssdkUiPackage.Timestamp; //ViewData["NonceStr"] = jssdkUiPackage.NonceStr; //ViewData["Signature"] = jssdkUiPackage.Signature; Console.WriteLine("生成测试参数", jssdkUiPackage.Signature); return(Rtn <object> .Success(jssdkUiPackage)); }
/// <summary> /// 生成同步微信按扭JS信息 /// </summary> /// <param name="cardid"></param> /// <param name="openid"></param> /// <param name="couponRecordId"></param> /// <param name="couponType"></param> /// <param name="url">当前页地址</param> /// <returns></returns> private WXSyncJSInfoCardInfo MakeSyncWXJSInfo(string cardid, long couponRecordId, WXCardLogInfo.CouponTypeEnum couponType) { WXSyncJSInfoCardInfo result = null; if (!string.IsNullOrWhiteSpace(cardid)) { var card = Context.WXCardLogInfo.FirstOrDefault(d => d.CardId == cardid); if (card != null) { string acctoken = GetAccessToken(card.AppId, card.AppSecret); string apiticket = GetCardJSApiTicket(acctoken); if (!string.IsNullOrWhiteSpace(apiticket)) { result = new WXSyncJSInfoCardInfo(); //生成记录 long logid = SyncCouponRecordInfo(cardid, couponRecordId, couponType); int outerid = (int)logid; JSSDKHelper jsshelper = new JSSDKHelper(); result.card_id = cardid; result.timestamp = JSSDKHelper.GetTimestamp(); result.nonce_str = ""; result.signature = jsshelper.GetCardSign2015(apiticket, result.nonce_str, result.timestamp, result.card_id); result.outerid = outerid; } else { Log.Info("[Coupon]票据获取失败"); } } } return(result); }
/// <summary> /// 活动宴席 /// </summary> /// <returns></returns> public IActionResult ActivityBanquet(string actFormId, int?actFormStatus, string openid, int?userType) { //actFormId = "E6200916-552A-44A4-FFD4-08D59A3C0EB3"; //actFormId = "73DF4187-AF25-422D-5601-08D59EB66341"; //openid = "C9E6F8A3-6A08-418A-A258-0ABCBEC17573"; //actFormStatus = 2; //userType = 2; var tenantId = GetTenantId(); //var user = _weChatUserAppService.GetWeChatUserAsync(openid, tenantId).Result; var activityBanquet = _activityBanquetAppService.GetActivityBanquetWeChatByFormIdAsync(Guid.Parse(actFormId), tenantId).Result; if (activityBanquet == null) { activityBanquet = new ActivityBanquets.Dtos.ActivityBanquetWeChatDto(); } var url = Request.GetAbsoluteUri(); var jsApiConfig = JSSDKHelper.GetJsSdkUiPackageAsync(WechatAppConfig.AppId, WechatAppConfig.AppSecret, url).Result; ViewBag.OpenId = openid; ViewBag.TenantId = tenantId; ViewBag.ActivityFormId = actFormId; ViewBag.UserType = userType; ViewBag.ActivityFormStatus = actFormStatus; var root = _appConfiguration["App:ServerRootAddress"]; ViewBag.ServerRootAddress = root; ActivityBanquetModel model = new ActivityBanquetModel(); model.JsSdkApiConfig = jsApiConfig; model.BanquetWeChat = activityBanquet; return(View(model)); }
/// <summary> /// 若不管用,请在公众号官方后台---功能设置----js接口安全域名 设置 /// 初始化微信分享 /// </summary> /// <param name="wxModel"></param> /// <param name="fxUrl">分享的目标url,如果传过来的值为空字符串或者为null则默认是当前的网址</param> public void jssdkInit(Model.wx_userweixin wxModel, string fxUrl = "") { fxModel.appId = wxModel.AppId; fxModel.timestamp = JSSDKHelper.GetTimestamp(); fxModel.nonceStr = JSSDKHelper.GetNoncestr(); fxModel.thisUrl = HttpContext.Current.Request.Url.ToString(); if (fxUrl == null || fxUrl.Trim() == "") { fxModel.fxUrl = fxModel.thisUrl; } else { fxModel.fxUrl = fxUrl; } string error = ""; string ticket = WeiXinPF.WeiXinComm.WeiXinCRMComm.getJsApiTicket(wxModel.id, out error); if (error != "") { //取临时票据出现问题 return; } JSSDKHelper jsHelper = new JSSDKHelper(); //获取签名 var signature = jsHelper.GetSignature(ticket, fxModel.nonceStr, fxModel.timestamp, fxModel.thisUrl); fxModel.signature = signature; }//end:function
/// <summary> /// 获取jssdk配置对象 /// </summary> /// <param name="httpContext"></param> /// <returns></returns> static async Task WxJsSdk(HttpContext httpContext) { string appName = null, url; if (httpContext.Request.Query.TryGetValue("app", out var app)) { appName = app.ToString(); } if (httpContext.Request.Query.TryGetValue("url", out var urlV)) { url = urlV.ToString(); } else { httpContext.Response.StatusCode = 400; return; } var options = httpContext.RequestServices.GetRequiredService <IOptions <WxOptions> >().Value; var mpOptions = appName.IsNullOrWhiteSpace() ? options.GetDefaultMp() : options.Get(appName); if (mpOptions == null || mpOptions.AppType != WxAppType.MP) { httpContext.Response.StatusCode = 400; return; } var jsSdkUiPackage = await JSSDKHelper.GetJsSdkUiPackageAsync(mpOptions.AppId, mpOptions.AppSecret, url); await httpContext.WriteJson(jsSdkUiPackage); }
private void GetSingInfo(HttpContext context) { try { var list = new List <object>(); var appid = WebConfigurationManager.AppSettings["wxappid"].ToString(); var appsecret = WebConfigurationManager.AppSettings["wxsecret"].ToString(); var timeStamp = JSSDKHelper.GetTimestamp(); var nonceStr = JSSDKHelper.GetNoncestr(); var url = context.Request.Params["urlinfo"]; if (!JsApiTicketContainer.CheckRegistered(appid)) { JsApiTicketContainer.Register(appid, appsecret); } string jsapiticket = JsApiTicketContainer.GetTicket(appid); JSSDKHelper cd = new JSSDKHelper(); var signature = cd.GetSignature(jsapiticket, nonceStr, timeStamp, url); list.Add(new { appid1 = appid, timeStamp1 = timeStamp, nonceStr1 = nonceStr, signature1 = signature }); string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = list, count = list.Count }); context.Response.Write(jsonstrlist); } catch (Exception) { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = "", count = 0 }); context.Response.Write(jsonstrlist); } }
/// <summary> /// 分享 /// </summary> /// <returns></returns> public IActionResult Share() { var shareEnum = ShareEnum.默认; var openId = Request.Query["openid"]; var shareId = Request.Query["shareid"]; if (string.IsNullOrWhiteSpace(openId)) { shareEnum = ShareEnum.非法; } else { if (!string.IsNullOrWhiteSpace(shareId)) { shareEnum = openId != shareId ? ShareEnum.分享点赞 : ShareEnum.分享无法点赞; } } var reurnUrl = "http://www.mblogs.top/Wechat/Share?shareid=" + openId; var model = new WeiXinShareLikeViewModel { OpenId = openId, ShareId = shareId, Url = $"http://www.mblogs.top/Wechat/ShareAuthorizeUrl?reurnUrl=" + reurnUrl }; ViewBag.WeiXinShareLike = model; ViewBag.ShareEnum = shareEnum; var jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(WechatAppSettings.AppId, WechatAppSettings.CorpSecret, Request.AbsoluteUri()); return(View(jssdkUiPackage)); }
public ActionResult SelectOutlet(string outletCn) { var jsapiticket = JsApiTicketContainer.GetTicket(_corpId, _secret); ViewBag.appId = _corpId; ViewBag.noncestr = JSSDKHelper.GetNoncestr(); ViewBag.timestamp = JSSDKHelper.GetTimestamp(); ViewBag.signature = JSSDKHelper.GetSignature(jsapiticket, ViewBag.nonceStr, ViewBag.timestamp, AbsoluteUri()); WxIdentifyDto dto = HttpContext.Session.GetObjectFromJson <WxIdentifyDto>("WxIdentify"); if (string.IsNullOrWhiteSpace(outletCn)) { ModelState.AddModelError("", "需要输入网点编号"); return(View("Identify", dto)); } var outlet = _outletCache.GetList().FindLast(x => x.Cn == outletCn); if (outlet != null) { SelectOutlet(outlet.Id, dto); return(View("Identify", dto)); } else { ModelState.AddModelError("", "此编号没有对应的网点"); return(View("Identify", dto)); } }
public async Task <ActionResult> Approval() { var workSetting = Senparc.Weixin.Config.SenparcWeixinSetting["企业微信审批"] as ISenparcWeixinSettingForWork; var url = "https://sdk.weixin.senparc.com/Work/Approval"; //获取 UI 信息包 var jsApiTicket = await JsApiTicketContainer.GetTicketAsync(workSetting.WeixinCorpId, workSetting.WeixinCorpSecret, false); var jsApiUiPackage = await JSSDKHelper.GetJsApiUiPackageAsync(workSetting.WeixinCorpId, workSetting.WeixinCorpSecret, url, jsApiTicket, false); ViewData["jsApiUiPackage"] = jsApiUiPackage; ViewData["thirdNo"] = DateTime.Now.Ticks + Guid.NewGuid().ToString("n"); ViewData["corpId"] = workSetting.WeixinCorpId; ViewData["agentId"] = workSetting.WeixinCorpAgentId; //注意这里需要使用 WeixinCorpAgentId,而不是 CorpId var agentConfigJsApiTicket = await JsApiTicketContainer.GetTicketAsync(workSetting.WeixinCorpId, workSetting.WeixinCorpSecret, true); var agentJsApiUiPackage = await JSSDKHelper.GetJsApiUiPackageAsync(workSetting.WeixinCorpId, workSetting.WeixinCorpSecret, url, agentConfigJsApiTicket, true); ViewData["agentJsApiUiPackage"] = agentJsApiUiPackage; //TODO:需要删除: ViewData["jsApiTicket"] = jsApiTicket; ViewData["agentConfigJsApiTicket"] = agentConfigJsApiTicket; return(View()); }
public static async Task <WeixinResponse> WeixinSignResponse(this string url) { var response = new WeixinResponse(); var timestamp = JSSDKHelper.GetTimestamp(); var noncestr = JSSDKHelper.GetNoncestr(); var ticket = await JsApiTicketContainer.TryGetJsApiTicketAsync(AppId, AppSecret); if (ticket.IsNullOrEmpty()) { response.Message = "获取ticket出错了~~"; } var signature = JSSDKHelper.GetSignature(ticket, noncestr, timestamp, url); if (signature.IsNullOrEmpty()) { response.Message = "获取signature出错了~~"; } response.Timestamp = timestamp; response.Noncestr = noncestr; response.Ticket = ticket; response.Signature = signature; return(response); }
public ActionResult VerifyOutlet(int taskId, string password) { var jsapiticket = JsApiTicketContainer.GetTicket(_corpId, _secret); ViewBag.appId = _corpId; ViewBag.noncestr = JSSDKHelper.GetNoncestr(); ViewBag.timestamp = JSSDKHelper.GetTimestamp(); ViewBag.signature = JSSDKHelper.GetSignature(jsapiticket, ViewBag.nonceStr, ViewBag.timestamp, AbsoluteUri()); WxIdentifyDto dto = HttpContext.Session.GetObjectFromJson <WxIdentifyDto>("WxIdentify"); if (dto != null && !string.IsNullOrEmpty(password) && dto.OutletPassword == password) { if (taskId != 0) { _weixinAppService.SetIdentifyTime(taskId); _context.Clients.All.SendAsync("getMessage", "keypoint " + string.Format("{0},{1}", dto.OutletName, dto.DepotId)); } else { string issuer = null; foreach (var w in dto.Workers) { issuer += $"{w.Cn} {w.Name},"; } _weixinAppService.SetIdentifyEvent(dto.RouteId, $"{dto.OutletCn} {dto.OutletName}", issuer); } return(View("Information2", dto)); } else { ModelState.AddModelError("", "网点密码不符,请重新输入"); return(View("Identify", dto)); } }
/// <summary> /// 结合使用 agentConfig /// </summary> /// <returns></returns> public async Task <ActionResult> AgentConfig() { //此处演示同时支持多个应用的注册,请参考 appsettings.json 文件 var workSetting = Senparc.Weixin.Config.SenparcWeixinSetting["企业微信审批"] as ISenparcWeixinSettingForWork; var url = "https://sdk.weixin.senparc.com/Work/Approval"; //获取 UI 信息包 /* 注意: * 所有应用中,jsApiUiPackage 是必备的 */ var jsApiTicket = await JsApiTicketContainer.GetTicketAsync(workSetting.WeixinCorpId, workSetting.WeixinCorpSecret, false); var jsApiUiPackage = await JSSDKHelper.GetJsApiUiPackageAsync(workSetting.WeixinCorpId, workSetting.WeixinCorpSecret, url, jsApiTicket, false); ViewData["jsApiUiPackage"] = jsApiUiPackage; /* 注意: * 1、这里需要使用 WeixinCorpAgentId,而不是 WeixinCorpId * 2、agentJsApiUiPackage 是否需要提供,请参考官方文档,此处演示了最复杂的情况 */ ViewData["thirdNo"] = DateTime.Now.Ticks + Guid.NewGuid().ToString("n"); ViewData["corpId"] = workSetting.WeixinCorpId; ViewData["agentId"] = workSetting.WeixinCorpAgentId; var agentConfigJsApiTicket = await JsApiTicketContainer.GetTicketAsync(workSetting.WeixinCorpId, workSetting.WeixinCorpSecret, true); var agentJsApiUiPackage = await JSSDKHelper.GetJsApiUiPackageAsync(workSetting.WeixinCorpId, workSetting.WeixinCorpSecret, url, agentConfigJsApiTicket, true); ViewData["agentJsApiUiPackage"] = agentJsApiUiPackage; return(View()); }
public ActionResult Index() { var code = Request.Params["code"]; var appid = ConfigurationManager.AppSettings["AppID"]; var secret = ConfigurationManager.AppSettings["AppSecret"]; WxModel model = new WxModel(); var ticket = JsApiTicketContainer.GetJsApiTicket(appid); var noncestr = JSSDKHelper.GetNoncestr(); var timeSpan = JSSDKHelper.GetTimestamp(); var signature = JSSDKHelper.GetSignature(ticket, noncestr, timeSpan, Request.Url.AbsoluteUri); var accessToken = OAuthApi.GetAccessToken(appid, secret, code); if (OAuthApi.Auth(accessToken.access_token, accessToken.openid).errcode == ReturnCode.合法的OpenID) { accessToken = OAuthApi.RefreshToken(appid, accessToken.refresh_token); } var accessUserInfo = OAuthApi.GetUserInfo(accessToken.access_token, accessToken.openid); model.UnioId = accessUserInfo.openid; model.TimeStamp = timeSpan; model.Signature = signature; model.NonceStr = noncestr; return(View(model)); }
public string GetJsapiSignature(string jsapi_ticket, string noncestr, string timestamp, string url) { //string sign = Senparc.Weixin.MP.Helpers.SHA1UtilHelper.GetSha1(string.Format("jsapi_ticket={0}&noncestr={1}×tamp={2}&url={3}",jsapi_ticket,noncestr,timestamp,url)).ToLower(); string s1 = JSSDKHelper.GetSignature(jsapi_ticket, noncestr, timestamp, url); return(s1); }
private WXSyncJSInfoByCard GetWXSyncJSInfo(string cardid, string url) { WXSyncJSInfoByCard wXSyncJSInfoByCard = null; if (!string.IsNullOrWhiteSpace(cardid)) { WXCardLogInfo wXCardLogInfo = context.WXCardLogInfo.FirstOrDefault((WXCardLogInfo d) => d.CardId == cardid); if (wXCardLogInfo != null) { string jSApiTicket = GetJSApiTicket(wXCardLogInfo.AppId, wXCardLogInfo.AppSecret); if (string.IsNullOrWhiteSpace(jSApiTicket)) { Log.Info("[Coupon]票据获取失败"); } else { wXSyncJSInfoByCard = new WXSyncJSInfoByCard(); JSSDKHelper jSSDKHelper = new JSSDKHelper(); wXSyncJSInfoByCard.appid = wXCardLogInfo.AppId; wXSyncJSInfoByCard.apiticket = jSApiTicket; wXSyncJSInfoByCard.timestamp = JSSDKHelper.GetTimestamp(); wXSyncJSInfoByCard.nonceStr = JSSDKHelper.GetNoncestr(); wXSyncJSInfoByCard.signature = JSSDKHelper.GetSignature(wXSyncJSInfoByCard.apiticket, wXSyncJSInfoByCard.nonceStr, wXSyncJSInfoByCard.timestamp, url); } } } return(wXSyncJSInfoByCard); }
public async Task <ResultDto> JsSdkAsync(string url) { var configSection = _configuration.GetSection("WeChat:Web"); //获取时间戳 var timestamp = JSSDKHelper.GetTimestamp(); //获取随机码 var nonceStr = JSSDKHelper.GetNoncestr(); var appId = configSection.GetValue <string>("AppId"); var appSecret = configSection.GetValue <string>("AppSecret"); //获取票证 var jsTicket = await JsApiTicketContainer.TryGetJsApiTicketAsync(appId, appSecret); //获取签名 //nonceStr = "Wm3WZYTPz0wzccnW"; //jsTicket = "sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg"; //timestamp = "1414587457"; //url = "http://mp.weixin.qq.com?params=value"; //url = url?? Request.GetAbsoluteUri(); var signature = JSSDKHelper.GetSignature(jsTicket, nonceStr, timestamp, url); var resultDto = new ResultDto { Result = true, Data = new { appId, timestamp, nonceStr, signature }, Message = "查询成功" }; _logger.LogDebug(Serialize.ToJson(new { url, appId, jsTicket, timestamp, nonceStr, signature })); return(resultDto); }
private WXSyncJSInfoCardInfo MakeSyncWXJSInfo(string cardid, long couponRecordId, WXCardLogInfo.CouponTypeEnum couponType) { WXSyncJSInfoCardInfo wXSyncJSInfoCardInfo = null; if (!string.IsNullOrWhiteSpace(cardid)) { WXCardLogInfo wXCardLogInfo = context.WXCardLogInfo.FirstOrDefault((WXCardLogInfo d) => d.CardId == cardid); if (wXCardLogInfo != null) { string accessToken = GetAccessToken(wXCardLogInfo.AppId, wXCardLogInfo.AppSecret); string cardJSApiTicket = GetCardJSApiTicket(accessToken); if (string.IsNullOrWhiteSpace(cardJSApiTicket)) { Log.Info("[Coupon]票据获取失败"); } else { wXSyncJSInfoCardInfo = new WXSyncJSInfoCardInfo(); int num = (int)SyncCouponRecordInfo(cardid, couponRecordId, couponType); JSSDKHelper jSSDKHelper = new JSSDKHelper(); wXSyncJSInfoCardInfo.card_id = cardid; wXSyncJSInfoCardInfo.timestamp = JSSDKHelper.GetTimestamp(); wXSyncJSInfoCardInfo.nonce_str = ""; wXSyncJSInfoCardInfo.signature = JSSDKHelper.GetcardExtSign( cardJSApiTicket, wXSyncJSInfoCardInfo.timestamp, wXSyncJSInfoCardInfo.card_id, wXSyncJSInfoCardInfo.nonce_str); wXSyncJSInfoCardInfo.outerid = num; } } } return(wXSyncJSInfoCardInfo); }
/// <summary> /// 赠送订单成功 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public ActionResult SendGiftSuccess(long?orderId) { var order = new OrderViewModel(); if (orderId.HasValue) { var tempOrder = OrderService.GetOrder(this.UserInfo.UserId, orderId.Value, false); if (tempOrder != null) { var user = UserService.GetUserByUserId(tempOrder.UserId); if (user != null) { order.SendUserMobile = user.Mobile; order.SendUserName = user.WxNickName; order.OrderId = tempOrder.OrderId; //获取时间戳 var timestamp = JSSDKHelper.GetTimestamp(); //获取随机码 var nonceStr = JSSDKHelper.GetNoncestr(); string ticket = JsApiTicketContainer.TryGetTicket(AppId, AppSecret); JSSDKHelper jsHelper = new JSSDKHelper(); //获取签名 var signature = jsHelper.GetSignature(ticket, nonceStr, timestamp, Request.Url.AbsoluteUri); ViewData["AppId"] = AppId; ViewData["Timestamp"] = timestamp; ViewData["NonceStr"] = nonceStr; ViewData["Signature"] = signature; } } } return(View(order)); }
// #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)); } }
/// <summary> /// 转账 /// </summary> /// <returns></returns> public ActionResult TransferAccount(long orderId) { var payTipViewModel = new PayTipViewModel(); var orderViewModel = OrderService.GetOrderViewModel(this.UserInfo.UserId, orderId); payTipViewModel.OrderId = orderViewModel.OrderId; payTipViewModel.PayMoney = orderViewModel.ProductCount * orderViewModel.Price; payTipViewModel.IsPaySuccess = orderViewModel.Status == OrderStatus.Paid.GetHashCode(); payTipViewModel.Message = payTipViewModel.IsPaySuccess ? "支付成功" : "支付失败"; payTipViewModel.BuyCount = orderViewModel.ProductCount; //获取时间戳 var timestamp = JSSDKHelper.GetTimestamp(); //获取随机码 var nonceStr = JSSDKHelper.GetNoncestr(); string ticket = JsApiTicketContainer.TryGetTicket(AppId, AppSecret); JSSDKHelper jsHelper = new JSSDKHelper(); //获取签名 var signature = jsHelper.GetSignature(ticket, nonceStr, timestamp, Request.Url.AbsoluteUri); ViewData["AppId"] = AppId; ViewData["Timestamp"] = timestamp; ViewData["NonceStr"] = nonceStr; ViewData["Signature"] = signature; ViewBag.uid = DotNet.Common.CryptographyHelper.Base64Encrypt(this.UserInfo.UserId.ToString()); return(View(payTipViewModel)); }
public ActionResult JsSDK() { var url = Request.Url.AbsoluteUri; var jsSdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(appId, appSecret, url); return(View(jsSdkUiPackage)); }
public ActionResult PlatStoreDescriptionRichText(int id = 0) { //string token = AccessTokenContainer.GetAccessToken(AccessTokenContainer.GetFirstOrDefaultAppId()); string token = WxHelper.GetToken(webview_appid, webview_appsecret, false); ViewBag.appid = AccessTokenContainer.GetFirstOrDefaultAppId(); ViewBag.ticket = JsApiTicketContainer.GetJsApiTicket(JsApiTicketContainer.GetFirstOrDefaultAppId()); ViewBag.timestamp = JSSDKHelper.GetTimestamp(); ViewBag.nonceStr = JSSDKHelper.GetNoncestr(); ViewBag.signature = JSSDKHelper.GetSignature(ViewBag.ticket, ViewBag.nonceStr, ViewBag.timestamp, GetPageUrl()); log4net.LogHelper.WriteInfo(this.GetType(), $"token={token};appid={ViewBag.appid};ticket={ViewBag.ticket};timestamp={ ViewBag.timestamp};nonceStr={ViewBag.nonceStr};signature={ViewBag.signature};pageUrl={GetPageUrl()}"); if (id == 0) { // string temp = RedisUtil.Get<string>("temp_psd_description_0"); ViewBag.description = "";//temp ?? ""; } else { PlatStore platStore = PlatStoreBLL.SingleModel.GetModel(id); if (platStore == null || platStore.State == -1) { ViewBag.description = ""; return(Content("店铺不存在或已删除")); } ViewBag.description = platStore.StoreDescription; } return(View()); }
public static ShareInfo GetPayInfo(string prepayid) { var shareInfo = new ShareInfo(); //检查是否已经注册jssdk if (!JsApiTicketContainer.CheckRegistered(ConfigHelper.WeChatAppId)) { JsApiTicketContainer.Register(ConfigHelper.WeChatAppId, ConfigHelper.WeChatSecret); } JsApiTicketResult jsApiTicket = JsApiTicketContainer.GetJsApiTicketResult(ConfigHelper.WeChatAppId); JSSDKHelper jssdkHelper = new JSSDKHelper(); shareInfo.Ticket = jsApiTicket.ticket; shareInfo.CorpId = ConfigHelper.WeChatAppId.ToLower(); shareInfo.Noncestr = JSSDKHelper.GetNoncestr().ToLower(); shareInfo.Timestamp = JSSDKHelper.GetTimestamp().ToLower(); shareInfo.Package = "prepay_id=" + prepayid.ToLower(); RequestHandler requestHandler = new RequestHandler(HttpContext.Current); requestHandler.SetParameter("appId", shareInfo.CorpId); requestHandler.SetParameter("timeStamp", shareInfo.Timestamp); requestHandler.SetParameter("nonceStr", shareInfo.Noncestr); requestHandler.SetParameter("package", shareInfo.Package); requestHandler.SetParameter("signType", "MD5"); requestHandler.SetKey(tenPayV3Info.Key); requestHandler.CreateMd5Sign(); requestHandler.GetRequestURL(); requestHandler.CreateSHA1Sign(); shareInfo.PaySign = (requestHandler.GetAllParameters()["sign"]).ToString(); return(shareInfo); }
public ActionResult RichText(int id = 0) { //string token = AccessTokenContainer.GetAccessToken(AccessTokenContainer.GetFirstOrDefaultAppId()); string token = WxHelper.GetToken(webview_appid, webview_appsecret, false); ViewBag.appid = AccessTokenContainer.GetFirstOrDefaultAppId(); ViewBag.ticket = JsApiTicketContainer.GetJsApiTicket(JsApiTicketContainer.GetFirstOrDefaultAppId()); ViewBag.timestamp = JSSDKHelper.GetTimestamp(); ViewBag.nonceStr = JSSDKHelper.GetNoncestr(); ViewBag.signature = JSSDKHelper.GetSignature(ViewBag.ticket, ViewBag.nonceStr, ViewBag.timestamp, GetPageUrl()); ViewBag.pageUrl = GetPageUrl(); if (id == 0) { ViewBag.description = ""; } else { EntGoods good = EntGoodsBLL.SingleModel.GetModel(id); if (good == null) { ViewBag.description = ""; return(Content("产品不存在或已删除")); } ViewBag.description = good.description; } return(View()); }
/// <summary> /// 同步微信JS信息获取 /// <para>卡券的票据与其他票据不同,请调用此功能</para> /// <param name="cardid"></param> /// <returns></returns> private WXSyncJSInfoByCard GetWXSyncJSInfo(string cardid, string url) { WXSyncJSInfoByCard result = null; if (!string.IsNullOrWhiteSpace(cardid)) { var card = Context.WXCardLogInfo.FirstOrDefault(d => d.CardId == cardid); if (card != null) { //string acctoken = GetAccessToken(card.AppId, card.AppSecret); string apiticket = GetJSApiTicket(card.AppId, card.AppSecret); if (!string.IsNullOrWhiteSpace(apiticket)) { result = new WXSyncJSInfoByCard(); JSSDKHelper jsshelper = new JSSDKHelper(); result.appid = card.AppId; result.apiticket = apiticket; result.timestamp = JSSDKHelper.GetTimestamp(); result.nonceStr = JSSDKHelper.GetNoncestr(); result.signature = jsshelper.GetSignature(result.apiticket, result.nonceStr, result.timestamp, url); } else { Log.Info("[Coupon]票据获取失败"); } } } return(result); }
/// <summary> /// 拼享惠产品描述编辑 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult PinRichText(int id = 0) { string token = WxHelper.GetToken(webview_appid, webview_appsecret, false); ViewBag.appid = AccessTokenContainer.GetFirstOrDefaultAppId(); ViewBag.ticket = JsApiTicketContainer.GetJsApiTicket(JsApiTicketContainer.GetFirstOrDefaultAppId()); ViewBag.timestamp = JSSDKHelper.GetTimestamp(); ViewBag.nonceStr = JSSDKHelper.GetNoncestr(); ViewBag.signature = JSSDKHelper.GetSignature(ViewBag.ticket, ViewBag.nonceStr, ViewBag.timestamp, Server.UrlDecode(GetPageUrl())); ViewBag.pageUrl = GetPageUrl(); if (id == 0) { //string temp = RedisUtil.Get<string>(PinGoodsBLL.key_new_pin_goods); ViewBag.description = ""; //temp ?? ""; } else { PinGoods good = PinGoodsBLL.SingleModel.GetModel(id); if (good == null) { ViewBag.description = ""; return(Content("产品不存在或已删除")); } ViewBag.description = good.description; } return(View("RichText")); }
// GET: WeixinJSSDK public ActionResult Index() { #region v13.6.4之前的写法 ////获取时间戳 //var timestamp = JSSDKHelper.GetTimestamp(); ////获取随机码 //var nonceStr = JSSDKHelper.GetNoncestr(); //string ticket = JsApiTicketContainer.TryGetJsApiTicket(appId, secret); ////获取签名 //var signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, Request.Url.AbsoluteUri); //ViewData["AppId"] = appId; //ViewData["Timestamp"] = timestamp; //ViewData["NonceStr"] = nonceStr; //ViewData["Signature"] = signature; #endregion var jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(base.AppId, base.AppSecret, Request.Url.AbsoluteUri); //ViewData["JsSdkUiPackage"] = jssdkUiPackage; //ViewData["AppId"] = appId; //ViewData["Timestamp"] = jssdkUiPackage.Timestamp; //ViewData["NonceStr"] = jssdkUiPackage.NonceStr; //ViewData["Signature"] = jssdkUiPackage.Signature; return(View(jssdkUiPackage)); }
public async Task <ActionResult> CountingView(string ids, string partUrl, string signUrl) { //using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MustHaveTenant)) //{ var jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(appId, appSecret, Request.AbsoluteUri().Split('#')[0]); ViewBag.Ids = ids; String srcArray = ""; foreach (var id in ids.Split(',')) { Logger.Error("\r\n\r\nid" + id); var path = await ProcessTaskManager.GetTaskPicSrc(Convert.ToInt32(id)); srcArray += path + ","; } srcArray.Substring(0, srcArray.Length - 1); Logger.Error("\r\n\r\nSrcArr" + srcArray); //var path = await ProcessTaskManager.GetTaskSheetImagePath(id); ViewBag.ImgPath = partUrl; ViewBag.SignUrl = signUrl; ViewBag.TaskUrls = srcArray; return(View("WeChat/process/CountingView", jssdkUiPackage)); //} }
/// <summary> /// 获取配置微信JSSDK的JS字符串; /// </summary> /// <param name="url"></param> /// <param name="interfaces"></param> /// <param name="debug"></param> /// <returns></returns> public string GetConfigWxJs(string url, string interfaces, bool debug = true) { if (string.IsNullOrEmpty(Config.AppId)) { return(""); } //url = url.ToLower(); //特别注意,url必须小写,否则验证通不过; JSSDKHelper helper = new JSSDKHelper(); var timestamp = JSSDKHelper.GetTimestamp(); var nonceStr = JSSDKHelper.GetNoncestr(); var jsticket = JsTicket; var signature = JSSDKHelper.GetSignature(jsticket, nonceStr, timestamp, url); string interfs = interfaces.Split(new char[] { ',' }) .Select(a => "'" + a.Trim() + "'").ToArray().ToString(","); string debugString = ""; if (debug) { debugString = "/**" + jsticket + @"**/"; } string configString = debugString + @" wx.config({debug:" + debug.ToString().ToLower() + ",appId:'" + Config.AppId + "',timestamp:" + timestamp + ",nonceStr:'" + nonceStr + "',signature:'" + signature + "',jsApiList:[" + interfs + "]});"; return(configString); }
public static System.Collections.Hashtable GetData(string appid, string secret) { if (string.IsNullOrEmpty(appid) || string.IsNullOrEmpty(secret)) { return(null); } var ticket = AccessTokenContainer.TryGetJsApiTicket(appid, secret); //获取时间戳 var timestamp = JSSDKHelper.GetTimestamp(); //获取随机码 var nonceStr = JSSDKHelper.GetNoncestr(); return(new System.Collections.Hashtable { { "appId", appid }, { "nonceStr", nonceStr }, { "timestamp", timestamp }, { "signature", JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, HttpContext.Current.Request.Url.AbsoluteUri) } }); }