Skip to content

Commit d84500d

Browse files
author
raoxudong
committed
v0.5.0新增一键登录同步接口
1 parent af8b0a0 commit d84500d

File tree

9 files changed

+109
-39
lines changed

9 files changed

+109
-39
lines changed

CHANGELOG.md

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
```yaml
99
//pub 集成
1010
dependencies:
11-
jverify: 0.4.0
11+
jverify: 0.5.0
1212

1313

1414
//github 集成

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ public void onMethodCall(MethodCall call, Result result) {
9191
getToken(call,result);
9292
}else if (call.method.equals("verifyNumber")) {
9393
verifyNumber(call,result);
94+
}else if (call.method.equals("preLogin")) {
95+
preLogin(call, result);
9496
}else if (call.method.equals("loginAuth")) {
9597
loginAuth(call, result);
96-
}else if (call.method.equals("preLogin")) {
97-
preLogin(call, result);
98+
}else if (call.method.equals("loginAuthSyncApi")) {
99+
loginAuthSyncApi(call, result);
98100
}else if (call.method.equals("dismissLoginAuthView")) {
99101
dismissLoginAuthView(call, result);
100102
}else if (call.method.equals("setCustomUI")) {
@@ -270,9 +272,18 @@ private void clearPreLoginCache(MethodCall call,final Result result) {
270272
}
271273

272274

273-
/** SDK请求授权一键登录 */
275+
/** SDK请求授权一键登录,异步 */
274276
private void loginAuth(MethodCall call,final Result result){
275277
Log.d(TAG,"Action - loginAuth:");
278+
loginAuthInterface(false,call,result);
279+
}
280+
/** SDK请求授权一键登录,同步 */
281+
private void loginAuthSyncApi(MethodCall call,final Result result) {
282+
Log.d(TAG,"Action - loginAuthSyncApi:");
283+
loginAuthInterface(true,call,result);
284+
}
285+
private void loginAuthInterface(final Boolean isSync, MethodCall call, final Result result) {
286+
Log.d(TAG,"Action - loginAuthInterface:");
276287

277288
Object autoFinish = getValueByKey(call,"autoDismiss");
278289

@@ -288,12 +299,13 @@ public void onResult(int code, String content, String operator) {
288299
map.put(j_code_key,code);
289300
map.put(j_msg_key,content);
290301
map.put(j_opr_key,operator);
291-
292-
// 通过 channel 返回
293-
channel.invokeMethod("onReceiveLoginAuthCallBackEvent",map);
294-
295-
// 通过回调返回
296-
result.success(map);
302+
if (isSync) {
303+
// 通过 channel 返回
304+
channel.invokeMethod("onReceiveLoginAuthCallBackEvent",map);
305+
}else {
306+
// 通过回调返回
307+
result.success(map);
308+
}
297309
}
298310
}, new AuthPageEventListener() {
299311
@Override

documents/APIs.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jverify.checkVerifyEnable().then((map){
4646
}else{
4747
// 当前网络环境不支持认证
4848
}
49-
});
49+
});
5050
```
5151

