Skip to content
phonegap plugin: qq, weibo and renren sso login
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
qq
renren
sso
weibo
README.md
cordova_plugins.js

README.md

phonegap-social-sso

I think people who will use this plugin should be Chinese, so I'll use Chinese in following content. YOOOOOOOO!

这是phonegap plugin,用来做第三方平台登录的,目前有qq、微博、人人三个平台

qq登录

首先要在qq互联,创建移动应用,获取appId神马的

然后搭建环境,ios环境搭建看这里android的在这里

环境配好了,Next,就是写代码了,直接把.java.m .h文件copy到工程里,然后把www/plugins下的qqLogin.js拷贝到对应的www/plugins目录下

还有一步,在工程的cordova_plugins.jsconfig.xml里增加对应plugin的说明

ios版

<feature name="QQLogin">
    <param name="ios-package" value="QQLogin" />
</feature>

android版

<feature name="QQLogin">
    <param name="android-package" value="com.example.cordova.qqLogin.QQLogin" />
</feature>

注意,android版value对应的是QQLogin.java这个文件所在的路径

最后在对应的js里写上登录按钮的点击事件,比如

$('#qq-login').click(function() {
    qqLogin.ssoLogin(function(res) {
        alert('uid:'+res.uid+' token:'+res.token);
    }, function() {
        alert('授权失败');
    });

});

另外,ios的AppDelegate.mopenURL里要加上如下所示代码,当然还要import对应的.h文件:

// this happens while we are running ( in the background, or from within our own app )
// only valid if Filpped-Info.plist specifies a protocol to handle
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
    if (!url) {
        return NO;
    }

    // calls into javascript global function 'handleOpenURL'
    NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", url];
    [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];

    // all plugins will get the notification, and their handlers will be called
    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
    // weiboLogin
    WeiboLogin *weiboPlugin = [self.viewController.pluginObjects objectForKey:@"WeiboLogin"];
    [WeiboSDK handleOpenURL:url delegate:weiboPlugin];
    
    // renrenLogin
    RenrenLogin *renrenPlugin = [self.viewController.pluginObjects objectForKey:@"RenrenLogin"];
    [RennClient handleOpenURL:url];
    [TencentOAuth HandleOpenURL:url ];
    QQLogin *qqPlugin = [self.viewController.pluginObjects objectForKey:@"QQLogin"];

    [QQApiInterface handleOpenURL:url delegate:qqPlugin];
    


    
    return YES;
}

微博登录

和qq基本一致,微博的文档po主放在doc目录下了

人人登录

人人文档在这里,ios版android

步骤和前面的一致

Update

加上了ios的demo

也有同学问为哈不写成phonegap标准的插件,这样可以命令行安装

因为涉及到第三方的library和配置,所以命令行一键安装不大可行,为了方便大家,准备写第三方登录的demo

notice

demo里涉及到第三方的appId或者appSecret,大家自己去注册一个吧,demo里由于appId的原因,微博登录是失败滴

to do

那啥,po主还写了微博、人人、qq、微信分享

等稍微空点写个完整能跑的demo出来

希望能帮到同样挣扎在phonegap这个大坑里的童鞋们

po主真是活雷锋有木有!!(~ ̄▽ ̄~)

You can’t perform that action at this time.