Exemplo n.º 1
0
        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)
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// 注册支付脚本
        /// <param name="weixinId"></param>
        /// <param name="errorMessage"></param>
        /// </summary>
        public bool RegisterJWeiXin(int weixinId, out string errorMessage)
        {
            try
            {
                errorMessage = string.Empty;
                var ticket = WeiXinCRMComm.getJsApiTicket(weixinId, out errorMessage);
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    return(false);
                }

                var wxModel = new BLL.wx_userweixin().GetModel(weixinId);
                if (wxModel == null)
                {
                    errorMessage = "不合法的参数wid";
                    return(false);
                }

                appId     = wxModel.AppId;
                nonceStr  = JSSDKHelper.GetNoncestr();
                timestamp = JSSDKHelper.GetTimestamp();
                signature = new JSSDKHelper().GetSignature(ticket, nonceStr, timestamp, Request.Url.ToString());

                IsRegister = 1;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <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));
        }
Exemplo n.º 4
0
        /// <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.CorpId))
            {
                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.CorpId + "',timestamp:" +
                                  timestamp + ",nonceStr:'" + nonceStr + "',signature:'" + signature + "',jsApiList:[" + interfs + "]});";

            return(configString);
        }
Exemplo n.º 5
0
        public ActionResult UserInfoCallback(string code, string state, string returnUrl)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Content("您拒绝了授权!"));
            }

            if (state != Session["State"] as string)
            {
                return(Content("验证失败!请从正规途径进入!"));
            }
            OAuthAccessTokenResult result   = OAuthApi.GetAccessToken(AppId, AppSecret, code);
            OAuthUserInfo          userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
            string ticket = string.Empty;

            timestamp = JSSDKHelper.GetTimestamp();
            nonceStr  = JSSDKHelper.GetNoncestr();
            JSSDKHelper jssdkhelper = new JSSDKHelper();

            ticket            = JsApiTicketContainer.TryGetJsApiTicket(AppId, AppSecret);
            signature         = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, Request.Url.AbsoluteUri.ToString());
            ViewBag.signature = signature;
            ViewBag.appid     = AppId;
            ViewBag.timestamp = timestamp;
            ViewBag.noncestr  = nonceStr;
            return(View(userInfo));
        }
Exemplo n.º 6
0
        public ActionResult Index()
        {
            string str;

            ViewBag.WeiXin = false;
            if (!string.IsNullOrWhiteSpace(_siteSetting.WeixinAppId) && !string.IsNullOrWhiteSpace(_siteSetting.WeixinAppSecret) && base.PlatformType == ChemCloud.Core.PlatformType.WeiXin)
            {
                ViewBag.WeiXin = true;
                string        empty        = string.Empty;
                IWXApiService wXApiService = ServiceHelper.Create <IWXApiService>();
                empty = wXApiService.GetTicket(_siteSetting.WeixinAppId, _siteSetting.WeixinAppSecret);
                JSSDKHelper jSSDKHelper = new JSSDKHelper();
                string      timestamp   = JSSDKHelper.GetTimestamp();
                string      noncestr    = JSSDKHelper.GetNoncestr();
                string      signature   = jSSDKHelper.GetSignature(empty, noncestr, timestamp, base.Request.Url.AbsoluteUri);
                ViewBag.Timestamp = timestamp;
                ViewBag.NonceStr  = noncestr;
                ViewBag.Signature = signature;
                ViewBag.AppId     = _siteSetting.WeixinAppId;
            }
            long                        id = base.CurrentUser.Id;
            UserInviteModel             memberInviteInfo   = ServiceHelper.Create <IMemberInviteService>().GetMemberInviteInfo(id);
            InviteRuleInfo              inviteRule         = ServiceHelper.Create <IMemberInviteService>().GetInviteRule();
            MemberIntegralExchangeRules integralChangeRule = ServiceHelper.Create <IMemberIntegralService>().GetIntegralChangeRule();

            if (integralChangeRule != null)
            {
                dynamic viewBag = base.ViewBag;
                int     value   = inviteRule.InviteIntegral.Value / integralChangeRule.IntegralPerMoney;
                viewBag.IntergralMoney = value.ToString("f2");
            }
            string host = base.Request.Url.Host;
            string str1 = host;

            if (base.Request.Url.Port != 80)
            {
                int port = base.Request.Url.Port;
                str = string.Concat(":", port.ToString());
            }
            else
            {
                str = "";
            }
            host = string.Concat(str1, str);
            memberInviteInfo.InviteLink = string.Format("http://{0}/Register/index/{1}", host, id);
            inviteRule.ShareIcon        = string.Format("http://{0}{1}", host, inviteRule.ShareIcon);
            Bitmap       bitmap       = QRCodeHelper.Create(memberInviteInfo.InviteLink);
            MemoryStream memoryStream = new MemoryStream();

            bitmap.Save(memoryStream, ImageFormat.Gif);
            string str2 = string.Concat("data:image/gif;base64,", Convert.ToBase64String(memoryStream.ToArray()));

            memoryStream.Dispose();
            memberInviteInfo.QR = str2;
            Tuple <UserInviteModel, InviteRuleInfo, UserMemberInfo> tuple = new Tuple <UserInviteModel, InviteRuleInfo, UserMemberInfo>(memberInviteInfo, inviteRule, base.CurrentUser);

            return(View(tuple));
        }
