示例#1
0
        public virtual Result Create( User user, String connectType, AccessToken token )
        {
            UserConnect connect = GetConnectInfo( token.Uid, connectType );
            if (connect != null) {
                return new Result( "本帐号已经绑定: uid=" + token.Uid + ",connectType=" + connectType );
            }

            UserConnect x = new UserConnect();

            x.User = user;
            x.ConnectType = connectType;

            x.Uid = token.Uid;
            x.Name = token.Name;

            x.AccessToken = token.Token;
            x.RefreshToken = token.RefreshToken;
            x.ExpiresIn = token.ExpiresIn;
            x.Scope = token.Scope;

            Result result = x.insert();

            if (result.IsValid) {
                user.IsBind = 1;
                user.update();
            }

            return result;
        }
示例#2
0
        private void loadUserProfile( AuthConnect connect, AccessToken accessToken )
        {
            OAuthUserProfile user = connect.GetUserProfile( accessToken );

            ctx.SetItem( "__currentOAuthUser", user );
            ctx.SetItem( "__currentAccessToken", accessToken );

            content( loadHtml( confirmUserInfo ) );
        }
示例#3
0
        private AccessToken getAccessToken()
        {
            AccessToken x = new AccessToken();

            String uid = ctx.Post( "uid" );
            String accessToken = ctx.Post( "accessToken" );
            String refreshToken = ctx.Post( "refreshToken" );
            int expiresIn = ctx.PostInt( "expiresIn" );
            String scope = ctx.Post( "scope" );

            x.Token = accessToken;
            x.RefreshToken = refreshToken;
            x.Uid = uid;
            x.ExpiresIn = expiresIn;
            x.Scope = scope;

            return x;
        }
示例#4
0
        private void checkAccessToken( UserConnect x, AccessToken token )
        {
            x.AccessToken = token.Token;
            x.RefreshToken = token.RefreshToken;
            x.ExpiresIn = token.ExpiresIn;
            x.Scope = token.Scope;

            // 重新获取access token之后,服务器会自动延续授权时间
            x.Updated = DateTime.Now;

            x.update();
        }
示例#5
0
文件: QQTest.cs 项目: bae2014/wojilu
        public void testProfile()
        {
            Console.WriteLine( "请按任意键,开始发布……" );
            Console.ReadLine();

            QQConnect connect = AuthConnectFactory.GetConnect( typeof( QQConnect ).FullName ) as QQConnect;
            if (connect == null) throw new Exception( "尚未配置" );

            AccessToken x = new AccessToken();
            x.Token = accessToken;

            OAuthUserProfile obj = connect.GetUserProfile( x );
            Assert.IsNotNull( obj );

            Console.WriteLine( "id=" + obj.Uid );
            Console.WriteLine( "name=" + obj.Name );

            Assert.IsNotNull( obj.Uid );
            Assert.IsNotNull( obj.Name );
            Assert.IsTrue( obj.Name.Length > 0 );

            // 用户头像(小50×50像素)
            Console.WriteLine( "profile_image_url=" + obj.PicUrlSmall );
            Assert.IsNotNull( obj.PicUrlSmall );
            Assert.IsTrue( obj.PicUrlSmall.Length > 0 );

            // 用户头像(大)
            Console.WriteLine( "avatar_large=" + obj.PicUrlBig );
            Assert.IsNotNull( obj.PicUrlBig );
            Assert.IsTrue( obj.PicUrlBig.Length > 0 );

            Console.WriteLine( "domain=" + obj.FriendlyUrl );

            Console.WriteLine( "请按 Enter 键结束……" );
            Console.ReadLine();
        }
示例#6
0
文件: QQTest.cs 项目: bae2014/wojilu
        public void testUploadPic()
        {
            QQConnect connect = AuthConnectFactory.GetConnect( typeof( QQConnect ).FullName ) as QQConnect;
            if (connect == null) throw new Exception( "尚未配置" );

            AccessToken x = new AccessToken { Token = accessToken };
            String content = "这是来自QQ互联api的微博内容" + DateTime.Now;

            JsonObject jsonValue = connect.PublishPic( x, content, "c:\\testpic.jpg" );
            Assert.AreEqual( "ok", jsonValue.Get( "msg" ) );
        }
