Exemple #1
0
        public ActionResult Index(string companyId)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(companyId))
                {
                    return(RedirectToAction("Index", "BrowseError", new { errorMsg = "请打开扫一扫" }));
                }
                WX_ApiConfig config    = WXApiConfigServices.QueryWXApiConfig(companyId);
                var          timeStamp = DateTimeHelper.TransferUnixDateTime(DateTime.Now).ToString();
                var          nonceStr  = StringHelper.GetRndString(16);
                var          url       = Request.Url.ToString();

                var    accessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, false);
                var    ticket      = WxAdvApi.GetTicket(accessToken);
                string signature   = WxService.GetJsApiSignature(nonceStr, ticket.ticket, timeStamp, url);
                ViewBag.Signature = signature;
                ViewBag.AppId     = config.AppId;
                ViewBag.Timestamp = timeStamp;
                ViewBag.NonceStr  = nonceStr;
                return(View());
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "调用扫码方法异常", ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "BrowseError", new { errorMsg = "调用扫码方法异常" }));
            }
        }
Exemple #2
0
 private string GetWeiXinSignature(WX_ApiConfig config, string noncestr, string url, string timestamp)
 {
     try
     {
         var accessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, false);
         var ticket      = WxAdvApi.GetTicket(accessToken);
         return(WxService.GetJsApiSignature(noncestr, ticket.ticket, timestamp, url));
     }
     catch (Exception ex) {
         ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "分享页面获取签名错误", ex, LogFrom.WeiXin);
         return(string.Empty);
     }
 }