Commit a27810f4 authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :接入归因SDK和登录
[实现方案] :接入appsflayer接入原生登录和Facebook登录
parent f3b79299
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'com.mob.sdk' //apply plugin: 'com.mob.sdk'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
android { android {
...@@ -63,37 +63,6 @@ android { ...@@ -63,37 +63,6 @@ android {
} }
} }
// MobSDK {
// appKey "357874b62b4c7"
// appSecret "c4d82ff12e0cde832960ddbb8d2d7250"
// gui false
// version '3.9.7'
// ShareSDK {
// loopShare true
// devInfo {
// Facebook {
// id 8
// sortId 8
// appKey "662970168312513"
// callbackUri "https://www.baidu.com"
// officialVersion "default"
// faceBookLoginProtocolScheme "fb662970168312513"
// shareByAppClient true
// enable true
// }
// GooglePlus {
// id 21
// sortId 21
// appId "236300675100-am5pm8km7md1memjevq8rl9pg5c4s4b8.apps.googleusercontent.com"
// callbackUri "http://localhost"
// officialVersion "default"
// shareByAppClient true
// enable true
// }
//
// }
// }
// }
productFlavors { productFlavors {
guanwang {} guanwang {}
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
<!-- GooglePay--> <!-- GooglePay-->
<uses-permission android:name="com.android.vending.BILLING" /> <uses-permission android:name="com.android.vending.BILLING" />
<uses-sdk tools:overrideLibrary="com.bun.miitmdid" /> <uses-sdk tools:overrideLibrary="com.bun.miitmdid" />
<application <application
...@@ -96,6 +98,7 @@ ...@@ -96,6 +98,7 @@
<uses-library <uses-library
android:name="org.apache.http.legacy" android:name="org.apache.http.legacy"
android:required="false" /> android:required="false" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -2,7 +2,7 @@ package com.zhangxin.magicbox ...@@ -2,7 +2,7 @@ package com.zhangxin.magicbox
import android.app.Application import android.app.Application
import android.text.TextUtils import android.text.TextUtils
import com.mob.MobSDK import com.appsflyer.AppsFlyerLib
import com.paypal.checkout.PayPalCheckout import com.paypal.checkout.PayPalCheckout
import com.paypal.checkout.config.CheckoutConfig import com.paypal.checkout.config.CheckoutConfig
import com.paypal.checkout.config.Environment import com.paypal.checkout.config.Environment
...@@ -15,12 +15,14 @@ import com.zxhl.cms.common.ApplicationAsLibrary ...@@ -15,12 +15,14 @@ import com.zxhl.cms.common.ApplicationAsLibrary
import com.zxhl.cms.common.Config import com.zxhl.cms.common.Config
import com.zxhl.cms.common.Constant import com.zxhl.cms.common.Constant
import com.zxhl.cms.net.SettingPreference import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.utils.EventUtils
import com.zxhl.cms.utils.EventUtils.onEvent import com.zxhl.cms.utils.EventUtils.onEvent
import com.zxhl.cms.utils.MiitHelper import com.zxhl.cms.utils.MiitHelper
import com.zxhl.cms.utils.TTAdManagerHolder import com.zxhl.cms.utils.TTAdManagerHolder
import com.zxhl.cms.utils.Utils import com.zxhl.cms.utils.Utils
import java.util.* import java.util.*
/** /**
* Created by gaoleichao on 2018/12/26 * Created by gaoleichao on 2018/12/26
*/ */
...@@ -36,27 +38,40 @@ class Appli : Application() { ...@@ -36,27 +38,40 @@ class Appli : Application() {
Config.init(this) Config.init(this)
getOaid() getOaid()
initByteDance() initByteDance()
MobSDK.submitPolicyGrantResult(true, null) // MobSDK.submitPolicyGrantResult(true, null)
MobSDK.init(this) // MobSDK.init(this)
initPayPal() initPayPal()
initAppsFlyer()
}
private fun initAppsFlyer() {
val afDevKey = "bbVuECGrv5oci77w97NMVg"
val appsflyer: AppsFlyerLib = AppsFlyerLib.getInstance()
// For debug - remove in production
appsflyer.setDebugLog(true)
//optional
appsflyer.setMinTimeBetweenSessions(0)
appsflyer.init(afDevKey, null, this)
appsflyer.start(this)
} }
private fun initPayPal() { private fun initPayPal() {
val config = CheckoutConfig( val config = CheckoutConfig(
application = this, application = this,
clientId = Constant.PAY_PAL_CLIENT_ID, clientId = Constant.PAY_PAL_CLIENT_ID,
environment = Environment.SANDBOX,//正式上线后,改为Environment.LIVE environment = Environment.LIVE,//正式上线后,改为Environment.LIVE
returnUrl = "com.zhangxin.magicbox://paypalpay",//创建应用时填的RETURN_URL returnUrl = "com.zhangxin.magicbox://paypalpay",//创建应用时填的RETURN_URL
currencyCode = CurrencyCode.USD,//货币种类:CNY-人民币;HKD-港币;TWD-新台币;USD-美元... currencyCode = CurrencyCode.USD,//货币种类:CNY-人民币;HKD-港币;TWD-新台币;USD-美元...
userAction = UserAction.PAY_NOW, userAction = UserAction.PAY_NOW,
settingsConfig = SettingsConfig( settingsConfig = SettingsConfig(
loggingEnabled = true, loggingEnabled = false,
shouldFailEligibility = false shouldFailEligibility = false
) )
) )
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
PayPalCheckout.setConfig(config) PayPalCheckout.setConfig(config)
} }
EventUtils
} }
private fun getOaid() { private fun getOaid() {
......
PACKAGE_NAME=com.zhangxin.magicbox PACKAGE_NAME=com.zhangxin.magicbox
VERSION_CODE=8 VERSION_CODE=10
VERSION_NAME=1.0.3.1 VERSION_NAME=1.0.3.2
\ No newline at end of file \ No newline at end of file
...@@ -4,22 +4,23 @@ buildscript { ...@@ -4,22 +4,23 @@ buildscript {
ext.kotlin_version = '1.4.32' ext.kotlin_version = '1.4.32'
// ext.kotlin_version = '1.6.20-RC' // ext.kotlin_version = '1.6.20-RC'
repositories { repositories {
maven { // maven {
url "https://mvn.mob.com/android" // url "https://mvn.mob.com/android"
} // }
google() google()
jcenter() jcenter()
mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.0.1' classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'me.tatarka:gradle-retrolambda:3.7.0' classpath 'me.tatarka:gradle-retrolambda:3.7.0'
classpath "com.mob.sdk:MobSDK:2018.0319.1724" // classpath "com.mob.sdk:MobSDK:2018.0319.1724"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
configurations.all { // configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds' // resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
} // }
} }
} }
......
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'com.mob.sdk' //apply plugin: 'com.mob.sdk'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
android { android {
...@@ -33,38 +33,38 @@ android { ...@@ -33,38 +33,38 @@ android {
} }
} }
MobSDK { // MobSDK {
appKey "//357874b62b4c7" // appKey "//357874b62b4c7"
appSecret "c4d82ff12e0cde832960ddbb8d2d7250" // appSecret "c4d82ff12e0cde832960ddbb8d2d7250"
gui false // gui false
version '3.9.7' // version '3.9.7'
appBundleMode true // appBundleMode false
ShareSDK { // ShareSDK {
loopShare true // loopShare true
devInfo { // devInfo {
Facebook { // Facebook {
id 8 // id 8
sortId 8 // sortId 8
appKey "1156014961815312" // appKey "1156014961815312"
callbackUri "https://www.baidu.com" // callbackUri "https://www.baidu.com"
officialVersion "default" // officialVersion "default"
faceBookLoginProtocolScheme "fb1156014961815312" // faceBookLoginProtocolScheme "fb1156014961815312"
shareByAppClient true // shareByAppClient true
enable true // enable true
} // }
GooglePlus { // GooglePlus {
id 21 // id 21
sortId 21 // sortId 21
appId "236300675100-am5pm8km7md1memjevq8rl9pg5c4s4b8.apps.googleusercontent.com" // appId "236300675100-am5pm8km7md1memjevq8rl9pg5c4s4b8.apps.googleusercontent.com"
callbackUri "http://localhost" // callbackUri "http://localhost"
officialVersion "default" // officialVersion "default"
shareByAppClient true // shareByAppClient true
enable true // enable true
} // }
//
} // }
} // }
} // }
kotlinOptions { kotlinOptions {
jvmTarget = "1.8" jvmTarget = "1.8"
...@@ -128,10 +128,17 @@ dependencies { ...@@ -128,10 +128,17 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
//implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0' //implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
//FaceBookLogin
api 'com.facebook.android:facebook-login:latest.release'
//GoogleLogin
implementation 'com.google.android.gms:play-services-auth:20.1.0'
//GooglePay //GooglePay
implementation("com.android.billingclient:billing:4.1.0") implementation("com.android.billingclient:billing:4.1.0")
//PayPal支付 //PayPal支付
api 'com.paypal.checkout:android-sdk:0.6.0' api 'com.paypal.checkout:android-sdk:0.6.0'
// api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10" // api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10"
// api "androidx.core:core-ktx:1.6.0" // api "androidx.core:core-ktx:1.6.0"
//归因
api 'com.appsflyer:af-android-sdk:6.3.2'
api("com.android.installreferrer:installreferrer:2.2")
} }
...@@ -42,6 +42,28 @@ ...@@ -42,6 +42,28 @@
<meta-data <meta-data
android:name="UMENG_CHANNEL" android:name="UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" /> android:value="${UMENG_CHANNEL_VALUE}" />
<!-- FaceBook-->
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<meta-data
android:name="com.facebook.sdk.ClientToken"
android:value="@string/facebook_client_token" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="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="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -48,7 +48,7 @@ object ApiClient { ...@@ -48,7 +48,7 @@ object ApiClient {
} }
.addInterceptor(paramsInterceptor) .addInterceptor(paramsInterceptor)
.addInterceptor(headInterceptor) .addInterceptor(headInterceptor)
.build()!! .build()
private val retrofit = retrofit2.Retrofit.Builder() private val retrofit = retrofit2.Retrofit.Builder()
.client(httpClient) .client(httpClient)
......
...@@ -3,6 +3,8 @@ package com.zxhl.cms.utils ...@@ -3,6 +3,8 @@ package com.zxhl.cms.utils
import android.content.Context import android.content.Context
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import com.appsflyer.AppsFlyerLib
import com.appsflyer.attribution.AppsFlyerRequestListener
import com.umeng.analytics.MobclickAgent import com.umeng.analytics.MobclickAgent
import com.zxhl.cms.AppContext import com.zxhl.cms.AppContext
import com.zxhl.cms.net.ApiClient import com.zxhl.cms.net.ApiClient
...@@ -38,6 +40,7 @@ object EventUtils { ...@@ -38,6 +40,7 @@ object EventUtils {
fun onEvent(action: String) { fun onEvent(action: String) {
val jsonObj = getJSON(action) val jsonObj = getJSON(action)
apiClient(jsonObj) apiClient(jsonObj)
appFlayerEvent(action,"")
// MobclickAgent.onEvent(AppContext.get(), action) // MobclickAgent.onEvent(AppContext.get(), action)
} }
...@@ -45,12 +48,11 @@ object EventUtils { ...@@ -45,12 +48,11 @@ object EventUtils {
val jsonObj = getJSON(action) val jsonObj = getJSON(action)
jsonObj.put("value", value) jsonObj.put("value", value)
apiClient(jsonObj) apiClient(jsonObj)
appFlayerEvent(action,value)
// MobclickAgent.onEvent(AppContext.get(), action, value) // MobclickAgent.onEvent(AppContext.get(), action, value)
} }
// /** // /**
// * 统计新用户首次登陆 男女生 // * 统计新用户首次登陆 男女生
// */ // */
...@@ -62,8 +64,6 @@ object EventUtils { ...@@ -62,8 +64,6 @@ object EventUtils {
private var time: Long = 0 private var time: Long = 0
fun getJSON(action: String): JSONObject { fun getJSON(action: String): JSONObject {
var data = JSONObject() var data = JSONObject()
data.put("event", EVENT) data.put("event", EVENT)
...@@ -77,20 +77,20 @@ object EventUtils { ...@@ -77,20 +77,20 @@ object EventUtils {
val key = AESUtils.encrypt(str) val key = AESUtils.encrypt(str)
Log.d("EventUtils", key) Log.d("EventUtils", key)
EventApiClient.cfgApi.requestEvent("behavior", key).subscribeOn(Schedulers.io()) EventApiClient.cfgApi.requestEvent("behavior", key).subscribeOn(Schedulers.io())
.subscribe(object : Observer<Any> { .subscribe(object : Observer<Any> {
override fun onComplete() { override fun onComplete() {
} }
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
} }
override fun onNext(t: Any) { override fun onNext(t: Any) {
} }
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
} }
}) })
} }
fun apiAppUpload(module: String, event: String, data: JSONObject) { fun apiAppUpload(module: String, event: String, data: JSONObject) {
...@@ -100,20 +100,36 @@ object EventUtils { ...@@ -100,20 +100,36 @@ object EventUtils {
val key = AESUtils.encrypt(str) val key = AESUtils.encrypt(str)
LogUtils.d("EventUtils", key) LogUtils.d("EventUtils", key)
EventApiClient.cfgApi.requestEvent(module, key).subscribeOn(Schedulers.io()) EventApiClient.cfgApi.requestEvent(module, key).subscribeOn(Schedulers.io())
.subscribe(object : Observer<Any> { .subscribe(object : Observer<Any> {
override fun onComplete() { override fun onComplete() {
}
override fun onSubscribe(d: Disposable) {
}
override fun onNext(t: Any) {
}
override fun onError(e: Throwable) {
}
})
}
}
override fun onSubscribe(d: Disposable) { fun appFlayerEvent(action: String, value: String) {
} var eventValues = HashMap<String, Any>()
eventValues[action] = value
AppsFlyerLib.getInstance().logEvent(AppContext.get(), action, eventValues,object :AppsFlyerRequestListener{
override fun onSuccess() {
Log.e("appsflyer","onSuccess")
}
override fun onNext(t: Any) { override fun onError(p0: Int, p1: String) {
} Log.e("appsflyer","p0 $p0 p1 $p1")
}
override fun onError(e: Throwable) { })
}
})
} }
} }
\ No newline at end of file
package com.zxhl.cms.utils
import android.app.Activity
import android.content.Intent
import android.os.Handler
import android.util.Log
import com.facebook.*
import com.facebook.login.LoginManager
import com.facebook.login.LoginResult
import com.zxhl.cms.common.Constant
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.other.WxBindEntity
/**
* @author (wangXuewei)
* @datetime 2022-03-26 11:04 GMT+8
* @detail :
*/
class FaceBookLoginUtil {
private val TAG = "FaceBookLoginUtil"
private var mActivity: Activity;
private var mLoginCallBack: LoginCallBack? = null;
private var callbackManager: CallbackManager? = null;
constructor(mActivity: Activity) {
this.mActivity = mActivity
}
interface LoginCallBack {
fun onLoginSuccess()
fun onLoginError(errorMsg: String)
}
fun init() {
callbackManager = CallbackManager.Factory.create()
LoginManager.getInstance().registerCallback(callbackManager,
object : FacebookCallback<LoginResult> {
override fun onSuccess(loginResult: LoginResult) {
//延时500毫秒获取信息,不然获取不到
val handler = Handler()
handler.postDelayed(
{
val accessToken = loginResult.accessToken
val profile = Profile.getCurrentProfile()
if (profile != null) {
bindFaceBookLogin(
accessToken.userId,
profile.name,
profile.getProfilePictureUri(
200,
200
).toString()
)
} else {
mLoginCallBack?.onLoginError("Success_未获取到登录信息")
}
}, 500
)
}
override fun onCancel() {
mLoginCallBack?.onLoginError("FaceBookLoginCancel")
}
override fun onError(exception: FacebookException) {
mLoginCallBack?.onLoginError("FaceBookLogin error:" + exception.message)
}
})
}
/**
* faceBook登录
*/
fun faceBookLogin(callBack: LoginCallBack) {
mLoginCallBack = callBack;
val accessToken = AccessToken.getCurrentAccessToken()
val profile = Profile.getCurrentProfile()
if (accessToken != null && !accessToken.isExpired && profile != null) {
bindFaceBookLogin(
accessToken.userId,
profile.name,
profile.getProfilePictureUri(200, 200).toString()
)
} else {
LoginManager.getInstance()
.logInWithReadPermissions(mActivity, listOf("public_profile"));
}
}
/**
* Activity 重写
* */
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
callbackManager?.onActivityResult(requestCode, resultCode, data)
}
/**
* faceBook 绑定后端服务器
* */
private fun bindFaceBookLogin(userId: String?, userName: String?, picture: String?) {
ApiClient.homeApi.authFaceBookLogin(userId, userName, picture)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<WxBindEntity>() {
override fun onSuccess(result: WxBindEntity?) {
SettingPreference.saveToken(result?.token)
UserDataUtils.updateUserInfo(null)
Constant.Switch.isLogin = true
mLoginCallBack?.onLoginSuccess()
}
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// callBack.loginSuccess(lottery)
mLoginCallBack?.onLoginError("net code:$code msg:$errorMsg")
}
})
}
/**
* 退出登录
*/
fun signOut() {
}
/**
* 断开链接
*/
fun revokeAccess() {
}
}
\ No newline at end of file
package com.zxhl.cms.utils
import android.app.Activity
import android.content.Intent
import android.util.Log
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import com.zxhl.cms.common.Constant
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.other.WxBindEntity
/**
* @author (wangXuewei)
* @datetime 2022-03-25 14:04 GMT+8
* @detail :
*/
class GoogleLoginUtil {
private val TAG = "GoogleLoginUtil"
private val RC_SIGN_IN = 9009
private val googleClientId =
"535211515800-fcblld827b8ojq7dccuohmeo199205ce.apps.googleusercontent.com"
private var mActivity: Activity;
private var mGoogleSignInClient: GoogleSignInClient? = null;
private var mLoginCallBack: LoginCallBack? = null;
constructor(mActivity: Activity) {
this.mActivity = mActivity
}
interface LoginCallBack {
fun onLoginSuccess()
fun onLoginError(errorMsg: String)
}
fun init() {
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(googleClientId)
.requestId()
.requestProfile()
.build()
mGoogleSignInClient = GoogleSignIn.getClient(mActivity, gso);
}
/**
* google登录
*/
fun googleLogin(callBack: LoginCallBack) {
mLoginCallBack = callBack;
val account = GoogleSignIn.getLastSignedInAccount(mActivity)
if (account != null) {
bindGoogle(account.id, account.displayName, account.photoUrl.toString())
} else {
mActivity.runOnUiThread {
val signInIntent = mGoogleSignInClient?.signInIntent
mActivity.startActivityForResult(signInIntent, RC_SIGN_IN)
}
}
}
/**
* Activity 重写
* */
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode === RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(data)
handleSignInResult(task)
}
}
private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
try {
// Signed in successfully, show authenticated UI.
val account = completedTask.getResult(ApiException::class.java)
if (account != null) {
bindGoogle(account.id, account.displayName, account.photoUrl.toString())
} else {
mLoginCallBack?.onLoginError("code:-2 msg:account is null")
}
} catch (e: ApiException) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
mLoginCallBack?.onLoginError("code:${e.statusCode} msg:${e.message}")
}
}
/**
* 绑定后端服务器
* */
private fun bindGoogle(userId: String?, userName: String?, picture: String?) {
ApiClient.homeApi.authGoogleLogin(userId, userName, picture)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<WxBindEntity>() {
override fun onSuccess(result: WxBindEntity?) {
SettingPreference.saveToken(result?.token)
UserDataUtils.updateUserInfo(null)
Constant.Switch.isLogin = true
mLoginCallBack?.onLoginSuccess()
}
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// callBack.loginSuccess(lottery)
mLoginCallBack?.onLoginError("net code:$code msg:$errorMsg")
}
})
}
/**
* 退出登录
*/
fun signOut() {
mGoogleSignInClient?.signOut()
?.addOnCompleteListener(mActivity) {
// ...
//it.result
}
}
/**
* 断开链接
*/
fun revokeAccess() {
mGoogleSignInClient?.revokeAccess()
?.addOnCompleteListener(mActivity) {
// ...
}
}
}
\ No newline at end of file
...@@ -3,15 +3,8 @@ package com.zxhl.cms.utils ...@@ -3,15 +3,8 @@ package com.zxhl.cms.utils
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import android.widget.Toast
import cn.sharesdk.facebook.Facebook
import cn.sharesdk.framework.Platform
import cn.sharesdk.framework.PlatformActionListener
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.google.GooglePlus
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.Constant import com.zxhl.cms.common.Constant
import com.zxhl.cms.net.ApiClient import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers import com.zxhl.cms.net.RxSchedulers
...@@ -157,29 +150,29 @@ class WeChatUtils { ...@@ -157,29 +150,29 @@ class WeChatUtils {
fun FackBooklogin() { fun FackBooklogin() {
val plat = ShareSDK.getPlatform(Facebook.NAME) // val plat = ShareSDK.getPlatform(Facebook.NAME)
//授权回调监听,监听oncomplete,onerror,oncancel三种状态 ////授权回调监听,监听oncomplete,onerror,oncancel三种状态
plat.platformActionListener = object : PlatformActionListener { // plat.platformActionListener = object : PlatformActionListener {
override fun onComplete(p0: Platform?, p1: Int, p2: HashMap<String, Any>?) { // override fun onComplete(p0: Platform?, p1: Int, p2: HashMap<String, Any>?) {
Log.e("MXL", "Data:" + p0?.db?.exportData() + "Image:" + p0?.db?.userIcon) // Log.e("MXL", "Data:" + p0?.db?.exportData() + "Image:" + p0?.db?.userIcon)
bindFaceBookLogin(p0?.db?.userId, p0?.db?.userName, p0?.db?.userIcon) // bindFaceBookLogin(p0?.db?.userId, p0?.db?.userName, p0?.db?.userIcon)
EventUtils.onEvent("FackBookloginSuccess") // EventUtils.onEvent("FackBookloginSuccess")
} // }
//
override fun onError(arg0: Platform, arg1: Int, arg2: Throwable) { // override fun onError(arg0: Platform, arg1: Int, arg2: Throwable) {
//失败的回调,arg:平台对象,arg1:表示当前的动作(8:有用户信息登录, 1:无用户信息登录),arg2:异常信息 // //失败的回调,arg:平台对象,arg1:表示当前的动作(8:有用户信息登录, 1:无用户信息登录),arg2:异常信息
Log.e("MXL", "FaceBook:onError" + arg2.printStackTrace()) // Log.e("MXL", "FaceBook:onError" + arg2.printStackTrace())
EventUtils.onEvent("FackBookloginError", "arg1" + arg1 + " arg2" + arg2.message+" arg2:"+arg2.printStackTrace()) // EventUtils.onEvent("FackBookloginError", "arg1" + arg1 + " arg2" + arg2.message+" arg2:"+arg2.printStackTrace())
} // }
//
override fun onCancel(arg0: Platform, arg1: Int) { // override fun onCancel(arg0: Platform, arg1: Int) {
//取消分享的回调 // //取消分享的回调
Log.e("MXL", "FaceBook:onCancel") // Log.e("MXL", "FaceBook:onCancel")
EventUtils.onEvent("FackBookloginCancel") // EventUtils.onEvent("FackBookloginCancel")
//
} // }
} // }
plat.showUser(null) // plat.showUser(null)
} }
fun bindFaceBookLogin(userId: String?, userName: String?, picture: String?) { fun bindFaceBookLogin(userId: String?, userName: String?, picture: String?) {
...@@ -204,43 +197,47 @@ class WeChatUtils { ...@@ -204,43 +197,47 @@ class WeChatUtils {
} }
fun GoogleLogin() { fun GoogleLogin() {
// MobSDK.submitPolicyGrantResult(true, null) // // MobSDK.submitPolicyGrantResult(true, null)
val plat = ShareSDK.getPlatform(GooglePlus.NAME) // val plat = ShareSDK.getPlatform(GooglePlus.NAME)
ShareSDK.setActivity(mContext as Activity) // ShareSDK.setActivity(mContext as Activity)
//授权回调监听,监听oncomplete,onerror,oncancel三种状态 ////授权回调监听,监听oncomplete,onerror,oncancel三种状态
plat.platformActionListener = object : PlatformActionListener { // plat.platformActionListener = object : PlatformActionListener {
override fun onComplete(p0: Platform?, p1: Int, p2: HashMap<String, Any>?) { // override fun onComplete(p0: Platform?, p1: Int, p2: HashMap<String, Any>?) {
Log.e("MXL", "onComplete" + p0?.db?.userIcon + p0?.db?.userId) // Log.e("MXL", "onComplete" + p0?.db?.userIcon + p0?.db?.userId)
Log.e("MXL", "Data:" + p0?.db?.exportData()) // Log.e("MXL", "Data:" + p0?.db?.exportData())
if (p2 != null) { // if (p2 != null) {
val g = Gson() // val g = Gson()
val obj: JsonObject = g.fromJson(p0?.db?.exportData(), JsonObject::class.java) // val obj: JsonObject = g.fromJson(p0?.db?.exportData(), JsonObject::class.java)
Log.e("MXL", "PIC:" + obj.get("picture")) // Log.e("MXL", "PIC:" + obj.get("picture"))
val pic = obj.get("picture").toString().replace("\"", "") // val pic = obj.get("picture").toString().replace("\"", "")
Log.e("MXL", "image:" + pic) // Log.e("MXL", "image:" + pic)
bindGoogle(p0?.db?.userId, p0?.db?.userName, pic) // bindGoogle(p0?.db?.userId, p0?.db?.userName, pic)
EventUtils.onEvent("GoogleLoginSuccess") // EventUtils.onEvent("GoogleLoginSuccess")
} // }
//
} // }
//
override fun onError(arg0: Platform, arg1: Int, arg2: Throwable) { // override fun onError(arg0: Platform, arg1: Int, arg2: Throwable) {
//失败的回调,arg:平台对象,arg1:表示当前的动作(8:有用户信息登录, 1:无用户信息登录),arg2:异常信息 // //失败的回调,arg:平台对象,arg1:表示当前的动作(8:有用户信息登录, 1:无用户信息登录),arg2:异常信息
Log.e("MXL", "onError" + arg2.printStackTrace()) // Log.e("MXL", "onError" + arg2.printStackTrace())
Log.e("MXL", "onError" + arg2.message) // Log.e("MXL", "onError" + arg2.message)
EventUtils.onEvent("GoogleLoginError", "arg1" + arg1 + " arg2" + arg2.message+" arg2:"+arg2.printStackTrace()) // EventUtils.onEvent("GoogleLoginError", "arg1" + arg1 + " arg2" + arg2.message+" arg2:"+arg2.printStackTrace())
} // }
//
override fun onCancel(arg0: Platform, arg1: Int) { // override fun onCancel(arg0: Platform, arg1: Int) {
//取消分享的回调 // //取消分享的回调
Log.e("MXL", "onCancel") // Log.e("MXL", "onCancel")
EventUtils.onEvent("GoogleLoginCancel") // EventUtils.onEvent("GoogleLoginCancel")
//
// }
// }
// // plat.authorize()
// plat.showUser(null)
} }
}
// plat.authorize()
plat.showUser(null)
fun GoogleLogin2() {
} }
fun bindGoogle(userId: String?, userName: String?, picture: String?) { fun bindGoogle(userId: String?, userName: String?, picture: String?) {
......
<resources> <resources>
<string name="facebook_app_id">1156014961815312</string>
<string name="fb_login_protocol_scheme">fb1156014961815312</string>
<string name="facebook_client_token">49f99977bc2d8a18f8271cf643379644</string>
<string name="app_name">MagicBox</string> <string name="app_name">MagicBox</string>
<string name="login_faild">登录失败</string> <string name="login_faild">登录失败</string>
<string name="login_success">登录成功</string> <string name="login_success">登录成功</string>
...@@ -59,7 +63,7 @@ ...@@ -59,7 +63,7 @@
<string name="order_detail">Order details</string> <string name="order_detail">Order details</string>
<string name="total_price">Total:</string> <string name="total_price">Total:</string>
<string name="pay">Pay</string> <string name="pay">Pay</string>
<string name="order_pay">订单支付</string> <string name="order_pay">Order payment</string>
<string name="write_info">Please input your delivery address</string> <string name="write_info">Please input your delivery address</string>
<!--下单成功--> <!--下单成功-->
<string name="order_suceess_title">Deliver</string> <string name="order_suceess_title">Deliver</string>
......
...@@ -4,7 +4,7 @@ if (isDebug.toBoolean()) { ...@@ -4,7 +4,7 @@ if (isDebug.toBoolean()) {
} else { } else {
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
} }
apply plugin: 'com.mob.sdk' //apply plugin: 'com.mob.sdk'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
android { android {
......
...@@ -95,7 +95,7 @@ class NewBoxGoodsDetailActivity : BaseActivity(), GoodsDetailContract.View, ...@@ -95,7 +95,7 @@ class NewBoxGoodsDetailActivity : BaseActivity(), GoodsDetailContract.View,
} }
//试玩 //试玩
id_detail_shiwan_rl?.setOnClickListener { id_detail_shiwan_rl?.setOnClickListener {
if (!Constant.Switch.isLogin){ if (Constant.Switch.isLogin){
JumpUtils.ThirdPardLoginJump() JumpUtils.ThirdPardLoginJump()
return@setOnClickListener return@setOnClickListener
} }
......
package com.zxhl.main.page.activity package com.zxhl.main.page.activity
import android.content.Intent
import android.util.Log
import android.view.View import android.view.View
import com.facebook.*
import com.facebook.login.LoginConfiguration
import com.facebook.login.LoginManager
import com.facebook.login.LoginResult
import com.zxhl.cms.AppContext import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseActivity import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.utils.EventUtils import com.zxhl.cms.utils.*
import com.zxhl.cms.utils.NoDoubleClickListener import com.zxhl.cms.widget.LoadingDialog
import com.zxhl.cms.utils.WeChatLoginSuccessCallBall
import com.zxhl.cms.utils.WeChatUtils
import com.zxhl.main.R import com.zxhl.main.R
import kotlinx.android.synthetic.main.activity_layout_third_party_login.* import kotlinx.android.synthetic.main.activity_layout_third_party_login.*
import java.util.*
class ThirdpartyLoginActivity : BaseActivity(), WeChatLoginSuccessCallBall { class ThirdpartyLoginActivity : BaseActivity(), WeChatLoginSuccessCallBall {
private var wechatutil: WeChatUtils? = null // private var wechatutil: WeChatUtils? = null
private var mLoading: LoadingDialog? = null
override fun onClick(v: View?) { override fun onClick(v: View?) {
} }
...@@ -25,25 +32,85 @@ class ThirdpartyLoginActivity : BaseActivity(), WeChatLoginSuccessCallBall { ...@@ -25,25 +32,85 @@ class ThirdpartyLoginActivity : BaseActivity(), WeChatLoginSuccessCallBall {
return R.layout.activity_layout_third_party_login return R.layout.activity_layout_third_party_login
} }
private var googleLogin: GoogleLoginUtil? = null;
private var faceBookLogin: FaceBookLoginUtil? = null;
override fun init() { override fun init() {
wechatutil = WeChatUtils(this, this) mLoading = LoadingDialog.getLoadingDialog(
this,
getString(R.string.wait_ing),
false,
false
)
// wechatutil = WeChatUtils(this, this)
//googleLogin init
googleLogin = GoogleLoginUtil(this)
googleLogin?.init()
//FaceBook
faceBookLogin = FaceBookLoginUtil(this)
faceBookLogin?.init()
id_ll_google_login?.setOnClickListener(object : NoDoubleClickListener() { id_ll_google_login?.setOnClickListener(object : NoDoubleClickListener() {
override fun onNoDoubleClick(v: View?) { override fun onNoDoubleClick(v: View?) {
EventUtils.onEvent("googleLoginClick") EventUtils.onEvent("googleLoginClick")
//WeChatUtils. mLoading?.setLoading(getString(R.string.wait_ing2))
wechatutil?.GoogleLogin() mLoading?.show()
googleLogin?.googleLogin(object : GoogleLoginUtil.LoginCallBack {
override fun onLoginSuccess() {
runOnUiThread {
mLoading?.setResult(true, "login success", 0)
finish()
}
}
override fun onLoginError(errorMsg: String) {
EventUtils.onEvent("GoogleLoginError", errorMsg)
runOnUiThread {
mLoading?.setResult(false, "login error", 1000)
}
}
})
} }
}) })
id_ll_facebook_login?.setOnClickListener(object : NoDoubleClickListener() { id_ll_facebook_login?.setOnClickListener(object : NoDoubleClickListener() {
override fun onNoDoubleClick(v: View?) { override fun onNoDoubleClick(v: View?) {
EventUtils.onEvent("facebookLoginClick") EventUtils.onEvent("facebookLoginClick")
wechatutil?.FackBooklogin() mLoading?.setLoading(getString(R.string.wait_ing2))
} mLoading?.show()
faceBookLogin?.faceBookLogin(object : FaceBookLoginUtil.LoginCallBack {
override fun onLoginSuccess() {
runOnUiThread {
mLoading?.setResult(true, "login success", 0)
finish()
}
}
override fun onLoginError(errorMsg: String) {
if (errorMsg == "Success_未获取到登录信息"){
runOnUiThread {
mLoading?.setResult(false, "try again", 1000)
}
}else{
runOnUiThread {
mLoading?.setResult(false, "login error", 1000)
}
}
EventUtils.onEvent("facebookLoginError", errorMsg)
// Log.e("FaceBookLoginUtil", "error $errorMsg")
}
})
}
}) })
} }
override fun loginSuccess(lottery: String?) { override fun loginSuccess(lottery: String?) {
this.finish() this.finish()
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
faceBookLogin?.onActivityResult(requestCode, resultCode, data)
googleLogin?.onActivityResult(requestCode, resultCode, data)
}
} }
\ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:src="@drawable/bj_login" android:src="@drawable/bj_login"
android:visibility="gone"/> android:visibility="gone" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
android:layout_height="44dp" android:layout_height="44dp"
app:defaultTabTextColor="@color/color_333333" app:defaultTabTextColor="@color/color_333333"
app:defaultTabTextHorizontalPadding="12dp" app:defaultTabTextHorizontalPadding="12dp"
app:defaultTabTextSize="14sp" app:defaultTabTextSize="16sp"
app:indicatorColor="@color/color_4c84ff" app:indicatorColor="@color/color_4c84ff"
app:indicatorCornerRadius="2dp" app:indicatorCornerRadius="2dp"
app:indicatorWidth="15dp" app:indicatorWidth="15dp"
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_above="@+id/id_detail_shiwan_rl" android:layout_above="@+id/id_detail_shiwan_rl"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:visibility="gone"
android:layout_marginBottom="13dp"> android:layout_marginBottom="13dp">
<ImageView <ImageView
......
...@@ -4,7 +4,7 @@ if (isDebug.toBoolean()) { ...@@ -4,7 +4,7 @@ if (isDebug.toBoolean()) {
} else { } else {
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
} }
apply plugin: 'com.mob.sdk' //apply plugin: 'com.mob.sdk'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
android { android {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment