清单文件不用配置啦jar包也不用导入啦
项目级别
将下面的脚本添加到您的根模块build.gradle中:
buildscript {
repositories {
jcenter()
}
dependencies {
// 注册MobSDK
classpath "com.mob.sdk:MobSDK:2018.0319.1724"
}
}
在使用相应模块的build.gradle中,添加MobSDK插件和扩展,如:
apply plugin: 'com.mob.sdk'
MobSDK {
appKey "替换为mob官方申请的appkey"
appSecret "替换为mob官方申请的appkey对应的appSecret"
ShareSDK {
devInfo {
SinaWeibo {
appKey "568898243"
appSecret "38a4f8204cc784f81f9f0daaf31e02e3"
callbackUri "http://www.sharesdk.cn"
}
Wechat {
appId "wx4868b35061f87885"
appSecret "64020361b8ec4c99936c0e3999a9f249"
userName "gh_afb25ac019c9"
path "pages/index/index.html?id=1"
withShareTicket true
miniprogramType 2
}
QQ {
appId "100371282"
appKey "aed9b0303e3ed1e27bae87c33761161d"
}
WechatMoments {
appId "wx4868b35061f87885"
appSecret "64020361b8ec4c99936c0e3999a9f249"
}
WechatFavorite {
appId "wx4868b35061f87885"
appSecret "64020361b8ec4c99936c0e3999a9f249"
}
}
}
}
MobSDK{}放在最下面位置
apply plugin: 'com.mob.sdk' 放在最上面的 apply 的最下位置
因为是模块化开发 所以最外层的module (一般默认app)的build.gradle 也要写上这句话
apply plugin: 'com.mob.sdk'
private void loginVx() {
keyType = "WECHAT";
Platform wechat = ShareSDK.getPlatform(Wechat.NAME);
wechat.SSOSetting(true);
wechat.setPlatformActionListener(this);
if (!wechat.isClientValid()) {
Toast.makeText(this, "微信未安装,请先安装微信", Toast.LENGTH_LONG).show();
}
authorize(wechat);
}
/**
* 授权
*
* @param platform
*/
private void authorize(Platform platform) {
if (platform == null) {
return;
}
if (platform.isAuthValid()) { //如果授权就删除授权资料
platform.removeAccount(true);
}
platform.showUser(null); //授权并获取用户信息
}
public class LoginActivity extends BaseActivity implements PlatformActionListener
@Override
public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
Message message = Message.obtain();
message.what = 1;
message.obj = platform;
mHandler.sendMessage(message);
}
@Override
public void onError(Platform platform, int i, Throwable throwable) {
Message message = Message.obtain();
message.what = 2;
message.obj = platform;
mHandler.sendMessage(message);
}
@Override
public void onCancel(Platform platform, int i) {
Message message = Message.obtain();
message.what = 3;
message.obj = platform;
mHandler.sendMessage(message);
;
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
Platform platform = (Platform) msg.obj;
loginSucess(platform);
break;
case 2:
Toast.makeText(LoginActivity.this, "授权登陆失败", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(LoginActivity.this, "授权登陆取消", Toast.LENGTH_SHORT).show();
break;
}
}
};
private void loginSucess(Platform platform) {
//platform.getDb().exportData()获取用户数据
// 这里授权成功跳转到程序主界面了
Toast.makeText(LoginActivity.this, "绑定手机号", Toast.LENGTH_SHORT).show();
String userId = platform.getDb().getUserId();//获取用户账号
String userName = platform.getDb().getUserName();//获取用户名字
String userIcon = platform.getDb().getUserIcon();//获取用户头像
String userGender = platform.getDb().getUserGender(); //获取用户性别,m = 男, f = 女,如果微信没有设置性别,默认返回null
//下面就可以利用获取的用户信息登录自己的服务器或者做自己想做的事啦!”}
然后这些帐号的申请呢
shareSdk
http://dashboard.mob.com/#!/index
qq开发者账号 这是qq互联 和qq开发者关联以后的号才行
https://connect.qq.com/manage.html#/appcreate/ios
关联后会让你新建一个应用那个应用的id号才可以
至于微博和QQ的登录主要就是这一句话的不同而已
Platform wechat = ShareSDK.getPlatform(Wechat.NAME);
Platform qq = ShareSDK.getPlatform(QQ.NAME);
第三方登录的openId 就是
String userId = platform.getDb().getUserId();//获取用户账号
其他参数需要就传递过来
String userId = platform.getDb().getUserId();//获取用户账号
String userName = platform.getDb().getUserName();//获取用户名字
String userIcon = platform.getDb().getUserIcon();//获取用户头像
String userGender = platform.getDb().getUserGender(); //获取用户性别,m = 男, f = 女,如果微信没有设置性别,默认返回null
//下面就可以利用获取的用户信息登录自己的服务器或者做自己想做的事啦!
至此 应用就具备了登录功能