Hibok
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

1505 行
45 KiB

  1. import 'dart:convert';
  2. import 'package:chat/data/WebData.dart';
  3. import 'package:chat/data/chat_data_mgr.dart';
  4. import 'package:chat/data/constants.dart';
  5. import 'package:chat/data/group_data_mgr.dart';
  6. import 'package:chat/generated/i18n.dart';
  7. import 'package:chat/home/EditData.dart';
  8. import 'package:chat/home/IndexPage.dart';
  9. import 'package:chat/home/MoneyPage.dart';
  10. import 'package:chat/home/SelectSexPage.dart';
  11. import 'package:chat/models/ChatMsg.dart';
  12. import 'package:chat/models/UserInfo.dart';
  13. import 'package:chat/models/daily_bonus.dart';
  14. import 'package:chat/models/money_change.dart';
  15. import 'package:chat/proto/all.pbserver.dart';
  16. import 'package:chat/utils/LoadingDialog.dart';
  17. import 'package:chat/utils/MessageMgr.dart';
  18. import 'package:chat/utils/NetUtil.dart';
  19. import 'package:chat/utils/blacklist_mgr.dart';
  20. import 'package:chat/utils/friend_list_mgr.dart';
  21. import 'package:chat/utils/image_util.dart';
  22. import 'package:chat/utils/local_notification_util.dart';
  23. import 'package:chat/utils/sp_utils.dart';
  24. import 'package:chat/utils/sql_util.dart';
  25. import 'package:chat/utils/user_info_table.dart';
  26. import 'package:device_info/device_info.dart';
  27. import 'dart:core';
  28. import 'package:dio/dio.dart';
  29. import 'package:flutter/material.dart';
  30. import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
  31. import 'package:oktoast/oktoast.dart';
  32. import 'package:provider/provider.dart';
  33. import 'package:shared_preferences/shared_preferences.dart';
  34. import 'dart:io';
  35. import '../data/UserData.dart';
  36. import '../utils/TokenMgr.dart';
  37. import 'package:http_parser/http_parser.dart';
  38. class HttpUtil {
  39. static HttpUtil _instance;
  40. Dio dio;
  41. BaseOptions options;
  42. //static const String BaseUrl = 'http://192.168.0.223:7001/';
  43. //static const String BaseUrl = 'http://192.168.0.207:9080/';
  44. static const String BaseUrl = 'http://120.79.107.63:9080/';
  45. //static const String BaseUrl = 'http://192.168.0.177:9016/';
  46. //static const String BaseUrl = 'https://datasm.chengyouhd.com/';
  47. static HttpUtil _getInstance() {
  48. if (_instance == null) {
  49. _instance = HttpUtil._();
  50. }
  51. return _instance;
  52. }
  53. factory HttpUtil() => _getInstance();
  54. Map friendCache = {};
  55. HttpUtil._() {
  56. options = BaseOptions(
  57. baseUrl: BaseUrl,
  58. headers: {},
  59. );
  60. dio = new Dio(options);
  61. // (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
  62. // (HttpClient client) {
  63. // client.findProxy = (uri) {
  64. // //proxy all request to localhost:8888
  65. // return "PROXY 192.168.0.181:8888";
  66. // };
  67. // client.badCertificateCallback =
  68. // (X509Certificate cert, String host, int port) => true;
  69. // };
  70. dio.interceptors
  71. .add(InterceptorsWrapper(onRequest: (RequestOptions options) async {
  72. // Do something before request is sent
  73. return options; //continue
  74. // If you want to resolve the request with some custom data,
  75. // you can return a `Response` object or return `dio.resolve(data)`.
  76. // If you want to reject the request with a error message,
  77. // you can return a `DioError` object or return `dio.reject(errMsg)`
  78. }, onResponse: (Response response) async {
  79. // Do something with response data
  80. return response; // continue
  81. }, onError: (DioError e) async {
  82. // Do something with response error
  83. showToast(I18n.of(Constants.getCurrentContext()).net_error);
  84. return e; //continue
  85. }));
  86. }
  87. Future get(url, {data, options, cancelToken}) async {
  88. print('get请求启动! url:$url ,body: $data');
  89. Response response;
  90. try {
  91. response = await dio.get(
  92. url,
  93. queryParameters: data,
  94. cancelToken: cancelToken,
  95. );
  96. print('get请求成功!$url');
  97. } on DioError catch (e) {
  98. if (CancelToken.isCancel(e)) {
  99. print('get请求取消! ' + e.message);
  100. }
  101. print('get请求发生错误:$e');
  102. }
  103. return response;
  104. }
  105. getFriendList(callback) async {
  106. Map data = {
  107. "userId": UserData().basicInfo.userId,
  108. };
  109. data['sign'] = TokenMgr().getSign(data);
  110. Response res = await HttpUtil().post('friendship/friends/list', data: data);
  111. Map resData = res.data;
  112. if (resData['code'] == 0) {
  113. if (callback != null) callback(resData['data']);
  114. }
  115. }
  116. Future getDataWX(url, {data, options, cancelToken}) async {
  117. print('get请求启动! url:$url ,body: $data');
  118. Response response;
  119. BaseOptions options = BaseOptions(
  120. headers: {},
  121. );
  122. Dio dio = new Dio(options);
  123. try {
  124. response = await dio.get(
  125. url,
  126. queryParameters: data,
  127. cancelToken: cancelToken,
  128. );
  129. print('get请求成功!$url');
  130. } on DioError catch (e) {
  131. if (CancelToken.isCancel(e)) {
  132. print('get请求取消! ' + e.message);
  133. }
  134. print('get请求发生错误:$e');
  135. }
  136. return response;
  137. }
  138. Future post(url,
  139. {data,
  140. options,
  141. cancelToken,
  142. bool isShowLoading = false,
  143. failback}) async {
  144. // print('post请求启动! url:$url ,body: $data');
  145. Response response;
  146. if (isShowLoading) LoadingManage().showLoading();
  147. try {
  148. response = await dio.post(
  149. url,
  150. data: data,
  151. cancelToken: cancelToken,
  152. );
  153. print('$url post请求成功! $BaseUrl');
  154. if (isShowLoading) LoadingManage().closeLoading();
  155. } on DioError catch (e) {
  156. if (CancelToken.isCancel(e)) {
  157. print('post请求取消! ' + e.message);
  158. }
  159. print('post请求发生错误 url:$url 参数:$data 错误:$e');
  160. if (isShowLoading) LoadingManage().closeLoading();
  161. showToast(I18n.of(Constants.getCurrentContext()).server_error_tips);
  162. if (failback != null) failback();
  163. }
  164. return response;
  165. }
  166. // 上传文件
  167. Future uploadFile(File imgfile, data, url, contentType,
  168. {isShowLoading = false}) async {
  169. FormData formData = new FormData.fromMap({
  170. "type": data["type"],
  171. "userId": data["userId"],
  172. "sex": data['sex'] == null ? 0 : data['sex'],
  173. "isBurn": data['isBurn'] == null ? 0 : data['isBurn'],
  174. "sign": data['sign'],
  175. "file": await getMultipartFile(imgfile, contentType)
  176. });
  177. print('post请求启动! url:$url');
  178. if (isShowLoading) LoadingManage().showLoading();
  179. Response response;
  180. try {
  181. response = await dio.post(
  182. url,
  183. data: formData,
  184. );
  185. print('post请求成功!response.data:${response.data}');
  186. if (isShowLoading) LoadingManage().closeLoading();
  187. } on DioError catch (e) {
  188. if (CancelToken.isCancel(e)) {
  189. print('post请求取消! ' + e.message);
  190. }
  191. print('post请求发生错误:$e');
  192. if (isShowLoading) LoadingManage().closeLoading();
  193. }
  194. return response;
  195. }
  196. Future<MultipartFile> getMultipartFile(
  197. File imgfile, String contentType) async {
  198. //压缩图片文件
  199. var size = await imgfile.length();
  200. String path = imgfile.path;
  201. var fileBytes;
  202. if (contentType == 'image' && size > 10240) {
  203. fileBytes =
  204. await WidgetUtil.getCompressImg(path, quality: 60, percentage: 60);
  205. } else {
  206. fileBytes = imgfile.readAsBytesSync();
  207. }
  208. var name = path.substring(path.lastIndexOf("/") + 1, path.length);
  209. var suffix = name.substring(name.lastIndexOf(".") + 1, name.length);
  210. return new MultipartFile.fromBytes(fileBytes,
  211. filename: name, contentType: MediaType(contentType, suffix));
  212. }
  213. // 上传多个图片
  214. Future uploadFiles(List<File> imgfileList, data, url, contentType,
  215. {isShowLoading = false}) async {
  216. var imgList = [];
  217. for (int i = 0; i < imgfileList.length; i++) {
  218. imgList.add(await getMultipartFile(imgfileList[i], contentType));
  219. }
  220. FormData formData = new FormData.fromMap({
  221. "type": data["type"],
  222. "userId": data["userId"],
  223. "sex": data['sex'] == null ? 0 : data['sex'],
  224. "isBurn": data['isBurn'] == null ? 0 : data['isBurn'],
  225. "sign": data['sign'],
  226. "file": imgList
  227. });
  228. print('post请求启动! url:$url');
  229. if (isShowLoading) LoadingManage().showLoading();
  230. Response response;
  231. try {
  232. response = await dio.post(
  233. url,
  234. data: formData,
  235. );
  236. print('post请求成功!response.data:${response.data}');
  237. if (isShowLoading) LoadingManage().closeLoading();
  238. } on DioError catch (e) {
  239. if (CancelToken.isCancel(e)) {
  240. print('post请求取消! ' + e.message);
  241. }
  242. print('post请求发生错误:$e');
  243. if (isShowLoading) LoadingManage().closeLoading();
  244. }
  245. return response;
  246. }
  247. Future getUserInfoFromServer(int friendId) async {
  248. Map<String, dynamic> data = {
  249. "visitUserId": UserData().basicInfo.userId,
  250. "userId": friendId,
  251. "language": UserData().language,
  252. };
  253. data['sign'] = TokenMgr().getSign(data);
  254. data['lat'] = UserData().latitude;
  255. data['lng'] = UserData().longitude;
  256. print('请求用户信息 $data}');
  257. print('从服务器获取用户信息$friendId');
  258. Response res = await HttpUtil().post('user/info/list', data: data);
  259. if (res == null) {
  260. return null;
  261. }
  262. Map resData = res.data;
  263. print('用户信息resData $resData');
  264. if (resData['code'] == 0 && resData['data'] != null) {
  265. var info = UserInfo.fromJson(resData['data']);
  266. info.isBlackened
  267. ? BlacklistMgr.addBlackListMe(info.userId)
  268. : BlacklistMgr.removeBalckListMe(info.userId);
  269. info.isBlackList
  270. ? BlacklistMgr.addMyBlackList(info.userId)
  271. : BlacklistMgr.removeMyBalckList(info.userId);
  272. friendCache[friendId] = info;
  273. FriendListMgr().updateFriendInfo(info);
  274. UserInfoTable().insertUser(info);
  275. MessageMgr().emit('UpdateUserInfo', info);
  276. return info;
  277. } else {
  278. return null;
  279. }
  280. }
  281. Future getFriendInfo(int friendId, [bool isUpdate = false]) async {
  282. print('开始获取用户信息$friendId');
  283. if (friendId == null) {
  284. print('用户Id为空,无法获取信息');
  285. return null;
  286. }
  287. if (friendCache[friendId] != null) {
  288. print('存在用户信息$friendId 缓存');
  289. if (isUpdate) {
  290. //如果需要更新,那么先读取旧数据,然后后台更新
  291. getUserInfoFromServer(friendId);
  292. }
  293. return friendCache[friendId];
  294. }
  295. var info = await SqlUtil.userInfoTable.getUserInfoFromLocal(friendId);
  296. print('从本地数据库读取用户$friendId 信息');
  297. if (info != null) {
  298. if (isUpdate) {
  299. //如果需要更新,那么先读取旧数据,然后后台更新
  300. getUserInfoFromServer(friendId);
  301. }
  302. friendCache[friendId] = info;
  303. return info;
  304. }
  305. return await getUserInfoFromServer(friendId);
  306. }
  307. getUserInfo(visitedUserId, [callback, failcallback, errorcallback]) async {
  308. var data = {
  309. "visitUserId": UserData().basicInfo.userId,
  310. "userId": visitedUserId,
  311. "language": UserData().language,
  312. };
  313. data['sign'] = TokenMgr().getSign(data);
  314. data['lat'] = UserData().latitude;
  315. data['lng'] = UserData().longitude;
  316. Response res = await HttpUtil()
  317. .post('user/info/list', data: data, failback: errorcallback);
  318. if (res == null) {
  319. print('请求异常');
  320. return;
  321. }
  322. Map resData = res.data;
  323. if (resData['code'] == 0) {
  324. var info = UserInfo.fromJson(resData['data']);
  325. info.isBlackened
  326. ? BlacklistMgr.addBlackListMe(info.userId)
  327. : BlacklistMgr.removeBalckListMe(info.userId);
  328. info.isBlackList
  329. ? BlacklistMgr.addMyBlackList(info.userId)
  330. : BlacklistMgr.removeMyBalckList(info.userId);
  331. FriendListMgr().updateFriendInfo(info);
  332. friendCache[info.userId] = info;
  333. MessageMgr().emit('UpdateUserInfo', info);
  334. if (callback != null) callback(resData['data']);
  335. } else if (resData['code'] == -4) {
  336. if (failcallback != null) failcallback();
  337. }
  338. }
  339. Future getTranslateState(int sessionId) async {
  340. Map data = {
  341. "userId": UserData().basicInfo.userId,
  342. "chatUserId": sessionId,
  343. };
  344. data['sign'] = TokenMgr().getSign(data);
  345. Response res =
  346. await HttpUtil().post('translate/get/user/status', data: data);
  347. if (res == null) {
  348. print('请求异常');
  349. return null;
  350. }
  351. var resData = res.data;
  352. if (resData['code'] == 0) {
  353. return resData['data'];
  354. }
  355. return null;
  356. }
  357. updateTranslateState(int sessionId, bool state) async {
  358. Map data = {
  359. "userId": UserData().basicInfo.userId,
  360. "chatUserId": sessionId,
  361. "status": state ? 1 : 0
  362. };
  363. data['sign'] = TokenMgr().getSign(data);
  364. Response res = await HttpUtil().post('translate/set/up/status', data: data);
  365. if (res == null) {
  366. print('请求异常');
  367. return false;
  368. }
  369. var resData = res.data;
  370. if (resData['code'] == 0) {
  371. return true;
  372. }
  373. return false;
  374. }
  375. changeLanguage(BuildContext context, lang, callback,
  376. [showLoading = false]) async {
  377. var data = {
  378. "userid": UserData().basicInfo.userId,
  379. "language": lang,
  380. };
  381. data['sign'] = TokenMgr().getSign(data);
  382. try {
  383. Response res = await HttpUtil().post('user/setting/language',
  384. data: data, isShowLoading: showLoading);
  385. if (res == null) {
  386. print('请求异常');
  387. return;
  388. }
  389. Map resData = res.data;
  390. if (resData['code'] == 0) {
  391. if (callback != null) callback();
  392. //重新登录
  393. // SocketUtil().reLogin();
  394. NetWork().reLogin();
  395. }
  396. } catch (e) {}
  397. }
  398. userFreeTime(BuildContext context, var viewUserId, int type, callback) async {
  399. Map data = {
  400. "userId": UserData().basicInfo.userId,
  401. "viewUserId": viewUserId,
  402. 'type': type,
  403. };
  404. data['sign'] = TokenMgr().getSign(data);
  405. try {
  406. Response res = await HttpUtil()
  407. .post('photos/unlock/permissions', data: data, isShowLoading: true);
  408. if (res == null) {
  409. print('请求异常');
  410. return;
  411. }
  412. Map resData = res.data;
  413. if (resData['code'] == 0) {
  414. if (callback != null) callback();
  415. }
  416. } catch (e) {}
  417. }
  418. saveAotuLoginKey(resData, {bool isSaveUserId = true}) async {
  419. //将用户信息存到本地
  420. if (resData['data']['aotuLoginKey'] != null) {
  421. SharedPreferences prefs = await SharedPreferences.getInstance();
  422. await prefs.setString(
  423. Constants.AutoLoginKey, resData['data']['aotuLoginKey']);
  424. if (isSaveUserId) {
  425. await prefs.setInt(Constants.LocalUserId, UserData().basicInfo.userId);
  426. }
  427. }
  428. }
  429. ///登录
  430. changePage(BuildContext context, Map resData) async {
  431. UserData().basicInfo.userId = resData['data']['userid'];
  432. UserData().basicInfo.sex = resData['data']['sex'];
  433. if (resData['data']['mobile'] != null && resData['data']['mobile'] != '') {
  434. UserData().mobile = int.parse(resData['data']['mobile']);
  435. }
  436. if (resData['data']['bindId'] != null) {
  437. UserData().agentId = resData['data']['bindId'];
  438. }
  439. //读取聊天信息
  440. await ChatDataMgr().initMsg();
  441. //读取群信息
  442. await GroupInfoMgr().initLocalGroupList();
  443. print('~~~~~~~~~~~~~changePage~~~~~~~~~~~~~~~~~~~~~~');
  444. changeLanguage(context, UserData().language, null);
  445. getRewardAndRedPacketState();
  446. //clearReadData(UserData().basicInfo.userId);
  447. if (resData['data']['sex'] == 0) {
  448. Navigator.of(context).push(
  449. new MaterialPageRoute(
  450. builder: (context) {
  451. return SelectSex();
  452. },
  453. ),
  454. );
  455. saveAotuLoginKey(resData, isSaveUserId: false);
  456. return;
  457. }
  458. if (resData['data']['info'] == 0) {
  459. Navigator.of(context).push(
  460. new MaterialPageRoute(
  461. builder: (context) {
  462. return EditPage(
  463. isEditPage: false,
  464. );
  465. },
  466. ),
  467. );
  468. saveAotuLoginKey(resData, isSaveUserId: false);
  469. return;
  470. }
  471. checkFriends();
  472. LocalNotificationUtil.instance.startPush();
  473. //ChatDataMgr().initMsg();
  474. Navigator.of(context)
  475. .pushNamedAndRemoveUntil('/main', (route) => route == null);
  476. MessageMgr().emit('update_system');
  477. saveAotuLoginKey(resData);
  478. initLocation();
  479. }
  480. initLocation() async {
  481. SharedPreferences prefs = await SharedPreferences.getInstance();
  482. var latitude = prefs.getDouble(Constants.Latitude);
  483. var longitude = prefs.getDouble(Constants.Longitude);
  484. print('存贮在本地的位置: $latitude------$longitude');
  485. if (latitude != null) UserData().latitude = latitude;
  486. if (longitude != null) UserData().longitude = longitude;
  487. }
  488. setPhote(BuildContext context, id, type, callback) async {
  489. var data = {
  490. "userId": UserData().basicInfo.userId,
  491. "type": type,
  492. "pId": id,
  493. };
  494. data['sign'] = TokenMgr().getSign(data);
  495. Response res = await HttpUtil()
  496. .post('photos/setting/burns', data: data, isShowLoading: true);
  497. if (res == null) {
  498. print('请求异常');
  499. return;
  500. }
  501. var resData = res.data;
  502. showToast(resData['msg']);
  503. if (resData['code'] == 0) {
  504. if (callback != null) callback();
  505. }
  506. }
  507. clearCacheData() async {
  508. print('######### 清除缓存key');
  509. SharedPreferences prefs = await SharedPreferences.getInstance();
  510. prefs.remove(Constants.AutoLoginKey);
  511. prefs.remove(Constants.LocalUserId);
  512. prefs.remove(Constants.LocalUsrInfo);
  513. }
  514. // clearReadData(userId) async {
  515. // SharedPreferences prefs = await SharedPreferences.getInstance();
  516. // var localUserId = prefs.getInt(Constants.LocalUserId);
  517. // if (userId != localUserId) {
  518. // prefs.remove(Constants.ApplyCount);
  519. // prefs.remove(Constants.EvaluateCount);
  520. // prefs.remove(Constants.ParkCount);
  521. // prefs.remove(Constants.CastCount);
  522. // prefs.remove(Constants.WalletCount);
  523. // }
  524. // }
  525. void postLoginOut(BuildContext context) async {
  526. Map data = {
  527. "userId": UserData().basicInfo.userId,
  528. };
  529. data['sign'] = TokenMgr().getSign(data);
  530. Response res = await HttpUtil().post('user/login/out', data: data);
  531. if (res == null) {
  532. print('请求异常');
  533. return;
  534. }
  535. Map resData = res.data;
  536. if (resData['code'] == 0) {
  537. clearCacheData();
  538. FriendListMgr().friendList?.clear();
  539. Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(
  540. builder: (context) {
  541. return IndexPage();
  542. },
  543. ), (route) => route == null);
  544. NetWork().singOut();
  545. UserData().reset();
  546. } else {
  547. showToast(resData['msg']);
  548. }
  549. }
  550. buyGoods(money, goodsId, detailtype, changeuserId, context, callback) async {
  551. if (Provider.of<MoneyChangeProvider>(context).money < money) {
  552. showToast(I18n.of(context).balance_insufficien);
  553. return;
  554. }
  555. var data = {
  556. "userId": UserData().basicInfo.userId,
  557. "type": 1,
  558. "detailtype": detailtype,
  559. };
  560. data['sign'] = TokenMgr().getSign(data);
  561. data['value'] = money;
  562. data['changeuserId'] = changeuserId;
  563. data['membergoodsId'] = goodsId;
  564. Response res = await HttpUtil()
  565. .post('wealth/user/add', data: data, isShowLoading: true);
  566. if (res == null) {
  567. print('请求异常');
  568. return;
  569. }
  570. Map resData = res.data;
  571. showToast(resData['msg']);
  572. if (resData['code'] == 0) {
  573. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(money);
  574. if (callback != null) callback();
  575. }
  576. }
  577. buyPictures(money, changeuserId, context, callback) async {
  578. if (Provider.of<MoneyChangeProvider>(context).money < money) {
  579. showToast(I18n.of(context).balance_insufficien);
  580. return;
  581. }
  582. var data = {
  583. "userId": UserData().basicInfo.userId,
  584. "viewUserId": changeuserId,
  585. "price": money,
  586. };
  587. data['sign'] = TokenMgr().getSign(data);
  588. Response res = await HttpUtil()
  589. .post('photos/user/unlock', data: data, isShowLoading: true);
  590. if (res == null) {
  591. print('请求异常');
  592. return;
  593. }
  594. Map resData = res.data;
  595. showToast(resData['msg']);
  596. if (resData['code'] == 0) {
  597. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(money);
  598. if (callback != null) callback();
  599. }
  600. }
  601. buyVIP(int money, int gid, int type, BuildContext context, callback) async {
  602. if (Provider.of<MoneyChangeProvider>(context).money < money) {
  603. showToast(I18n.of(context).balance_insufficien);
  604. return;
  605. }
  606. Map data = {
  607. "userId": UserData().basicInfo.userId,
  608. "gid": gid,
  609. "type": type,
  610. "price": money,
  611. };
  612. data['sign'] = TokenMgr().getSign(data);
  613. Response res = await HttpUtil()
  614. .post('goods/user/purchase', data: data, isShowLoading: true);
  615. if (res == null) {
  616. print('请求异常');
  617. return;
  618. }
  619. Map resData = res.data;
  620. showToast(resData['msg']);
  621. if (resData['code'] == 0) {
  622. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(money);
  623. if (callback != null) callback();
  624. }
  625. }
  626. buyChatAccount(money, changeuserId, context, callback) async {
  627. if (Provider.of<MoneyChangeProvider>(context).money < money) {
  628. showToast(I18n.of(context).balance_insufficien);
  629. return;
  630. }
  631. var data = {
  632. "userId": UserData().basicInfo.userId,
  633. "unlockUserId": changeuserId,
  634. "price": money,
  635. };
  636. data['sign'] = TokenMgr().getSign(data);
  637. Response res = await HttpUtil()
  638. .post('photos/pay/unlock/chat', data: data, isShowLoading: true);
  639. if (res == null) {
  640. print('请求异常');
  641. return;
  642. }
  643. Map resData = res.data;
  644. showToast(resData['msg']);
  645. if (resData['code'] == 0) {
  646. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(money);
  647. if (callback != null) callback();
  648. }
  649. }
  650. void getMoneyInfo(BuildContext context, callback) async {
  651. if (Platform.isIOS) {
  652. await MoneyPageState.initPayConf(context);
  653. }
  654. Map data = {
  655. "userid": UserData().basicInfo.userId,
  656. "moneytype":
  657. UserData().language == LanguageType.SimplifiedChinese ? 0 : 1,
  658. "mobiletype": Platform.isIOS ? 0 : 1,
  659. };
  660. if (Platform.isIOS) {
  661. data['moneytype'] = 1;
  662. }
  663. print('moneytype ${data['moneytype']}');
  664. data['sign'] = TokenMgr().getSign(data);
  665. Response res = await HttpUtil()
  666. .post('goods/info/list', data: data, isShowLoading: true);
  667. if (res == null) {
  668. print('请求异常');
  669. return;
  670. }
  671. Map resData = res.data;
  672. if (resData['code'] == 0) {
  673. if (callback != null) callback(resData['data']);
  674. }
  675. }
  676. void getWealth(BuildContext context, callback) async {
  677. Map data = {
  678. "userId": UserData().basicInfo.userId,
  679. };
  680. data['sign'] = TokenMgr().getSign(data);
  681. Response res = await HttpUtil().post('wealth/user/info', data: data);
  682. if (res == null) {
  683. print('请求异常');
  684. return;
  685. }
  686. Map resData = res.data;
  687. print(resData);
  688. if (resData['code'] == 0 && resData['data'] != null) {
  689. UserData().basicInfo.isMember = resData['data']['IsMember'] ?? 0;
  690. UserData().incomeMoney = resData['data']['IncomeCoin'];
  691. UserData().frozenMoney = resData['data']['FrozenCoin'];
  692. UserData().memberEndTime = resData['data']['MemberEnd'];
  693. if (callback != null) callback(resData['data']);
  694. }
  695. }
  696. //获取红包与打赏开关状态
  697. getRewardAndRedPacketState() async {
  698. var myId = UserData().basicInfo.userId;
  699. Map data = {
  700. "userId": myId,
  701. };
  702. data['sign'] = TokenMgr().getSign(data);
  703. Response res = await HttpUtil().post('system/switch', data: data);
  704. if (res == null) {
  705. print('请求异常');
  706. return;
  707. }
  708. Map resData = res.data;
  709. print('### system/switch' + resData.toString());
  710. if (resData['code'] == 0) {
  711. var config = resData['data'];
  712. if (config != null) {
  713. UserData().redPacketSW = config['redPacket'];
  714. UserData().giftSwitch = config['reward'];
  715. UserData().bannerZF = config['iapPay'];
  716. UserData().sign = config['sign'];
  717. UserData().groupQRCode = config['groupQRCode'];
  718. UserData().addFdDistanceSwitch = config['distance'] ?? 0;
  719. UserData().stationOpenSwitch = config['station'] == 1;
  720. UserData().myProgramOpenSwitch = config['myProgram'] == 1;
  721. UserData().nearbyOpenSwitch = config['nearby'] == 1;
  722. // print('### config: start');
  723. // print('### config: iapPay:${config['iapPay']}');
  724. }
  725. }
  726. }
  727. ///检查是否有缓存的内购单-有的话向服务器发送请求重新创建订单
  728. void checkReceiptCache() async {
  729. String str = await SPUtils.get(Constants.IOS_IAP_Receipt);
  730. if (str != null && str.isNotEmpty) {
  731. print('### 有缓存单');
  732. List<String> split = str.split("@");
  733. createOrder(split[0], split[1], split[2]);
  734. } else {
  735. print('### 没有缓存单');
  736. }
  737. }
  738. ///ios内购-创建订单
  739. void createOrder(String currentGoodsId, String receipt, String purchaseToken,
  740. {BuildContext context}) async {
  741. // String base84str = base64Encode(utf8.encode(receipt));
  742. var data = {
  743. "userid": UserData().basicInfo.userId,
  744. "moneytype": 1,
  745. 'gid': currentGoodsId,
  746. "payway": 1,
  747. };
  748. data['sign'] = TokenMgr().getSign(data);
  749. data['receipt'] = receipt;
  750. data['isenable'] = Constants.isSandbox ? 0 : 1;
  751. Response res = await HttpUtil().post('order/add/goods', data: data);
  752. print('#### 创建订单-返回');
  753. if (res == null) {
  754. print('请求异常');
  755. return;
  756. }
  757. Map resData = res.data;
  758. print('#### 创建订单-返回:' + resData.toString());
  759. if (resData['code'] == 0) {
  760. // String OrderNo = resData['data']['OrderNo'];
  761. Future.delayed(Duration(seconds: 3), () {
  762. MessageMgr().emit('refresh_money');
  763. });
  764. if (context == null) {
  765. await FlutterInappPurchase.instance.initConnection;
  766. }
  767. FlutterInappPurchase.instance.finishTransaction(purchaseToken);
  768. SPUtils.remove(Constants.IOS_IAP_Receipt);
  769. } else {
  770. ///创建订单失败-
  771. await SPUtils.saveString(Constants.IOS_IAP_Receipt,
  772. currentGoodsId + '@' + receipt + '@' + purchaseToken);
  773. }
  774. if (context != null) {
  775. Navigator.of(context).pop();
  776. }
  777. }
  778. ///登陆
  779. void login(
  780. String _phoneNumber, String _passWorld, BuildContext context) async {
  781. var data = {
  782. "mobile": _phoneNumber,
  783. "text": _passWorld,
  784. "type": 0,
  785. "language": UserData().language,
  786. };
  787. data['sign'] = TokenMgr().getSign(data);
  788. Response res = await HttpUtil()
  789. .post('user/mobile/login', data: data, isShowLoading: true);
  790. if (res == null) {
  791. print('请求异常');
  792. return;
  793. }
  794. var resData = res.data;
  795. if (resData['code'] == 0 && resData['data'] != null) {
  796. HttpUtil().changePage(context, resData);
  797. } else {
  798. showToast(resData['msg']);
  799. }
  800. }
  801. ///获取推送设置
  802. getSettingInfo() async {
  803. Map data = {
  804. "userId": UserData().basicInfo.userId,
  805. "sex": UserData().basicInfo.sex,
  806. };
  807. data['sign'] = TokenMgr().getSign(data);
  808. try {
  809. Response res = await HttpUtil().post('message/push/message', data: data);
  810. if (res == null) {
  811. print('请求异常');
  812. return;
  813. }
  814. Map resData = res.data;
  815. bool isMan = UserData().isMan();
  816. ///女号 {data: {PrivacyChat: 1, NewBroadcast: 1, ApplyCheck: 1, CheckAccount: 1, CheckPhoto: 1, SendAccount: 1}, code: 0, msg: 成功}
  817. ///男号 {data: {PrivacyChat: 1, NewBroadcast: 1, AcceptCheck: 1, ApplySuccess: 1}, code: 0, msg: 成功}
  818. print('###settingdata res.data ${res.data}');
  819. if (resData['code'] == 0) {
  820. UserData().privatyMsgPushSwitch = resData['data']['PrivacyChat'] == 1;
  821. UserData().newDateSwitch = resData['data']['NewBroadcast'] == 1;
  822. if (isMan) {
  823. UserData().acceptCheckSwitch = resData['data']['AcceptCheck'] == 1;
  824. UserData().codeSucessSwitch = resData['data']['ApplySuccess'] == 1;
  825. } else {
  826. UserData().applyCheckSwitch = resData['data']['ApplyCheck'] == 1;
  827. UserData().checkPhotoSwitch = resData['data']['CheckPhoto'] == 1;
  828. }
  829. }
  830. } catch (e) {}
  831. MessageMgr().emit(MessageMgr.REFRESH_PUSH_PERMISSION);
  832. }
  833. ///版本控制
  834. appVersionUpdate(Function callBack) async {
  835. Map data = {
  836. "ditch": Constants.isStoreVersion ? 0 : 1,
  837. "type": Platform.isAndroid ? 0 : 1,
  838. };
  839. data['sign'] = TokenMgr().getSign(data);
  840. data['language'] = UserData().language;
  841. try {
  842. Response res = await HttpUtil().post('system/version/info', data: data);
  843. Map resData = res.data;
  844. print('###appVersionUpdate res.data ${res.data}');
  845. if (resData['code'] == 0) {
  846. bool needNotice = resData['data']['Notice'] == 1;
  847. ///是否通知更新
  848. bool forceUpdate = resData['data']['IsStronger'] == 1;
  849. ///是否通知强更
  850. String version = resData['data']['VersionNo'];
  851. String describe = resData['data']['Describe'];
  852. String downloadUrl = resData['data']['DownloadUrl'];
  853. String appId = resData['data']['AppId'];
  854. callBack(
  855. needNotice, forceUpdate, version, describe, downloadUrl, appId);
  856. }
  857. } catch (e) {}
  858. }
  859. downloadApk(
  860. BuildContext context,
  861. String filePath,
  862. String downloadUrl,
  863. Function downloadCallback,
  864. ) async {
  865. final file = new File(filePath);
  866. bool isExist = await file.exists();
  867. if (isExist) {
  868. print('### 文件存在 : ${file.path}');
  869. file.delete();
  870. }
  871. // else {
  872. //
  873. // print('### 开始下载 $downloadUrl');
  874. // dio.download(downloadUrl, filePath, onReceiveProgress: downloadCallback);
  875. // }
  876. // downloadUrl ='oemarket.com/app0/30/30970/apk/2085562.apk?channel_id=426&tid=d73j9ihlkucuxfqpgnxgjeif';
  877. dio.download(downloadUrl, filePath, onReceiveProgress: downloadCallback);
  878. }
  879. ///获取用户每日签到信息
  880. Future<DailyBonusBean> getDailyBonus() async {
  881. Map data = {
  882. "userId": UserData().basicInfo.userId,
  883. };
  884. data['sign'] = TokenMgr().getSign(data);
  885. data['userId'] = UserData().basicInfo.userId;
  886. try {
  887. Response res = await HttpUtil().post('sign/in/user/info', data: data);
  888. Map resData = res.data;
  889. print('###getDailyBonus res.data ${res.data}');
  890. if (resData['code'] == 0) {
  891. return DailyBonusBean.fromMap(resData['data']);
  892. }
  893. return null;
  894. } catch (e) {
  895. return null;
  896. }
  897. }
  898. ///点击签到
  899. Future<bool> signInBounus(int score) async {
  900. Map data = {
  901. "userId": UserData().basicInfo.userId,
  902. "score": score,
  903. };
  904. data['sign'] = TokenMgr().getSign(data);
  905. data['userId'] = UserData().basicInfo.userId;
  906. data['score'] = score;
  907. try {
  908. Response res = await HttpUtil().post('sign/in/user', data: data);
  909. Map resData = res.data;
  910. print('###signInBounus res.data ${res.data}');
  911. if (resData['code'] == 0) {
  912. return true;
  913. // bool needNotice = resData['data']['Notice']==1; ///是否通知更新
  914. // return DailyBonusBean.fromMap(resData['data']);
  915. } else {
  916. showToast(resData['msg']);
  917. }
  918. return false;
  919. } catch (e) {
  920. return false;
  921. }
  922. }
  923. /// 用户签到积分兑换商品
  924. Future<bool> signInExchange(GoodsBean goodsBean) async {
  925. Map data = {
  926. "userId": UserData().basicInfo.userId,
  927. "id": goodsBean.id,
  928. "score": goodsBean.s,
  929. };
  930. data['sign'] = TokenMgr().getSign(data);
  931. data['userId'] = UserData().basicInfo.userId;
  932. data['score'] = goodsBean.s;
  933. data['id'] = goodsBean.id;
  934. try {
  935. Response res =
  936. await HttpUtil().post('sign/in/score/exchange', data: data);
  937. Map resData = res.data;
  938. print('###signInExchange res.data ${res.data}');
  939. if (resData['code'] == 0) {
  940. return true;
  941. } else {
  942. showToast(resData['msg']);
  943. }
  944. return false;
  945. } catch (e) {
  946. return false;
  947. }
  948. }
  949. addFriends(
  950. BuildContext context, int friendId, String content, callback) async {
  951. Map data = {
  952. "userId": UserData().basicInfo.userId,
  953. "friendsUserId": friendId
  954. };
  955. data['sign'] = TokenMgr().getSign(data);
  956. data['content'] = content;
  957. Response res = await HttpUtil().post('friendship/add/friends', data: data);
  958. Map resData = res.data;
  959. print(resData);
  960. if (resData['code'] == 0) {
  961. showToast(resData['msg']);
  962. if (callback != null) callback();
  963. }
  964. }
  965. //付费人工翻译
  966. getPersonalTranslate(MsgModel msgModel) async {
  967. Map data = {
  968. "suserid": msgModel.from,
  969. "chatmsgid": msgModel.time,
  970. "tlanguage": UserData().language,
  971. "chattype": msgModel.msgType,
  972. "chatchanneltype": msgModel.channelType,
  973. "targetid": msgModel.sessionId
  974. };
  975. data['sign'] = TokenMgr().getSign(data);
  976. if (msgModel.msgType == 0) {
  977. data['content'] = base64Encode(msgModel.msgContent);
  978. } else {
  979. if (msgModel.localFile == null) {
  980. showToast('请稍后再试');
  981. return;
  982. }
  983. data['content'] =
  984. base64Encode(File(msgModel.localFile).readAsBytesSync());
  985. print('语音转换的文字: ${utf8.decode(msgModel.enTranslateContent)}');
  986. data['vcontent'] = base64Encode(msgModel.enTranslateContent);
  987. }
  988. if (msgModel.channelType == ChatChannelType.Group.value) {
  989. data['theme'] = GroupInfoMgr().getGroupName(msgModel.sessionId);
  990. } else {
  991. data['theme'] = '';
  992. }
  993. data['list'] = ChatDataMgr().getForeChatRecord(msgModel);
  994. data["tuserids"] = [UserData().basicInfo.userId];
  995. data['duration'] =
  996. msgModel.extraInfo != null ? msgModel.extraInfo ~/ 1000 : 0;
  997. data['ispay'] = true;
  998. if (msgModel.msgType == ChatType.TextChatType.value) {
  999. int length = utf8.decode(msgModel.msgContent).length;
  1000. data['money'] = length ~/ 50 + 1; //每50个字耗费1H币
  1001. print('字数 $length 价格 ${length % 50 + 1}');
  1002. } else if (msgModel.msgType == ChatType.ShortVoiceChatType.value) {
  1003. //没20秒扣除1Hb
  1004. data['money'] =
  1005. msgModel.extraInfo != null ? msgModel.extraInfo ~/ 20000 + 1 : 0;
  1006. }
  1007. if (msgModel.translateContent != null &&
  1008. msgModel.translateContent.length > 0) {
  1009. data['mcontent'] = base64Encode(msgModel.translateContent);
  1010. }
  1011. Response res =
  1012. await HttpUtil().post('service/paid/translation', data: data);
  1013. if (res == null) {
  1014. return false;
  1015. }
  1016. Map resData = res.data;
  1017. print('付费翻译请求$resData');
  1018. if (resData['code'] == 0) {
  1019. print('扣除 H 币 ${data['money']}');
  1020. return true;
  1021. }
  1022. print(resData['msg']);
  1023. showToast(resData['msg']);
  1024. return false;
  1025. }
  1026. //用户评价人工翻译,差评
  1027. Future<bool> rateTranslateResult(MsgModel msg, Function callback) async {
  1028. Map data = {
  1029. "userId": UserData().basicInfo.userId,
  1030. "chatUserId": msg.from,
  1031. "chatMsgId": msg.time,
  1032. "score": 1
  1033. };
  1034. data['sign'] = TokenMgr().getSign(data);
  1035. Response res = await HttpUtil().post('translate/user/score', data: data);
  1036. if (res == null) {
  1037. return false;
  1038. }
  1039. var resData = res.data;
  1040. if (resData['code'] == 0) {
  1041. msg.transTag = 10; //已评价过
  1042. if (callback != null) {
  1043. callback();
  1044. }
  1045. SqlUtil().updateUserTranslateState(msg.sessionId, msg.time, msg.transTag);
  1046. return true;
  1047. }
  1048. return false;
  1049. }
  1050. //根据经纬度获取用户国家城市
  1051. getAddress(double lon, double lat) async {
  1052. Map data = {
  1053. "lon": lon.toString(),
  1054. "lat": lat.toString(),
  1055. };
  1056. data['sign'] = TokenMgr().getSign(data);
  1057. data['language'] = UserData().language;
  1058. Response res = await HttpUtil().post('user/get/address', data: data);
  1059. if (res == null) return;
  1060. Map resData = res.data;
  1061. if (resData['code'] == 0 && resData['data'] != null) {
  1062. print(resData['data']);
  1063. List address = resData['data'].split(',');
  1064. if (address.length != 2) return;
  1065. String country = address[0];
  1066. String city = address[1];
  1067. UserData().isInChina = false;
  1068. if (country == '越南') {
  1069. UserData().currentCity = 'VietNam-';
  1070. List citys = constData[3]['city'][0]['List'];
  1071. for (int i = 0; i < citys.length; i++) {
  1072. if (citys[i]['Value'] == city) {
  1073. UserData().currentCity += citys[i]['Key'];
  1074. break;
  1075. }
  1076. }
  1077. } else if (country == '中国') {
  1078. UserData().isInChina = true;
  1079. UserData().currentCity = 'China-ChinaRepeat';
  1080. } else {
  1081. UserData().currentCity = 'VietNam-HoChiMinhCIty';
  1082. }
  1083. if (UserData().currentCity != UserData().basicInfo.meetPlace) {
  1084. UserData().basicInfo.meetPlace = UserData().currentCity;
  1085. changeCurrentCity(lon, lat, () {});
  1086. }
  1087. MessageMgr().emit('change_currentcity');
  1088. }
  1089. }
  1090. //根据经纬度获取用户国家城市
  1091. changeCurrentCity(double lon, double lat, callback) async {
  1092. if (UserData().basicInfo.userId == null) return;
  1093. Map data = {
  1094. "userId": UserData().basicInfo.userId,
  1095. "lon": lon.toString(),
  1096. "lat": lat.toString(),
  1097. };
  1098. data['sign'] = TokenMgr().getSign(data);
  1099. Response res = await HttpUtil().post('user/update/meetPlace', data: data);
  1100. if (res == null) return;
  1101. Map resData = res.data;
  1102. print(resData);
  1103. if (resData['code'] == 0) {
  1104. callback();
  1105. }
  1106. }
  1107. //通过手机号查询用户
  1108. searchNewFrindsByPhone(String phone, callback) async {
  1109. Map data = {
  1110. "userId": UserData().basicInfo.userId,
  1111. "value": phone,
  1112. };
  1113. data['sign'] = TokenMgr().getSign(data);
  1114. Response res = await HttpUtil()
  1115. .post('/friendship/search/userPhone', data: data, isShowLoading: true);
  1116. if (res == null) return;
  1117. Map resData = res.data;
  1118. print(resData);
  1119. if (resData['code'] == 0) {
  1120. callback(resData['data']['UserId']);
  1121. }
  1122. }
  1123. //拉黑用户
  1124. blackUser(int userId, callback) async {
  1125. Map data = {
  1126. "userid": UserData().basicInfo.userId,
  1127. "type": 1,
  1128. "followUserId": userId,
  1129. };
  1130. data['sign'] = TokenMgr().getSign(data);
  1131. Response res =
  1132. await HttpUtil().post('userfollow/follow/insert', data: data);
  1133. Map resData = res.data;
  1134. showToast(resData['msg']);
  1135. if (resData['code'] == 0) {
  1136. BlacklistMgr.addMyBlackList(userId);
  1137. callback();
  1138. }
  1139. }
  1140. //取消拉黑用户
  1141. cancleBlackUser(int userId, callback) async {
  1142. Map data = {
  1143. "userid": UserData().basicInfo.userId,
  1144. "type": 1,
  1145. "followUserId": userId,
  1146. };
  1147. data['sign'] = TokenMgr().getSign(data);
  1148. Response res = await HttpUtil()
  1149. .post('userfollow/follow/cancel', data: data, isShowLoading: true);
  1150. Map resData = res.data;
  1151. showToast(resData['msg']);
  1152. if (resData['code'] == 0) {
  1153. BlacklistMgr.removeMyBalckList(userId);
  1154. callback();
  1155. }
  1156. }
  1157. //收藏用户
  1158. setLove(int userId, callback) async {
  1159. Map data = {
  1160. "userid": UserData().basicInfo.userId,
  1161. "type": 0,
  1162. "followUserId": userId,
  1163. };
  1164. data['sign'] = TokenMgr().getSign(data);
  1165. Response res = await HttpUtil()
  1166. .post('userfollow/follow/insert', data: data, isShowLoading: true);
  1167. Map resData = res.data;
  1168. if (resData['code'] == 0) {
  1169. showToast(resData['msg']);
  1170. callback();
  1171. }
  1172. }
  1173. //取消收藏用户
  1174. cancleLove(int userId, callback) async {
  1175. Map data = {
  1176. "userid": UserData().basicInfo.userId,
  1177. "type": 0,
  1178. "followUserId": userId,
  1179. };
  1180. data['sign'] = TokenMgr().getSign(data);
  1181. Response res = await HttpUtil()
  1182. .post('userfollow/follow/cancel', data: data, isShowLoading: true);
  1183. Map resData = res.data;
  1184. if (resData['code'] == 0) {
  1185. showToast(resData['msg']);
  1186. callback();
  1187. }
  1188. }
  1189. //向企业服务助手提交信息
  1190. Future<bool> commitInfoToCompany(MsgModel msgModel) async {
  1191. Map data = {
  1192. "userid": msgModel.from,
  1193. "msgType": msgModel.msgType,
  1194. };
  1195. data['sign'] = TokenMgr().getSign(data);
  1196. data['msgContent'] = base64Encode(msgModel.msgContent);
  1197. msgModel.state = MsgState.Sending;
  1198. print('commitInfoToCompany 参数 $data');
  1199. Response res = await HttpUtil().post('feedback/user/insert', data: data);
  1200. if (res == null) {
  1201. msgModel.state = MsgState.SendingFailed;
  1202. ChatDataMgr().updateMsgState(msgModel.sessionId, msgModel.time,
  1203. msgModel.channelType, msgModel.state);
  1204. return false;
  1205. }
  1206. Map resData = res.data;
  1207. print('commitInfoToCompany $resData');
  1208. if (resData['code'] == 0) {
  1209. msgModel.state = MsgState.SendingSuccess;
  1210. ChatDataMgr().updateMsgState(msgModel.sessionId, msgModel.time,
  1211. msgModel.channelType, msgModel.state);
  1212. return true;
  1213. } else {
  1214. showToast(resData['msg']);
  1215. }
  1216. return false;
  1217. }
  1218. //焚阅照片恢复
  1219. resetPhoto(callback) async {
  1220. Map data = {
  1221. "userId": UserData().basicInfo.userId,
  1222. };
  1223. data['sign'] = TokenMgr().getSign(data);
  1224. Response res = await HttpUtil()
  1225. .post('user/recover/photos', data: data, isShowLoading: true);
  1226. Map resData = res.data;
  1227. if (resData['code'] == 0) {
  1228. showToast(resData['msg']);
  1229. callback();
  1230. }
  1231. }
  1232. //获取好友校验值
  1233. checkFriends() async {
  1234. Map data = {
  1235. "userId": UserData().basicInfo.userId,
  1236. };
  1237. data['sign'] = TokenMgr().getSign(data);
  1238. Response res =
  1239. await HttpUtil().post('friendship/check/userFriends', data: data);
  1240. Map resData = res.data;
  1241. if (resData['code'] == 0) {
  1242. FriendListMgr().checkFromServer(resData['data']);
  1243. }
  1244. }
  1245. //保存设备名称和编码
  1246. saveMobileInfo() async {
  1247. String mobileType = '';
  1248. DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  1249. if (Platform.isAndroid) {
  1250. AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
  1251. mobileType = androidInfo.model;
  1252. print('Running on ${androidInfo.model}'); // e.g. "Moto G (4)"
  1253. } else if (Platform.isIOS) {
  1254. IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
  1255. mobileType = iosInfo.utsname.machine;
  1256. }
  1257. Map data = {
  1258. "userId": UserData().basicInfo.userId,
  1259. };
  1260. data['sign'] = TokenMgr().getSign(data);
  1261. data['model'] = mobileType;
  1262. data['coding'] = UserData().deviceLanguageCode;
  1263. Response res =
  1264. await HttpUtil().post('user/save/modelAndCoding', data: data);
  1265. Map resData = res.data;
  1266. print(resData);
  1267. }
  1268. ///实时帮-翻译管家评价
  1269. evaluationTransalteHK(
  1270. String orderNo, String value, bool isGood, Function callback) async {
  1271. Map data = {
  1272. "userId": UserData().basicInfo.userId,
  1273. "orderNo": orderNo,
  1274. "gradeStatus": isGood ? 1 : 2
  1275. };
  1276. data['sign'] = TokenMgr().getSign(data);
  1277. data['value'] = value;
  1278. Response res = await HttpUtil().post('steward/evaluation', data: data);
  1279. callback();
  1280. if (res == null) {
  1281. print('请求异常');
  1282. return;
  1283. }
  1284. var resData = res.data;
  1285. if (resData['code'] == 0) {
  1286. showToast('评价成功');
  1287. } else {
  1288. showToast(I18n.of(Constants.getCurrentContext()).net_error);
  1289. }
  1290. }
  1291. ///实时帮-用户测距
  1292. userRanging(int distance, String origin, String ending) async {
  1293. Map data = {
  1294. "userId": UserData().basicInfo.userId,
  1295. "distance": distance,
  1296. };
  1297. data['sign'] = TokenMgr().getSign(data);
  1298. data['origin'] = origin;
  1299. data['ending'] = ending;
  1300. Response res = await HttpUtil().post('steward/userRanging', data: data);
  1301. if (res == null) {
  1302. print('请求异常');
  1303. return;
  1304. }
  1305. var resData = res.data;
  1306. if (resData['code'] == 0) {
  1307. print('实时帮-用户测距提交 成功');
  1308. } else {
  1309. print('实时帮-用户测距提交 失败');
  1310. }
  1311. }
  1312. ///实时帮-翻译人员上线、下线
  1313. translateHKloginRecord(bool isLogin, Function callback) async {
  1314. Map data = {
  1315. "userId": UserData().basicInfo.userId,
  1316. "type": isLogin ? 1 : 2,
  1317. };
  1318. data['sign'] = TokenMgr().getSign(data);
  1319. print('请求data : $data');
  1320. Response res = await HttpUtil().post('steward/loginRecord', data: data);
  1321. if (res == null) {
  1322. print('请求异常');
  1323. return;
  1324. }
  1325. var resData = res.data;
  1326. if (resData['code'] == 0) {
  1327. callback();
  1328. print('翻译人员上线、下线 成功');
  1329. } else {
  1330. print('翻译人员上线、下线 失败 ${resData['msg']}');
  1331. }
  1332. }
  1333. }