Skip to content

Commit af8b0a0

Browse files
authored
Merge pull request #18 from raoxudong/dev
v0.4.0 一键登录回调支持添加监听接收数据
2 parents bf80261 + 694582e commit af8b0a0

File tree

9 files changed

+115
-36
lines changed

9 files changed

+115
-36
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 0.4.0
2+
+ 新增:一键登录接口(loginAuth)返回数据支持添加监听获取 [addLoginAuthCallBackListener],具体使用查看 API 文档或者 demo 样例;
13
## 0.3.0
24
+ 新增:关闭授权页面接口
35
## 0.2.0

README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,14 @@
66
在工程 pubspec.yaml 中加入 dependencies
77

88
```yaml
9+
//pub 集成
910
dependencies:
10-
jverify: 0.3.0
11-
```
12-
13-
### 安装
11+
jverify: 0.4.0
1412

15-
在工程 pubspec.yaml 中加入 dependencies
16-
17-
```yaml
18-
//pub.dev 集成
19-
dependencies:
20-
jpush_flutter: 0.2.0
2113

2214
//github 集成
2315
dependencies:
24-
jmessage_flutter:
16+
jverify:
2517
git:
2618
url: git://github.com/jpush/jverify-flutter-plugin.git
2719
ref: master

android/src/main/java/com/jiguang/jverify/JverifyPlugin.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public void onResult(int code, String content, String operator) {
288288
map.put(j_code_key,code);
289289
map.put(j_msg_key,content);
290290
map.put(j_opr_key,operator);
291+
292+
// 通过 channel 返回
293+
channel.invokeMethod("onReceiveLoginAuthCallBackEvent",map);
294+
295+
// 通过回调返回
291296
result.success(map);
292297
}
293298
}, new AuthPageEventListener() {
@@ -981,19 +986,21 @@ private int getResourceByReflect(String imageName){
981986
r_id = field.getInt(field.getName());
982987
} catch (Exception e) {
983988
r_id = 0;
984-
Log.e(TAG, "image【"+imageName + "】field no found!");
989+
//Log.d(TAG, "image【"+imageName + "】field no found!");
985990
}
986991

987992
if (r_id == 0) {
988993
r_id = context.getResources().getIdentifier(imageName, "drawable",context.getPackageName());
989-
Log.d(TAG, "image【"+ imageName + "】 drawable found ! r_id = " + r_id);
994+
//Log.d(TAG, "image【"+ imageName + "】 drawable found ! r_id = " + r_id);
990995
}
991996

992997
if (r_id == 0) {
993998
r_id = context.getResources().getIdentifier(imageName, "mipmap",context.getPackageName());
994-
Log.d(TAG, "image【"+ imageName + "】 mipmap found! r_id = " + r_id);
999+
//Log.d(TAG, "image【"+ imageName + "】 mipmap found! r_id = " + r_id);
1000+
}
1001+
if (r_id == 0) {
1002+
Log.d(TAG, "image【"+imageName + "】field no found!");
9951003
}
996-
9971004
return r_id;
9981005
}
9991006
}

documents/APIs.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,24 @@ jverify.getToken().then((map){
7070

7171
调起一键登录授权页面,在用户授权后获取loginToken
7272
**说明:** ios在拉起授权页面之前,必须先setCustomUI 。
73+
7374
```dart
75+
///具体使用可以查看 example 样例
76+
7477
Jverify jverify = new Jverify();
75-
jverify.loginAuth().then((map){
76-
int _code = map["code"]; // 返回码,6000代表loginToken获取成功,6001代表loginToken获取失败,其他返回码详见描述
77-
String _token = map["content"]; // 返回码的解释信息,若获取成功,内容信息代表loginToken。
78-
String _operator = map["operator"]; // 成功时为对应运营商,CM代表中国移动,CU代表中国联通,CT代表中国电信。失败时可能为null
79-
...
80-
});
78+
79+
/// 步骤 1:调用接口设置 UI
80+
jverify.setCustomAuthorizationView();
81+
82+
/// 步骤 2: 添加 loginAuth 接口回调的监听 (如果想通过 loginAuth 接口异步返回获取接口数据,则忽略此步骤)
83+
jverify.addLoginAuthCallBackListener((event){
84+
print("通过添加监听,获取到 loginAuth 接口返回数据,code=${event.code},message = ${event.message},operator = ${event.operator}");
85+
});
86+
/// 步骤 3:开始调用一键登录接口
87+
jverify.loginAuth(true).then((map){
88+
/// 步骤 4:获取 loginAuth 接口异步返回数据(如果是通过添加 JVLoginAuthCallBackListener 监听来获取返回数据,则忽略此步骤)
89+
print("通过接口异步返回,获取到 loginAuth 接口返回数据,code=$code,message = $content,operator = $operator");
90+
});
8191
```
8292

8393
#### setCustomAuthorizationView

example/lib/main.dart

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,30 @@ class _MyAppState extends State<MyApp> {
409409
*/
410410

411411

412-
/// 调用接口设置 UI
413-
jverify.setCustomAuthorizationView(true, uiConfig, landscapeConfig: uiConfig);
412+
/// 步骤 1:调用接口设置 UI
413+
jverify.setCustomAuthorizationView(true, uiConfig, landscapeConfig: uiConfig);
414414

415-
/// 开始一键登录
415+
/// 步骤 2: 添加 loginAuth 接口回调的监听 (如果想通过 loginAuth 接口异步返回获取接口数据,则忽略此步骤)
416+
jverify.addLoginAuthCallBackListener((event){
417+
setState(() {
418+
_loading = false;
419+
_result = "监听获取返回数据:[${event.code}] message = ${event.message}";
420+
});
421+
print("通过添加监听,获取到 loginAuth 接口返回数据,code=${event.code},message = ${event.message},operator = ${event.operator}");
422+
});
423+
424+
/// 步骤 3:开始调用一键登录接口
416425
jverify.loginAuth(true).then((map) {
426+
427+
/// 步骤 4:获取 loginAuth 接口异步返回数据(如果是通过添加 JVLoginAuthCallBackListener 监听来获取返回数据,则忽略此步骤)
417428
int code = map[f_code_key];
418429
String content = map[f_msg_key];
430+
String operator = map[f_opr_key];
419431
setState(() {
420432
_loading = false;
421-
_result = "[$code] message = $content";
433+
_result = "接口异步返回数据:[$code] message = $content";
422434
});
435+
print("通过接口异步返回,获取到 loginAuth 接口返回数据,code=$code,message = $content,operator = $operator");
423436
});
424437

425438
} else {

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ packages:
5252
path: ".."
5353
relative: true
5454
source: path
55-
version: "0.3.0"
55+
version: "0.4.0"
5656
matcher:
5757
dependency: transitive
5858
description:

ios/Classes/JverifyPlugin.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ -(void)loginAuth:(FlutterMethodCall*) call result:(FlutterResult)result{
261261
j_msg_key :content,
262262
j_opr_key :res[@"operator"]?:@""
263263
};
264+
__strong typeof(weakself) strongself = weakself;
264265
dispatch_async(dispatch_get_main_queue(), ^{
266+
//通过 channel 返回
267+
[strongself.channel invokeMethod:@"onReceiveLoginAuthCallBackEvent" arguments:dict];
268+
// 通过回调返回
265269
result(dict);
266270
});
267271
} actionBlock:^(NSInteger type, NSString *content) {

lib/jverify.dart

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import 'package:platform/platform.dart';
1111
typedef JVClickWidgetEventListener = void Function(String widgetId);
1212
/// 授权页事件回调 @since 2.4.0
1313
typedef JVAuthPageEventListener = void Function(JVAuthPageEvent event);
14+
/**
15+
* 一键登录接口的回调监听
16+
*
17+
* @param event
18+
* code :返回码,6000代表loginToken获取成功,6001代表loginToken获取失败,其他返回码详见描述
19+
* message :返回码的解释信息,若获取成功,内容信息代表loginToken。
20+
* operator :成功时为对应运营商,CM代表中国移动,CU代表中国联通,CT代表中国电信。失败时可能为 null
21+
*
22+
* @discussion 调用 loginAuth 接口后,可以通过添加此监听事件来监听接口的返回结果
23+
* */
24+
typedef JVLoginAuthCallBackListener = void Function(JVListenerEvent event);
1425

1526

1627

@@ -22,6 +33,7 @@ class JVEventHandlers {
2233

2334
Map<String, JVClickWidgetEventListener> clickEventsMap = Map();
2435
List<JVAuthPageEventListener> authPageEvents = [];
36+
List<JVLoginAuthCallBackListener> loginAuthCallBackEvents = [];
2537
}
2638

2739

@@ -54,7 +66,10 @@ class Jverify {
5466
addAuthPageEventListener(JVAuthPageEventListener callback) {
5567
_eventHanders.authPageEvents.add(callback);
5668
}
57-
69+
/// loginAuth 接口回调的监听
70+
addLoginAuthCallBackListener(JVLoginAuthCallBackListener callback) {
71+
_eventHanders.loginAuthCallBackEvents.add(callback);
72+
}
5873

5974
Future<void> _handlerMethod(MethodCall call) async {
6075
print("handleMethod method = ${call.method}");
@@ -76,6 +91,15 @@ class Jverify {
7691
}
7792
}
7893
break;
94+
case 'onReceiveLoginAuthCallBackEvent': {
95+
for (JVLoginAuthCallBackListener cb in _eventHanders.loginAuthCallBackEvents) {
96+
Map json = call.arguments.cast<dynamic, dynamic>();
97+
JVListenerEvent event = JVListenerEvent.fromJson(json);
98+
cb(event);
99+
_eventHanders.loginAuthCallBackEvents.remove(cb);
100+
}
101+
}
102+
break;
79103
default:
80104
throw new UnsupportedError("Unrecognized Event");
81105
}
@@ -160,7 +184,12 @@ class Jverify {
160184
/*
161185
* SDK请求授权一键登录
162186
*
163-
* v2.4.0 之后同时支持授权页事件监听,开发者需添加 JVAuthPageEventListener 监听
187+
* 获取接口回调数据的两种方式:
188+
* 1、可通过接口异步返回的 map 获得
189+
* 2、通过添加 JVLoginAuthCallBackListener 监听,来监听接口的返回结果
190+
*
191+
* 授权页面点击事件监听:
192+
* 通过添加 JVAuthPageEventListener 监听,来监听授权页点击事件, SDK v2.4.0 开始支持
164193
*
165194
* */
166195
Future<Map<dynamic, dynamic>> loginAuth(bool autoDismiss) async {
@@ -481,21 +510,43 @@ enum JVTextAlignmentType {
481510
center
482511
}
483512

513+
/// 监听返回类
514+
class JVListenerEvent {
515+
int code;//返回码,具体事件返回码请查看(https://docs.jiguang.cn/jverification/client/android_api/)
516+
String message;//事件描述、事件返回值等
517+
String operator;//成功时为对应运营商,CM代表中国移动,CU代表中国联通,CT代表中国电信。失败时可能为null
484518

485-
/// 授权页事件
486-
class JVAuthPageEvent {
487-
final int code;//返回码 // 具体事件返回码请查看(https://docs.jiguang.cn/jverification/client/android_api/)
488-
final String message;//事件描述
519+
JVListenerEvent.fromJson(Map<dynamic, dynamic> json)
520+
: code = json['code'],
521+
message = json['message'],
522+
operator = json['operator'];
523+
524+
Map toMap() {
525+
return {
526+
'code': code ??= null,
527+
'message': message ??= null,
528+
'operator': operator ??= null
529+
};
530+
}
531+
}
489532

533+
/// 授权页事件
534+
class JVAuthPageEvent extends JVListenerEvent {
535+
@override
490536
JVAuthPageEvent.fromJson(Map<dynamic, dynamic> json)
491-
: code = json['code'],
492-
message = json['message'];
537+
: super.fromJson(json);
493538

539+
@override
494540
Map toMap() {
495-
return {'code': code, 'message': message};
541+
return {
542+
'code': code ??= null,
543+
'message': message ??= null,
544+
};
496545
}
497546
}
498547

548+
549+
499550
/*
500551
* iOS 布局参照 item (Android 只)
501552
*

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: jverify
22
description: JIGUANG Official Jverifycation SDK flutter plugin project.
3-
version: 0.3.0
3+
version: 0.4.0
44
author: shikk <[email protected]>
55
homepage: https://www.jiguang.cn
66

0 commit comments

Comments
 (0)