Ejemplo n.º 1
0
 public static string GetAppUrl(this WidgetFactory ace, string url, params string[] appendQueries)
 {
     url = $"/{ace.AppName}/{url}";
     foreach (var query in appendQueries)
     {
         url = UrlHelper.Append(url, query, App.GetQuery(query, ""));
     }
     return(url);
 }
Ejemplo n.º 2
0
 public static string GetUrl(this WidgetFactory ace, string url, params string[] appendQueries)
 {
     foreach (var query in appendQueries)
     {
         var value = App.GetQuery(query, "");
         if (value.HasValue())
         {
             url = UrlHelper.Append(url, query, value);
         }
     }
     return(url);
 }
Ejemplo n.º 3
0
        public static bool WeChatAuthorize(this IAccessControl ac, string openIdParamName)
        {
            var context = ac.Context;

            // 是否微信运行
            if (!context.SideInWeixinBrowser())
            {
                return(true);
            }

            // 检查是否wechat oauth, 是否传入appid
            if (!App.GetQuery("appid", "").HasValue())
            {
                return(true);
            }

            try
            {
                var returnUrl = App.GetQuery("returnurl", "/wechat");
                if (ac.Logined && ac.Auths.ContainsKey("wechat"))
                {
                    if (returnUrl.StartsWith("http"))
                    {
                        returnUrl = UrlHelper.Append(returnUrl, openIdParamName, ac.Auths["wechat"].AuthId);
                    }
                    context.Response.Redirect(returnUrl);
                    return(true);
                }
                else if (ac.Logined)
                {
                    // logout first
                    ac.Logout();
                }

                var app          = ac.Context.RequestServices.GetService <IWeChatContainer>().GetApp();
                var state        = App.GetQuery("state", "state");
                var scope        = (OAuthScope)App.GetQuery("scope", 0);
                var redirectUrl  = $"{App.GetWebRoot(true)}plat/account/wechat?appid={app.Id}&redirect_uri={returnUrl}";
                var authorizeUrl = OAuthApi.GetAuthorizeUrl(app.AppId, redirectUrl, state, scope);
                context.Response.Redirect(authorizeUrl);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        public static JsApiToken GetJsApiToken(this IAccessControl ac, bool resetUrl)
        {
            var app = ac.Context.RequestServices.GetService <IWeChatContainer>().GetApp();

            var timestamp   = JSSDKHelper.GetTimestamp();
            var noncestr    = JSSDKHelper.GetNoncestr();
            var jsApiTicket = JsApiTicketContainer.GetJsApiTicket(app.AppId);
            var url         = ac.Context.Request.GetUrl();

            if (resetUrl)
            {
                url = UrlHelper.Append(url, "t", timestamp);
            }
            var signature = JSSDKHelper.GetSignature(jsApiTicket, noncestr, timestamp, url);

            return(new JsApiToken
            {
                AppId = app.AppId,
                Ticket = jsApiTicket,
                Timestamp = timestamp,
                Nonce = noncestr,
                Signature = signature
            });
        }