Commit a4e8a4b1 authored by shiyl's avatar shiyl

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

parent 3f8d4d0c
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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>
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
import android.content.pm.PackageManager
import android.util.Log
/**
* 检查APK是否安装
*/
class CheckApkExistUtil {
companion object{
const val weChatPkgName = "com.tencent.mm"
const val mobileQQPkgName = "com.tencent.mobileqq"
const val sinaBlogPkgName = "com.sina.weibo"
companion object {
const val weChatPkgName = "com.tencent.mm"
const val mobileQQPkgName = "com.tencent.mobileqq"
const val sinaBlogPkgName = "com.sina.weibo"
fun checkApkExist(context: Context, packageName: String): Boolean{
if(packageName.isEmpty()) return false
var packageInfo: ApplicationInfo?
try {
packageInfo = context.packageManager.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES)
}catch (e: PackageManager.NameNotFoundException){
packageInfo = null
}
return packageInfo != null
}
fun checkApkExist(context: Context, packageName: String): Boolean {
if (packageName.isEmpty()) return false
val packageInfo: ApplicationInfo? = try {
context.packageManager.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES)
} catch (e: PackageManager.NameNotFoundException) {
null
}
return packageInfo != null
}
}
\ No newline at end of file
}
}
......@@ -5,41 +5,44 @@ import android.net.ConnectivityManager
import android.telephony.TelephonyManager
class NetWorkUtils {
companion object{
const val NET_TYPE_WIFI = "wifi"
const val NET_TYPE_4G = "4g"
const val NET_TYPE_5G = "5g"
const val NET_TYPE_3G = "3g"
const val NET_TYPE_2G = "2g"
companion object {
private const val NET_TYPE_WIFI = "wifi"
const val NET_TYPE_4G = "4g"
const val NET_TYPE_5G = "5g"
const val NET_TYPE_3G = "3g"
const val NET_TYPE_2G = "2g"
fun getNetWorkType(context: Context): String{
var netType = "unknown"
val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = manager.activeNetworkInfo ?: return netType
val nType = networkInfo.type
if (nType == ConnectivityManager.TYPE_WIFI) {
netType = "wifi"
} else if (nType == ConnectivityManager.TYPE_MOBILE) {
val nSubType = networkInfo.subtype
val telephonyManager: TelephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
netType = if(nSubType ==TelephonyManager.NETWORK_TYPE_NR){
"5g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_LTE && !telephonyManager.isNetworkRoaming) {
"4g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA || (nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
&& !telephonyManager.isNetworkRoaming)) {
"3g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS || nSubType == TelephonyManager.NETWORK_TYPE_EDGE || (nSubType == TelephonyManager.NETWORK_TYPE_CDMA
&& !telephonyManager.isNetworkRoaming)) {
"2g"
} else {
"unknown"
}
}
return netType
}
fun isWifiConnected(context: Context):Boolean{
return NET_TYPE_WIFI == getNetWorkType(context)
fun getNetWorkType(context: Context): String {
var netType = "unknown"
val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = manager.activeNetworkInfo ?: return netType
val nType = networkInfo.type
if (nType == ConnectivityManager.TYPE_WIFI) {
netType = "wifi"
} else if (nType == ConnectivityManager.TYPE_MOBILE) {
val nSubType = networkInfo.subtype
val telephonyManager: TelephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
netType = if (nSubType == TelephonyManager.NETWORK_TYPE_NR) {
"5g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_LTE && !telephonyManager.isNetworkRoaming) {
"4g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA || (nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
&& !telephonyManager.isNetworkRoaming)
) {
"3g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS || nSubType == TelephonyManager.NETWORK_TYPE_EDGE || (nSubType == TelephonyManager.NETWORK_TYPE_CDMA
&& !telephonyManager.isNetworkRoaming)
) {
"2g"
} else {
"unknown"
}
}
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.*
object ToolsUtil {
//防止连续点击
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()
}
//防止连续点击
private var lastClickTime: Long = 0
fun dp2px(dpValue: Float): Int {
return TypedValue.applyDimension(1, dpValue, DisplayMetrics()).toInt()
}
//自定义快速点击时间
private var currentLastClickTime: Long = 0
//格式化展示
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
}
//备用自定义快速点击时间
private var tempLastClickTime: Long = 0
//event事件
fun doAction(name: String, params: Any) {
Log.d("song_test", "event_bus.name = $name")
val xBaseEvent = XBaseEvent(name, params)
XEventService.postEvent(xBaseEvent)
//快速点击检测
val isFastClick: Boolean
get() {
val time = System.currentTimeMillis()
val timeD = time - lastClickTime
if (timeD < 500) {
return false
}
lastClickTime = 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 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()
}
//格式化展示
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") + "亿"
}
}
//备用自定义时间检测
fun isCustomFastStatus(timeNum: Long): Boolean {
val time = System.currentTimeMillis()
val timeD = time - tempLastClickTime
if (timeD < timeNum) {
return false
}
tempLastClickTime = time
return true
return showCount
}
//event事件
fun doAction(name: String, params: Any) {
Log.d("song_test", "event_bus.name = $name")
val xBaseEvent = XBaseEvent(name, params)
XEventService.postEvent(xBaseEvent)
}
//自定义时间检测
fun isCustomFastClick(timeNum: Long): Boolean {
val time = System.currentTimeMillis()
val timeD = time - currentLastClickTime
if (timeD < timeNum) {
return false
}
//机型判断
fun judgePhone(): Boolean {
val manufacturer: String = Build.MANUFACTURER
return if (manufacturer.isNotEmpty()) {
when (manufacturer.toLowerCase(Locale.ROOT)) {
"oppo" -> true
"xiaomi" -> true
else -> false
}
} else false
currentLastClickTime = time
return true
}
//备用自定义时间检测
fun isCustomFastStatus(timeNum: Long): Boolean {
val time = System.currentTimeMillis()
val timeD = time - tempLastClickTime
if (timeD < timeNum) {
return false
}
fun getYDEncryptionToken(): String {
val temp = StringBuilder()
//架构组提供的设备指纹
temp.append(AppConfig.appid)
Log.d("song_test", "appid = " + AppConfig.appid)
temp.append(FtDeviceFingerManager.getDeviceFinger())
Log.d("song_test", "getDeviceFinger = " + FtDeviceFingerManager.getDeviceFinger())
return "UMPPTYKO" + MD5Util.md5Encrypt32Upper(temp.toString())
}
fun getDeviceBrandMask(): Int {
val brand = Build.BRAND
var mask = 64 //0100 0000
if ("huawei".equals(brand, ignoreCase = true) || "honor".equals(brand, ignoreCase = true)) {
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
tempLastClickTime = time
return true
}
//机型判断
fun judgePhone(): Boolean {
val manufacturer: String = Build.MANUFACTURER
return if (manufacturer.isNotEmpty()) {
when (manufacturer.toLowerCase(Locale.ROOT)) {
"oppo" -> true
"xiaomi" -> true
else -> false
}
} else false
}
fun getYDEncryptionToken(): String {
val temp = StringBuilder()
//架构组提供的设备指纹
temp.append(AppConfig.appid)
Log.d("song_test", "appid = " + AppConfig.appid)
temp.append(FtDeviceFingerManager.getDeviceFinger())
Log.d("song_test", "getDeviceFinger = " + FtDeviceFingerManager.getDeviceFinger())
return "UMPPTYKO" + MD5Util.md5Encrypt32Upper(temp.toString())
}
fun getDeviceBrandMask(): Int {
val brand = Build.BRAND
var mask = 64 //0100 0000
if ("huawei".equals(brand, ignoreCase = true) || "honor".equals(brand, ignoreCase = true)) {
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
}
fun saveImage(bitmap: Bitmap, name: String, context: Context):Boolean {
try {
val sdcardPath = System.getenv("EXTERNAL_STORAGE")
val dir = "$sdcardPath/life_circle_business/"
val file = File(dir)
if (!file.exists()){
file.mkdirs()
}
val mFile = File(dir + name)
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)
context.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri))
return true
} catch (e: FileNotFoundException) {
e.printStackTrace()
}
return false
return mask
}
fun saveImage(bitmap: Bitmap, name: String, context: Context): Boolean {
try {
val sdcardPath = System.getenv("EXTERNAL_STORAGE")
val dir = "$sdcardPath/life_circle_business/"
val file = File(dir)
if (!file.exists()) {
file.mkdirs()
}
val mFile = File(dir + name)
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)
context.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri))
return true
} catch (e: FileNotFoundException) {
e.printStackTrace()
}
return false
}
fun randomName(): String {
val randomNum = (Math.random() * 1000).toInt()
return "lifeCircle$randomNum"
}
fun randomName(): String {
val randomNum = (Math.random() * 1000).toInt()
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"?>
<paths>
<external-files-path name="umeng_cache" path="umeng_cache/"/>
<external-files-path name="opensdk_external" path="Images/tmp"/>
<root-path name="opensdk_root" path=""/>
<external-cache-path name="video_cache" path="video_cache/"/>
<external-cache-path name="ocr" path="ocr" />
<!--友盟微信分享SDK 共享路径 -->
<external-files-path
name="umeng_cache"
path="umeng_cache/" />
<!-- 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>
\ No newline at end of file
......@@ -39,59 +39,12 @@
tools:replace="android:allowBackup,android:label"
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
android:name="org.apache.http.legacy"
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图片裁剪相册-->
<activity
android:name="com.yalantis.ucrop.UCropActivity"
......
......@@ -9,7 +9,9 @@ buildscript {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
// 友盟 SDK maven仓库地址
maven { url 'https://repo1.maven.org/maven2/' }
// 新浪微博官方分享SDK
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
dependencies {
......@@ -28,7 +30,9 @@ allprojects {
jcenter()
mavenCentral()
maven { url "https://www.jitpack.io" }
// 友盟 SDK maven仓库地址
maven { url 'https://repo1.maven.org/maven2/' }
// 新浪微博官方分享SDK
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
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