From 4adda0eceb48624aa869e97a4b5a2f4ee4332aa4 Mon Sep 17 00:00:00 2001 From: jack ning Date: Sat, 7 May 2022 19:16:11 +0800 Subject: [PATCH] update --- bytedesk_kefu/CHANGELOG.md | 4 ++ bytedesk_kefu/README.md | 2 +- bytedesk_kefu/example/lib/main.dart | 15 ++++++ bytedesk_kefu/lib/http/bytedesk_user_api.dart | 54 +++++++++++-------- bytedesk_kefu/lib/model/messageProvider.dart | 2 +- bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart | 11 +--- bytedesk_kefu/lib/util/bytedesk_utils.dart | 4 +- bytedesk_kefu/pubspec.yaml | 10 ++-- 8 files changed, 63 insertions(+), 39 deletions(-) diff --git a/bytedesk_kefu/CHANGELOG.md b/bytedesk_kefu/CHANGELOG.md index f3b72af..70d993c 100644 --- a/bytedesk_kefu/CHANGELOG.md +++ b/bytedesk_kefu/CHANGELOG.md @@ -1,5 +1,9 @@ # Upgrade Log +## 1.2.6 + +* optimize user experience + ## 1.2.5 * optimize user experience diff --git a/bytedesk_kefu/README.md b/bytedesk_kefu/README.md index 4990fcf..e3ad2bc 100644 --- a/bytedesk_kefu/README.md +++ b/bytedesk_kefu/README.md @@ -8,7 +8,7 @@ bytedesk flutter helpdesk sdk - [Website](https://www.bytedesk.com) - [Download Gitee Demo](https://git.oschina.net/270580156/bytedesk-flutter) - [Download Github Demo](https://github.com/Bytedesk/bytedesk-flutter) -- [Download ApkDemo](https://bytedesk.oss-cn-shenzhen.aliyuncs.com/apk/bytedesk-android-sdk-demo.apk) + ## Features diff --git a/bytedesk_kefu/example/lib/main.dart b/bytedesk_kefu/example/lib/main.dart index 4a618ef..c01f927 100644 --- a/bytedesk_kefu/example/lib/main.dart +++ b/bytedesk_kefu/example/lib/main.dart @@ -43,6 +43,10 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State with WidgetsBindingObserver { + // 获取appkey,登录后台->渠道管理->Flutter->添加应用->获取appkey + String _appKey = '81f427ea-4467-4c7c-b0cd-5c0e4b51456f'; + // 获取subDomain,也即企业号:登录后台->客服管理->客服账号->企业号 + String _subDomain = "vip"; // String _title = '萝卜丝客服Demo(连接中...)'; // AudioCache audioCache = AudioCache(); @@ -140,6 +144,17 @@ class _MyAppState extends State with WidgetsBindingObserver { // BytedeskKefu.logout(); // }, // ), + // ListTile( + // title: Text('重新初始化'), + // onTap: () { + // BytedeskKefu.initWithUsernameAndNicknameAndAvatar( + // 'myflutterusername2', + // '我是帅哥', + // 'https://bytedesk.oss-cn-shenzhen.aliyuncs.com/avatars/boy.png', + // _appKey, + // _subDomain); + // }, + // ), ListTile( title: Text('技术支持: QQ-3群: 825257535'), ) diff --git a/bytedesk_kefu/lib/http/bytedesk_user_api.dart b/bytedesk_kefu/lib/http/bytedesk_user_api.dart index 2d57872..deba63b 100755 --- a/bytedesk_kefu/lib/http/bytedesk_user_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_user_api.dart @@ -30,13 +30,14 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { }; final oauthResponse = await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap); - print('oauth result: $oauthResponse'); + // print('oauth result: $oauthResponse'); // check the status code for the result int statusCode = oauthResponse.statusCode; - // print("statusCode $statusCode"); + print("statusCode $statusCode"); // 200: 授权成功,否则授权失败 final oauthJson = jsonDecode(oauthResponse.body); - // print('oauthJson:' + oauthJson); + print('oauth:'); + print(oauthJson); SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putString(BytedeskConstants.accessToken, oauthJson['access_token']); // @@ -66,7 +67,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { int statusCode = oauthResponse.statusCode; // 200: 授权成功,否则授权失败 final oauthJson = jsonDecode(oauthResponse.body); - print("oauthJson $oauthJson"); + print('smsOAuth:'); + print(oauthJson); if (statusCode == 200) { SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putBool(BytedeskConstants.isAuthenticated, true); @@ -100,7 +102,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { // print("statusCode $statusCode"); // 200: 授权成功,否则授权失败 final oauthJson = jsonDecode(oauthResponse.body); - print("oauthJson $oauthJson"); + print('unionIdOAuth:'); + print(oauthJson); if (statusCode == 200) { SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putBool(BytedeskConstants.isAuthenticated, true); @@ -134,8 +137,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // final responseJson = json.decode(initResponse.body); - // print("responseJson $responseJson"); + // print("register:"); + // print(responseJson); return JsonResult.fromJson(responseJson); } @@ -154,7 +157,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // print("registerAnonymous:"); + // print(responseJson); // User user = User.fromJson(responseJson['data']); // @@ -192,8 +196,9 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); - // + print("registerUser:"); + print(responseJson); + // int statusCode = responseJson['status_code']; if (statusCode == 200) { User user = User.fromJson(responseJson['data']); @@ -210,7 +215,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { } else { // SpUtil.putString(BytedeskConstants.uid, responseJson['data']); - SpUtil.putString(BytedeskConstants.username, username! + '@' + subDomain!); + SpUtil.putString( + BytedeskConstants.username, username! + '@' + subDomain!); SpUtil.putString(BytedeskConstants.password, password!); SpUtil.putString(BytedeskConstants.nickname, nickname!); SpUtil.putString(BytedeskConstants.avatar, avatar!); @@ -227,7 +233,6 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { var body = json.encode({"mobile": mobile, "password": password, "client": client}); - // final initUrl = '$baseUrl/visitors/api/v1/change'; final initUrl = Uri.http(BytedeskConstants.host, '/visitors/api/v1/change'); final initResponse = await this.httpClient.post(initUrl, headers: headers, body: body); @@ -238,7 +243,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); // final responseJson = json.decode(initResponse.body); - print("responseJson $responseJson"); + // print("changePassword"); + // print(responseJson); return JsonResult.fromJson(responseJson); } @@ -255,7 +261,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + // print("requestCode:"); + // print(responseJson); SpUtil.putBool(BytedeskConstants.exist, responseJson['data']['exist']); SpUtil.putString(BytedeskConstants.code, responseJson['data']['code']); @@ -299,7 +306,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + // print("getProfile:"); + // print(responseJson); // User user = User.fromJson(responseJson['data']); // @@ -762,8 +770,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); - // + // print("unfollow:"); + // print(responseJson); return JsonResult.fromJson(responseJson); } @@ -777,10 +785,14 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { {'access_token': accessToken}); final initResponse = await this.httpClient.post(initUrl, headers: headers, body: body); - - final responseJson = json.decode(initResponse.body); - print("responseJson $responseJson"); - // + //解决json解析中的乱码问题 + Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 + //将string类型数据 转换为json类型的数据 + final responseJson = + json.decode(utf8decoder.convert(initResponse.bodyBytes)); + print("logout:"); + print(responseJson); BytedeskUtils.clearUserCache(); } + } diff --git a/bytedesk_kefu/lib/model/messageProvider.dart b/bytedesk_kefu/lib/model/messageProvider.dart index f8f2a56..ed13da1 100755 --- a/bytedesk_kefu/lib/model/messageProvider.dart +++ b/bytedesk_kefu/lib/model/messageProvider.dart @@ -67,7 +67,7 @@ class MessageProvider { version: 9, ); // database path:/Users/ningjinpeng/Library/Developer/CoreSimulator/Devices/715CBA02-A602-4DE1-8C57-75A64B53BF03/data/Containers/Data/Application/8F46273D-9492-4C42-A618-4DF3815562BA/Documents/bytedesk-message-v9.db - print('database path:' + database!.path); + // print('database path:' + database!.path); } Future insert(Message message) async { diff --git a/bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart b/bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart index ec2131f..538d624 100755 --- a/bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart +++ b/bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart @@ -45,16 +45,9 @@ class BytedeskMqtt { factory BytedeskMqtt() { return _singleton; } - BytedeskMqtt._internal() { - // _connect(); - reconnect(); - } - // - // void _connect() async { - // reconnect(); - // } + BytedeskMqtt._internal() {} - void reconnect() async { + void connect() async { // eventbus发送广播,连接中... bytedeskEventBus .fire(ConnectionEventBus(BytedeskConstants.USER_STATUS_CONNECTING)); diff --git a/bytedesk_kefu/lib/util/bytedesk_utils.dart b/bytedesk_kefu/lib/util/bytedesk_utils.dart index 0d3e109..f9c666b 100755 --- a/bytedesk_kefu/lib/util/bytedesk_utils.dart +++ b/bytedesk_kefu/lib/util/bytedesk_utils.dart @@ -121,7 +121,7 @@ class BytedeskUtils { static bool mqttConnect() { var isLogin = SpUtil.getBool(BytedeskConstants.isLogin); if (isLogin!) { - new BytedeskMqtt(); + new BytedeskMqtt().connect(); return true; } return false; @@ -130,7 +130,7 @@ class BytedeskUtils { static bool mqttReConnect() { bool isConnected = new BytedeskMqtt().isConnected(); if (!isConnected) { - new BytedeskMqtt().reconnect(); + new BytedeskMqtt().connect(); return true; } return false; diff --git a/bytedesk_kefu/pubspec.yaml b/bytedesk_kefu/pubspec.yaml index 31df6c1..f8ee640 100644 --- a/bytedesk_kefu/pubspec.yaml +++ b/bytedesk_kefu/pubspec.yaml @@ -1,6 +1,6 @@ name: bytedesk_kefu description: the best app chat sdk in china, you can chat with the agent freely at anytime. the agent can chat with the visitor by web/pc/mac/ios/android client. -version: 1.2.5 +version: 1.2.6 homepage: https://www.weikefu.net environment: @@ -49,7 +49,7 @@ dependencies: # https://pub.dev/packages/flutter_easyloading flutter_easyloading: ^3.0.3 # H5-webchat https://pub.dev/packages/webview_flutter - webview_flutter: ^2.8.0 + webview_flutter: ^3.0.2 # https://pub.dev/packages/device_info device_info: ^2.0.3 # 查看大图 https://pub.dev/packages/photo_view @@ -77,7 +77,7 @@ dependencies: # audioplayers: ^0.16.1 # https://pub.dev/packages/flutter_html # https://github.com/Sub6Resources/flutter_html - flutter_html: ^2.2.1 + flutter_html: ^3.0.0-alpha.3 # https://pub.dev/packages/flutter_cache_manager flutter_cache_manager: ^3.3.0 # 保存图片到相册 @@ -99,7 +99,7 @@ dependencies: css_colors: ^1.1.1 # Plugins for rendering the