Skip to content

Commit db47d0f

Browse files
authored
Merge pull request #33 from raoxudong/dev
0.6.1
2 parents 267bc56 + 1a28ffd commit db47d0f

File tree

10 files changed

+342
-220
lines changed

10 files changed

+342
-220
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.6.1
2+
+ 优化:Android 回调 flutter 的回调函数
3+
+ 优化重复请求逻辑
14
## 0.6.0
25
+ 新增:SDK 初始化回调监听
36
+ 新增:授权页弹窗模式

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55

66
在工程 pubspec.yaml 中加入 dependencies
77

8-
```yaml
9-
//pub 集成
10-
dependencies:
11-
jverify: 0.6.0
8+
+ github 集成
129

13-
14-
//github 集成
10+
```
1511
dependencies:
1612
jverify:
1713
git:
1814
url: git://github.com/jpush/jverify-flutter-plugin.git
1915
ref: master
2016
```
17+
18+
+ pub 集成
19+
20+
```
21+
dependencies:
22+
jverify: 0.6.1
23+
```
24+
2125
### 配置
2226

2327
##### Android:

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

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import android.graphics.drawable.StateListDrawable;
1111
import android.media.Image;
1212
import android.nfc.Tag;
13+
import android.os.Handler;
14+
import android.os.HandlerThread;
15+
import android.os.Looper;
1316
import android.util.Log;
1417
import android.util.TypedValue;
1518
import android.view.Gravity;
@@ -43,6 +46,11 @@
4346
import io.flutter.plugin.common.MethodChannel.Result;
4447
import io.flutter.plugin.common.PluginRegistry.Registrar;
4548

49+
class JVRequestItem {
50+
public MethodCall call;
51+
Result result;
52+
}
53+
4654
/** JverifyPlugin */
4755
public class JverifyPlugin implements MethodCallHandler {
4856

@@ -60,10 +68,13 @@ public class JverifyPlugin implements MethodCallHandler {
6068
private static String j_opr_key = "operator";
6169
// 默认超时时间
6270
private static int j_default_timeout = 5000;
71+
// 重复请求
72+
private static int j_error_code_repeat = -1;
6373

6474

6575
private Context context;
6676
private MethodChannel channel;
77+
private HashMap<String,JVRequestItem> requestQueue = new HashMap();
6778

6879
/** Plugin registration. */
6980
public static void registerWith(Registrar registrar) {
@@ -81,6 +92,29 @@ private JverifyPlugin(Registrar registrar,MethodChannel channel){
8192
public void onMethodCall(MethodCall call, Result result) {
8293
Log.d(TAG,"onMethodCall:" + call.method);
8394

95+
// JVRequestItem item = requestQueue.get(call.method);
96+
// if (item == null) {
97+
// item = new JVRequestItem();
98+
// item.call = call;
99+
// item.result = result;
100+
//
101+
// requestQueue.put(call.method,item);
102+
//
103+
// processMethod(call, result);
104+
// }else {
105+
// String error_repeat_desc = call.method + " is requesting, please try again later.";
106+
//
107+
// Map<String,Object> map = new HashMap<>();
108+
// map.put(j_code_key,j_error_code_repeat);
109+
// map.put(j_msg_key,error_repeat_desc);
110+
//
111+
// result.success(map);
112+
// }
113+
processMethod(call,result);
114+
}
115+
116+
private void processMethod(MethodCall call, Result result) {
117+
Log.d(TAG,"processMethod:" + call.method);
84118
if (call.method.equals("setup")) {
85119
setup(call,result);
86120
}else if (call.method.equals("setDebugMode")) {
@@ -115,6 +149,34 @@ public void onMethodCall(MethodCall call, Result result) {
115149
}
116150
}
117151

152+
private void methodCallBack(Object object,String method) {
153+
Log.d(TAG,"Action - methodCallBack:" + method);
154+
155+
JVRequestItem item = requestQueue.get(method);
156+
if (item != null) {
157+
if (item.result != null) {
158+
item.result.success(object);
159+
}
160+
}
161+
requestQueue.remove(method);
162+
}
163+
164+
// 主线程再返回数据
165+
private void runMainThread(final Map<String,Object> map, final Result result, final String method) {
166+
android.os.Handler handler = new Handler(Looper.getMainLooper());
167+
handler.post(new Runnable() {
168+
@Override
169+
public void run() {
170+
if (result == null && method != null){
171+
channel.invokeMethod(method,map);
172+
} else {
173+
result.success(map);
174+
}
175+
}
176+
});
177+
}
178+
179+
118180
/** SDK 初始换 */
119181
private void setup(MethodCall call,Result result){
120182
Log.d(TAG,"Action - setup:");
@@ -127,7 +189,8 @@ public void onResult(int code, String message) {
127189
map.put(j_code_key,code);
128190
map.put(j_msg_key,message);
129191
// 通过 channel 返回
130-
channel.invokeMethod("onReceiveSDKSetupCallBackEvent",map);
192+
//channel.invokeMethod("onReceiveSDKSetupCallBackEvent",map);
193+
runMainThread(map,null,"onReceiveSDKSetupCallBackEvent");
131194
}
132195
});
133196
}
@@ -142,7 +205,7 @@ private void setDebugMode(MethodCall call,Result result){
142205

143206
Map<String,Object> map = new HashMap<>();
144207
map.put(j_result_key,enable);
145-
result.success(map);
208+
runMainThread(map,result,null);
146209
}
147210

148211
/** 获取 SDK 初始化是否成功标识 */
@@ -155,7 +218,7 @@ private boolean isInitSuccess(MethodCall call, Result result) {
155218

156219
Map<String,Object> map = new HashMap<>();
157220
map.put(j_result_key, isSuccess);
158-
result.success(map);
221+
runMainThread(map,result,null);
159222

160223
return isSuccess;
161224
}
@@ -171,13 +234,13 @@ private boolean checkVerifyEnable(MethodCall call,Result result){
171234

172235
Map<String,Object> map = new HashMap<>();
173236
map.put(j_result_key, verifyEnable);
174-
result.success(map);
237+
runMainThread(map,result,null);
175238

176239
return verifyEnable;
177240
}
178241

179242
/** SDK获取号码认证token*/
180-
private void getToken(MethodCall call, final Result result) {
243+
private void getToken(final MethodCall call, final Result result) {
181244
Log.d(TAG,"Action - getToken:");
182245

183246
int timeOut = j_default_timeout;
@@ -206,7 +269,8 @@ public void onResult(int code, String content, String operator) {
206269
map.put(j_code_key,code);
207270
map.put(j_msg_key,content);
208271
map.put(j_opr_key,operator);
209-
result.success(map);
272+
273+
runMainThread(map,result,null);
210274
}
211275
});
212276
}
@@ -251,7 +315,7 @@ public void onResult(int code, String content, String operator) {
251315
}
252316

253317
/** SDK 一键登录预取号 */
254-
private void preLogin(MethodCall call,final Result result) {
318+
private void preLogin(final MethodCall call, final Result result) {
255319
Log.d(TAG,"Action - preLogin:" + call.arguments);
256320

257321
int timeOut = j_default_timeout;
@@ -265,19 +329,21 @@ private void preLogin(MethodCall call,final Result result) {
265329
public void onResult(int code, String message) {
266330

267331
if (code == 7000){//code: 返回码,7000代表获取成功,其他为失败,详见错误码描述
268-
Log.d(TAG, "verify consistent, message =" + message);
332+
Log.d(TAG, "verify success, message =" + message);
269333
}else {
270-
Log.e(TAG, "code=" + code + ", message =" + message);
334+
Log.e(TAG, "verify fail,code=" + code + ", message =" + message);
271335
}
272-
273336
Map<String,Object> map = new HashMap<>();
274337
map.put(j_code_key,code);
275338
map.put(j_msg_key,message);
276-
result.success(map);
339+
340+
runMainThread(map,result,null);
277341
}
278342
});
279343
}
280344

345+
346+
281347
/** SDK清除预取号缓存 */
282348
private void clearPreLoginCache(MethodCall call,final Result result) {
283349
Log.d(TAG,"Action - clearPreLoginCache:");
@@ -295,7 +361,7 @@ private void loginAuthSyncApi(MethodCall call,final Result result) {
295361
Log.d(TAG,"Action - loginAuthSyncApi:");
296362
loginAuthInterface(true,call,result);
297363
}
298-
private void loginAuthInterface(final Boolean isSync, MethodCall call, final Result result) {
364+
private void loginAuthInterface(final Boolean isSync, final MethodCall call, final Result result) {
299365
Log.d(TAG,"Action - loginAuthInterface:");
300366

301367
Object autoFinish = getValueByKey(call,"autoDismiss");
@@ -312,7 +378,8 @@ public void onEvent(int cmd, String msg) {
312378
final HashMap jsonMap = new HashMap();
313379
jsonMap.put(j_code_key, cmd);
314380
jsonMap.put(j_msg_key, msg);
315-
channel.invokeMethod("onReceiveAuthPageEvent", jsonMap);
381+
382+
runMainThread(jsonMap,null,"onReceiveAuthPageEvent");
316383
}
317384
});
318385

@@ -330,10 +397,10 @@ public void onResult(int code, String content, String operator) {
330397
map.put(j_opr_key,operator);
331398
if (isSync) {
332399
// 通过 channel 返回
333-
channel.invokeMethod("onReceiveLoginAuthCallBackEvent",map);
400+
runMainThread(map,null,"onReceiveLoginAuthCallBackEvent");
334401
}else {
335402
// 通过回调返回
336-
result.success(map);
403+
runMainThread(map,result,null);
337404
}
338405
}
339406
});
@@ -928,7 +995,7 @@ private void addCustomButtonWidgets(Map para, JVerifyUIConfig.Builder builder)
928995
@Override
929996
public void onClicked(Context context, View view) {
930997
Log.d(TAG,"onClicked button widget.");
931-
channel.invokeMethod("onReceiveClickWidgetEvent", jsonMap);
998+
runMainThread(jsonMap,null,"onReceiveClickWidgetEvent");
932999
}
9331000
});
9341001
}

example/ios/Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
PODS:
22
- Flutter (1.0.0)
3-
- JCore (2.1.4-noidfa)
4-
- JVerification (2.5.2):
3+
- JCore (2.1.8)
4+
- JVerification (2.5.3):
55
- JCore (< 3.0.0, >= 1.2.6)
66
- jverify (0.0.1):
77
- Flutter
8-
- JCore (= 2.1.4-noidfa)
8+
- JCore
99
- JVerification
1010

1111
DEPENDENCIES:
1212
- Flutter (from `.symlinks/flutter/ios`)
1313
- jverify (from `.symlinks/plugins/jverify/ios`)
1414

1515
SPEC REPOS:
16-
https://github.com/cocoapods/specs.git:
16+
trunk:
1717
- JCore
1818
- JVerification
1919

@@ -25,10 +25,10 @@ EXTERNAL SOURCES:
2525

2626
SPEC CHECKSUMS:
2727
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
28-
JCore: 2f15311e6889ab43ed5d629802ef793cac566465
29-
JVerification: e62574b51a4a38ee5f7b46140a4698cb215d34ce
30-
jverify: ebdfc61d824bb06ba49ba46f52ad3f3b27f00401
28+
JCore: a7f1dead960d77a97717c73ea8b0aa5b33706491
29+
JVerification: 0d0b4474a250f19ef2bc45da7bd0d0e151350012
30+
jverify: 39f3e355cdb0d7c03fd2f8497ea11b273339547f
3131

3232
PODFILE CHECKSUM: aff02bfeed411c636180d6812254b2daeea14d09
3333

34-
COCOAPODS: 1.7.0.beta.2
34+
COCOAPODS: 1.8.4

example/lib/main.dart

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,13 @@ class _MyAppState extends State<MyApp> {
116116
),
117117
margin: EdgeInsets.fromLTRB(40, 5, 40, 5),
118118
),
119-
new Container(
120-
child: SizedBox(
121-
child: new CustomButton(
122-
onPressed: () {
123-
verifyNumber();
124-
},
125-
title: "验证号码",
126-
),
127-
width: double.infinity,
128-
),
129-
margin: EdgeInsets.fromLTRB(40, 5, 40, 5),
130-
),
131119
new Container(
132120
child: SizedBox(
133121
child: new CustomButton(
134122
onPressed: () {
135123
preLogin();
136124
},
137-
title: "登录预号",
125+
title: "预取号",
138126
),
139127
width: double.infinity,
140128
),
@@ -213,47 +201,18 @@ class _MyAppState extends State<MyApp> {
213201
});
214202
}
215203

216-
/// 发起号码认证,验证手机号码和本机SIM卡号码是否一致
217-
void verifyNumber() {
218-
print(controllerPHone.text);
219-
if (controllerPHone.text == null || controllerPHone.text == "") {
220-
setState(() {
221-
_result = "电话号码不能为空";
222-
});
223-
return;
224-
}
225-
setState(() {
226-
_loading = true;
227-
});
228-
jverify.checkVerifyEnable().then((map) {
229-
bool result = map[f_result_key];
230-
if (result) {
231-
jverify.verifyNumber(controllerPHone.text, token: _token ?? null).then((map) {
232-
int code = map[f_code_key];
233-
String content = map[f_msg_key];
234-
setState(() {
235-
_loading = false;
236-
_result = "[$code] message = $content";
237-
});
238-
});
239-
} else {
240-
setState(() {
241-
_loading = false;
242-
_result = "[2016], msg = 当前网络环境不支持认证";
243-
});
244-
}
245-
});
246-
}
247204

248205
/// 登录预取号
249206
void preLogin(){
250207
setState(() {
251208
_loading = true;
252209
});
210+
253211
jverify.checkVerifyEnable().then((map) {
254212
bool result = map[f_result_key];
255213
if (result) {
256214
jverify.preLogin().then((map) {
215+
print("预取号接口回调:${map.toString()}");
257216
int code = map[f_code_key];
258217
String message = map[f_msg_key];
259218
setState(() {
@@ -477,7 +436,7 @@ class _MyAppState extends State<MyApp> {
477436

478437
jverify.setDebugMode(true); // 打开调试模式
479438
jverify.setup(
480-
appKey: "你自己应用的 AppKey",//"你自己应用的 AppKey",
439+
appKey: "a0e6ace8d5b3e0247e3f58db",//"你自己应用的 AppKey",
481440
channel: "devloper-default"); // 初始化sdk, appKey 和 channel 只对ios设置有效
482441
// If the widget was removed from the tree while the asynchronous platform
483442
// message was in flight, we want to discard the reply rather than calling

0 commit comments

Comments
 (0)