Giter VIP home page Giter VIP logo

androidok / jjdxm_social Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xiaobinghe/jjdxm_social

0.0 1.0 0.0 5.95 MB

社会化第三方登录、分享实现流程社会化功能:授权登录、分享等主要功能。支持微信、微博、QQ登录授权、微信好友、微信朋友圈、微博、QQ好友、QQ空间分享以及系统默认分享。当前项目将微信、QQ和微博三个不同平台提供的SDK分别打包到jCenter上面,主要是为了避免使用本类库而造成和三方平台微信支付等其他功能的SDK架包发生冲突

Java 100.00%

jjdxm_social's Introduction

jjdxm_social

Copyright notice

我在网上写的文章、项目都可以转载,但请注明出处,这是我唯一的要求。当然纯我个人原创的成果被转载了,不注明出处也是没有关系的,但是由我转载或者借鉴了别人的成果的请注明他人的出处,算是对前辈们的一种尊重吧!

虽然我支持写禁止转载的作者,这是他们的成果,他们有这个权利,但我不觉得强行扭转用户习惯会有一个很好的结果。纯属个人的观点,没有特别的意思。可能我是一个版权意识很差的人吧,所以以前用了前辈们的文章、项目有很多都没有注明出处,实在是抱歉!有想起或看到的我都会逐一补回去。

从一开始,就没指望从我写的文章、项目上获得什么回报,一方面是为了自己以后能够快速的回忆起曾经做过的事情,避免重复造轮子做无意义的事,另一方面是为了锻炼下写文档、文字组织的能力和经验。如果在方便自己的同时,对你们也有很大帮助,自然是求之不得的事了。要是有人转载或使用了我的东西觉得有帮助想要打赏给我,多少都行哈,心里却很开心,被人认可总归是件令人愉悦的事情。

站在了前辈们的肩膀上,才能走得更远视野更广。前辈们写的文章、项目给我带来了很多知识和帮助,我没有理由不去努力,没有理由不让自己成长的更好。写出好的东西于人于己都是好的,但是由于本人自身视野和能力水平有限,错误或者不好的望多多指点交流。

项目中如有不同程度的参考借鉴前辈们的文章、项目会在下面注明出处的,纯属为了个人以后开发工作或者文档能力的方便。如有侵犯到您的合法权益,对您造成了困惑,请联系协商解决,望多多谅解哈!若您也有共同的兴趣交流技术上的问题加入交流群QQ: 548545202

感谢作者elbbbird,本项目是基于ESSocialSDK项目

Introduction

社会化功能:授权登录、分享等主要功能。支持微信、微博、QQ登录授权、微信好友、微信朋友圈、微博、QQ好友、QQ空间分享以及系统默认分享。当前项目将微信、QQ和微博三个不同平台提供的SDK分别打包到jCenter上面,主要是为了避免使用本类库而造成和三方平台微信支付等其他功能的SDK架包发生冲突。

Screenshots

Download

demo apk下载

Download or grab via Maven:

<dependency>
  <groupId>com.dou361.social</groupId>
  <artifactId>jjdxm-social</artifactId>
  <version>x.x.x</version>
</dependency>

or Gradle:

compile 'com.dou361.social:jjdxm-social:x.x.x'

历史版本

compile 'com.dou361.social:jjdxm-social:1.0.4'
compile 'com.dou361.social:jjdxm-social:1.0.3'
compile 'com.dou361.social:jjdxm-social:1.0.2'
compile 'com.dou361.social:jjdxm-social:1.0.1'
compile 'com.dou361.social:jjdxm-social:1.0.0'

jjdxm-social requires at minimum Java 9 or Android 2.3.

架包的打包引用以及冲突解决

Proguard

类库中使用consumerProguardFiles属性,它指定了编译时,库自动引入的混淆规则。也就是说应用打包时候会自动的寻找库里的混淆文件,不需要手工配置了。

AndroidStudio代码混淆注意的问题

Get Started

step1

需要申请的一些权限已经集成到类库中了,引入依赖,如果主程序项目中有重复的类库,可以用打开注释来移除重复依赖。

    compile ('com.dou361.social:jjdxm-social:1.0.4'){
//        exclude group: 'com.android.support', module: 'support-v4'
//        exclude group: 'com.squareup', module: 'otto'
//        exclude group: 'com.dou361.weibo', module: 'jjdxm-weibo'
//        exclude group: 'com.dou361.wechat', module: 'jjdxm-wechat'
//        exclude group: 'com.dou361.tencent', module: 'jjdxm-tencent'
    }

step2

设置Debug模式

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

step3

项目配置,配置微博后台回调地址
SDK的默认回调地址为http://www.sina.com,需要在微博后台配置,否则会提示回调地址错误。
如果在SocialSDK.init()方法自定义了回调地址,需要在后台配置为相应地址。

WXEntryActivity
创建包名:

package_name.wxapi

在该包名下创建类WXEntryActivity继承自WXCallbackActivity

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

}


<activity
    android:name=".wxapi.WXEntryActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:exported="true"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
    android:name="com.tencent.tauth.AuthActivity"
    android:launchMode="singleTask"
    android:noHistory="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="tencentXXXXXXXXX" />
    </intent-filter>
</activity>

以上配置中的XXXXXXXXX换成app_id.

step4

一键分享功能(微博,微信,朋友圈,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;
    }
}

分享

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

step5

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

授权结果回调
SDK使用了Otto作为事件库,用以组件通信。 在调用SocialSDK.oauth()接口Activity的onCreate()`方法内添加

BusProvider.getInstance().register(this);

在该Activity的onDestroy()方法添加

@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);

移除授权

SocialSDK.revoke(context);

QQ: jjdxm-tencent

微信: jjdxm-winchat

微博: jjdxm-weibo

More Actions

ChangeLog

2016.12.04 1.0.4版本打包,添加混淆规则权限打包到架包内部简化接入成本 2016.12.02 1.0.3版本打包,移除反射,避免混淆出错

About Author

个人网站:http://www.dou361.com

GitHub:jjdxmashl

QQ:316988670

交流QQ群:548545202

License

Copyright (C) dou361, The Framework Open Source Project

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.

(Frequently Asked Questions)FAQ

Bugs Report and Help

If you find any bug when using project, please report here. Thanks for helping us building a better one.

jjdxm_social's People

Contributors

kebuwei avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.