Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
a0ff9a14
提交
a0ff9a14
authored
3月 09, 2020
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
capality: auth by qrCode
上级
c0efd481
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
105 行增加
和
14 行删除
+105
-14
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+1
-0
FluwxAuthHandler.kt
...main/kotlin/com/jarvan/fluwx/handlers/FluwxAuthHandler.kt
+2
-6
FluwxAuthHandler.m
ios/Classes/FluwxAuthHandler.m
+6
-8
fluwx_iml.dart
lib/src/fluwx_iml.dart
+34
-0
wechat_response.dart
lib/src/response/wechat_response.dart
+62
-0
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
a0ff9a14
...
@@ -63,6 +63,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
...
@@ -63,6 +63,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
override
fun
onDetachedFromEngine
(
@NonNull
binding
:
FlutterPlugin
.
FlutterPluginBinding
)
{
override
fun
onDetachedFromEngine
(
@NonNull
binding
:
FlutterPlugin
.
FlutterPluginBinding
)
{
shareHandler
?.
onDestroy
()
shareHandler
?.
onDestroy
()
authHandler
?.
removeAllListeners
()
}
}
override
fun
onDetachedFromActivity
()
{
override
fun
onDetachedFromActivity
()
{
...
...
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxAuthHandler.kt
浏览文件 @
a0ff9a14
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
*/
*/
package
com.jarvan.fluwx.handlers
package
com.jarvan.fluwx.handlers
import
com.tencent.mm.opensdk.diffdev.DiffDevOAuthFactory
import
com.tencent.mm.opensdk.diffdev.DiffDevOAuthFactory
import
com.tencent.mm.opensdk.diffdev.OAuthErrCode
import
com.tencent.mm.opensdk.diffdev.OAuthErrCode
import
com.tencent.mm.opensdk.diffdev.OAuthListener
import
com.tencent.mm.opensdk.diffdev.OAuthListener
...
@@ -39,11 +38,11 @@ internal class FluwxAuthHandler(private val methodChannel: MethodChannel) {
...
@@ -39,11 +38,11 @@ internal class FluwxAuthHandler(private val methodChannel: MethodChannel) {
}
}
override
fun
onAuthGotQrcode
(
p0
:
String
?,
p1
:
ByteArray
)
{
override
fun
onAuthGotQrcode
(
p0
:
String
?,
p1
:
ByteArray
)
{
methodChannel
.
invokeMethod
(
"onAuthGotQRCode"
,
p1
)
methodChannel
.
invokeMethod
(
"onAuthGotQRCode"
,
mapOf
(
"errCode"
to
0
,
"qrCode"
to
p1
)
)
}
}
override
fun
onQrcodeScanned
()
{
override
fun
onQrcodeScanned
()
{
methodChannel
.
invokeMethod
(
"onQRCodeScanned"
,
null
)
methodChannel
.
invokeMethod
(
"onQRCodeScanned"
,
mapOf
(
"errCode"
to
0
)
)
}
}
}
}
...
@@ -59,7 +58,6 @@ internal class FluwxAuthHandler(private val methodChannel: MethodChannel) {
...
@@ -59,7 +58,6 @@ internal class FluwxAuthHandler(private val methodChannel: MethodChannel) {
req
.
openId
=
call
.
argument
(
"openId"
)
req
.
openId
=
call
.
argument
(
"openId"
)
}
}
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
req
))
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
req
))
}
}
...
@@ -82,5 +80,4 @@ internal class FluwxAuthHandler(private val methodChannel: MethodChannel) {
...
@@ -82,5 +80,4 @@ internal class FluwxAuthHandler(private val methodChannel: MethodChannel) {
fun
removeAllListeners
()
{
fun
removeAllListeners
()
{
qrCodeAuth
.
removeAllListeners
()
qrCodeAuth
.
removeAllListeners
()
}
}
}
}
\ No newline at end of file
ios/Classes/FluwxAuthHandler.m
浏览文件 @
a0ff9a14
...
@@ -4,11 +4,7 @@
...
@@ -4,11 +4,7 @@
#import "FluwxAuthHandler.h"
#import "FluwxAuthHandler.h"
#import "WXApi.h"
#import "WechatAuthSDK.h"
#import "FluwxPlugin.h"
#import "WXApiRequestHandler.h"
#import "WechatAuthSDK.h"
@implementation
FluwxAuthHandler
@implementation
FluwxAuthHandler
WechatAuthSDK
*
_qrauth
;
WechatAuthSDK
*
_qrauth
;
...
@@ -30,7 +26,9 @@ FlutterMethodChannel *_fluwxMethodChannel = nil;
...
@@ -30,7 +26,9 @@ FlutterMethodChannel *_fluwxMethodChannel = nil;
[
WXApiRequestHandler
sendAuthRequestScope
:
call
.
arguments
[
@"scope"
]
[
WXApiRequestHandler
sendAuthRequestScope
:
call
.
arguments
[
@"scope"
]
State
:(
call
.
arguments
[
@"state"
]
==
(
id
)
[
NSNull
null
])
?
nil
:
call
.
arguments
[
@"state"
]
State
:(
call
.
arguments
[
@"state"
]
==
(
id
)
[
NSNull
null
])
?
nil
:
call
.
arguments
[
@"state"
]
OpenID:
(
openId
==
(
id
)
[
NSNull
null
])
?
nil
:
openId
completion
:^
(
BOOL
done
)
{
result
(
@
(
done
));}];
OpenID:
(
openId
==
(
id
)
[
NSNull
null
])
?
nil
:
openId
completion
:^
(
BOOL
done
)
{
result
(
@
(
done
));
}];
}
}
-
(
void
)
authByQRCode
:(
FlutterMethodCall
*
)
call
result
:(
FlutterResult
)
result
{
-
(
void
)
authByQRCode
:(
FlutterMethodCall
*
)
call
result
:(
FlutterResult
)
result
{
...
@@ -51,7 +49,7 @@ FlutterMethodChannel *_fluwxMethodChannel = nil;
...
@@ -51,7 +49,7 @@ FlutterMethodChannel *_fluwxMethodChannel = nil;
}
}
-
(
void
)
onQrcodeScanned
{
-
(
void
)
onQrcodeScanned
{
[
_fluwxMethodChannel
invokeMethod
:
@"onQRCodeScanned"
arguments
:
nil
];
[
_fluwxMethodChannel
invokeMethod
:
@"onQRCodeScanned"
arguments
:
@{
@"errCode"
:
@0
}
];
}
}
-
(
void
)
onAuthGotQrcode
:
(
UIImage
*
)
image
{
-
(
void
)
onAuthGotQrcode
:
(
UIImage
*
)
image
{
...
@@ -60,7 +58,7 @@ FlutterMethodChannel *_fluwxMethodChannel = nil;
...
@@ -60,7 +58,7 @@ FlutterMethodChannel *_fluwxMethodChannel = nil;
// imageData = UIImageJPEGRepresentation(image, 1);
// imageData = UIImageJPEGRepresentation(image, 1);
// }
// }
[
_fluwxMethodChannel
invokeMethod
:
@"onAuthGotQRCode"
arguments
:
imageData
];
[
_fluwxMethodChannel
invokeMethod
:
@"onAuthGotQRCode"
arguments
:
@{
@"errCode"
:
@0
,
@"qrCode"
:
imageData
}
];
}
}
-
(
void
)
onAuthFinish
:
(
int
)
errCode
AuthCode
:
(
nullable
NSString
*
)
authCode
{
-
(
void
)
onAuthFinish
:
(
int
)
errCode
AuthCode
:
(
nullable
NSString
*
)
authCode
{
...
...
lib/src/fluwx_iml.dart
浏览文件 @
a0ff9a14
...
@@ -194,6 +194,40 @@ Future<bool> autoDeDuctWeChat(
...
@@ -194,6 +194,40 @@ Future<bool> autoDeDuctWeChat(
});
});
}
}
/// Sometimes WeChat is not installed on users's devices.However we can
/// request a QRCode so that we can get AuthCode by scanning the QRCode
/// All required params must not be null or empty
/// [schemeData] only works on iOS
/// see * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=215238808828h4XN&token=&lang=zh_CN
Future
<
bool
>
authWeChatByQRCode
(
{
@required
String
appId
,
@required
String
scope
,
@required
String
nonceStr
,
@required
String
timeStamp
,
@required
String
signature
,
String
schemeData
})
async
{
assert
(
appId
!=
null
&&
appId
.
isNotEmpty
);
assert
(
scope
!=
null
&&
scope
.
isNotEmpty
);
assert
(
nonceStr
!=
null
&&
nonceStr
.
isNotEmpty
);
assert
(
timeStamp
!=
null
&&
timeStamp
.
isNotEmpty
);
assert
(
signature
!=
null
&&
signature
.
isNotEmpty
);
return
await
_channel
.
invokeMethod
(
"authByQRCode"
,
{
"appId"
:
appId
,
"scope"
:
scope
,
"nonceStr"
:
nonceStr
,
"timeStamp"
:
timeStamp
,
"signature"
:
signature
,
"schemeData"
:
schemeData
});
}
/// stop [authWeChatByQRCode]
Future
stopWeChatAuthByQRCode
(
)
async
{
return
await
_channel
.
invokeMethod
(
"stopAuthByQRCode"
);
}
Future
_methodHandler
(
MethodCall
methodCall
)
{
Future
_methodHandler
(
MethodCall
methodCall
)
{
var
response
=
var
response
=
BaseWeChatResponse
.
create
(
methodCall
.
method
,
methodCall
.
arguments
);
BaseWeChatResponse
.
create
(
methodCall
.
method
,
methodCall
.
arguments
);
...
...
lib/src/response/wechat_response.dart
浏览文件 @
a0ff9a14
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
* the License.
* the License.
*/
*/
import
'dart:typed_data'
;
const
String
_errCode
=
"errCode"
;
const
String
_errCode
=
"errCode"
;
const
String
_errStr
=
"errStr"
;
const
String
_errStr
=
"errStr"
;
...
@@ -32,6 +34,12 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
...
@@ -32,6 +34,12 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
WeChatSubscribeMsgResponse
.
fromMap
(
argument
),
WeChatSubscribeMsgResponse
.
fromMap
(
argument
),
"onAutoDeductResponse"
:
(
Map
argument
)
=>
"onAutoDeductResponse"
:
(
Map
argument
)
=>
WeChatAutoDeductResponse
.
fromMap
(
argument
),
WeChatAutoDeductResponse
.
fromMap
(
argument
),
"onAuthByQRCodeFinished"
:
(
Map
argument
)
=>
WeChatAuthByQRCodeFinishedResponse
.
fromMap
(
argument
),
"onAuthGotQRCode"
:
(
Map
argument
)
=>
WeChatAuthGotQRCodeResponse
.
fromMap
(
argument
),
"onQRCodeScanned"
:
(
Map
argument
)
=>
WeChatQRCodeScannedResponse
.
fromMap
(
argument
),
};
};
class
BaseWeChatResponse
{
class
BaseWeChatResponse
{
...
@@ -139,3 +147,57 @@ class WeChatAutoDeductResponse extends BaseWeChatResponse {
...
@@ -139,3 +147,57 @@ class WeChatAutoDeductResponse extends BaseWeChatResponse {
resultInfo
=
map
[
"resultInfo"
],
resultInfo
=
map
[
"resultInfo"
],
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
}
}
class
WeChatAuthByQRCodeFinishedResponse
extends
BaseWeChatResponse
{
final
String
authCode
;
final
AuthByQRCodeErrorCode
qrCodeErrorCode
;
WeChatAuthByQRCodeFinishedResponse
.
fromMap
(
Map
map
)
:
authCode
=
map
[
"authCode"
],
qrCodeErrorCode
=
(
_authByQRCodeErrorCodes
[
_errCode
]
??
AuthByQRCodeErrorCode
.
UNKNOWN
),
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
}
///[qrCode] in memory.
class
WeChatAuthGotQRCodeResponse
extends
BaseWeChatResponse
{
final
Uint8List
qrCode
;
WeChatAuthGotQRCodeResponse
.
fromMap
(
Map
map
)
:
qrCode
=
map
[
"qrCode"
],
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
}
class
WeChatQRCodeScannedResponse
extends
BaseWeChatResponse
{
WeChatQRCodeScannedResponse
.
fromMap
(
Map
map
)
:
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
}
///WechatAuth_Err_OK(0),
///WechatAuth_Err_NormalErr(-1),
///WechatAuth_Err_NetworkErr(-2),
///WechatAuth_Err_JsonDecodeErr(-3),
///WechatAuth_Err_Cancel(-4),
///WechatAuth_Err_Timeout(-5),
///WechatAuth_Err_Auth_Stopped(-6);
///[AuthByQRCodeErrorCode.JSON_DECODE_ERR] means WechatAuth_Err_GetQrcodeFailed when platform is iOS
///only Android will get [AUTH_STOPPED]
enum
AuthByQRCodeErrorCode
{
OK
,
NORMAL_ERR
,
NETWORK_ERR
,
JSON_DECODE_ERR
,
CANCEL
,
TIMEOUT
,
AUTH_STOPPED
,
UNKNOWN
}
const
Map
<
int
,
AuthByQRCodeErrorCode
>
_authByQRCodeErrorCodes
=
{
0
:
AuthByQRCodeErrorCode
.
OK
,
-
1
:
AuthByQRCodeErrorCode
.
NORMAL_ERR
,
-
2
:
AuthByQRCodeErrorCode
.
NETWORK_ERR
,
-
3
:
AuthByQRCodeErrorCode
.
JSON_DECODE_ERR
,
-
4
:
AuthByQRCodeErrorCode
.
CANCEL
,
-
5
:
AuthByQRCodeErrorCode
.
AUTH_STOPPED
};
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论