前言
網上的各種第三方資料蠻多的,但大多都只是將官網的解釋文檔用代碼翻譯一次,實際集成也需要自己去一個個集成,那麼因此本人將QQ/微信的分享登陸功能以及微信/支付寶的支付功能集成, 方便使用.
ThirdToolsLib
集成第三方登陸分享(微信/QQ),第三方支付(支付寶,微信,盛付通)
本Demo並不能直接使用,若要使用此項目,請將主項目的applicationId改爲你的包名,signingConfigs配置簽名配置
使用方式
gradle引入:
compile 'com.allure0:ThirdToolsLib:1.0.0'
主項目的gradle.properties裏必須配置isCompile,默認填寫true,參見demo
屬性 解釋 true 使用libs裏的第三包 false 自行選擇功能與第三方jar包 例:只需要使用支付寶的支付功能:
主項目build放入最新的支付寶jar包:dependencies { ··· compile files('libs/alipaySdk-20161222.jar') ··· }
gradle.properties配置:
isCompile=true
對於QQ需要在主項目build文件配置如下qq_id,將1105787445替換爲你的QQ的APPKEY,參見主項目build.gradle
manifestPlaceholders = [
qq_id: "1105787445"
]
效果圖
初始化配置
PlatformConfig platformConfig = PlatformConfig.getInstance()
.setQqId("xxx")
.setWeChatId("xxxx")
.setWeChatSecret("");//如果是服務處理token和code不需要傳此參數
PlatformManager.getInstance()
.setPlatformConfig(platformConfig)
.initQQ(this)
.initWx(this);
QQ登陸
LoginManager
.with(MainActivity.this)
.thirdLogin(LoginPlatform.PLATFORM_QQ);
微信登陸
LoginManager.with(MainActivity.this)
.thirdLogin(LoginPlatform.PLATFORM_WECHAT);
微信分享
ShareUtils.initShareUtils(
BaseApplication.getInstance(), text, text, imgUrl, url,
BitmapFactory.decodeResource(BaseApplication.getInstance().getResources(),
R.drawable.ic_launcher)
).shareToWX(MainActivity.this, ShareUtils.WECHAT_CIRCLE);
QQ分享
ShareUtils.initShareUtils(
BaseApplication.getInstance(), text, text, imgUrl, url,
BitmapFactory.decodeResource(BaseApplication.getInstance().getResources(),
R.drawable.ic_launcher)
).shareToQQ(MainActivity.this, "測試啦");
微信支付
PayManager.with(MainActivity.this)
.wxPay( wxPayBean);
支付寶支付
PayManager.with(MainActivity.this)
.aliPay(ali_orderinfo, new AliPayListener() {
@Override
public void aliPayResult(String string, AliPayResult payResult) {
Log.e("支付狀態", string);
Log.e("支付狀態", payResult.getResultStatus());
}
});
觀察者模式接受處理結果
@Override
public void thirdLoginSuccess(Object obj, LoginPlatform platform, LoginResult loginResult) {
}
@Override
public void thirdLoginFailed(Object object, LoginPlatform loginPlatform) {
}
@Override
public void thirdLoginCancel(LoginPlatform loginPlatform) {
}
@Override
public void shareSuccess(SharePlatform sharePlatform) {
}
@Override
public void shareFailed(SharePlatform sharePlatform) {
}
@Override
public void paySuccess(PayPlatform payPlatform) {
}
@Override
public void payFailed(PayPlatform payPlatform) {
}