提交 8921699b authored 作者: JarvanMo's avatar JarvanMo

lauch mini program on Android

上级 2b3b15d7
......@@ -24,20 +24,21 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar
class FluwxPlugin(private val registrar: Registrar,private val channel: MethodChannel) : MethodCallHandler {
class FluwxPlugin(private val registrar: Registrar, private val channel: MethodChannel) : MethodCallHandler {
companion object {
@JvmStatic
fun registerWith(registrar: Registrar): Unit {
val channel = MethodChannel(registrar.messenger(), "com.jarvanmo/fluwx")
WXAPiHandler.setRegistrar(registrar)
FluwxResponseHandler.setMethodChannel(channel)
channel.setMethodCallHandler(FluwxPlugin(registrar,channel))
channel.setMethodCallHandler(FluwxPlugin(registrar, channel))
}
}
private val fluwxShareHandler = FluwxShareHandler()
private val fluwxAuthHandler = FluwxAuthHandler()
private val fluwxPayHandler =FluwxPayHandler()
private val fluwxPayHandler = FluwxPayHandler()
private val fluwxLaunchMiniProgramHandler = FluwxLaunchMiniProgramHandler()
init {
fluwxShareHandler.setRegistrar(registrar)
......@@ -72,6 +73,11 @@ class FluwxPlugin(private val registrar: Registrar,private val channel: MethodCh
return
}
if (call.method == WeChatPluginMethods.LAUNCH_MINI_PROGRAM){
fluwxLaunchMiniProgramHandler.launchMiniProgram(call,result)
return
}
if (call.method.startsWith("share")) {
fluwxShareHandler.handle(call, result)
} else {
......
......@@ -9,6 +9,7 @@ public class WeChatPluginMethods {
public static final String REGISTER_APP = "registerApp";
public static final String UNREGISTER_APP = "unregisterApp";
public static final String WE_CHAT_SHARE_RESPONSE = "onShareResponse";
public static final String WE_CHAT_LAUNCHMINIPROGRAM_RESPONSE ="onLaunchMiniProgramResponse";
public static final String IS_WE_CHAT_INSTALLED = "isWeChatInstalled";
......@@ -19,6 +20,7 @@ public class WeChatPluginMethods {
public static final String SHARE_WEB_PAGE = "shareWebPage";
public static final String SHARE_MINI_PROGRAM = "shareMiniProgram";
public static final String LAUNCH_MINI_PROGRAM = "launchMiniProgram";
public static final String PAY = "payWithFluwx";
public static final String WE_CHAT_PAY_RESPONSE = "onPayResponse";
......
package com.jarvan.fluwx.handler
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
internal class FluwxLaunchMiniProgramHandler {
fun launchMiniProgram(call: MethodCall,result: MethodChannel.Result){
val req = WXLaunchMiniProgram.Req()
req.userName = call.argument<String?>("userName") // 填小程序原始id
req.path = call.argument<String?>("path") //拉起小程序页面的可带参路径,不填默认拉起小程序首页
val type = call.argument("miniProgramType")?:0
req.miniprogramType = when(type){
1 -> WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_TEST
2-> WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_PREVIEW
else-> WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE
}// 可选打开 开发版,体验版和正式版
result.success(WXAPiHandler.wxApi?.sendReq(req))
}
}
\ No newline at end of file
......@@ -18,7 +18,6 @@ package com.jarvan.fluwx.handler
import com.jarvan.fluwx.constant.CallResult
import com.jarvan.fluwx.constant.WechatPluginKeys
import com.tencent.mm.opensdk.modelpay.PayReq
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
......
......@@ -18,6 +18,7 @@ package com.jarvan.fluwx.handler
import com.jarvan.fluwx.constant.WeChatPluginMethods
import com.jarvan.fluwx.constant.WechatPluginKeys
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import com.tencent.mm.opensdk.modelpay.PayResp
......@@ -38,15 +39,28 @@ object FluwxResponseHandler {
fun handleResponse(response: BaseResp) {
if (response is SendAuth.Resp) {
handleAuthResponse(response)
} else if (response is SendMessageToWX.Resp) {
handleSendMessageResp(response)
} else if (response is PayResp) {
handlePayResp(response)
when (response) {
is SendAuth.Resp -> handleAuthResponse(response)
is SendMessageToWX.Resp -> handleSendMessageResp(response)
is PayResp -> handlePayResp(response)
is WXLaunchMiniProgram.Resp -> handleLaunchMiniProgramResponse(response)
}
}
private fun handleLaunchMiniProgramResponse(response: WXLaunchMiniProgram.Resp) {
val result = mapOf(
errStr to response.errStr,
WechatPluginKeys.TRANSACTION to response.transaction,
type to response.type,
errCode to response.errCode,
openId to response.openId,
"extMsg" to response.extMsg,
WechatPluginKeys.PLATFORM to WechatPluginKeys.ANDROID
)
channel?.invokeMethod(WeChatPluginMethods.WE_CHAT_LAUNCHMINIPROGRAM_RESPONSE, result)
}
private fun handlePayResp(response: PayResp) {
val result = mapOf(
......
......@@ -25,7 +25,6 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.UI
/***
......
......@@ -83,12 +83,8 @@ class WeChatLaunchMiniProgramResponse {
final int errCode;
final String androidOpenId;
final String iOSDescription;
final String country;
final String lang;
final String code;
final String androidUrl;
final String state;
final String androidTransaction;
final String extMsg;
WeChatLaunchMiniProgramResponse.fromMap(Map map)
: errStr = map["errStr"],
......@@ -96,12 +92,8 @@ class WeChatLaunchMiniProgramResponse {
errCode = map["errCode"],
androidOpenId = map["openId"],
iOSDescription = map["description"],
country = map["country"],
lang = map["lang"],
code = map["code"],
androidUrl = map["url"],
state = map["state"],
androidTransaction = map["transaction"];
androidTransaction = map["transaction"],
extMsg = map["extMsg"];
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论