第三方SDK整合庫,支援授權/分享/付款等功能
目前這個函式庫還不穩定,有些細節並未仔細考慮,有些功能也沒有進行測試,支援的平台也不多,歡迎大家star/issue/pr,共同完善這個函式庫
成功後的結果為"code|{code}", "token|{openId}|{token}" 兩種形式
但客戶端其實不需要關心是code還是token,直接把result發結服務端就好了
很多支付類庫會在客戶端處理商品支付訊息,其實這是不必要的,直接由服務端回傳資料交給支付SDK,然後處理付款結果就好了
支援純文字/純圖片/圖文/網頁/音樂/影片等分享類型
平台 | 純文字 | 純圖片 | 圖文 | 網頁 | 音樂 | 影片 |
---|---|---|---|---|---|---|
x | o | x | o | o | x | |
QZone | o | o | o | o | x | o |
WXSession | o | o | x | o | o | o |
WXTimeline | o | o | x | o | o | o |
o | o | o | x | x | x | |
SendToQQ | o | o | x | x | x | x |
SendToWXS | o | o | x | x | x | x |
SendToWXT | o | o | x | x | x | x |
運行demo需要在gradle.properties
中修改app的包名,簽名和為app申請的APPID
APPLICATION_ID=ezy.demo.sdk3rd
APPID_QQ=YOUR_APPID
APPID_WEIXIN=YOUR_APPID
APPID_WEIBO=YOUR_APPID
SINGING_ALIAS=androiddebugkey
SINGING_PASSWORD=android
SINGING_FILE=debug.keystore
repositories {
maven { url " https://jitpack.io " }
}
dependencies {
compile ' com.github.czy1121.sdk3rd:sdk3rd:0.1.2 '
compile ' com.github.czy1121.sdk3rd:sdk3rd-alipay:0.1.1 '
compile ' com.github.czy1121.sdk3rd:sdk3rd-qq:0.1.0 '
compile ' com.sina.weibo.sdk:core:1.0.0:openDefaultRelease@aar '
compile ' com.tencent.mm.opensdk:wechat-sdk-android-without-mta:1.0.2 '
}
配置APPID
PlatformConfig . useQQ ( BuildConfig . APPID_QQ );
PlatformConfig . useWeixin ( BuildConfig . APPID_WEIXIN );
PlatformConfig . useWeibo ( BuildConfig . APPID_WEIBO , "http://www.sina.com/" );
PlatformConfig . usePayments ();
設定全域事件回呼(非必要)
AuthorizeSDK . setDefaultCallback ( new OnCallback () {
@ Override
public void onStarted ( Activity activity ) {
Log . e ( "ezy" , "authorize started" );
}
@ Override
public void onCompleted ( Activity activity ) {
Log . e ( "ezy" , "authorize completed" );
}
@ Override
public void onSucceed ( Activity activity , Object result ) {
Log . e ( "ezy" , "authorize succeed" );
}
@ Override
public void onFailed ( Activity activity , int code , String message ) {
Log . e ( "ezy" , "authorize failed [" + code + "]" + message );
}
});
接收授權結果(新浪微博/QQ)
@ Override
protected void onActivityResult ( int requestCode , int resultCode , Intent data ) {
super . onActivityResult ( requestCode , resultCode , data );
AuthorizeSDK . onHandleResult ( this , requestCode , resultCode , data );
}
調用授權
AuthorizeSDK . authorize ( MainActivity . this , platform , new OnSucceed < String >() {
@ Override
public void onSucceed ( String result ) {
Toast . makeText ( MainActivity . this , "登陆成功 - " + result , Toast . LENGTH_LONG ). show ();
}
});
註冊自訂平台,需要實作IAuthorize 與對應的IFactory
AuthorizeSDK . register ( IFactory < IAuthorize > factory );
AuthorizeSDK . register ( String platformName , String appId , Class < IAuthorize > clazz );
全域事件回呼的設定與授權SDK類似
呼叫支付
PaymentSDK . pay ( MainActivity . this , platform , paydata , new OnSucceed < String >() {
@ Override
public void onSucceed ( String result ) {
// todo
}
});
註冊自訂平台,需要實作IPayable 與對應的IFactory
PaymentSDK . register ( IFactory < IPayable > factory );
PaymentSDK . register ( String platformName , Class < IPayable > clazz );
全域事件回呼的設定與授權SDK類似
……
分享結果的接收也與授權SDK類似(QQ)
……
註冊自訂平台,需要實作IShareable 與對應的IFactory
ShareSDK . register ( IFactory < IShareable > factory );
ShareSDK . register ( String platformName , Class < IShareable > clazz );
分享
// 分享纯文本
ShareSDK . make ( this , text ). share ( platform );
// 分享纯图片
ShareSDK . make ( this , new MoImage ( image )). share ( platform );
// 分享图文
ShareSDK . make ( this , text , new MoImage ( image )). share ( platform );
// 分享网页链接
ShareSDK . make ( this , new MoWeb ( url ))
. withTitle ( "这是标题" )
. withDescription ( "这是摘要" )
. withThumb ( thumb )
. share ( platform , new OnSucceed < String >() {
@ Override
public void onSucceed ( String result ) {
Toast . makeText ( MainActivity . this , "分享成功" , Toast . LENGTH_LONG ). show ();
}
});
// 分享音乐
ShareSDK . make ( this , new MoMusic ( url ))
. withTitle ( "这是标题" )
. withDescription ( "这是摘要" )
. withThumb ( thumb )
. share ( platform );
友盟+分享組件90%常見問題彙整http://bbs.umeng.com/thread-17764-1-1.html
友盟各平台可分享內容預覽http://dev.umeng.com/social/android/share-detail#5
Android 不同平台分享內容的詳細說明http://wiki.mob.com/不同平台分享內容的詳細說明
新浪微博SDK https://github.com/sinaweibosdk/weibo_android_sdk
Copyright 2017 czy1121
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.