ESSocialSDK

Build Status [version]() [LICENSE]() [forks]() [stars]()

社交登录授权,分享SDK
支持微信、微博、QQ登录授权
微信好友、微信朋友圈、微博、QQ好友、QQ空间分享以及系统默认分享

说明

每单个平台全部提供文档说明,内容较多,易混淆集成过程,所以,这里只提供一键登录,一键分享文档,使用默认UI。
如果需要单个平台的详细集成文档,参考README_Detail.md
默认UI效果截图:
一键登录 一键分享

Gradle

compile 'com.elbbbird.android:socialsdk:[email protected]'

Debug模式

SocialSDK.setDebugMode(true); //默认false

项目配置

package com.encore.actionnow.wxapi;
public class WXEntryActivity extends WXCallbackActivity {

}

一键登录授权功能(微博,微信,QQ)

授权结果回调

SDK使用了Otto作为事件库,用以组件通信。 在调用SocialSDK.oauth()接口ActivityonCreate()方法内添加

BusProvider.getInstance().register(this);

在该ActivityonDestroy()方法添加

@Override
protected void onDestroy() {
    BusProvider.getInstance().unregister(this);
    super.onDestroy();
}

添加回调接口

@Subscribe
public void onOauthResult(SSOBusEvent event) {
    switch (event.getType()) {
        case SSOBusEvent.TYPE_GET_TOKEN:
            SocialToken token = event.getToken();
            Log.i(TAG, "onOauthResult#BusEvent.TYPE_GET_TOKEN " + token.toString());
            break;
        case SSOBusEvent.TYPE_GET_USER:
            SocialUser user = event.getUser();
            Log.i(TAG, "onOauthResult#BusEvent.TYPE_GET_USER " + user.toString());
            break;
        case SSOBusEvent.TYPE_FAILURE:
            Exception e = event.getException();
            Log.i(TAG, "onOauthResult#BusEvent.TYPE_FAILURE " + e.toString());
            break;
        case SSOBusEvent.TYPE_CANCEL:
            Log.i(TAG, "onOauthResult#BusEvent.TYPE_CANCEL");
            break;
    }
}

Oauth

SocialSDK.init("wechat_app_id", "wechat_app_secret", "weibo_app_id", "qq_app_id");
SocialSDK.oauth(context);

Revoke

SocialSDK.revoke(context);

一键分享功能(微博,微信,朋友圈,QQ,QQ空间)

SDK中SocialShareScene的定义

/**
 * 社会化分享数据类
 */
public class SocialShareScene implements Serializable {

    public static final int SHARE_TYPE_DEFAULT = 0;
    public static final int SHARE_TYPE_WEIBO = 1;
    public static final int SHARE_TYPE_WECHAT = 2;
    public static final int SHARE_TYPE_WECHAT_TIMELINE = 3;
    public static final int SHARE_TYPE_QQ = 4;
    public static final int SHARE_TYPE_QZONE = 5;

    /**
     * @param id        分享唯一标识符,可随意指定,会在分享结果ShareBusEvent中返回
     * @param appName   分享到QQ时需要指定,会在分享弹窗中显示该字段
     * @param type      分享类型
     * @param title     标题
     * @param desc      简短描述
     * @param thumbnail 缩略图网址
     * @param url       WEB网址
     */
    public SocialShareScene(int id, String appName, int type, String title, String desc, String thumbnail, String url) {
        this.id = id;
        this.appName = appName;
        this.type = type;
        this.title = title;
        this.desc = desc;
        this.thumbnail = thumbnail;
        this.url = url;
    }

    public SocialShareScene(int id, String appName, String title, String desc, String thumbnail, String url) {
    ....
}

一键分享需要调用第二个构造函数,type类型在SDK内部自动指定

分享结果回调

@Subscribe
public void onShareResult(ShareBusEvent event) {
    switch (event.getType()) {
        case ShareBusEvent.TYPE_SUCCESS:
            Log.i(TAG, "onShareResult#ShareBusEvent.TYPE_SUCCESS " + event.getId());
            break;
        case ShareBusEvent.TYPE_FAILURE:
            Exception e = event.getException();
            Log.i(TAG, "onShareResult#ShareBusEvent.TYPE_FAILURE " + e.toString());
            break;
        case ShareBusEvent.TYPE_CANCEL:
            Log.i(TAG, "onShareResult#ShareBusEvent.TYPE_CANCEL");
            break;
    }
}

ShareTo

SocialSDK.setDebugMode(true);
SocialSDK.init("wechat_app_id", "weibo_app_id", "qq_app_id");
SocialSDK.shareTo(context, scene);

FAQ

##微信
-keep class com.tencent.mm.sdk.** {*;}

##微博
-keep public class com.sina.weibo.** {*;}
-keep public class com.sina.sso.** {*;}

##otto
-keepattributes *Annotation*
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}

LICENSE

Copyright 2015 The ESSocialSDK authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.