Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
2577031c
提交
2577031c
authored
8月 10, 2018
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wechat plugin android
上级
c3dd00a7
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
127 行增加
和
31 行删除
+127
-31
WechatPlugin.kt
...src/main/kotlin/com/jarvanmo/wechatplugin/WechatPlugin.kt
+23
-24
WeChatPluginMethods.java
...com/jarvanmo/wechatplugin/config/WeChatPluginMethods.java
+5
-2
WeChatPluginHandler.kt
.../com/jarvanmo/wechatplugin/handler/WeChatPluginHandler.kt
+66
-5
wechat_reponse_code.dart
lib/src/wechat_reponse_code.dart
+9
-0
wechat_plugin.dart
lib/wechat_plugin.dart
+24
-0
没有找到文件。
android/src/main/kotlin/com/jarvanmo/wechatplugin/WechatPlugin.kt
浏览文件 @
2577031c
package
com.jarvanmo.wechatplugin
package
com.jarvanmo.wechatplugin
import
com.jarvanmo.wechatplugin.config.WechatPluginMethods
import
com.jarvanmo.wechatplugin.config.WeChatPluginMethods
import
com.jarvanmo.wechatplugin.handler.WechatPluginHandler
import
com.jarvanmo.wechatplugin.handler.WeChatPluginHandler
import
com.tencent.mm.opensdk.openapi.WXAPIFactory
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.PluginRegistry.Registrar
import
io.flutter.plugin.common.PluginRegistry.Registrar
class
WechatPlugin
():
MethodCallHandler
{
class
WechatPlugin
(
private
var
channel
:
MethodChannel
,
private
var
registrar
:
Registrar
)
:
MethodCallHandler
{
companion
object
{
companion
object
{
@JvmStatic
@JvmStatic
fun
registerWith
(
registrar
:
Registrar
):
Unit
{
fun
registerWith
(
registrar
:
Registrar
):
Unit
{
val
channel
=
MethodChannel
(
registrar
.
messenger
(),
"wechat_plugin"
)
val
channel
=
MethodChannel
(
registrar
.
messenger
(),
"wechat_plugin"
)
channel
.
setMethodCallHandler
(
WechatPlugin
())
channel
.
setMethodCallHandler
(
WechatPlugin
(
channel
,
registrar
))
WeChatPluginHandler
.
setMethodChannel
(
channel
)
}
}
}
}
override
fun
onMethodCall
(
call
:
MethodCall
,
result
:
Result
):
Unit
{
override
fun
onMethodCall
(
call
:
MethodCall
,
result
:
Result
):
Unit
{
when
{
WeChatPluginMethods
.
INIT
==
call
.
method
->
{
val
api
=
WXAPIFactory
.
createWXAPI
(
registrar
.
context
().
applicationContext
,
call
.
arguments
as
String
?)
WeChatPluginHandler
.
setWxApi
(
api
)
}
WeChatPluginHandler
.
apiIsNull
()
->
{
result
.
error
(
"config your wxapi first"
,
"config your wxapi first"
,
null
)
return
}
else
->
WeChatPluginHandler
.
handle
(
call
,
result
)
}
if
(
WechatPluginHandler
.
wxApi
==
null
){
result
.
error
(
"config your wxapi first"
,
"config your wxapi first"
,
null
)
return
}
when
(
call
.
method
)
{
WechatPluginMethods
.
SHARE_TEXT
->
{
WechatPluginHandler
.
shareText
(
call
)
}
else
->
{
result
.
notImplemented
()
}
}
}
}
}
}
android/src/main/kotlin/com/jarvanmo/wechatplugin/config/We
c
hatPluginMethods.java
→
android/src/main/kotlin/com/jarvanmo/wechatplugin/config/We
C
hatPluginMethods.java
浏览文件 @
2577031c
...
@@ -5,9 +5,12 @@ package com.jarvanmo.wechatplugin.config;
...
@@ -5,9 +5,12 @@ package com.jarvanmo.wechatplugin.config;
* 冷风如刀,以大地为砧板,视众生为鱼肉。
* 冷风如刀,以大地为砧板,视众生为鱼肉。
* 万里飞雪,将穹苍作烘炉,熔万物为白银。
* 万里飞雪,将穹苍作烘炉,熔万物为白银。
**/
**/
public
class
WechatPluginMethods
{
public
class
WeChatPluginMethods
{
public
static
final
String
INIT
=
"initWeChat"
;
public
static
final
String
WE_CHAT_RESPONSE
=
"onWeChatResponse"
;
public
static
final
String
SHARE_TEXT
=
"shareText"
;
public
static
final
String
SHARE_TEXT
=
"shareText"
;
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_WEBSITE
=
"shareWebsite"
;
...
...
android/src/main/kotlin/com/jarvanmo/wechatplugin/handler/We
c
hatPluginHandler.kt
→
android/src/main/kotlin/com/jarvanmo/wechatplugin/handler/We
C
hatPluginHandler.kt
浏览文件 @
2577031c
package
com.jarvanmo.wechatplugin.handler
package
com.jarvanmo.wechatplugin.handler
import
com.jarvanmo.wechatplugin.config.WeChatPluginMethods
import
com.tencent.mm.opensdk.openapi.IWXAPI
import
com.tencent.mm.opensdk.openapi.IWXAPI
import
com.tencent.mm.opensdk.modelbase.BaseResp
import
com.tencent.mm.opensdk.modelbase.BaseResp
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodCall
...
@@ -7,6 +8,7 @@ import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
...
@@ -7,6 +8,7 @@ import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import
com.jarvanmo.wechatplugin.config.WechatPluginConfig
import
com.jarvanmo.wechatplugin.config.WechatPluginConfig
import
com.tencent.mm.opensdk.modelmsg.WXMediaMessage
import
com.tencent.mm.opensdk.modelmsg.WXMediaMessage
import
com.tencent.mm.opensdk.modelmsg.WXTextObject
import
com.tencent.mm.opensdk.modelmsg.WXTextObject
import
io.flutter.plugin.common.MethodChannel
/***
/***
...
@@ -14,11 +16,34 @@ import com.tencent.mm.opensdk.modelmsg.WXTextObject
...
@@ -14,11 +16,34 @@ import com.tencent.mm.opensdk.modelmsg.WXTextObject
* 冷风如刀,以大地为砧板,视众生为鱼肉。
* 冷风如刀,以大地为砧板,视众生为鱼肉。
* 万里飞雪,将穹苍作烘炉,熔万物为白银。
* 万里飞雪,将穹苍作烘炉,熔万物为白银。
**/
**/
object
We
c
hatPluginHandler
{
object
We
C
hatPluginHandler
{
var
wxApi
:
IWXAPI
?
=
null
private
var
wxApi
:
IWXAPI
?
=
null
private
var
channel
:
MethodChannel
?
=
null
fun
shareText
(
call
:
MethodCall
)
{
fun
apiIsNull
()
=
wxApi
==
null
fun
setMethodChannel
(
channel
:
MethodChannel
)
{
this
.
channel
=
channel
}
fun
setWxApi
(
wxApi
:
IWXAPI
)
{
this
.
wxApi
=
wxApi
}
fun
handle
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
when
(
call
.
method
)
{
WeChatPluginMethods
.
SHARE_TEXT
->
{
shareText
(
call
)
}
else
->
{
result
.
notImplemented
()
}
}
}
private
fun
shareText
(
call
:
MethodCall
)
{
val
textObj
=
WXTextObject
()
val
textObj
=
WXTextObject
()
textObj
.
text
=
call
.
argument
(
WechatPluginConfig
.
TEXT
)
textObj
.
text
=
call
.
argument
(
WechatPluginConfig
.
TEXT
)
...
@@ -34,21 +59,54 @@ object WechatPluginHandler {
...
@@ -34,21 +59,54 @@ object WechatPluginHandler {
}
}
fun
onResp
(
resp
:
BaseResp
)
{
fun
onResp
(
resp
:
BaseResp
)
{
var
result
=
0
var
code
=-
99
// val ERR_OK = 0
// val ERR_COMM = -1
// val ERR_USER_CANCEL = -2
// val ERR_SENT_FAILED = -3
// val ERR_AUTH_DENIED = -4
// val ERR_UNSUPPORT = -5
// val ERR_BAN = -6
when
(
resp
.
errCode
)
{
when
(
resp
.
errCode
)
{
BaseResp
.
ErrCode
.
ERR_OK
->
{
BaseResp
.
ErrCode
.
ERR_OK
->
{
code
=
0
}
BaseResp
.
ErrCode
.
ERR_COMM
->
{
code
=
1
}
}
BaseResp
.
ErrCode
.
ERR_USER_CANCEL
->
{
BaseResp
.
ErrCode
.
ERR_USER_CANCEL
->
{
code
=
2
}
BaseResp
.
ErrCode
.
ERR_SENT_FAILED
->
{
code
=
-
3
}
}
BaseResp
.
ErrCode
.
ERR_AUTH_DENIED
->
{
BaseResp
.
ErrCode
.
ERR_AUTH_DENIED
->
{
code
=
-
4
}
}
BaseResp
.
ErrCode
.
ERR_UNSUPPORT
->
{
BaseResp
.
ErrCode
.
ERR_UNSUPPORT
->
{
code
=
-
5
}
}
else
->
{
else
->
{
}
}
}
}
val
result
=
mapOf
(
"errStr"
to
resp
.
errStr
,
"transaction"
to
resp
.
transaction
,
"type"
to
resp
.
type
,
"errCode"
to
code
,
"openId"
to
resp
.
openId
)
channel
?.
invokeMethod
(
WeChatPluginMethods
.
WE_CHAT_RESPONSE
,
result
)
}
}
private
fun
getScene
(
value
:
String
)
=
when
(
value
)
{
private
fun
getScene
(
value
:
String
)
=
when
(
value
)
{
...
@@ -58,4 +116,6 @@ object WechatPluginHandler {
...
@@ -58,4 +116,6 @@ object WechatPluginHandler {
else
->
SendMessageToWX
.
Req
.
WXSceneTimeline
else
->
SendMessageToWX
.
Req
.
WXSceneTimeline
}
}
}
}
\ No newline at end of file
lib/src/wechat_reponse_code.dart
0 → 100644
浏览文件 @
2577031c
class
WeChatResponseCode
{
static
const
int
ERR_OK
=
0
;
static
const
int
ERR_COMM
=
-
1
;
static
const
int
ERR_USER_CANCEL
=
-
2
;
static
const
int
ERR_SENT_FAILED
=
-
3
;
static
const
int
ERR_AUTH_DENIED
=
-
4
;
static
const
int
ERR_UNSUPPORTED
=
-
5
;
static
const
int
ERR_BAN
=
-
6
;
}
lib/wechat_plugin.dart
浏览文件 @
2577031c
...
@@ -7,6 +7,21 @@ class WechatPlugin {
...
@@ -7,6 +7,21 @@ class WechatPlugin {
static
const
MethodChannel
_channel
=
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'wechat_plugin'
);
const
MethodChannel
(
'wechat_plugin'
);
static
StreamController
<
Map
>
_responseStreamController
=
new
StreamController
.
broadcast
();
static
Stream
<
Map
>
get
weChatResponseUpdate
=>
_responseStreamController
.
stream
;
static
Future
<
int
>
init
(
String
appId
)
async
{
return
await
_channel
.
invokeMethod
(
"initWeChat"
);
}
static
void
listen
(){
_channel
.
setMethodCallHandler
(
_handler
);
}
static
void
dispose
(){
_responseStreamController
.
close
();
}
static
Future
<
String
>
get
platformVersion
async
{
static
Future
<
String
>
get
platformVersion
async
{
final
String
version
=
await
_channel
.
invokeMethod
(
'getPlatformVersion'
);
final
String
version
=
await
_channel
.
invokeMethod
(
'getPlatformVersion'
);
return
version
;
return
version
;
...
@@ -15,4 +30,13 @@ class WechatPlugin {
...
@@ -15,4 +30,13 @@ class WechatPlugin {
static
Future
shareText
(
WeChatShareTextModel
model
)
async
{
static
Future
shareText
(
WeChatShareTextModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"shareText"
,
model
.
toMap
());
return
await
_channel
.
invokeMethod
(
"shareText"
,
model
.
toMap
());
}
}
static
Future
<
dynamic
>
_handler
(
MethodCall
methodCall
){
if
(
"onWeChatResponse"
==
methodCall
.
method
){
_responseStreamController
.
add
(
methodCall
.
arguments
);
}
return
Future
.
value
(
true
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论