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

register api 调整

上级 c5546371
......@@ -14,6 +14,5 @@ public class AppRegister extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
final IWXAPI api = WXAPIFactory.createWXAPI(context, null);
// 将该app注册到微信
api.registerApp(WechatPluginKeys.appId);
}
}
......@@ -29,7 +29,7 @@ class FluwxPlugin(private var registrar: Registrar) : MethodCallHandler {
if(call.method == WeChatPluginMethods.UNREGISTER_APP){
WeChatPluginHandler.unregisterApp()
WeChatPluginHandler.unregisterApp(call)
result.success(true)
return
}
......
......@@ -6,7 +6,12 @@ package com.jarvan.fluwx.constant;
* 万里飞雪,将穹苍作烘炉,熔万物为白银。
**/
public class WechatPluginKeys {
public static String appId = "";
public static final String ANDROID = "android";
public static final String APP_ID = "appId";
public static final String PLATFORM = "platform";
public static final String RESULT = "result";
public static final String SCENE = "scene";
public static final String SCENE_TIMELINE = "WeChatScene.TIMELINE";
public static final String SCENE_SESSION = "WeChatScene.SESSION";
......@@ -22,7 +27,7 @@ public class WechatPluginKeys {
public static final String PACKAGE = "?package=";
public static final String MESSAGE_EXT ="messageExt";
public static final String MESSAGE_EXT = "messageExt";
public static final String MEDIA_TAG_NAME = "mediaTagName ";
public static final String MESSAGE_ACTION = "messageAction";
}
......@@ -39,12 +39,20 @@ object WeChatPluginHandler {
fun registerApp(call: MethodCall, result: MethodChannel.Result) {
if(!call.argument<Boolean>(WechatPluginKeys.ANDROID)){
return
}
if (wxApi != null) {
result.success(true)
result.success(mapOf(
WechatPluginKeys.PLATFORM to WechatPluginKeys.ANDROID,
WechatPluginKeys.RESULT to true
))
return
}
val appId = call.arguments as String?
val appId:String? = call.argument(WechatPluginKeys.APP_ID)
if (appId.isNullOrBlank()) {
result.error("invalid app id", "are you sure your app id is correct ?", appId)
return
......@@ -53,10 +61,16 @@ object WeChatPluginHandler {
val api = WXAPIFactory.createWXAPI(registrar!!.context().applicationContext, appId)
val registered = api.registerApp(appId)
wxApi = api
result.success(registered)
result.success(mapOf(
WechatPluginKeys.PLATFORM to WechatPluginKeys.ANDROID,
WechatPluginKeys.RESULT to registered
))
}
fun unregisterApp() {
fun unregisterApp(call: MethodCall) {
if(!call.argument<Boolean>(WechatPluginKeys.ANDROID)){
return
}
wxApi?.unregisterApp()
wxApi = null
}
......@@ -317,7 +331,7 @@ object WeChatPluginHandler {
"type" to resp.type,
"errCode" to resp.errCode,
"openId" to resp.openId,
"platform" to "android"
WechatPluginKeys.PLATFORM to "android"
)
channel?.invokeMethod(WeChatPluginMethods.WE_CHAT_RESPONSE, result)
......
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:fluwx/main.dart';
void main() => runApp(new MyApp());
......@@ -16,7 +15,7 @@ class _MyAppState extends State<MyApp> {
void initState() {
super.initState();
// initPlatformState();
Fluwx.registerApp("wxd930ea5d5a258f4f").then((result) {
Fluwx.registerApp(RegisterModel(appId: "wxd930ea5d5a258f4f")).then((result) {
print("succes-->$result");
}, onError: (value) {
print("--->$value");
......
......@@ -3,3 +3,4 @@ export 'src/fluwx.dart';
export 'src/models/wechat_share_models.dart';
export 'src/wechat_scene.dart';
export 'src/wechat_reponse.dart';
export 'src/models/flutter_register_model.dart';
\ No newline at end of file
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:fluwx/src/models/wechat_share_models.dart';
import 'models/flutter_register_model.dart';
import 'models/wechat_share_models.dart';
class Fluwx {
static const Map<Type, String> _shareModelMethodMapper = {
......@@ -20,12 +21,12 @@ class Fluwx {
Stream<Map> get weChatResponseUpdate => _responseStreamController.stream;
static Future registerApp(String appId) async {
return await _channel.invokeMethod("registerApp", appId);
static Future registerApp(RegisterModel model) async {
return await _channel.invokeMethod("registerApp", model.toMap());
}
static Future unregisterApp() async{
return await _channel.invokeMethod("unregisterApp");
static Future unregisterApp(RegisterModel model) async{
return await _channel.invokeMethod("unregisterApp",model.toMap());
}
void listen() {
_channel.setMethodCallHandler(_handler);
......
class RegisterModel {
final String appId;
final bool doIOS;
final bool doAndroid;
RegisterModel({
this.appId,
this.doIOS: true,
this.doAndroid: true});
Map toMap(){
return {
"appId":appId,
"iOS":doIOS,
"android":doAndroid
};
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论