提交 3cd11b5f authored 作者: JarvanMo's avatar JarvanMo

share mini program

上级 4a9ff87c
......@@ -14,5 +14,6 @@ public class WeChatPluginMethods {
public static final String SHARE_MUSIC = "shareMusic";
public static final String SHARE_VIDEO ="shareVideo";
public static final String SHARE_WEBSITE = "shareWebsite";
public static final String SHARE_MINI_PROGRAM = "shareMiniProgram";
}
package com.jarvanmo.wechatplugin.handler
import com.jarvanmo.wechatplugin.config.WeChatPluginMethods
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.jarvanmo.wechatplugin.config.WechatPluginConfig
import com.tencent.mm.opensdk.modelbase.BaseResp
import io.flutter.plugin.common.MethodCall
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import com.jarvanmo.wechatplugin.config.WechatPluginConfig
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage
import com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject
import com.tencent.mm.opensdk.modelmsg.WXTextObject
import com.tencent.mm.opensdk.openapi.IWXAPI
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
......@@ -34,9 +35,8 @@ object WeChatPluginHandler {
fun handle(call: MethodCall, result: MethodChannel.Result) {
when (call.method) {
WeChatPluginMethods.SHARE_TEXT -> {
shareText(call)
}
WeChatPluginMethods.SHARE_TEXT -> shareText(call)
WeChatPluginMethods.SHARE_MINI_PROGRAM -> shareMiniProgram(call)
else -> {
result.notImplemented()
}
......@@ -58,45 +58,37 @@ object WeChatPluginHandler {
}
fun onResp(resp: BaseResp) {
var code =-99
when (resp.errCode) {
BaseResp.ErrCode.ERR_OK -> {
code = 0
}
BaseResp.ErrCode.ERR_COMM -> {
code = 1
}
BaseResp.ErrCode.ERR_USER_CANCEL -> {
code = 2
}
BaseResp.ErrCode.ERR_SENT_FAILED -> {
code = -3
}
BaseResp.ErrCode.ERR_AUTH_DENIED -> {
code = -4
}
BaseResp.ErrCode.ERR_UNSUPPORT -> {
code = -5
}
private fun shareMiniProgram(call: MethodCall){
val miniProgramObj = WXMiniProgramObject()
miniProgramObj.webpageUrl = call.argument("webPageUrl") // 兼容低版本的网页链接
miniProgramObj.miniprogramType = call.argument("miniProgramType")// 正式版:0,测试版:1,体验版:2
miniProgramObj.userName = call.argument("userName") // 小程序原始id
miniProgramObj.path = call.argument("path") //小程序页面路径
val msg = WXMediaMessage(miniProgramObj)
msg.title = call.argument("title") // 小程序消息title
msg.description = call.argument("description") // 小程序消息desc
// msg.thumbData = getThumb() // 小程序消息封面图片,小于128k
else -> {
}
}
val req = SendMessageToWX.Req()
req.transaction = call.argument("transaction")
req.message = msg
req.scene = call.argument("scene") // 目前支持会话
wxApi.sendReq(req)
}
fun onResp(resp: BaseResp) {
val result = mapOf(
"errStr" to resp.errStr,
"transaction" to resp.transaction,
"type" to resp.type,
"errCode" to code,
"errCode" to resp.errCode,
"openId" to resp.openId
)
channel?.invokeMethod(WeChatPluginMethods.WE_CHAT_RESPONSE, result)
}
......
import 'package:wechat_plugin/src/wechat_scene.dart';
class WeChatShareTextModel{
class WeChatShareTextModel {
final String text;
final String transaction;
final WeChatScene scene;
final WeChatScene scene;
WeChatShareTextModel({
String text,
String transaction,
WeChatScene scene}):
this.text = text??"",
this.transaction = transaction??"text",
WeChatShareTextModel({String text, String transaction, WeChatScene scene})
: this.text = text ?? "",
this.transaction = transaction ?? "text",
this.scene = scene ?? WeChatScene.TIMELINE;
Map toMap() {
return {
"text": text,
"transaction": transaction,
"scene": scene.toString()
};
}
}
class WeChatMiniProgramModel {
static const int MINI_PTOGRAM_TYPE_RELEASE = 0;
static const int MINI_PROGRAM_TYPE_TEST = 1;
static const int MINI_PROGRAM_TYPE_PREVIEW = 2;
final WeChatScene scene = WeChatScene.SESSION;
final String webPageUrl;
final int miniProgramType;
final String userName;
final String path;
final String title;
final String description;
final String transaction;
final String thumbnail;
WeChatMiniProgramModel(
{this.webPageUrl,
int miniProgramType,
this.userName,
this.path,
this.title,
this.description,
this.thumbnail,
String transaction})
: this.transaction = transaction ?? "miniProgram",
this.miniProgramType = miniProgramType??MINI_PTOGRAM_TYPE_RELEASE,
assert(webPageUrl != null && webPageUrl.isNotEmpty),
assert(userName != null && userName.isNotEmpty) ,
assert(path != null && path.isNotEmpty );
Map toMap(){
return {"text":text,"transaction":transaction,"scene":scene.toString()};
return {
'webPageUrl':webPageUrl,
"miniProgramType":miniProgramType,
"userName":userName,
"path":path,
"title":title,
"description":description,
"transaction":transaction,
"scene":scene,
"thumbnail":thumbnail
};
}
}
\ No newline at end of file
}
......@@ -31,6 +31,12 @@ class WechatPlugin {
return await _channel.invokeMethod("shareText",model.toMap());
}
static Future shareMiniProgram(WeChatMiniProgramModel model)async{
return await _channel.invokeMethod("shareMiniProgram",model.toMap());
}
static Future<dynamic> _handler(MethodCall methodCall){
if("onWeChatResponse" == methodCall.method){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论