Exemplo n.º 7
0
        public string WeChatShare()
        {
            string jsTicket  = string.Empty;
            var    timeStamp = JSSDKHelper.GetTimestamp(); //时间戳
            var    noceStr   = JSSDKHelper.GetNoncestr();  //随机字符串

            //JsApiTicketContainer.TryGetTicket(appID, appSecret);
            return("");
        }
Exemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string ticket = string.Empty;

        timestamp = JSSDKHelper.GetTimestamp();
        nonceStr  = JSSDKHelper.GetNoncestr();
        appID     = "wx422044a7a4be9609";
        ticket    = JsApiTicketContainer.GetJsApiTicket(appID);
        signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, Request.Url.AbsoluteUri.ToString());
    }
Exemplo n.º 9
0
        public (string, string, string, string) getJsSdkSign(string url)
        {
            var    timestamp    = JSSDKHelper.GetTimestamp();
            var    nonceStr     = JSSDKHelper.GetNoncestr();
            string jsapi_ticket = JsApiTicketContainer.TryGetJsApiTicket(_options.Value.AppId, _options.Value.AppSecret);
            string strurl       = url;
            var    signature    = JSSDKHelper.GetSignature(jsapi_ticket, nonceStr, timestamp, strurl);

            return(timestamp, nonceStr, signature, _options.Value.AppId);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取微信分享参数
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="appsecret"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public WeiXinShareArgs GetWeiXinShareArgs(string appid, string appsecret, string url)
        {
            string ticket = GetTicket(appid, appsecret);

            var    jssdk     = new JSSDKHelper();
            string timestamp = JSSDKHelper.GetTimestamp();
            string nonceStr  = JSSDKHelper.GetNoncestr();
            string signature = jssdk.GetSignature(ticket, nonceStr, timestamp, url);

            return(new WeiXinShareArgs(appid, timestamp, nonceStr, signature, ticket));
        }
Exemplo n.º 11
0
        /// <summary>
        /// 获取当前页面卡券JS配置信息
        /// </summary>
        /// <returns></returns>
        public JSSDKConfigInfo GetCardJSSDKConfigInfo()
        {
            var ticket     = WeChatApisContext.Current.TicketApi.GetSafeCardAccessToken().Ticket;
            var configInfo = new JSSDKConfigInfo
            {
                AppId     = Current.GetConfig().AppId,
                Timestamp = JSSDKHelper.GetTimestamp(),
                NonceStr  = JSSDKHelper.GetNoncestr()
            };

            return(configInfo);
        }
Exemplo n.º 12
0
        public JsSdkUiPackage GetJSSDKConfig([FromBody] JSSDKPostModel model)
        {
            //获取时间戳
            var timestamp = JSSDKHelper.GetTimestamp();
            //获取随机码
            var nonceStr = JSSDKHelper.GetNoncestr();
            //获取JS票据
            var JsapiTicket = JsApiTicketContainer.TryGetTicket(option.CorpId, option.Secret);
            //获取签名
            var signature = JSSDKHelper.GetSignature(JsapiTicket, nonceStr, timestamp, model.OriginalUrl);

            return(new JsSdkUiPackage(option.CorpId, timestamp.ToString(), nonceStr, signature));
        }
Exemplo n.º 13
0
        public static Dictionary <string, string> SignParams(Dictionary <string, string> dic)
        {
            // TODO: Free Pen
            dic.Add("nonce", JSSDKHelper.GetNoncestr(16));
            dic.Add("timestamp", JSSDKHelper.GetTimestamp().ToString());
            var signature = Sign(dic);

            dic.Remove("appSecret");
            dic.Add("signature", signature);
            dic.Add("system", "html5");

            return(dic);
        }
Exemplo n.º 14
0
        public JsSdkUiPackage GetJsSdkUiPackage(string appId, string appSecret, string url)
        {
            //获取时间戳
            var timestamp = JSSDKHelper.GetTimestamp();
            //获取随机码
            string nonceStr = JSSDKHelper.GetNoncestr();
            string ticket   = JsApiTicketContainer.TryGetJsApiTicket(appId, appSecret);
            //获取签名
            string signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, url);

            //返回信息包
            return(new JsSdkUiPackage(appId, timestamp, nonceStr, signature));
        }