5252
#### getToken
@@ -62,7 +62,7 @@ jverify.getToken().then((map){
6262
String _token = map["content"]; // 成功时为token,可用于调用验证手机号接口。token有效期为1分钟,超过时效需要重新获取才能使用。失败时为失败信息
6363
String _operator = map["operator"]; // 成功时为对应运营商,CM代表中国移动,CU代表中国联通,CT代表中国电信。失败时可能为null
6464
...
65-
});
65+
});
6666
```
6767

6868

@@ -77,17 +77,40 @@ jverify.getToken().then((map){
7777
Jverify jverify = new Jverify();
7878
7979
/// 步骤 1:调用接口设置 UI
80-
jverify.setCustomAuthorizationView();
80+
jverify.setCustomAuthorizationView(true, uiConfig, landscapeConfig: uiConfig);
8181
82-
/// 步骤 2: 添加 loginAuth 接口回调的监听 (如果想通过 loginAuth 接口异步返回获取接口数据,则忽略此步骤)
82+
/// 步骤 2:调用一键登录接口
83+
84+
/// 方式一:使用同步接口 (如果想使用异步接口,则忽略此步骤,看方式二)
85+
/// 先,添加 loginAuthSyncApi 接口回调的监听
8386
jverify.addLoginAuthCallBackListener((event){
84-
print("通过添加监听,获取到 loginAuth 接口返回数据,code=${event.code},message = ${event.message},operator = ${event.operator}");
87+
setState(() {
88+
_loading = false;
89+
_result = "监听获取返回数据:[${event.code}] message = ${event.message}";
90+
});
91+
print("通过添加监听,获取到 loginAuthSyncApi 接口返回数据,code=${event.code},message = ${event.message},operator = ${event.operator}");
8592
});
86-
/// 步骤 3:开始调用一键登录接口
87-
jverify.loginAuth(true).then((map){
88-
/// 步骤 4:获取 loginAuth 接口异步返回数据(如果是通过添加 JVLoginAuthCallBackListener 监听来获取返回数据,则忽略此步骤)
93+
/// 再,执行同步的一键登录接口
94+
jverify.loginAuthSyncApi(autoDismiss: true);
95+
96+
/*
97+
/// 方式二:使用异步接口 (如果想使用异步接口,则忽略此步骤,看方式一)
98+
99+
/// 先,执行异步的一键登录接口
100+
jverify.loginAuth(true).then((map) {
101+
102+
/// 再,在回调里获取 loginAuth 接口异步返回数据(如果是通过添加 JVLoginAuthCallBackListener 监听来获取返回数据,则忽略此步骤)
103+
int code = map[f_code_key];
104+
String content = map[f_msg_key];
105+
String operator = map[f_opr_key];
106+
setState(() {
107+
_loading = false;
108+
_result = "接口异步返回数据:[$code] message = $content";
109+
});
89110
print("通过接口异步返回,获取到 loginAuth 接口返回数据,code=$code,message = $content,operator = $operator");
90-
});
111+
});
112+
*/
113+
91114
```
92115

93116
#### setCustomAuthorizationView