示例#7
0
        // access_token=xxx&expires_in=888888&refresh_token=xxx&openid=xxx&name=xxx&nick=xxx&state=
        private static AccessToken parseAccessTokenQueryString( string response )
        {
            String[] arr = response.Split( '&' );
            AccessToken x = new AccessToken();
            foreach (String item in arr) {
                String[] arrPair = item.Split( '=' );
                if (arrPair.Length != 2) continue;

                if (arrPair[0] == "openid") {
                    x.Uid = arrPair[1];
                }
                else if (arrPair[0] == "name") {
                    continue; // 有openId的场合
                }
                else {
                    x.SetValue( arrPair[0], arrPair[1] );
                }
            }
            return x;
        }
示例#8
0
        private static AccessToken getAccessTokenByResponse( String response )
        {
            if (strUtil.IsNullOrEmpty( response )) throw new NullReferenceException( "无法获取 access token,response为空" );

            logger.Info( "parse access token: " + response );

            response = response.Trim();

            try {

                AccessToken accessToken;

                if (response.StartsWith( "{" ) == false && response.IndexOf( "&" ) > 0 && response.IndexOf( "=" ) > 0) {
                    accessToken = parseAccessTokenQueryString( response );
                }
                else {
                    // {"access_token":"XXX","expires_in":157679999,"uid":"XXX"}
                    accessToken = new AccessToken( response );
                }

                if (strUtil.IsNullOrEmpty( accessToken.Token )) {
                    throw new HttpClientException( "解析 access token,结果为空:" + response );
                }

                return accessToken;
            }
            catch (Exception ex) {
                throw new HttpClientException( "解析 access token 失败" + Environment.NewLine + ex.Message );
            }
        }
示例#9
0
 public abstract OAuthUserProfile GetUserProfile( AccessToken accessToken );
示例#10
0
 public virtual String GetUid( AccessToken accessToken )
 {
     return accessToken.Uid;
 }
示例#11
0
        public void testProfile()
        {
            // 如果报错 source paramter(appkey) is missing,很有可能是 access token 过期

            Console.WriteLine( "请按任意键,开始发布……" );
            Console.ReadLine();

            WeiboConnect connect = AuthConnectFactory.GetConnect( typeof( WeiboConnect ).FullName ) as WeiboConnect;
            if (connect == null) throw new Exception( "尚未配置" );

            AccessToken x = new AccessToken();
            x.Token = accessToken;
            x.Uid = "3214151865";

            OAuthUserProfile obj = connect.GetUserProfile( x );

            Console.WriteLine( "id=" + obj.Uid );
            Console.WriteLine( "name=" + obj.Name );

            // 用户头像(小50×50像素)
            Console.WriteLine( "profile_image_url=" + obj.PicUrlSmall );
            // 用户头像(大)
            Console.WriteLine( "avatar_large=" + obj.PicUrlBig );

            Console.WriteLine( "domain=" + obj.FriendlyUrl );

            Console.WriteLine( "请按 Enter 键结束……" );
            Console.ReadLine();
        }
示例#12
0
        public void testUploadPic()
        {
            Console.WriteLine( "请按任意键开始……" );
            Console.ReadLine();

            QQWeiboConnect connect = AuthConnectFactory.GetConnect( typeof( QQWeiboConnect ).FullName ) as QQWeiboConnect;
            if (connect == null) throw new Exception( "尚未配置" );

            AccessToken x = new AccessToken { Token = accessToken, Uid = openId };
            JsonObject jsonValue = connect.PublishPic( x, "这是测试的微博内容" + DateTime.Now, "c:\\testpic.jpg" );

            Assert.AreEqual( "ok", jsonValue["msg"].ToString() );
        }
示例#13
0
        public void testPublish()
        {
            Console.WriteLine( "请按任意键,开始发布……" );
            Console.ReadLine();

            QQWeiboConnect connect = AuthConnectFactory.GetConnect( typeof( QQWeiboConnect ).FullName ) as QQWeiboConnect;
            if (connect == null) throw new Exception( "尚未配置" );

            AccessToken x = new AccessToken { Token = accessToken, Uid = openId };
            JsonObject jsonValue = connect.PublishPost( x, "这是测试的微博内容" + DateTime.Now );

            Assert.AreEqual( "ok", jsonValue["msg"] );
        }