提交 07539a8e authored 作者: JarvanMo's avatar JarvanMo

share video web

上级 c84e51a8
...@@ -41,7 +41,7 @@ android { ...@@ -41,7 +41,7 @@ android {
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+' implementation 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:5.1.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0'
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:0.24.0' // implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:0.24.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.24.0' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.24.0'
......
...@@ -13,7 +13,7 @@ public class WeChatPluginMethods { ...@@ -13,7 +13,7 @@ public class WeChatPluginMethods {
public static final String SHARE_IMAGE = "shareImage"; public static final String SHARE_IMAGE = "shareImage";
public static final String SHARE_MUSIC = "shareMusic"; public static final String SHARE_MUSIC = "shareMusic";
public static final String SHARE_VIDEO ="shareVideo"; public static final String SHARE_VIDEO ="shareVideo";
public static final String SHARE_WEBSITE = "shareWebsite"; public static final String SHARE_WEB_PAGE = "shareWebPage";
public static final String SHARE_MINI_PROGRAM = "shareMiniProgram"; public static final String SHARE_MINI_PROGRAM = "shareMiniProgram";
} }
...@@ -6,7 +6,7 @@ package com.jarvanmo.wechatplugin.constant; ...@@ -6,7 +6,7 @@ package com.jarvanmo.wechatplugin.constant;
* 万里飞雪,将穹苍作烘炉,熔万物为白银。 * 万里飞雪,将穹苍作烘炉,熔万物为白银。
**/ **/
public class WechatPluginKeys { public class WechatPluginKeys {
public static String appId =""; public static String appId = "";
public static final String SCENE = "scene"; public static final String SCENE = "scene";
public static final String TIMELINE = "timeline"; public static final String TIMELINE = "timeline";
public static final String SESSION = "session"; public static final String SESSION = "session";
...@@ -16,8 +16,10 @@ public class WechatPluginKeys { ...@@ -16,8 +16,10 @@ public class WechatPluginKeys {
public static final String TEXT = "text"; public static final String TEXT = "text";
public static final String IMAGE ="image"; public static final String TITLE = "title";
public static final String THUMBNAIL ="thumbnail"; public static final String IMAGE = "image";
public static final String THUMBNAIL = "thumbnail";
public static final String DESCRIPTION = "description";
public static final String PACKAGE = "?package="; public static final String PACKAGE = "?package=";
} }
...@@ -62,6 +62,8 @@ object WeChatPluginHandler { ...@@ -62,6 +62,8 @@ object WeChatPluginHandler {
WeChatPluginMethods.SHARE_MINI_PROGRAM -> shareMiniProgram(call, result) WeChatPluginMethods.SHARE_MINI_PROGRAM -> shareMiniProgram(call, result)
WeChatPluginMethods.SHARE_IMAGE -> shareImage(call, result) WeChatPluginMethods.SHARE_IMAGE -> shareImage(call, result)
WeChatPluginMethods.SHARE_MUSIC -> shareMusic(call,result) WeChatPluginMethods.SHARE_MUSIC -> shareMusic(call,result)
WeChatPluginMethods.SHARE_VIDEO -> shareVideo(call,result)
WeChatPluginMethods.SHARE_WEB_PAGE -> shareVideo(call,result)
else -> { else -> {
result.notImplemented() result.notImplemented()
} }
...@@ -159,6 +161,52 @@ object WeChatPluginHandler { ...@@ -159,6 +161,52 @@ object WeChatPluginHandler {
result.success(true) result.success(true)
} }
private fun shareVideo(call: MethodCall, result: MethodChannel.Result){
val video = WXVideoObject()
val videoUrl :String? = call.argument("videoUrl")
val videoLowBandUrl :String? = call.argument("videoLowBandUrl")
if (videoUrl != null){
video.videoUrl = videoUrl
}else{
video.videoLowBandUrl = videoLowBandUrl
}
val msg = WXMediaMessage()
msg.mediaObject = video
msg.title = call.argument(WechatPluginKeys.TITLE)
msg.description = call.argument(WechatPluginKeys.DESCRIPTION)
val thumbnail:String? = call.argument(WechatPluginKeys.THUMBNAIL)
if(thumbnail != null && thumbnail.isNotBlank()){
msg.thumbData = WeChatThumbnailUtil.thumbnailForCommon(thumbnail,registrar)
}
val req = SendMessageToWX.Req()
setCommonArguments(call, req)
req.message = msg
wxApi?.sendReq(req)
result.success(true)
}
private fun shareWebPage(call: MethodCall, result: MethodChannel.Result){
val webPage = WXWebpageObject()
webPage.webpageUrl = call.argument("webPage")
val msg = WXMediaMessage()
msg.mediaObject = webPage
msg.title = call.argument(WechatPluginKeys.TITLE)
msg.description = call.argument(WechatPluginKeys.DESCRIPTION)
val thumbnail:String? = call.argument(WechatPluginKeys.THUMBNAIL)
if(thumbnail != null && thumbnail.isNotBlank()){
msg.thumbData = WeChatThumbnailUtil.thumbnailForCommon(thumbnail,registrar)
}
val req = SendMessageToWX.Req()
setCommonArguments(call, req)
req.message = msg
wxApi?.sendReq(req)
result.success(true)
}
// private fun createWxImageObject(imagePath:String):WXImageObject?{ // private fun createWxImageObject(imagePath:String):WXImageObject?{
// var imgObj: WXImageObject? = null // var imgObj: WXImageObject? = null
// var imageFile:File? = null // var imageFile:File? = null
......
...@@ -27,8 +27,7 @@ android { ...@@ -27,8 +27,7 @@ android {
} }
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "net.sourceforge.simcpux"
applicationId "com.jarvanmo.wechatpluginexample"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 27 targetSdkVersion 27
versionCode 1 versionCode 1
......
import 'package:flutter/material.dart';
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:wechat_plugin/src/wechat_share_models.dart';
import 'package:wechat_plugin/wechat_plugin.dart'; import 'package:wechat_plugin/wechat_plugin.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
class MyApp extends StatefulWidget { class MyApp extends StatefulWidget {
@override @override
_MyAppState createState() => new _MyAppState(); _MyAppState createState() => new _MyAppState();
} }
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown'; String _platformVersion = 'Unknown';
//wxd930ea5d5a258f4f
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WechatPlugin.init("wxd930ea5d5a258f4f");
initPlatformState(); initPlatformState();
} }
// Platform messages are asynchronous, so we initialize in an async method. // Platform messages are asynchronous, so we initialize in an async method.
...@@ -49,7 +52,14 @@ class _MyAppState extends State<MyApp> { ...@@ -49,7 +52,14 @@ class _MyAppState extends State<MyApp> {
title: const Text('Plugin example app'), title: const Text('Plugin example app'),
), ),
body: new Center( body: new Center(
child: new Text('Running on: $_platformVersion\n'), child: GestureDetector(
onTap:(){
var wx = WechatPlugin();
wx.shareText(WeChatShareTextModel(text: "wq kcg r",
transaction: "xxxx${DateTime.now().millisecondsSinceEpoch}",
));
} ,
child: new Text('Running on: $_platformVersion\n')),
), ),
), ),
); );
......
...@@ -66,7 +66,7 @@ class WeChatShareMiniProgramModel { ...@@ -66,7 +66,7 @@ class WeChatShareMiniProgramModel {
"title": title, "title": title,
"description": description, "description": description,
_transaction: transaction, _transaction: transaction,
_scene: scene, _scene: scene.toString(),
_thumbnail: thumbnail _thumbnail: thumbnail
}; };
} }
...@@ -127,7 +127,77 @@ class WeChatShareMusicModel { ...@@ -127,7 +127,77 @@ class WeChatShareMusicModel {
"musicLowBandUrl":musicLowBandUrl, "musicLowBandUrl":musicLowBandUrl,
_thumbnail: thumbnail, _thumbnail: thumbnail,
_title:title, _title:title,
_description:description,
};
}
}
class WeChatShareVideoModel {
final String transaction;
final WeChatScene scene;
final String videoUrl;
final String videoLowBandUrl;
final String thumbnail;
final String title;
final String description;
WeChatShareVideoModel(
{String transaction,
WeChatScene scene,
this.videoUrl,
this.videoLowBandUrl ,
this.title:"",
this.description:"",
String thumbnail})
: this.transaction = transaction ?? "text",
this.scene = scene ?? WeChatScene.TIMELINE,
this.thumbnail = thumbnail ?? "",
assert(videoUrl != null || videoLowBandUrl != null ),
assert(thumbnail != null);
Map toMap() {
return {
_transaction: transaction,
_scene: scene.toString(),
"videoUrl": videoUrl,
"videoLowBandUrl":videoLowBandUrl,
_thumbnail: thumbnail,
_title:title,
_description:description _description:description
}; };
} }
} }
class WeChatShareWebPageModel {
final String transaction;
final WeChatScene scene;
final String webPage;
final String thumbnail;
final String title;
final String description;
WeChatShareWebPageModel(
{String transaction,
WeChatScene scene,
this.webPage,
this.title:"",
this.description:"",
String thumbnail})
: this.transaction = transaction ?? "text",
this.scene = scene ?? WeChatScene.TIMELINE,
this.thumbnail = thumbnail ?? "",
assert(webPage != null ),
assert(thumbnail != null);
Map toMap() {
return {
_transaction: transaction,
_scene: scene.toString(),
"webPage": webPage,
_thumbnail: thumbnail,
_title:title,
_description:description
};
}
}
\ No newline at end of file
...@@ -4,14 +4,14 @@ import 'package:flutter/services.dart'; ...@@ -4,14 +4,14 @@ import 'package:flutter/services.dart';
import 'package:wechat_plugin/src/wechat_share_models.dart'; import 'package:wechat_plugin/src/wechat_share_models.dart';
class WechatPlugin { class WechatPlugin {
static const MethodChannel _channel = const MethodChannel('wechat_plugin');
static const MethodChannel _channel = const MethodChannel('wechat_plugin');
StreamController<Map> _responseStreamController = new StreamController.broadcast(); StreamController<Map> _responseStreamController = new StreamController.broadcast();
Stream<Map> get weChatResponseUpdate=>_responseStreamController.stream; Stream<Map> get weChatResponseUpdate=>_responseStreamController.stream;
Future<int> init(String appId) async{ static Future<int> init(String appId) async{
return await _channel.invokeMethod("initWeChat"); return await _channel.invokeMethod("initWeChat");
} }
...@@ -23,10 +23,7 @@ class WechatPlugin { ...@@ -23,10 +23,7 @@ class WechatPlugin {
_responseStreamController.close(); _responseStreamController.close();
} }
Future<String> get platformVersion async {
final String version = await _channel.invokeMethod('getPlatformVersion');
return version;
}
Future shareText(WeChatShareTextModel model) async{ Future shareText(WeChatShareTextModel model) async{
await _channel.invokeMethod("shareText",model.toMap()); await _channel.invokeMethod("shareText",model.toMap());
...@@ -41,6 +38,14 @@ class WechatPlugin { ...@@ -41,6 +38,14 @@ class WechatPlugin {
return await _channel.invokeMethod("shareMusic",model.toMap()); return await _channel.invokeMethod("shareMusic",model.toMap());
} }
Future shareVideo(WeChatShareVideoModel model)async{
return await _channel.invokeMethod("shareVideo",model.toMap());
}
Future shareWebPage(WeChatShareWebPageModel model)async{
return await _channel.invokeMethod("shareWebPage",model.toMap());
}
Future<dynamic> _handler(MethodCall methodCall){ Future<dynamic> _handler(MethodCall methodCall){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论