Exemplo n.º 1
0
        public platforminfo RegisterSinaWeiboPlatform(OAuth2Base oa, long userId)
        {
            if (oa != null&&!string.IsNullOrEmpty(oa.AccessToken))
            {
                var service = new SinaWeiboService(oa.AccessToken);
                var platformInfo = service.GetPlatformBySessionKey(oa.AccessToken);

                if (platformInfo != null)
                {
                    platformInfo.AuthDate = DateTime.Now;
                    platformInfo.ExpireDate = oa.ExpireTime;
                    platformInfo.Refresh_token = "";
                    platformInfo.Platform = Mappings.PlatForm.SinaWeiBo.ToString("G");
                    service.UpdateWeiboInfo(platformInfo);
                    return platformInfo;
                }

                return service.SavePlatforminfo(oa, userId);
            }
            else
            {
                throw new NullReferenceException("Auth2SinaWeibo 对象为空");
            }
        }
Exemplo n.º 2
0
        private void SendSinaWeibo(string content, string url)
        {
            var weiboSessionKeyObj = Session[Helper.PlatformSessionKeyHelper.SinaWeiboSessionKeyName];
            string weiboSessionKey = null;
            if (weiboSessionKeyObj == null)
            {
                if (Session["UID"] == null)
                {
                    throw new Exception("用户名为空");
                }
                int uid = int.Parse(Session["UID"].ToString());
                var pName = Mappings.PlatForm.SinaWeiBo.ToString("G");
                var weiboPF = new OAuthService().QueryPlatforminfo(p => p.UserId == uid && p.Platform == pName);

                if (weiboPF == null)
                {
                    //ViewBag.ErrorMessage = "用户平台信息为空";
                    //return this.View("ShowError");
                    throw new Exception("用户平台信息为空");
                }

                var result = new SinaWeiboService(weiboPF.SessionKey).VerifyAccessToken();

                if (result != TokenResult.Success)
                {
                    throw new Exception("授权无效或已过期,请重新授权。");
                }

                weiboSessionKey = weiboPF.SessionKey;
            }
            else
            {
                weiboSessionKey = weiboSessionKeyObj.ToString();
            }

            ws = new SinaWeiboService(weiboSessionKey);
            ws.Send(new Model.WeiboMessage() { Content = content, Url = url });
        }