提交 ff367cf4 authored 作者: JarvanMo's avatar JarvanMo

support OpenCustomerServiceChat on android

上级 1b7ff6e9
......@@ -16,6 +16,10 @@ import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat
/** FluwxPlugin */
class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegistry.NewIntentListener {
......@@ -79,6 +83,7 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
call.method.startsWith("share") -> shareHandler?.share(call, result)
call.method == "isWeChatInstalled" -> WXAPiHandler.checkWeChatInstallation(result)
call.method == "getExtMsg" -> getExtMsg(result)
call.method == "openWeChatCustomerServiceChat" -> openWeChatCustomerServiceChat(call, result)
else -> result.notImplemented()
}
}
......@@ -145,6 +150,16 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
result.success(WXAPiHandler.wxApi?.sendReq(request))
}
private fun openWeChatCustomerServiceChat(call: MethodCall, result: Result) {
val url = call.argument<String>("url") ?: ""
val corpId = call.argument<String>("corpId") ?: ""
val request = WXOpenCustomerServiceChat.Req()
request.corpId = corpId // 企业ID
request.url = url
result.success(WXAPiHandler.wxApi?.sendReq(request))
}
private fun signAutoDeduct(call: MethodCall, result: Result) {
val appId: String = call.argument<String>("appid") ?: ""
val mchId = call.argument<String>("mch_id") ?: ""
......
......@@ -88,7 +88,7 @@ object FluwxRequestHandler {
fun onReq(baseReq: BaseReq, activity: Activity) {
try {
val packageManager = activity.packageManager
var appInfo = packageManager.getApplicationInfo(activity.packageName, PackageManager.GET_META_DATA)
val appInfo = packageManager.getApplicationInfo(activity.packageName, PackageManager.GET_META_DATA)
val defaultHandle = appInfo.metaData.getBoolean("handleWeChatRequestByFluwx", true)
if (defaultHandle) {
defaultOnReqDelegate(baseReq, activity)
......
......@@ -20,6 +20,7 @@ import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.modelbiz.SubscribeMessage
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
import com.tencent.mm.opensdk.modelbiz.WXOpenBusinessWebview
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat
import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import com.tencent.mm.opensdk.modelpay.PayResp
......@@ -40,6 +41,7 @@ object FluwxResponseHandler {
is WXLaunchMiniProgram.Resp -> handleLaunchMiniProgramResponse(response)
is SubscribeMessage.Resp -> handleSubscribeMessage(response)
is WXOpenBusinessWebview.Resp -> handlerWXOpenBusinessWebviewResponse(response)
is WXOpenCustomerServiceChat.Resp -> handlerWXOpenCustomerServiceChatResponse(response)
}
}
......@@ -119,4 +121,14 @@ object FluwxResponseHandler {
FluwxPlugin.callingChannel?.invokeMethod("onWXOpenBusinessWebviewResponse", result)
}
private fun handlerWXOpenCustomerServiceChatResponse(response: WXOpenCustomerServiceChat.Resp) {
val result = mapOf(
errCode to response.errCode,
errStr to response.errStr,
openId to response.openId,
type to response.type)
FluwxPlugin.callingChannel?.invokeMethod("onWXOpenCustomerServiceChatResponse", result)
}
}
\ No newline at end of file
......@@ -4,10 +4,11 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.Bitmap.CompressFormat
import android.graphics.BitmapFactory
import id.zelory.compressor.Compressor
import id.zelory.compressor.constraint.size
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okio.*
import top.zibin.luban.Luban
import java.io.*
import java.io.IOException
import java.util.*
......@@ -22,17 +23,19 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
override suspend fun readByteArray(): ByteArray = image.readByteArray()
override suspend fun compressedByteArray(context: Context, maxSize: Int): ByteArray = withContext(Dispatchers.IO) {
override suspend fun compressedByteArray(context: Context, maxSize: Int): ByteArray =
withContext(Dispatchers.IO) {
val originalByteArray = readByteArray()
if (originalByteArray.isEmpty())
return@withContext originalByteArray
val originFile = inputStreamToFile(ByteArrayInputStream(originalByteArray))
val compressedFile = Luban
.with(context)
.ignoreBy(maxSize)
.setTargetDir(context.cacheDir.absolutePath)
.get(originFile.absolutePath)
if (image.suffix.contains("gif")) {
return@withContext originalByteArray
}
val compressedFile = Compressor.compress(context, originFile) {
size(maxFileSize = maxSize * 1024L)
}
if (compressedFile.length() < maxSize) {
val source = compressedFile.source()
......@@ -67,7 +70,11 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
return bmpToByteArray(result, image.suffix) ?: byteArrayOf()
}
private fun createScaledBitmapWithRatio(bitmap: Bitmap, maxLength: Int, recycle: Boolean): Bitmap? {
private fun createScaledBitmapWithRatio(
bitmap: Bitmap,
maxLength: Int,
recycle: Boolean
): Bitmap? {
var result = bitmap
while (true) {
val ratio = maxLength.toDouble() / result.byteCount
......@@ -88,7 +95,10 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
return result
}
private fun bmpToByteArray(bitmap: Bitmap, suffix: String): ByteArray? { // int bytes = bitmap.getByteCount();
private fun bmpToByteArray(
bitmap: Bitmap,
suffix: String
): ByteArray? { // int bytes = bitmap.getByteCount();
val byteArrayOutputStream = ByteArrayOutputStream()
var format = CompressFormat.PNG
......
......@@ -37,12 +37,12 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
try {
if (!WXAPiHandler.wxApiRegistered) {
var appInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
val appInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
val wechatAppId = appInfo.metaData.getString("weChatAppId")
if (wechatAppId != null ){
WXAPiHandler.setupWxApi(wechatAppId,this)
WXAPiHandler.setCoolBool(true)
Log.d("fluwx","weChatAppId:" + wechatAppId)
Log.d("fluwx","weChatAppId: $wechatAppId")
}else {
Log.e("fluwx","can't load meta-data weChatAppId")
}
......
......@@ -73,7 +73,7 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
......@@ -16,7 +16,7 @@ class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//If you didn't configure WxAPI, add the following code
WXAPiHandler.setupWxApi("wxd930ea5d5a258f4f",this)
// WXAPiHandler.setupWxApi("wxd930ea5d5a258f4f",this)
//Get Ext-Info from Intent.
FluwxRequestHandler.handleRequestInfoFromIntent(intent)
}
......
buildscript {
ext.kotlin_version = '1.4.10'
ext.kotlin_version = '1.5.21'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
......@@ -15,7 +14,6 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
......
......@@ -42,6 +42,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
WeChatQRCodeScannedResponse.fromMap(argument),
"onWXShowMessageFromWX": (Map argument) =>
WeChatShowMessageFromWXRequest.fromMap(argument),
"onWXOpenCustomerServiceChatResponse": (Map argument) =>
WeChatOpenCustomerServiceChatResponse.fromMap(argument),
};
class BaseWeChatResponse {
......@@ -125,6 +127,11 @@ class WeChatPaymentResponse extends BaseWeChatResponse {
super._(map[_errCode], map[_errStr]);
}
class WeChatOpenCustomerServiceChatResponse extends BaseWeChatResponse {
WeChatOpenCustomerServiceChatResponse.fromMap(Map map)
:super._(map[_errCode], map[_errStr]);
}
class WeChatSubscribeMsgResponse extends BaseWeChatResponse {
final String? openid;
final String? templateId;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论