Exemple #1
0
        /// <summary>
        /// Returns true if OutputInfo instances are equal
        /// </summary>
        /// <param name="other">Instance of OutputInfo to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OutputInfo other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Specs == other.Specs ||
                     Specs != null &&
                     Specs.Equals(other.Specs)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Logo == other.Logo ||
                     Logo != null &&
                     Logo.Equals(other.Logo)
                 ) &&
                 (
                     Region == other.Region ||
                     Region != null &&
                     Region.Equals(other.Region)
                 ) &&
                 (
                     Lang == other.Lang ||
                     Lang != null &&
                     Lang.Equals(other.Lang)
                 ) &&
                 (
                     AuthType == other.AuthType ||
                     AuthType != null &&
                     AuthType.Equals(other.AuthType)
                 ) &&
                 (
                     Oauth2 == other.Oauth2 ||
                     Oauth2 != null &&
                     Oauth2.Equals(other.Oauth2)
                 ) &&
                 (
                     Methods == other.Methods ||
                     Methods != null &&
                     Methods.Equals(other.Methods)
                 ));
        }
Exemple #2
0
 private void SetToken2Cache(string cacheName, Oauth2 oauth2)
 {
     onRemove = new CacheItemRemovedCallback(this.RemovedCallback);
     try
     {
         HttpContext.Current.Cache.Add(cacheName, oauth2, null, DateTime.Now.Add(new TimeSpan(1, 50, 0)), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, onRemove);
         //logs.Fatal("SetToken2Cache >> "+ cacheName);
     }
     catch (Exception e)
     {
         //NCD.WebLog.SysWebLog.WriteLog("error:" + e.ToString());
     }
 }
Exemple #3
0
        //ILog logs = LogManager.GetLogger("redirect_uri");

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string code         = context.Request["code"];
            string state        = context.Request["state"];
            string callback_url = context.Request["callback_url"];

            if (!string.IsNullOrWhiteSpace(code) && !string.IsNullOrWhiteSpace(state) && callback_url.IndexOf("http://") != -1)
            {
                int id = int.Parse(state.Split(char.Parse("|"))[1]);
                callback_url = context.Server.UrlDecode(callback_url);

                Oauth2Token access_token = new Oauth2Token();

                Oauth2 oauth2 = access_token.Get(code, state);

                string paras;
                string nonce_str, timestamp, sign;
                AgentSign.SetSign(id, out nonce_str, out timestamp, out sign);

                if (oauth2.scope == "snsapi_base")
                {
                    paras        = "openid=" + oauth2.openid + "&scope=" + oauth2.scope;
                    paras       += "&nonce_str=" + nonce_str + "&timestamp=" + timestamp + "&sign=" + sign;
                    callback_url = SetCallbackUrl(callback_url, paras);
                }
                else if (oauth2.scope == "snsapi_userinfo")
                {
                    UserInfoApi userInfoEntity = new UserInfo().Get(oauth2.access_token, oauth2.openid);

                    paras  = "&scope=" + oauth2.scope + "&openid=" + userInfoEntity.openid + "&nickname=" + userInfoEntity.nickname + "&sex=" + userInfoEntity.sex;
                    paras += "&city=" + userInfoEntity.city + "&province=" + userInfoEntity.province + "&country=" + userInfoEntity.country;
                    paras += "&headimgurl=" + userInfoEntity.headimgurl + "&unionid=" + userInfoEntity.unionid;
                    paras += "&nonce_str=" + nonce_str + "&timestamp=" + timestamp + "&sign=" + sign;

                    //logs.Fatal("paras:" + paras);

                    callback_url = SetCallbackUrl(callback_url, paras);
                }

                //logs.Fatal("callback_url:" + callback_url);

                context.Response.Redirect(callback_url);
            }
        }
Exemple #4
0
        private Oauth2 GetFromWeixin(string code)
        {
            string appid  = GZH.CL.Config.ConfigSetting.GetWeixin().AppID;
            string secret = GZH.CL.Config.ConfigSetting.GetWeixin().AppSecret;

            string requestUri = GZH.CL.Config.ConfigSetting.GetWeixinWeb().Oauth2Url;

            requestUri += "?appid=" + appid + "&secret=" + secret;
            requestUri += "&code=" + code + "&grant_type=authorization_code";

            //logs.Fatal("requestUri:" + requestUri);
            string result = HttpService.Get(requestUri);
            //logs.Fatal("result:" + result);

            Oauth2 r = JsonHelper.ScriptDeserialize <Oauth2>(result);

            return(r);
        }
Exemple #5
0
        public Oauth2 Get(string code, string state)
        {
            Oauth2 r = this.GetFromWeixin(code);

            //string scope = state.Split(char.Parse("|"))[0] == "0" ? "snsapi_base" : "snsapi_userinfo";
            //string cacheName = GZH.CL.Config.ConfigSetting.GetWeixinWeb().SnsTokenCacheName + "_"+ scope;
            //if (HttpContext.Current.Cache[cacheName] == null || HttpContext.Current.Cache[cacheName].ToString() == "")
            //{
            //    r = this.GetFromWeixin(code);
            //    //logs.Fatal("Oauth2 Access_Token From Weixin >> " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
            //    this.SetToken2Cache(cacheName, r);
            //}
            //else
            //{
            //    //logs.Fatal("Oauth2 Access_Token From Cache......");
            //    r = (Oauth2)HttpContext.Current.Cache.Get(cacheName);
            //}

            return(r);
        }
Exemple #6
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Specs != null)
         {
             hashCode = hashCode * 59 + Specs.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Logo != null)
         {
             hashCode = hashCode * 59 + Logo.GetHashCode();
         }
         if (Region != null)
         {
             hashCode = hashCode * 59 + Region.GetHashCode();
         }
         if (Lang != null)
         {
             hashCode = hashCode * 59 + Lang.GetHashCode();
         }
         if (AuthType != null)
         {
             hashCode = hashCode * 59 + AuthType.GetHashCode();
         }
         if (Oauth2 != null)
         {
             hashCode = hashCode * 59 + Oauth2.GetHashCode();
         }
         if (Methods != null)
         {
             hashCode = hashCode * 59 + Methods.GetHashCode();
         }
         return(hashCode);
     }
 }
Exemple #7
0
        public Oauth2 Get(string code, string state)
        {
            Oauth2 r = this.GetFromWeixin(code);

            return(r);
        }