Commit a4e8a4b1 authored by shiyl's avatar shiyl

add 集成友盟三方登录,实现微信授权

parent 3f8d4d0c
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.yidian.common"> package="com.yidian.common">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application>
<!-- 以下为友盟分享基本配置信息 start-->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${file_provider}"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"
tools:replace="android:resource" />
</provider>
<!--微信分享/登录-->
<activity
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
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="tencent101923771" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.umeng.socialize.media.WBShareCallBackActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:windowSoftInputMode="adjustResize" />
<!-- 以上为友盟分享基本配置信息 end-->
</application>
</manifest> </manifest>
package com.yidian.common.utils
import android.app.Activity
import com.umeng.socialize.UMAuthListener
import com.umeng.socialize.UMShareAPI
import com.umeng.socialize.bean.SHARE_MEDIA
import com.yidian.utils.ToastUtil
/**
* 授权登录工具类
*/
object AuthUtils {
/**
* 校验是否已经授权
*/
fun checkIsAuth(activity: Activity, platform: SHARE_MEDIA): Boolean {
return UMShareAPI.get(activity).isAuthorize(activity, platform)
}
/**
* 进行平台授权
*
* @return 返回授权信息的map
*/
fun toAuthorize(activity: Activity, platform: SHARE_MEDIA): Map<String, String> {
var authMap: Map<String, String> = HashMap()
UMShareAPI.get(activity).getPlatformInfo(activity, platform, object : UMAuthListener {
override fun onStart(share_media: SHARE_MEDIA) {}
override fun onComplete(share_media: SHARE_MEDIA, i: Int, map: Map<String, String>) {
authMap = map
}
override fun onError(share_media: SHARE_MEDIA, i: Int, throwable: Throwable) {
ToastUtil.showToast(activity, throwable.message)
}
override fun onCancel(share_media: SHARE_MEDIA, i: Int) {
ToastUtil.showToast(activity, "用户已取消")
}
})
return authMap
}
}
...@@ -5,21 +5,24 @@ import android.content.pm.ApplicationInfo ...@@ -5,21 +5,24 @@ import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.util.Log import android.util.Log
/**
* 检查APK是否安装
*/
class CheckApkExistUtil { class CheckApkExistUtil {
companion object{ companion object {
const val weChatPkgName = "com.tencent.mm" const val weChatPkgName = "com.tencent.mm"
const val mobileQQPkgName = "com.tencent.mobileqq" const val mobileQQPkgName = "com.tencent.mobileqq"
const val sinaBlogPkgName = "com.sina.weibo" const val sinaBlogPkgName = "com.sina.weibo"
fun checkApkExist(context: Context, packageName: String): Boolean{ fun checkApkExist(context: Context, packageName: String): Boolean {
if(packageName.isEmpty()) return false if (packageName.isEmpty()) return false
var packageInfo: ApplicationInfo? val packageInfo: ApplicationInfo? = try {
try { context.packageManager.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES)
packageInfo = context.packageManager.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES) } catch (e: PackageManager.NameNotFoundException) {
}catch (e: PackageManager.NameNotFoundException){ null
packageInfo = null }
} return packageInfo != null
return packageInfo != null
}
} }
} }
\ No newline at end of file }
...@@ -5,41 +5,44 @@ import android.net.ConnectivityManager ...@@ -5,41 +5,44 @@ import android.net.ConnectivityManager
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
class NetWorkUtils { class NetWorkUtils {
companion object{ companion object {
const val NET_TYPE_WIFI = "wifi" private const val NET_TYPE_WIFI = "wifi"
const val NET_TYPE_4G = "4g" const val NET_TYPE_4G = "4g"
const val NET_TYPE_5G = "5g" const val NET_TYPE_5G = "5g"
const val NET_TYPE_3G = "3g" const val NET_TYPE_3G = "3g"
const val NET_TYPE_2G = "2g" const val NET_TYPE_2G = "2g"
fun getNetWorkType(context: Context): String{ fun getNetWorkType(context: Context): String {
var netType = "unknown" var netType = "unknown"
val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = manager.activeNetworkInfo ?: return netType val networkInfo = manager.activeNetworkInfo ?: return netType
val nType = networkInfo.type val nType = networkInfo.type
if (nType == ConnectivityManager.TYPE_WIFI) { if (nType == ConnectivityManager.TYPE_WIFI) {
netType = "wifi" netType = "wifi"
} else if (nType == ConnectivityManager.TYPE_MOBILE) { } else if (nType == ConnectivityManager.TYPE_MOBILE) {
val nSubType = networkInfo.subtype val nSubType = networkInfo.subtype
val telephonyManager: TelephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager val telephonyManager: TelephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
netType = if(nSubType ==TelephonyManager.NETWORK_TYPE_NR){ netType = if (nSubType == TelephonyManager.NETWORK_TYPE_NR) {
"5g" "5g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_LTE && !telephonyManager.isNetworkRoaming) { } else if (nSubType == TelephonyManager.NETWORK_TYPE_LTE && !telephonyManager.isNetworkRoaming) {
"4g" "4g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA || (nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0 } else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA || (nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
&& !telephonyManager.isNetworkRoaming)) { && !telephonyManager.isNetworkRoaming)
"3g" ) {
} else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS || nSubType == TelephonyManager.NETWORK_TYPE_EDGE || (nSubType == TelephonyManager.NETWORK_TYPE_CDMA "3g"
&& !telephonyManager.isNetworkRoaming)) { } else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS || nSubType == TelephonyManager.NETWORK_TYPE_EDGE || (nSubType == TelephonyManager.NETWORK_TYPE_CDMA
"2g" && !telephonyManager.isNetworkRoaming)
} else { ) {
"unknown" "2g"
} } else {
} "unknown"
return netType
}
fun isWifiConnected(context: Context):Boolean{
return NET_TYPE_WIFI == getNetWorkType(context)
} }
}
return netType
}
fun isWifiConnected(context: Context): Boolean {
return NET_TYPE_WIFI == getNetWorkType(context)
} }
} }
\ No newline at end of file }
package com.yidian.common.utils
import android.content.Context
/**
* 分享工具类
*/
object ShareUtils {
}
...@@ -30,167 +30,167 @@ import java.util.* ...@@ -30,167 +30,167 @@ import java.util.*
object ToolsUtil { object ToolsUtil {
//防止连续点击 //防止连续点击
private var lastClickTime: Long = 0 private var lastClickTime: Long = 0
//自定义快速点击时间
private var currentLastClickTime: Long = 0
//备用自定义快速点击时间
private var tempLastClickTime: Long = 0
//快速点击检测
val isFastClick: Boolean
get() {
val time = System.currentTimeMillis()
val timeD = time - lastClickTime
if (timeD < 500) {
return false
}
lastClickTime = time
return true
}
//单位转换
fun dp2px(context: Context, dpVal: Float): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dpVal,
context.resources.displayMetrics
).toInt()
}
fun dp2px(dpValue: Float): Int { //自定义快速点击时间
return TypedValue.applyDimension(1, dpValue, DisplayMetrics()).toInt() private var currentLastClickTime: Long = 0
}
//格式化展示 //备用自定义快速点击时间
fun formatShowNum(count: Int): String{ private var tempLastClickTime: Long = 0
var showCount = count.toString()
when{
count in 1000..9999 -> {
val floutCount = count / 1000
showCount = floutCount.toString().format("%.1f") + "K"
}
count in 10000..99999999 -> {
val floutCount = count / 10000
showCount = floutCount.toString().format("%.1f") + "W"
}
count >= 100000000 -> {
val floutCount = count / 100000000
showCount = floutCount.toString().format("%.1f") + "亿"
}
}
return showCount
}
//event事件 //快速点击检测
fun doAction(name: String, params: Any) { val isFastClick: Boolean
Log.d("song_test", "event_bus.name = $name") get() {
val xBaseEvent = XBaseEvent(name, params) val time = System.currentTimeMillis()
XEventService.postEvent(xBaseEvent) val timeD = time - lastClickTime
if (timeD < 500) {
return false
}
lastClickTime = time
return true
} }
//自定义时间检测 //单位转换
fun isCustomFastClick(timeNum: Long): Boolean { fun dp2px(context: Context, dpVal: Float): Int {
val time = System.currentTimeMillis() return TypedValue.applyDimension(
val timeD = time - currentLastClickTime TypedValue.COMPLEX_UNIT_DIP,
if (timeD < timeNum) { dpVal,
return false context.resources.displayMetrics
} ).toInt()
currentLastClickTime = time }
return true
fun dp2px(dpValue: Float): Int {
return TypedValue.applyDimension(1, dpValue, DisplayMetrics()).toInt()
}
//格式化展示
fun formatShowNum(count: Int): String {
var showCount = count.toString()
when {
count in 1000..9999 -> {
val floutCount = count / 1000
showCount = floutCount.toString().format("%.1f") + "K"
}
count in 10000..99999999 -> {
val floutCount = count / 10000
showCount = floutCount.toString().format("%.1f") + "W"
}
count >= 100000000 -> {
val floutCount = count / 100000000
showCount = floutCount.toString().format("%.1f") + "亿"
}
} }
return showCount
//备用自定义时间检测 }
fun isCustomFastStatus(timeNum: Long): Boolean {
val time = System.currentTimeMillis() //event事件
val timeD = time - tempLastClickTime fun doAction(name: String, params: Any) {
if (timeD < timeNum) { Log.d("song_test", "event_bus.name = $name")
return false val xBaseEvent = XBaseEvent(name, params)
} XEventService.postEvent(xBaseEvent)
tempLastClickTime = time }
return true
//自定义时间检测
fun isCustomFastClick(timeNum: Long): Boolean {
val time = System.currentTimeMillis()
val timeD = time - currentLastClickTime
if (timeD < timeNum) {
return false
} }
currentLastClickTime = time
//机型判断 return true
fun judgePhone(): Boolean { }
val manufacturer: String = Build.MANUFACTURER
return if (manufacturer.isNotEmpty()) { //备用自定义时间检测
when (manufacturer.toLowerCase(Locale.ROOT)) { fun isCustomFastStatus(timeNum: Long): Boolean {
"oppo" -> true val time = System.currentTimeMillis()
"xiaomi" -> true val timeD = time - tempLastClickTime
else -> false if (timeD < timeNum) {
return false
}
} else false
} }
tempLastClickTime = time
fun getYDEncryptionToken(): String { return true
val temp = StringBuilder() }
//架构组提供的设备指纹
temp.append(AppConfig.appid) //机型判断
Log.d("song_test", "appid = " + AppConfig.appid) fun judgePhone(): Boolean {
temp.append(FtDeviceFingerManager.getDeviceFinger()) val manufacturer: String = Build.MANUFACTURER
Log.d("song_test", "getDeviceFinger = " + FtDeviceFingerManager.getDeviceFinger()) return if (manufacturer.isNotEmpty()) {
when (manufacturer.toLowerCase(Locale.ROOT)) {
return "UMPPTYKO" + MD5Util.md5Encrypt32Upper(temp.toString()) "oppo" -> true
} "xiaomi" -> true
else -> false
fun getDeviceBrandMask(): Int {
val brand = Build.BRAND }
var mask = 64 //0100 0000 } else false
if ("huawei".equals(brand, ignoreCase = true) || "honor".equals(brand, ignoreCase = true)) { }
mask = 32 //0010 0000
} else if ("meizu".equals(brand, ignoreCase = true)) { fun getYDEncryptionToken(): String {
mask = 48 //0011 0000 val temp = StringBuilder()
} else if ("xiaomi".equals(brand, ignoreCase = true)) { //架构组提供的设备指纹
mask = 16 //0001 0000 temp.append(AppConfig.appid)
} else if ("nubia".equals(brand, ignoreCase = true)) { Log.d("song_test", "appid = " + AppConfig.appid)
mask = 80 //0101 0000 temp.append(FtDeviceFingerManager.getDeviceFinger())
} else if ("ZTE".equals(brand, ignoreCase = true)) { Log.d("song_test", "getDeviceFinger = " + FtDeviceFingerManager.getDeviceFinger())
mask = 96 //0110 0000
} else if ("oppo".equals(brand, ignoreCase = true)) { return "UMPPTYKO" + MD5Util.md5Encrypt32Upper(temp.toString())
mask = 112 //0111 0000 }
} else if ("vivo".equals(brand, ignoreCase = true)) {
mask = 128 //0001 0000 0000 fun getDeviceBrandMask(): Int {
} else if ("samsung".equals(brand, ignoreCase = true)) { val brand = Build.BRAND
mask = 144 //0001 0001 0000 var mask = 64 //0100 0000
} if ("huawei".equals(brand, ignoreCase = true) || "honor".equals(brand, ignoreCase = true)) {
return mask mask = 32 //0010 0000
} else if ("meizu".equals(brand, ignoreCase = true)) {
mask = 48 //0011 0000
} else if ("xiaomi".equals(brand, ignoreCase = true)) {
mask = 16 //0001 0000
} else if ("nubia".equals(brand, ignoreCase = true)) {
mask = 80 //0101 0000
} else if ("ZTE".equals(brand, ignoreCase = true)) {
mask = 96 //0110 0000
} else if ("oppo".equals(brand, ignoreCase = true)) {
mask = 112 //0111 0000
} else if ("vivo".equals(brand, ignoreCase = true)) {
mask = 128 //0001 0000 0000
} else if ("samsung".equals(brand, ignoreCase = true)) {
mask = 144 //0001 0001 0000
} }
return mask
fun saveImage(bitmap: Bitmap, name: String, context: Context):Boolean { }
try {
val sdcardPath = System.getenv("EXTERNAL_STORAGE") fun saveImage(bitmap: Bitmap, name: String, context: Context): Boolean {
val dir = "$sdcardPath/life_circle_business/" try {
val file = File(dir) val sdcardPath = System.getenv("EXTERNAL_STORAGE")
if (!file.exists()){ val dir = "$sdcardPath/life_circle_business/"
file.mkdirs() val file = File(dir)
} if (!file.exists()) {
file.mkdirs()
val mFile = File(dir + name) }
if (mFile.exists()) { val mFile = File(dir + name)
Toast.makeText(context, "该图片已存在!", Toast.LENGTH_SHORT).show();
return false; if (mFile.exists()) {
} Toast.makeText(context, "该图片已存在!", Toast.LENGTH_SHORT).show();
return false;
val outputStream = FileOutputStream(mFile) }
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
val uri: Uri = Uri.fromFile(mFile) val outputStream = FileOutputStream(mFile)
context.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri)) bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
return true val uri: Uri = Uri.fromFile(mFile)
} catch (e: FileNotFoundException) { context.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri))
e.printStackTrace() return true
} } catch (e: FileNotFoundException) {
return false e.printStackTrace()
} }
return false
}
fun randomName(): String { fun randomName(): String {
val randomNum = (Math.random() * 1000).toInt() val randomNum = (Math.random() * 1000).toInt()
return "lifeCircle$randomNum" return "lifeCircle$randomNum"
} }
} }
\ No newline at end of file
package com.yidian.common.wxapi
import com.umeng.socialize.weixin.view.WXCallbackActivity
class WXEntryActivity : WXCallbackActivity() {
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<paths> <paths>
<external-files-path name="umeng_cache" path="umeng_cache/"/> <!--友盟微信分享SDK 共享路径 -->
<external-files-path name="opensdk_external" path="Images/tmp"/> <external-files-path
<root-path name="opensdk_root" path=""/> name="umeng_cache"
<external-cache-path name="video_cache" path="video_cache/"/> path="umeng_cache/" />
<external-cache-path name="ocr" path="ocr" /> <!-- QQ 官方分享SDK 共享路径 -->
<external-files-path
name="opensdk_external"
path="Images/tmp" />
<root-path
name="opensdk_root"
path="" />
<!-- 新浪微博分享SDK 共享路径-->
<external-files-path
name="share_files"
path="." />
<external-cache-path
name="video_cache"
path="video_cache/" />
<external-cache-path
name="ocr"
path="ocr" />
</paths> </paths>
\ No newline at end of file
...@@ -39,59 +39,12 @@ ...@@ -39,59 +39,12 @@
tools:replace="android:allowBackup,android:label" tools:replace="android:allowBackup,android:label"
tools:targetApi="n"> tools:targetApi="n">
<!-- 以下为友盟分享基本配置信息 start-->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${file_provider}"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"
tools:replace="android:resource" />
</provider>
<uses-library <uses-library
android:name="org.apache.http.legacy" android:name="org.apache.http.legacy"
android:required="false" /> android:required="false" />
<activity
android:name="com.yidian.common.wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
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="tencent101923771" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.umeng.socialize.media.WBShareCallBackActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:windowSoftInputMode="adjustResize" />
<!-- 以上为友盟分享基本配置信息 end-->
<!-- Flutter图片裁剪相册--> <!-- Flutter图片裁剪相册-->
<activity <activity
android:name="com.yalantis.ucrop.UCropActivity" android:name="com.yalantis.ucrop.UCropActivity"
......
...@@ -9,7 +9,9 @@ buildscript { ...@@ -9,7 +9,9 @@ buildscript {
jcenter() jcenter()
mavenCentral() mavenCentral()
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
// 友盟 SDK maven仓库地址
maven { url 'https://repo1.maven.org/maven2/' } maven { url 'https://repo1.maven.org/maven2/' }
// 新浪微博官方分享SDK
maven { url "https://dl.bintray.com/thelasterstar/maven/" } maven { url "https://dl.bintray.com/thelasterstar/maven/" }
} }
dependencies { dependencies {
...@@ -28,7 +30,9 @@ allprojects { ...@@ -28,7 +30,9 @@ allprojects {
jcenter() jcenter()
mavenCentral() mavenCentral()
maven { url "https://www.jitpack.io" } maven { url "https://www.jitpack.io" }
// 友盟 SDK maven仓库地址
maven { url 'https://repo1.maven.org/maven2/' } maven { url 'https://repo1.maven.org/maven2/' }
// 新浪微博官方分享SDK
maven { url "https://dl.bintray.com/thelasterstar/maven/" } maven { url "https://dl.bintray.com/thelasterstar/maven/" }
maven { url "http://dailybuild2.yidian-inc.com:8088/repository/maven-public/" } maven { url "http://dailybuild2.yidian-inc.com:8088/repository/maven-public/" }
} }
......
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