Exemplo n.º 15
0
        /// <summary>
        ///     获取当前页面JS配置信息
        /// </summary>
        /// <returns></returns>
        public JSSDKConfigInfo GetJSSDKConfigInfo()
        {
            var ticket     = WeChatApisContext.Current.TicketApi.SafeGet().Ticket;
            var configInfo = new JSSDKConfigInfo
            {
                AppId     = WeChatConfigManager.Current.GetConfig().AppId,
                Timestamp = JSSDKHelper.GetTimestamp(),
                NonceStr  = JSSDKHelper.GetNoncestr()
            };

            configInfo.Signature = JSSDKHelper.GetSignature(ticket, configInfo.NonceStr, configInfo.Timestamp,
                                                            HttpContext.Current.Request.Url.AbsoluteUri);
            return(configInfo);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 获取当前页面JS配置信息
        /// </summary>
        /// <param name="absoluteUrl">The absoluteUrl<see cref="string"/></param>
        /// <returns></returns>
        public JSSDKConfigInfo GetJSSDKConfigInfo(string absoluteUrl)
        {
            var ticket     = WeChatApisContext.Current.TicketApi.SafeGet().Ticket;
            var configInfo = new JSSDKConfigInfo
            {
                AppId     = Current.GetConfig().AppId,
                Timestamp = JSSDKHelper.GetTimestamp(),
                NonceStr  = JSSDKHelper.GetNoncestr()
            };

            configInfo.Signature = JSSDKHelper.GetSignature(ticket, configInfo.NonceStr, configInfo.Timestamp,
                                                            absoluteUrl);
            return(configInfo);
        }
Exemplo n.º 17
0
        private void SetViewBag()
        {
            var timestamp = JSSDKHelper.GetTimestamp();
            //获取随机码
            var    nonceStr = JSSDKHelper.GetNoncestr();
            string ticket   = JsApiTicketContainer.GetTicket(_corpId, _secret);
            //获取签名
            var signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, AbsoluteUri());

            ViewBag.AppId     = _corpId;
            ViewBag.Timestamp = timestamp;
            ViewBag.NonceStr  = nonceStr;
            ViewBag.Signature = signature;
        }
Exemplo n.º 18
0
        public ActionResult WxSignature(string url)
        {
            try
            {
                if (!AccessTokenContainer.CheckRegistered(appid)) //检查是否已经注册
                {
                    AccessTokenContainer.Register(appid, secret); //如果没有注册则进行注册
                }

                var tokenResult = HttpRuntimeCache.GetCache("LocalAccessToken") as LocalAccessToken;
                var useCache    = true;
                if (tokenResult == null || string.IsNullOrWhiteSpace(tokenResult?.access_token) || tokenResult.ExpiresTime == null || System.DateTime.Now > tokenResult.ExpiresTime) //过期
                {
                    useCache = false;
                    var result = AccessTokenContainer.GetAccessTokenResult(appid, true);
                    if (!string.IsNullOrWhiteSpace(result?.errmsg))
                    {
                        return(Json(new { ErrMsg = JsonConvert.SerializeObject(result) }, JsonRequestBehavior.AllowGet));
                        //return Json(new { data = JsonConvert.SerializeObject(new { appid, secret }), ErrMsg = JsonConvert.SerializeObject(tokenResult) }, JsonRequestBehavior.AllowGet);
                    }

                    tokenResult = new LocalAccessToken(result)
                    {
                    };

                    HttpRuntimeCache.SetCache("LocalAccessToken", tokenResult, 7260);
                }


                var ticket = JsApiTicketContainer.GetJsApiTicket(appid);

                var model = new WXShare()
                {
                    appId     = appid,
                    timestamp = JSSDKHelper.GetTimestamp(),
                    nonce     = JSSDKHelper.GetNoncestr(),
                    url       = Server.UrlDecode(url),
                    ticket    = ticket,
                    //result = JsonConvert.SerializeObject(tokenResult),
                    useCache = useCache
                };

                model.signature = JSSDKHelper.GetSignature(ticket, model.nonce, model.timestamp, model.url);
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            catch (System.Exception ex)
            {
                return(Json(new { ErrMsg = ex.Message, StackTrace = JsonConvert.SerializeObject(ex.StackTrace) }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 19
0
        private void SetShareData()
        {
            IWXApiService wXApiService = ServiceHelper.Create <IWXApiService>();
            string        ticket       = wXApiService.GetTicket(_siteSetting.WeixinAppId, _siteSetting.WeixinAppSecret);
            JSSDKHelper   jSSDKHelper  = new JSSDKHelper();
            string        timestamp    = JSSDKHelper.GetTimestamp();
            string        noncestr     = JSSDKHelper.GetNoncestr();
            string        signature    = jSSDKHelper.GetSignature(ticket, noncestr, timestamp, base.Request.Url.AbsoluteUri);

            ViewBag.Timestamp = timestamp;
            ViewBag.NonceStr  = noncestr;
            ViewBag.Signature = signature;
            ViewBag.AppId     = _siteSetting.WeixinAppId;
        }
        public IActionResult Index()
        {
            var nonce     = JSSDKHelper.GetNoncestr();
            var timestamp = JSSDKHelper.GetTimestamp();
            var ticket    = JsApiTicketContainer.TryGetTicket(WeixinWorkOptions.CorpId, WeixinWorkOptions.Secret);
            var signature = JSSDKHelper.GetSignature(ticket, nonce, timestamp, Request.AbsoluteUri());

            ViewBag.CorpId    = WeixinWorkOptions.CorpId;
            ViewBag.Nonce     = nonce;
            ViewBag.TimeStamp = timestamp;
            ViewBag.Signature = signature;

            return(View());
        }
Exemplo n.º 21
0
        /// <summary>
        /// 获取给UI使用的JSSDK信息包
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static JsSdkUiPackage GetJsSdkUiPackage(string url)
        {
            string appId = System.Web.Configuration.WebConfigurationManager.AppSettings["WeixinAppId"];
            
            string timestamp = JSSDKHelper.GetTimestamp();
            //获取随机码
            string nonceStr = JSSDKHelper.GetNoncestr();
            
            string ticket = CommonMicroModels.GetTicket("Ticket");
            //获取签名
            string signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, url);

            return new JsSdkUiPackage { AppId=appId, Timestamp = timestamp, NonceStr=nonceStr, Signature=signature };
        }
Exemplo n.º 22
0
        public ActionResult SelectTask(int taskId, int outletId)
        {
            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");

            dto.TaskId = taskId;
            SelectOutlet(outletId, dto);
            return(View("Identify", dto));
        }
Exemplo n.º 23
0
        //
        // GET: /JSSDK/

        public ActionResult Index()
        {
            //获取时间戳
            var timestamp = JSSDKHelper.GetTimestamp();
            //获取随机码
            var    nonceStr = JSSDKHelper.GetNoncestr();
            string ticket   = AccessTokenContainer.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;
            return(View());
        }
Exemplo n.º 24
0
        /// <summary>
        /// 创建UI参数
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="appSecret"></param>
        /// <param name="cardId"></param>
        /// <param name="code"></param>
        /// <param name="openId"></param>
        public JsSdkAddCardUiPackage(string appId,
                                     string appSecret,
                                     string cardId,
                                     string code   = "",
                                     string openId = "")
        {
            AppId     = appId;
            CardId    = cardId;
            Timestamp = JSSDKHelper.GetTimestamp();
            NonceStr  = JSSDKHelper.GetNoncestr();
            string ticket = WxCardApiTicketContainer.TryGetWxCardApiTicket(appId, appSecret);

            Signature = JSSDKHelper.GetcardExtSign(ticket, Timestamp, cardId, NonceStr);
            Code      = code;
            OpenId    = openId;
        }
Exemplo n.º 25
0
        /// <summary>
        /// 获取jsapi权限签名
        /// </summary>
        /// <param name="currentURL">当前URL地址</param>
        /// <returns></returns>
        public JsApiTicketResult GetSignature(string url)
        {
            var jsapi_ticket = JsApiTicketManager.TryGetTicket(AppConfig.CorpId, AppConfig.Secret);
            var timestamp    = JSSDKHelper.GetTimestamp();
            var noncestr     = JSSDKHelper.GetNoncestr();
            var signature    = JSSDKHelper.GetSignature(jsapi_ticket, noncestr, timestamp, url);

            return(new JsApiTicketResult
            {
                AppId = AppConfig.CorpId, // 必填,企业号的唯一标识,此处填写企业号corpid
                Timestamp = timestamp,    // 必填,生成签名的时间戳
                Noncestr = noncestr,      // 必填,生成签名的随机串
                Signature = signature,    // 必填,签名,见附录1
                JsapiTicket = jsapi_ticket
            });
        }
Exemplo n.º 26
0
        public ShareParmModel GetSign(string url)
        {
            var timestamp = JSSDKHelper.GetTimestamp();
            //获取随机码
            var    nonceStr = JSSDKHelper.GetNoncestr();
            string ticket   = JsApiTicketContainer.TryGetJsApiTicket(AppId, Secret);
            //获取签名
            var            signature  = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, url);
            ShareParmModel shareModel = new ShareParmModel();

            shareModel.appid     = AppId;
            shareModel.timestamp = timestamp;
            shareModel.nonceStr  = nonceStr;
            shareModel.signature = signature;
            return(shareModel);
        }
Exemplo n.º 27
0
        public ActionResult Audio()
        {
            WxDemoAudioViewModel vm = new WxDemoAudioViewModel();
            string appId            = ConfigurationManager.AppSettings["appId"];
            string appSecret        = ConfigurationManager.AppSettings["appSecret"];

            vm.AppId     = appId;
            vm.NonceStr  = JSSDKHelper.GetNoncestr();
            vm.TimeStamp = JSSDKHelper.GetTimestamp();
            string ticket = JsApiTicketContainer.TryGetJsApiTicket(appId, appSecret);
            string url    = System.Web.HttpContext.Current.Request.Url.AbsoluteUri.ToString();

            vm.Signature = JSSDKHelper.GetSignature(ticket, vm.NonceStr, vm.TimeStamp, url);

            return(View(vm));
        }
Exemplo n.º 28
0
#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
        public WeChatSignatureInfo GetSign(string url)
#pragma warning restore CS1591 // 缺少对公共可见类型或成员的 XML 注释
        {
            string ticket    = JsApiTicketContainer.TryGetJsApiTicket(Options.WeChatBaseOptions.AppId, Options.WeChatBaseOptions.Appsecret);
            string timestamp = JSSDKHelper.GetTimestamp();
            string nonceStr  = JSSDKHelper.GetNoncestr();
            string signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, url);

            return(new WeChatSignatureInfo
            {
                Ticket = ticket,
                Timestamp = timestamp,
                NonceStr = nonceStr,
                Signature = signature
            });
        }
        public ActionResult WeChatShare(string shareUrl)
        {
            string jsTicket  = string.Empty;
            var    timeStamp = JSSDKHelper.GetTimestamp(); //时间戳
            var    nonceStr  = JSSDKHelper.GetNoncestr();  //随机字符串
            var    ticket    = string.Empty;               //jsapi_ticket

            if ("" != SessionHelper.GetSession(CodeMessageEnum.ShareJsapiTicket))
            {
                ticket = SessionHelper.GetSession(CodeMessageEnum.ShareJsapiTicket);
            }
            else
            {
                var shareAccessToken = SessionHelper.GetSession(CodeMessageEnum.ShareAuthorizationAccessToken);
                if ("" == shareAccessToken)//先判断session中是否存在Access_token
                {
                    var commonMessage = JSSDKHelper.TryGetAccessToken(WChatAppid, WChatAppSecret);
                    if (null != commonMessage.Data)
                    {
                        shareAccessToken = commonMessage.Data.ToString();
                    }
                }

                if ("" != shareAccessToken)
                {
                    var commonMessage = JSSDKHelper.TryGetJsApiTicket(shareAccessToken);
                    if (null != commonMessage.Data)
                    {
                        ticket = commonMessage.Data.ToString();
                    }
                }
            }
            if (string.Empty == ticket)//如果最后没能获取到jsapiTicket,则直接返回错误
            {
                return(Content(CommonMessage.Error(CodeMessageEnum.FaildGotJsApiTicket).ToString(), "application/json"));
            }
            var         signature = JSSDKHelper.GenerateSignature(ticket, nonceStr, timeStamp, shareUrl);//获取签名
            WeixinShare weiShare  = new WeixinShare()
            {
                Appid     = WChatAppid,
                Timestamp = timeStamp,
                Noncestr  = nonceStr,
                Signature = signature
            };

            return(Content(CommonMessage.Success(weiShare).ToString(), "application/json"));
        }
Exemplo n.º 30
0
        internal static Ticket GetTicket(string url)
        {
            var ticket    = JsApiTicketContainer.GetJsApiTicket(WeixinSetting.WeixinAppId);
            var timestamp = JSSDKHelper.GetTimestamp();
            var nonceStr  = JSSDKHelper.GetNoncestr();
            var signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, url);

            var model = new Ticket
            {
                ticket    = ticket,
                nonceStr  = nonceStr,
                timestamp = timestamp,
                signature = signature
            };

            return(model);
        }