Hibok
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1505 lines
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. UserData().shockNoticSwitch = resData['data']['VibrationReminder'] ==1;
  823. if (isMan) {
  824. UserData().acceptCheckSwitch = resData['data']['AcceptCheck'] == 1;
  825. UserData().codeSucessSwitch = resData['data']['ApplySuccess'] == 1;
  826. } else {
  827. UserData().applyCheckSwitch = resData['data']['ApplyCheck'] == 1;
  828. UserData().checkPhotoSwitch = resData['data']['CheckPhoto'] == 1;
  829. }
  830. }
  831. } catch (e) {}
  832. MessageMgr().emit(MessageMgr.REFRESH_PUSH_PERMISSION);
  833. }
  834. ///版本控制
  835. appVersionUpdate(Function callBack) async {
  836. Map data = {
  837. "ditch": Constants.isStoreVersion ? 0 : 1,
  838. "type": Platform.isAndroid ? 0 : 1,
  839. };
  840. data['sign'] = TokenMgr().getSign(data);
  841. data['language'] = UserData().language;
  842. try {
  843. Response res = await HttpUtil().post('system/version/info', data: data);
  844. Map resData = res.data;
  845. print('###appVersionUpdate res.data ${res.data}');
  846. if (resData['code'] == 0) {
  847. bool needNotice = resData['data']['Notice'] == 1;
  848. ///是否通知更新
  849. bool forceUpdate = resData['data']['IsStronger'] == 1;
  850. ///是否通知强更
  851. String version = resData['data']['VersionNo'];
  852. String describe = resData['data']['Describe'];
  853. String downloadUrl = resData['data']['DownloadUrl'];
  854. String appId = resData['data']['AppId'];
  855. callBack(
  856. needNotice, forceUpdate, version, describe, downloadUrl, appId);
  857. }
  858. } catch (e) {}
  859. }
  860. downloadApk(
  861. BuildContext context,
  862. String filePath,
  863. String downloadUrl,
  864. Function downloadCallback,
  865. ) async {
  866. final file = new File(filePath);
  867. bool isExist = await file.exists();
  868. if (isExist) {
  869. print('### 文件存在 : ${file.path}');
  870. file.delete();
  871. }
  872. // else {
  873. //
  874. // print('### 开始下载 $downloadUrl');
  875. // dio.download(downloadUrl, filePath, onReceiveProgress: downloadCallback);
  876. // }
  877. // downloadUrl ='oemarket.com/app0/30/30970/apk/2085562.apk?channel_id=426&tid=d73j9ihlkucuxfqpgnxgjeif';
  878. dio.download(downloadUrl, filePath, onReceiveProgress: downloadCallback);
  879. }
  880. ///获取用户每日签到信息
  881. Future<DailyBonusBean> getDailyBonus() async {
  882. Map data = {
  883. "userId": UserData().basicInfo.userId,
  884. };
  885. data['sign'] = TokenMgr().getSign(data);
  886. data['userId'] = UserData().basicInfo.userId;
  887. try {
  888. Response res = await HttpUtil().post('sign/in/user/info', data: data);
  889. Map resData = res.data;
  890. print('###getDailyBonus res.data ${res.data}');
  891. if (resData['code'] == 0) {
  892. return DailyBonusBean.fromMap(resData['data']);
  893. }
  894. return null;
  895. } catch (e) {
  896. return null;
  897. }
  898. }
  899. ///点击签到
  900. Future<bool> signInBounus(int score) async {
  901. Map data = {
  902. "userId": UserData().basicInfo.userId,
  903. "score": score,
  904. };
  905. data['sign'] = TokenMgr().getSign(data);
  906. data['userId'] = UserData().basicInfo.userId;
  907. data['score'] = score;
  908. try {
  909. Response res = await HttpUtil().post('sign/in/user', data: data);
  910. Map resData = res.data;
  911. print('###signInBounus res.data ${res.data}');
  912. if (resData['code'] == 0) {
  913. return true;
  914. // bool needNotice = resData['data']['Notice']==1; ///是否通知更新
  915. // return DailyBonusBean.fromMap(resData['data']);
  916. } else {
  917. showToast(resData['msg']);
  918. }
  919. return false;
  920. } catch (e) {
  921. return false;
  922. }
  923. }
  924. /// 用户签到积分兑换商品
  925. Future<bool> signInExchange(GoodsBean goodsBean) async {
  926. Map data = {
  927. "userId": UserData().basicInfo.userId,
  928. "id": goodsBean.id,
  929. "score": goodsBean.s,
  930. };
  931. data['sign'] = TokenMgr().getSign(data);
  932. data['userId'] = UserData().basicInfo.userId;
  933. data['score'] = goodsBean.s;
  934. data['id'] = goodsBean.id;
  935. try {
  936. Response res =
  937. await HttpUtil().post('sign/in/score/exchange', data: data);
  938. Map resData = res.data;
  939. print('###signInExchange res.data ${res.data}');
  940. if (resData['code'] == 0) {
  941. return true;
  942. } else {
  943. showToast(resData['msg']);
  944. }
  945. return false;
  946. } catch (e) {
  947. return false;
  948. }
  949. }
  950. addFriends(
  951. BuildContext context, int friendId, String content, callback) async {
  952. Map data = {
  953. "userId": UserData().basicInfo.userId,
  954. "friendsUserId": friendId
  955. };
  956. data['sign'] = TokenMgr().getSign(data);
  957. data['content'] = content;
  958. Response res = await HttpUtil().post('friendship/add/friends', data: data);
  959. Map resData = res.data;
  960. print(resData);
  961. if (resData['code'] == 0) {
  962. showToast(resData['msg']);
  963. if (callback != null) callback();
  964. }
  965. }
  966. //付费人工翻译
  967. getPersonalTranslate(MsgModel msgModel) async {
  968. Map data = {
  969. "suserid": msgModel.from,
  970. "chatmsgid": msgModel.time,
  971. "tlanguage": UserData().language,
  972. "chattype": msgModel.msgType,
  973. "chatchanneltype": msgModel.channelType,
  974. "targetid": msgModel.sessionId
  975. };
  976. data['sign'] = TokenMgr().getSign(data);
  977. if (msgModel.msgType == 0) {
  978. data['content'] = base64Encode(msgModel.msgContent);
  979. } else {
  980. if (msgModel.localFile == null) {
  981. showToast('请稍后再试');
  982. return;
  983. }
  984. data['content'] =
  985. base64Encode(File(msgModel.localFile).readAsBytesSync());
  986. print('语音转换的文字: ${utf8.decode(msgModel.enTranslateContent)}');
  987. data['vcontent'] = base64Encode(msgModel.enTranslateContent);
  988. }
  989. if (msgModel.channelType == ChatChannelType.Group.value) {
  990. data['theme'] = GroupInfoMgr().getGroupName(msgModel.sessionId);
  991. } else {
  992. data['theme'] = '';
  993. }
  994. data['list'] = ChatDataMgr().getForeChatRecord(msgModel);
  995. data["tuserids"] = [UserData().basicInfo.userId];
  996. data['duration'] =
  997. msgModel.extraInfo != null ? msgModel.extraInfo ~/ 1000 : 0;
  998. data['ispay'] = true;
  999. if (msgModel.msgType == ChatType.TextChatType.value) {
  1000. int length = utf8.decode(msgModel.msgContent).length;
  1001. data['money'] = length ~/ 50 + 1; //每50个字耗费1H币
  1002. print('字数 $length 价格 ${length % 50 + 1}');
  1003. } else if (msgModel.msgType == ChatType.ShortVoiceChatType.value) {
  1004. //没20秒扣除1Hb
  1005. data['money'] =
  1006. msgModel.extraInfo != null ? msgModel.extraInfo ~/ 20000 + 1 : 0;
  1007. }
  1008. if (msgModel.translateContent != null &&
  1009. msgModel.translateContent.length > 0) {
  1010. data['mcontent'] = base64Encode(msgModel.translateContent);
  1011. }
  1012. Response res =
  1013. await HttpUtil().post('service/paid/translation', data: data);
  1014. if (res == null) {
  1015. return false;
  1016. }
  1017. Map resData = res.data;
  1018. print('付费翻译请求$resData');
  1019. if (resData['code'] == 0) {
  1020. print('扣除 H 币 ${data['money']}');
  1021. return true;
  1022. }
  1023. print(resData['msg']);
  1024. showToast(resData['msg']);
  1025. return false;
  1026. }
  1027. //用户评价人工翻译,差评
  1028. Future<bool> rateTranslateResult(MsgModel msg, Function callback) async {
  1029. Map data = {
  1030. "userId": UserData().basicInfo.userId,
  1031. "chatUserId": msg.from,
  1032. "chatMsgId": msg.time,
  1033. "score": 1
  1034. };
  1035. data['sign'] = TokenMgr().getSign(data);
  1036. Response res = await HttpUtil().post('translate/user/score', data: data);
  1037. if (res == null) {
  1038. return false;
  1039. }
  1040. var resData = res.data;
  1041. if (resData['code'] == 0) {
  1042. msg.transTag = 10; //已评价过
  1043. if (callback != null) {
  1044. callback();
  1045. }
  1046. SqlUtil().updateUserTranslateState(msg.sessionId, msg.time, msg.transTag);
  1047. return true;
  1048. }
  1049. return false;
  1050. }
  1051. //根据经纬度获取用户国家城市
  1052. getAddress(double lon, double lat) async {
  1053. Map data = {
  1054. "lon": lon.toString(),
  1055. "lat": lat.toString(),
  1056. };
  1057. data['sign'] = TokenMgr().getSign(data);
  1058. data['language'] = UserData().language;
  1059. Response res = await HttpUtil().post('user/get/address', data: data);
  1060. if (res == null) return;
  1061. Map resData = res.data;
  1062. if (resData['code'] == 0 && resData['data'] != null) {
  1063. print(resData['data']);
  1064. List address = resData['data'].split(',');
  1065. if (address.length != 2) return;
  1066. String country = address[0];
  1067. String city = address[1];
  1068. UserData().isInChina = false;
  1069. if (country == '越南') {
  1070. UserData().currentCity = 'VietNam-';
  1071. List citys = constData[3]['city'][0]['List'];
  1072. for (int i = 0; i < citys.length; i++) {
  1073. if (citys[i]['Value'] == city) {
  1074. UserData().currentCity += citys[i]['Key'];
  1075. break;
  1076. }
  1077. }
  1078. } else if (country == '中国') {
  1079. UserData().isInChina = true;
  1080. UserData().currentCity = 'China-ChinaRepeat';
  1081. } else {
  1082. UserData().currentCity = 'VietNam-HoChiMinhCIty';
  1083. }
  1084. if (UserData().currentCity != UserData().basicInfo.meetPlace) {
  1085. UserData().basicInfo.meetPlace = UserData().currentCity;
  1086. changeCurrentCity(lon, lat, () {});
  1087. }
  1088. MessageMgr().emit('change_currentcity');
  1089. }
  1090. }
  1091. //根据经纬度获取用户国家城市
  1092. changeCurrentCity(double lon, double lat, callback) async {
  1093. if (UserData().basicInfo.userId == null) return;
  1094. Map data = {
  1095. "userId": UserData().basicInfo.userId,
  1096. "lon": lon.toString(),
  1097. "lat": lat.toString(),
  1098. };
  1099. data['sign'] = TokenMgr().getSign(data);
  1100. Response res = await HttpUtil().post('user/update/meetPlace', data: data);
  1101. if (res == null) return;
  1102. Map resData = res.data;
  1103. print(resData);
  1104. if (resData['code'] == 0) {
  1105. callback();
  1106. }
  1107. }
  1108. //通过手机号查询用户
  1109. searchNewFrindsByPhone(String phone, callback) async {
  1110. Map data = {
  1111. "userId": UserData().basicInfo.userId,
  1112. "value": phone,
  1113. };
  1114. data['sign'] = TokenMgr().getSign(data);
  1115. Response res = await HttpUtil()
  1116. .post('/friendship/search/userPhone', data: data, isShowLoading: true);
  1117. if (res == null) return;
  1118. Map resData = res.data;
  1119. print(resData);
  1120. if (resData['code'] == 0) {
  1121. callback(resData['data']['UserId']);
  1122. }
  1123. }
  1124. //拉黑用户
  1125. blackUser(int userId, callback) async {
  1126. Map data = {
  1127. "userid": UserData().basicInfo.userId,
  1128. "type": 1,
  1129. "followUserId": userId,
  1130. };
  1131. data['sign'] = TokenMgr().getSign(data);
  1132. Response res =
  1133. await HttpUtil().post('userfollow/follow/insert', data: data);
  1134. Map resData = res.data;
  1135. showToast(resData['msg']);
  1136. if (resData['code'] == 0) {
  1137. BlacklistMgr.addMyBlackList(userId);
  1138. callback();
  1139. }
  1140. }
  1141. //取消拉黑用户
  1142. cancleBlackUser(int userId, callback) async {
  1143. Map data = {
  1144. "userid": UserData().basicInfo.userId,
  1145. "type": 1,
  1146. "followUserId": userId,
  1147. };
  1148. data['sign'] = TokenMgr().getSign(data);
  1149. Response res = await HttpUtil()
  1150. .post('userfollow/follow/cancel', data: data, isShowLoading: true);
  1151. Map resData = res.data;
  1152. showToast(resData['msg']);
  1153. if (resData['code'] == 0) {
  1154. BlacklistMgr.removeMyBalckList(userId);
  1155. callback();
  1156. }
  1157. }
  1158. //收藏用户
  1159. setLove(int userId, callback) async {
  1160. Map data = {
  1161. "userid": UserData().basicInfo.userId,
  1162. "type": 0,
  1163. "followUserId": userId,
  1164. };
  1165. data['sign'] = TokenMgr().getSign(data);
  1166. Response res = await HttpUtil()
  1167. .post('userfollow/follow/insert', data: data, isShowLoading: true);
  1168. Map resData = res.data;
  1169. if (resData['code'] == 0) {
  1170. showToast(resData['msg']);
  1171. callback();
  1172. }
  1173. }
  1174. //取消收藏用户
  1175. cancleLove(int userId, callback) async {
  1176. Map data = {
  1177. "userid": UserData().basicInfo.userId,
  1178. "type": 0,
  1179. "followUserId": userId,
  1180. };
  1181. data['sign'] = TokenMgr().getSign(data);
  1182. Response res = await HttpUtil()
  1183. .post('userfollow/follow/cancel', data: data, isShowLoading: true);
  1184. Map resData = res.data;
  1185. if (resData['code'] == 0) {
  1186. showToast(resData['msg']);
  1187. callback();
  1188. }
  1189. }
  1190. //向企业服务助手提交信息
  1191. Future<bool> commitInfoToCompany(MsgModel msgModel) async {
  1192. Map data = {
  1193. "userid": msgModel.from,
  1194. "msgType": msgModel.msgType,
  1195. };
  1196. data['sign'] = TokenMgr().getSign(data);
  1197. data['msgContent'] = base64Encode(msgModel.msgContent);
  1198. msgModel.state = MsgState.Sending;
  1199. print('commitInfoToCompany 参数 $data');
  1200. Response res = await HttpUtil().post('feedback/user/insert', data: data);
  1201. if (res == null) {
  1202. msgModel.state = MsgState.SendingFailed;
  1203. ChatDataMgr().updateMsgState(msgModel.sessionId, msgModel.time,
  1204. msgModel.channelType, msgModel.state);
  1205. return false;
  1206. }
  1207. Map resData = res.data;
  1208. print('commitInfoToCompany $resData');
  1209. if (resData['code'] == 0) {
  1210. msgModel.state = MsgState.SendingSuccess;
  1211. ChatDataMgr().updateMsgState(msgModel.sessionId, msgModel.time,
  1212. msgModel.channelType, msgModel.state);
  1213. return true;
  1214. } else {
  1215. showToast(resData['msg']);
  1216. }
  1217. return false;
  1218. }
  1219. //焚阅照片恢复
  1220. resetPhoto(callback) async {
  1221. Map data = {
  1222. "userId": UserData().basicInfo.userId,
  1223. };
  1224. data['sign'] = TokenMgr().getSign(data);
  1225. Response res = await HttpUtil()
  1226. .post('user/recover/photos', data: data, isShowLoading: true);
  1227. Map resData = res.data;
  1228. if (resData['code'] == 0) {
  1229. showToast(resData['msg']);
  1230. callback();
  1231. }
  1232. }
  1233. //获取好友校验值
  1234. checkFriends() async {
  1235. Map data = {
  1236. "userId": UserData().basicInfo.userId,
  1237. };
  1238. data['sign'] = TokenMgr().getSign(data);
  1239. Response res =
  1240. await HttpUtil().post('friendship/check/userFriends', data: data);
  1241. Map resData = res.data;
  1242. if (resData['code'] == 0) {
  1243. FriendListMgr().checkFromServer(resData['data']);
  1244. }
  1245. }
  1246. //保存设备名称和编码
  1247. saveMobileInfo() async {
  1248. String mobileType = '';
  1249. DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  1250. if (Platform.isAndroid) {
  1251. AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
  1252. mobileType = androidInfo.model;
  1253. print('Running on ${androidInfo.model}'); // e.g. "Moto G (4)"
  1254. } else if (Platform.isIOS) {
  1255. IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
  1256. mobileType = iosInfo.utsname.machine;
  1257. }
  1258. Map data = {
  1259. "userId": UserData().basicInfo.userId,
  1260. };
  1261. data['sign'] = TokenMgr().getSign(data);
  1262. data['model'] = mobileType;
  1263. data['coding'] = UserData().deviceLanguageCode;
  1264. Response res =
  1265. await HttpUtil().post('user/save/modelAndCoding', data: data);
  1266. Map resData = res.data;
  1267. print(resData);
  1268. }
  1269. ///实时帮-翻译管家评价
  1270. evaluationTransalteHK(
  1271. String orderNo, String value, bool isGood, Function callback) async {
  1272. Map data = {
  1273. "userId": UserData().basicInfo.userId,
  1274. "orderNo": orderNo,
  1275. "gradeStatus": isGood ? 1 : 2
  1276. };
  1277. data['sign'] = TokenMgr().getSign(data);
  1278. data['value'] = value;
  1279. Response res = await HttpUtil().post('steward/evaluation', data: data);
  1280. callback();
  1281. if (res == null) {
  1282. print('请求异常');
  1283. return;
  1284. }
  1285. var resData = res.data;
  1286. if (resData['code'] == 0) {
  1287. showToast('评价成功');
  1288. } else {
  1289. showToast(I18n.of(Constants.getCurrentContext()).net_error);
  1290. }
  1291. }
  1292. ///实时帮-用户测距
  1293. userRanging(int distance, String origin, String ending) async {
  1294. Map data = {
  1295. "userId": UserData().basicInfo.userId,
  1296. "distance": distance,
  1297. };
  1298. data['sign'] = TokenMgr().getSign(data);
  1299. data['origin'] = origin;
  1300. data['ending'] = ending;
  1301. Response res = await HttpUtil().post('steward/userRanging', data: data);
  1302. if (res == null) {
  1303. print('请求异常');
  1304. return;
  1305. }
  1306. var resData = res.data;
  1307. if (resData['code'] == 0) {
  1308. print('实时帮-用户测距提交 成功');
  1309. } else {
  1310. print('实时帮-用户测距提交 失败');
  1311. }
  1312. }
  1313. ///实时帮-翻译人员上线、下线
  1314. translateHKloginRecord(bool isLogin, Function callback) async {
  1315. Map data = {
  1316. "userId": UserData().basicInfo.userId,
  1317. "type": isLogin ? 1 : 2,
  1318. };
  1319. data['sign'] = TokenMgr().getSign(data);
  1320. print('请求data : $data');
  1321. Response res = await HttpUtil().post('steward/loginRecord', data: data);
  1322. if (res == null) {
  1323. print('请求异常');
  1324. return;
  1325. }
  1326. var resData = res.data;
  1327. if (resData['code'] == 0) {
  1328. callback();
  1329. print('翻译人员上线、下线 成功');
  1330. } else {
  1331. print('翻译人员上线、下线 失败 ${resData['msg']}');
  1332. }
  1333. }
  1334. }