example/lib/main.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,28 @@ class _MyAppState extends State<MyApp> {
412412
/// 步骤 1:调用接口设置 UI
413413
jverify.setCustomAuthorizationView(true, uiConfig, landscapeConfig: uiConfig);
414414

415-
/// 步骤 2: 添加 loginAuth 接口回调的监听 (如果想通过 loginAuth 接口异步返回获取接口数据,则忽略此步骤)
415+
/// 步骤 2:调用一键登录接口
416+
417+
/// 方式一:使用同步接口 (如果想使用异步接口,则忽略此步骤,看方式二)
418+
/// 先,添加 loginAuthSyncApi 接口回调的监听
416419
jverify.addLoginAuthCallBackListener((event){
417420
setState(() {
418421
_loading = false;
419422
_result = "监听获取返回数据:[${event.code}] message = ${event.message}";
420423
});
421-
print("通过添加监听,获取到 loginAuth 接口返回数据,code=${event.code},message = ${event.message},operator = ${event.operator}");
424+
print("通过添加监听,获取到 loginAuthSyncApi 接口返回数据,code=${event.code},message = ${event.message},operator = ${event.operator}");
422425
});
426+
/// 再,执行同步的一键登录接口
427+
jverify.loginAuthSyncApi(autoDismiss: true);
428+
429+
/*
423430
424-
/// 步骤 3:开始调用一键登录接口
431+
/// 方式二:使用异步接口 (如果想使用异步接口,则忽略此步骤,看方式二)
432+
433+
/// 先,执行异步的一键登录接口
425434
jverify.loginAuth(true).then((map) {
426435
427-
/// 步骤 4:获取 loginAuth 接口异步返回数据(如果是通过添加 JVLoginAuthCallBackListener 监听来获取返回数据,则忽略此步骤)
436+
/// 再,在回调里获取 loginAuth 接口异步返回数据(如果是通过添加 JVLoginAuthCallBackListener 监听来获取返回数据,则忽略此步骤)
428437
int code = map[f_code_key];
429438
String content = map[f_msg_key];
430439
String operator = map[f_opr_key];
@@ -435,6 +444,8 @@ class _MyAppState extends State<MyApp> {
435444
print("通过接口异步返回,获取到 loginAuth 接口返回数据,code=$code,message = $content,operator = $operator");
436445
});
437446
447+
*/
448+
438449
} else {
439450
setState(() {
440451
_loading = false;

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.4.0"
55+
version: "0.5.0"
5656
matcher:
5757
dependency: transitive
5858
description:

ios/Classes/JverifyPlugin.m

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
4949
[self verifyNumber:call result:result];
5050
}else if([methodName isEqualToString:@"loginAuth"]){
5151
[self loginAuth:call result:result];
52-
}else if([methodName isEqualToString:@"preLogin"]){
52+
}else if ([methodName isEqualToString:@"loginAuthSyncApi"]){
53+
[self loginAuthSyncApi:call result:result];
54+
} else if([methodName isEqualToString:@"preLogin"]){
5355
[self preLogin:call result:result];
5456
}else if([methodName isEqualToString:@"dismissLoginAuthView"]){
5557
[self dismissLoginController:call result:result];
@@ -237,8 +239,16 @@ - (void)clearPreLoginCache:(FlutterMethodCall*) call result:(FlutterResult)resul
237239
[JVERIFICATIONService clearPreLoginCache];
238240
}
239241
#pragma mark - SDK 请求授权一键登录
240-
-(void)loginAuth:(FlutterMethodCall*) call result:(FlutterResult)result{
242+
-(void)loginAuth:(FlutterMethodCall*) call result:(FlutterResult)result {
241243
JVLog(@"Action - loginAuth::%@",call.arguments);
244+
[self loginAuthSync:NO call:call result:result];
245+
}
246+
-(void)loginAuthSyncApi:(FlutterMethodCall*) call result:(FlutterResult)result {
247+
JVLog(@"Action - loginAuthSyncApi::%@",call.arguments);
248+
[self loginAuthSync:YES call:call result:result];
249+
}
250+
-(void)loginAuthSync:(BOOL)isSync call:(FlutterMethodCall*)call result:(FlutterResult)result {
251+
JVLog(@"Action - loginAuthSync::%@",call.arguments);
242252

243253
NSDictionary *arguments = [call arguments];
244254
NSNumber *hide = arguments[@"autoDismiss"];
@@ -263,10 +273,13 @@ -(void)loginAuth:(FlutterMethodCall*) call result:(FlutterResult)result{
263273
};
264274
__strong typeof(weakself) strongself = weakself;
265275
dispatch_async(dispatch_get_main_queue(), ^{
266-
//通过 channel 返回
267-
[strongself.channel invokeMethod:@"onReceiveLoginAuthCallBackEvent" arguments:dict];
268-
// 通过回调返回
269-
result(dict);
276+
if (isSync) {
277+
//通过 channel 返回
278+
[strongself.channel invokeMethod:@"onReceiveLoginAuthCallBackEvent" arguments:dict];
279+
}else{
280+
// 通过回调返回
281+
result(dict);
282+
}
270283
});
271284
} actionBlock:^(NSInteger type, NSString *content) {
272285
JVLog("Authorization actionBlock: type = %ld", (long)type);

lib/jverify.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,29 @@ class Jverify {
182182
}
183183

184184
/*
185-
* SDK请求授权一键登录
185+
* SDK请求授权一键登录(异步接口)
186186
*
187-
* 获取接口回调数据的两种方式:
188-
* 1、可通过接口异步返回的 map 获得
189-
* 2、通过添加 JVLoginAuthCallBackListener 监听,来监听接口的返回结果
187+
* @return 通过接口异步返回的 map 获得
190188
*
191-
* 授权页面点击事件监听:
192-
* 通过添加 JVAuthPageEventListener 监听,来监听授权页点击事件, SDK v2.4.0 开始支持
189+
* @discussion since SDK v2.4.0,授权页面点击事件监听:通过添加 JVAuthPageEventListener 监听,来监听授权页点击事件
193190
*
194191
* */
195192
Future<Map<dynamic, dynamic>> loginAuth(bool autoDismiss) async {
196193
print("$flutter_log" + "loginAuth");
197-
return await _channel
198-
.invokeMethod("loginAuth", {"autoDismiss": autoDismiss});
194+
return await _channel.invokeMethod("loginAuth", {"autoDismiss": autoDismiss});
195+
}
196+
197+
/*
198+
* SDK请求授权一键登录(同步接口)
199+
*
200+
* 通过添加 JVLoginAuthCallBackListener 监听,来监听接口的返回结果
201+
*
202+
* @discussion since SDK v2.4.0,授权页面点击事件监听:通过添加 JVAuthPageEventListener 监听,来监听授权页点击事件
203+
*
204+
* */
205+
void loginAuthSyncApi({@required bool autoDismiss}) {
206+
print("$flutter_log" + "loginAuthSyncApi");
207+
_channel.invokeMethod("loginAuthSyncApi", {"autoDismiss": autoDismiss});
199208
}
200209

201210
/*

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.4.0
3+
version: 0.5.0
44
author: shikk <[email protected]>
55
homepage: https://www.jiguang.cn
66

0 commit comments

Comments
 (0)