Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
07539a8e
提交
07539a8e
authored
8月 14, 2018
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
share video web
上级
c84e51a8
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
153 行增加
和
18 行删除
+153
-18
build.gradle
android/build.gradle
+1
-1
WeChatPluginMethods.java
...m/jarvanmo/wechatplugin/constant/WeChatPluginMethods.java
+1
-1
WechatPluginKeys.java
.../com/jarvanmo/wechatplugin/constant/WechatPluginKeys.java
+5
-3
WeChatPluginHandler.kt
.../com/jarvanmo/wechatplugin/handler/WeChatPluginHandler.kt
+48
-0
build.gradle
example/android/app/build.gradle
+1
-2
main.dart
example/lib/main.dart
+14
-4
wechat_share_models.dart
lib/src/wechat_share_models.dart
+72
-1
wechat_plugin.dart
lib/wechat_plugin.dart
+11
-6
没有找到文件。
android/build.gradle
浏览文件 @
07539a8e
...
@@ -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'
...
...
android/src/main/kotlin/com/jarvanmo/wechatplugin/constant/WeChatPluginMethods.java
浏览文件 @
07539a8e
...
@@ -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_WEB
SITE
=
"shareWebsit
e"
;
public
static
final
String
SHARE_WEB
_PAGE
=
"shareWebPag
e"
;
public
static
final
String
SHARE_MINI_PROGRAM
=
"shareMiniProgram"
;
public
static
final
String
SHARE_MINI_PROGRAM
=
"shareMiniProgram"
;
}
}
android/src/main/kotlin/com/jarvanmo/wechatplugin/constant/WechatPluginKeys.java
浏览文件 @
07539a8e
...
@@ -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="
;
}
}
android/src/main/kotlin/com/jarvanmo/wechatplugin/handler/WeChatPluginHandler.kt
浏览文件 @
07539a8e
...
@@ -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
...
...
example/android/app/build.gradle
浏览文件 @
07539a8e
...
@@ -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
...
...
example/lib/main.dart
浏览文件 @
07539a8e
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
'
)),
),
),
),
),
);
);
...
...
lib/src/wechat_share_models.dart
浏览文件 @
07539a8e
...
@@ -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
lib/wechat_plugin.dart
浏览文件 @
07539a8e
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论