Hibok
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

1524 linhas
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请求发生错误:$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: 80, percentage: 80);
  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) {
  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. getFirstProgram() async {
  340. Map data = {
  341. "userId": UserData().basicInfo.userId,
  342. "visitUserId": UserData().basicInfo.userId,
  343. "type": 1,
  344. };
  345. data['sign'] = TokenMgr().getSign(data);
  346. data['page'] = 1;
  347. data['rows'] = 1;
  348. Response res = await HttpUtil().post('station/gain/program', data: data);
  349. if (res == null) {
  350. print('请求异常');
  351. return;
  352. }
  353. var resData = res.data;
  354. if (resData['code'] == 0) {
  355. UserData().isCanProgram =
  356. resData['data'] == null || resData['data'][0]['Status'] == 1;
  357. }
  358. }
  359. Future getTranslateState(int sessionId) async {
  360. Map data = {
  361. "userId": UserData().basicInfo.userId,
  362. "chatUserId": sessionId,
  363. };
  364. data['sign'] = TokenMgr().getSign(data);
  365. Response res =
  366. await HttpUtil().post('translate/get/user/status', data: data);
  367. if (res == null) {
  368. print('请求异常');
  369. return null;
  370. }
  371. var resData = res.data;
  372. if (resData['code'] == 0) {
  373. return resData['data'];
  374. }
  375. return null;
  376. }
  377. updateTranslateState(int sessionId, bool state) async {
  378. Map data = {
  379. "userId": UserData().basicInfo.userId,
  380. "chatUserId": sessionId,
  381. "status": state ? 1 : 0
  382. };
  383. data['sign'] = TokenMgr().getSign(data);
  384. Response res = await HttpUtil().post('translate/set/up/status', data: data);
  385. if (res == null) {
  386. print('请求异常');
  387. return false;
  388. }
  389. var resData = res.data;
  390. if (resData['code'] == 0) {
  391. return true;
  392. }
  393. return false;
  394. }
  395. changeLanguage(BuildContext context, lang, callback,
  396. [showLoading = false]) async {
  397. var data = {
  398. "userid": UserData().basicInfo.userId,
  399. "language": lang,
  400. };
  401. data['sign'] = TokenMgr().getSign(data);
  402. try {
  403. Response res = await HttpUtil().post('user/setting/language',
  404. data: data, isShowLoading: showLoading);
  405. if (res == null) {
  406. print('请求异常');
  407. return;
  408. }
  409. Map resData = res.data;
  410. if (resData['code'] == 0) {
  411. if (callback != null) callback();
  412. //重新登录
  413. // SocketUtil().reLogin();
  414. NetWork().reLogin();
  415. }
  416. } catch (e) {}
  417. }
  418. userFreeTime(BuildContext context, var viewUserId, int type, callback) async {
  419. Map data = {
  420. "userId": UserData().basicInfo.userId,
  421. "viewUserId": viewUserId,
  422. 'type': type,
  423. };
  424. data['sign'] = TokenMgr().getSign(data);
  425. try {
  426. Response res = await HttpUtil()
  427. .post('photos/unlock/permissions', data: data, isShowLoading: true);
  428. if (res == null) {
  429. print('请求异常');
  430. return;
  431. }
  432. Map resData = res.data;
  433. if (resData['code'] == 0) {
  434. if (callback != null) callback();
  435. }
  436. } catch (e) {}
  437. }
  438. saveAotuLoginKey(resData, {bool isSaveUserId = true}) async {
  439. //将用户信息存到本地
  440. if (resData['data']['aotuLoginKey'] != null) {
  441. SharedPreferences prefs = await SharedPreferences.getInstance();
  442. await prefs.setString(
  443. Constants.AutoLoginKey, resData['data']['aotuLoginKey']);
  444. if (isSaveUserId) {
  445. await prefs.setInt(Constants.LocalUserId, UserData().basicInfo.userId);
  446. }
  447. }
  448. }
  449. ///登录
  450. changePage(BuildContext context, Map resData) async {
  451. UserData().basicInfo.userId = resData['data']['userid'];
  452. UserData().basicInfo.sex = resData['data']['sex'];
  453. if (resData['data']['mobile'] != null && resData['data']['mobile'] != '') {
  454. UserData().mobile = int.parse(resData['data']['mobile']);
  455. }
  456. if (resData['data']['bindId'] != null) {
  457. UserData().agentId = resData['data']['bindId'];
  458. }
  459. //读取聊天信息
  460. await ChatDataMgr().initMsg();
  461. //读取群信息
  462. await GroupInfoMgr().initLocalGroupList();
  463. print('~~~~~~~~~~~~~changePage~~~~~~~~~~~~~~~~~~~~~~');
  464. changeLanguage(context, UserData().language, null);
  465. getRewardAndRedPacketState();
  466. //clearReadData(UserData().basicInfo.userId);
  467. if (resData['data']['sex'] == 0) {
  468. Navigator.of(context).push(
  469. new MaterialPageRoute(
  470. builder: (context) {
  471. return SelectSex();
  472. },
  473. ),
  474. );
  475. saveAotuLoginKey(resData, isSaveUserId: false);
  476. return;
  477. }
  478. if (resData['data']['info'] == 0) {
  479. Navigator.of(context).push(
  480. new MaterialPageRoute(
  481. builder: (context) {
  482. return EditPage(
  483. isEditPage: false,
  484. );
  485. },
  486. ),
  487. );
  488. saveAotuLoginKey(resData, isSaveUserId: false);
  489. return;
  490. }
  491. checkFriends();
  492. LocalNotificationUtil.instance.startPush();
  493. //ChatDataMgr().initMsg();
  494. Navigator.of(context)
  495. .pushNamedAndRemoveUntil('/main', (route) => route == null);
  496. MessageMgr().emit('update_system');
  497. saveAotuLoginKey(resData);
  498. getFirstProgram();
  499. initLocation();
  500. }
  501. initLocation() async {
  502. SharedPreferences prefs = await SharedPreferences.getInstance();
  503. var latitude = prefs.getDouble(Constants.Latitude);
  504. var longitude = prefs.getDouble(Constants.Longitude);
  505. print('存贮在本地的位置: $latitude------$longitude');
  506. if (latitude != null) UserData().latitude = latitude;
  507. if (longitude != null) UserData().longitude = longitude;
  508. }
  509. setPhote(BuildContext context, id, type, callback) async {
  510. var data = {
  511. "userId": UserData().basicInfo.userId,
  512. "type": type,
  513. "pId": id,
  514. };
  515. data['sign'] = TokenMgr().getSign(data);
  516. Response res = await HttpUtil()
  517. .post('photos/setting/burns', data: data, isShowLoading: true);
  518. if (res == null) {
  519. print('请求异常');
  520. return;
  521. }
  522. var resData = res.data;
  523. showToast(resData['msg']);
  524. if (resData['code'] == 0) {
  525. if (callback != null) callback();
  526. }
  527. }
  528. clearCacheData() async {
  529. print('######### 清除缓存key');
  530. SharedPreferences prefs = await SharedPreferences.getInstance();
  531. prefs.remove(Constants.AutoLoginKey);
  532. prefs.remove(Constants.LocalUserId);
  533. prefs.remove(Constants.LocalUsrInfo);
  534. }
  535. // clearReadData(userId) async {
  536. // SharedPreferences prefs = await SharedPreferences.getInstance();
  537. // var localUserId = prefs.getInt(Constants.LocalUserId);
  538. // if (userId != localUserId) {
  539. // prefs.remove(Constants.ApplyCount);
  540. // prefs.remove(Constants.EvaluateCount);
  541. // prefs.remove(Constants.ParkCount);
  542. // prefs.remove(Constants.CastCount);
  543. // prefs.remove(Constants.WalletCount);
  544. // }
  545. // }
  546. void postLoginOut(BuildContext context) async {
  547. Map data = {
  548. "userId": UserData().basicInfo.userId,
  549. };
  550. data['sign'] = TokenMgr().getSign(data);
  551. Response res = await HttpUtil().post('user/login/out', data: data);
  552. if (res == null) {
  553. print('请求异常');
  554. return;
  555. }
  556. Map resData = res.data;
  557. if (resData['code'] == 0) {
  558. clearCacheData();
  559. FriendListMgr().friendList?.clear();
  560. Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(
  561. builder: (context) {
  562. return IndexPage();
  563. },
  564. ), (route) => route == null);
  565. NetWork().singOut();
  566. UserData().reset();
  567. } else {
  568. showToast(resData['msg']);
  569. }
  570. }
  571. buyGoods(money, goodsId, detailtype, changeuserId, context, callback) async {
  572. if (Provider.of<MoneyChangeProvider>(context).money < money) {
  573. showToast(I18n.of(context).balance_insufficien);
  574. return;
  575. }
  576. var data = {
  577. "userId": UserData().basicInfo.userId,
  578. "type": 1,
  579. "detailtype": detailtype,
  580. };
  581. data['sign'] = TokenMgr().getSign(data);
  582. data['value'] = money;
  583. data['changeuserId'] = changeuserId;
  584. data['membergoodsId'] = goodsId;
  585. Response res = await HttpUtil()
  586. .post('wealth/user/add', data: data, isShowLoading: true);
  587. if (res == null) {
  588. print('请求异常');
  589. return;
  590. }
  591. Map resData = res.data;
  592. showToast(resData['msg']);
  593. if (resData['code'] == 0) {
  594. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(money);
  595. if (callback != null) callback();
  596. }
  597. }
  598. buyPictures(money, changeuserId, context, callback) async {
  599. if (Provider.of<MoneyChangeProvider>(context).money < money) {
  600. showToast(I18n.of(context).balance_insufficien);
  601. return;
  602. }
  603. var data = {
  604. "userId": UserData().basicInfo.userId,
  605. "viewUserId": changeuserId,
  606. "price": money,
  607. };
  608. data['sign'] = TokenMgr().getSign(data);
  609. Response res = await HttpUtil()
  610. .post('photos/user/unlock', data: data, isShowLoading: true);
  611. if (res == null) {
  612. print('请求异常');
  613. return;
  614. }
  615. Map resData = res.data;
  616. showToast(resData['msg']);
  617. if (resData['code'] == 0) {
  618. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(money);
  619. if (callback != null) callback();
  620. }
  621. }
  622. buyVIP(int money, int gid, int type, BuildContext context, callback) async {
  623. if (Provider.of<MoneyChangeProvider>(context).money < money) {
  624. showToast(I18n.of(context).balance_insufficien);
  625. return;
  626. }
  627. Map data = {
  628. "userId": UserData().basicInfo.userId,
  629. "gid": gid,
  630. "type": type,
  631. "price": money,
  632. };
  633. data['sign'] = TokenMgr().getSign(data);
  634. Response res = await HttpUtil()
  635. .post('goods/user/purchase', data: data, isShowLoading: true);
  636. if (res == null) {
  637. print('请求异常');
  638. return;
  639. }
  640. Map resData = res.data;
  641. showToast(resData['msg']);
  642. if (resData['code'] == 0) {
  643. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(money);
  644. if (callback != null) callback();
  645. }
  646. }
  647. buyChatAccount(money, changeuserId, context, callback) async {
  648. if (Provider.of<MoneyChangeProvider>(context).money < money) {
  649. showToast(I18n.of(context).balance_insufficien);
  650. return;
  651. }
  652. var data = {
  653. "userId": UserData().basicInfo.userId,
  654. "unlockUserId": changeuserId,
  655. "price": money,
  656. };
  657. data['sign'] = TokenMgr().getSign(data);
  658. Response res = await HttpUtil()
  659. .post('photos/pay/unlock/chat', data: data, isShowLoading: true);
  660. if (res == null) {
  661. print('请求异常');
  662. return;
  663. }
  664. Map resData = res.data;
  665. showToast(resData['msg']);
  666. if (resData['code'] == 0) {
  667. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(money);
  668. if (callback != null) callback();
  669. }
  670. }
  671. void getMoneyInfo(BuildContext context, callback) async {
  672. if (Platform.isIOS) {
  673. await MoneyPageState.initPayConf(context);
  674. }
  675. Map data = {
  676. "userid": UserData().basicInfo.userId,
  677. "moneytype":
  678. UserData().language == LanguageType.SimplifiedChinese ? 0 : 1,
  679. "mobiletype": Platform.isIOS ? 0 : 1,
  680. };
  681. if (Platform.isIOS) {
  682. data['moneytype'] = 1;
  683. }
  684. print('moneytype ${data['moneytype']}');
  685. data['sign'] = TokenMgr().getSign(data);
  686. Response res = await HttpUtil()
  687. .post('goods/info/list', data: data, isShowLoading: true);
  688. if (res == null) {
  689. print('请求异常');
  690. return;
  691. }
  692. Map resData = res.data;
  693. if (resData['code'] == 0) {
  694. if (callback != null) callback(resData['data']);
  695. }
  696. }
  697. void getWealth(BuildContext context, callback) async {
  698. Map data = {
  699. "userId": UserData().basicInfo.userId,
  700. };
  701. data['sign'] = TokenMgr().getSign(data);
  702. Response res = await HttpUtil().post('wealth/user/info', data: data);
  703. if (res == null) {
  704. print('请求异常');
  705. return;
  706. }
  707. Map resData = res.data;
  708. print(resData);
  709. if (resData['code'] == 0 && resData['data'] != null) {
  710. UserData().basicInfo.isMember = resData['data']['IsMember'] ?? 0;
  711. UserData().incomeMoney = resData['data']['IncomeCoin'];
  712. UserData().frozenMoney = resData['data']['FrozenCoin'];
  713. UserData().memberEndTime = resData['data']['MemberEnd'];
  714. if (callback != null) callback(resData['data']);
  715. }
  716. }
  717. //获取红包与打赏开关状态
  718. getRewardAndRedPacketState() async {
  719. var myId = UserData().basicInfo.userId;
  720. Map data = {
  721. "userId": myId,
  722. };
  723. data['sign'] = TokenMgr().getSign(data);
  724. Response res = await HttpUtil().post('system/switch', data: data);
  725. if (res == null) {
  726. print('请求异常');
  727. return;
  728. }
  729. Map resData = res.data;
  730. print('### system/switch' + resData.toString());
  731. if (resData['code'] == 0) {
  732. var config = resData['data'];
  733. if (config != null) {
  734. UserData().redPacketSW = config['redPacket'];
  735. UserData().giftSwitch = config['reward'];
  736. UserData().bannerZF = config['iapPay'];
  737. UserData().sign = config['sign'];
  738. UserData().groupQRCode = config['groupQRCode'];
  739. UserData().addFdDistanceSwitch = config['distance'] ?? 0;
  740. UserData().stationOpenSwitch = config['station'] == 1;
  741. UserData().myProgramOpenSwitch = config['myProgram'] == 1;
  742. UserData().nearbyOpenSwitch = config['nearby'] == 1;
  743. // print('### config: start');
  744. // print('### config: iapPay:${config['iapPay']}');
  745. }
  746. }
  747. }
  748. ///检查是否有缓存的内购单-有的话向服务器发送请求重新创建订单
  749. void checkReceiptCache() async {
  750. String str = await SPUtils.get(Constants.IOS_IAP_Receipt);
  751. if (str != null && str.isNotEmpty) {
  752. print('### 有缓存单');
  753. List<String> split = str.split("@");
  754. createOrder(split[0], split[1], split[2]);
  755. } else {
  756. print('### 没有缓存单');
  757. }
  758. }
  759. ///ios内购-创建订单
  760. void createOrder(String currentGoodsId, String receipt, String purchaseToken,
  761. {BuildContext context}) async {
  762. // String base84str = base64Encode(utf8.encode(receipt));
  763. var data = {
  764. "userid": UserData().basicInfo.userId,
  765. "moneytype": 1,
  766. 'gid': currentGoodsId,
  767. "payway": 1,
  768. };
  769. data['sign'] = TokenMgr().getSign(data);
  770. data['receipt'] = receipt;
  771. data['isenable'] = Constants.isSandbox ? 0 : 1;
  772. Response res = await HttpUtil().post('order/add/goods', data: data);
  773. print('#### 创建订单-返回');
  774. if (res == null) {
  775. print('请求异常');
  776. return;
  777. }
  778. Map resData = res.data;
  779. print('#### 创建订单-返回:' + resData.toString());
  780. if (resData['code'] == 0) {
  781. // String OrderNo = resData['data']['OrderNo'];
  782. Future.delayed(Duration(seconds: 3), () {
  783. MessageMgr().emit('refresh_money');
  784. });
  785. if (context == null) {
  786. await FlutterInappPurchase.instance.initConnection;
  787. }
  788. FlutterInappPurchase.instance.finishTransaction(purchaseToken);
  789. SPUtils.remove(Constants.IOS_IAP_Receipt);
  790. } else {
  791. ///创建订单失败-
  792. await SPUtils.saveString(Constants.IOS_IAP_Receipt,
  793. currentGoodsId + '@' + receipt + '@' + purchaseToken);
  794. }
  795. if (context != null) {
  796. Navigator.of(context).pop();
  797. }
  798. }
  799. ///登陆
  800. void login(
  801. String _phoneNumber, String _passWorld, BuildContext context) async {
  802. var data = {
  803. "mobile": _phoneNumber,
  804. "text": _passWorld,
  805. "type": 0,
  806. "language": UserData().language,
  807. };
  808. data['sign'] = TokenMgr().getSign(data);
  809. Response res = await HttpUtil()
  810. .post('user/mobile/login', data: data, isShowLoading: true);
  811. if (res == null) {
  812. print('请求异常');
  813. return;
  814. }
  815. var resData = res.data;
  816. if (resData['code'] == 0 && resData['data'] != null) {
  817. HttpUtil().changePage(context, resData);
  818. } else {
  819. showToast(resData['msg']);
  820. }
  821. }
  822. ///获取推送设置
  823. getSettingInfo() async {
  824. Map data = {
  825. "userId": UserData().basicInfo.userId,
  826. "sex": UserData().basicInfo.sex,
  827. };
  828. data['sign'] = TokenMgr().getSign(data);
  829. try {
  830. Response res = await HttpUtil().post('message/push/message', data: data);
  831. if (res == null) {
  832. print('请求异常');
  833. return;
  834. }
  835. Map resData = res.data;
  836. bool isMan = UserData().isMan();
  837. ///女号 {data: {PrivacyChat: 1, NewBroadcast: 1, ApplyCheck: 1, CheckAccount: 1, CheckPhoto: 1, SendAccount: 1}, code: 0, msg: 成功}
  838. ///男号 {data: {PrivacyChat: 1, NewBroadcast: 1, AcceptCheck: 1, ApplySuccess: 1}, code: 0, msg: 成功}
  839. print('###settingdata res.data ${res.data}');
  840. if (resData['code'] == 0) {
  841. UserData().privatyMsgPushSwitch = resData['data']['PrivacyChat'] == 1;
  842. UserData().newDateSwitch = resData['data']['NewBroadcast'] == 1;
  843. if (isMan) {
  844. UserData().acceptCheckSwitch = resData['data']['AcceptCheck'] == 1;
  845. UserData().codeSucessSwitch = resData['data']['ApplySuccess'] == 1;
  846. } else {
  847. UserData().applyCheckSwitch = resData['data']['ApplyCheck'] == 1;
  848. UserData().checkPhotoSwitch = resData['data']['CheckPhoto'] == 1;
  849. }
  850. }
  851. } catch (e) {}
  852. MessageMgr().emit(MessageMgr.REFRESH_PUSH_PERMISSION);
  853. }
  854. ///版本控制
  855. appVersionUpdate(Function callBack) async {
  856. Map data = {
  857. "ditch": Constants.isStoreVersion ? 0 : 1,
  858. "type": Platform.isAndroid ? 0 : 1,
  859. };
  860. data['sign'] = TokenMgr().getSign(data);
  861. data['language'] = UserData().language;
  862. try {
  863. Response res = await HttpUtil().post('system/version/info', data: data);
  864. Map resData = res.data;
  865. print('###appVersionUpdate res.data ${res.data}');
  866. if (resData['code'] == 0) {
  867. bool needNotice = resData['data']['Notice'] == 1;
  868. ///是否通知更新
  869. bool forceUpdate = resData['data']['IsStronger'] == 1;
  870. ///是否通知强更
  871. String version = resData['data']['VersionNo'];
  872. String describe = resData['data']['Describe'];
  873. String downloadUrl = resData['data']['DownloadUrl'];
  874. String appId = resData['data']['AppId'];
  875. callBack(
  876. needNotice, forceUpdate, version, describe, downloadUrl, appId);
  877. }
  878. } catch (e) {}
  879. }
  880. downloadApk(
  881. BuildContext context,
  882. String filePath,
  883. String downloadUrl,
  884. Function downloadCallback,
  885. ) async {
  886. final file = new File(filePath);
  887. bool isExist = await file.exists();
  888. if (isExist) {
  889. print('### 文件存在 : ${file.path}');
  890. file.delete();
  891. }
  892. // else {
  893. //
  894. // print('### 开始下载 $downloadUrl');
  895. // dio.download(downloadUrl, filePath, onReceiveProgress: downloadCallback);
  896. // }
  897. // downloadUrl ='oemarket.com/app0/30/30970/apk/2085562.apk?channel_id=426&tid=d73j9ihlkucuxfqpgnxgjeif';
  898. dio.download(downloadUrl, filePath, onReceiveProgress: downloadCallback);
  899. }
  900. ///获取用户每日签到信息
  901. Future<DailyBonusBean> getDailyBonus() async {
  902. Map data = {
  903. "userId": UserData().basicInfo.userId,
  904. };
  905. data['sign'] = TokenMgr().getSign(data);
  906. data['userId'] = UserData().basicInfo.userId;
  907. try {
  908. Response res = await HttpUtil().post('sign/in/user/info', data: data);
  909. Map resData = res.data;
  910. print('###getDailyBonus res.data ${res.data}');
  911. if (resData['code'] == 0) {
  912. return DailyBonusBean.fromMap(resData['data']);
  913. }
  914. return null;
  915. } catch (e) {
  916. return null;
  917. }
  918. }
  919. ///点击签到
  920. Future<bool> signInBounus(int score) async {
  921. Map data = {
  922. "userId": UserData().basicInfo.userId,
  923. "score": score,
  924. };
  925. data['sign'] = TokenMgr().getSign(data);
  926. data['userId'] = UserData().basicInfo.userId;
  927. data['score'] = score;
  928. try {
  929. Response res = await HttpUtil().post('sign/in/user', data: data);
  930. Map resData = res.data;
  931. print('###signInBounus res.data ${res.data}');
  932. if (resData['code'] == 0) {
  933. return true;
  934. // bool needNotice = resData['data']['Notice']==1; ///是否通知更新
  935. // return DailyBonusBean.fromMap(resData['data']);
  936. } else {
  937. showToast(resData['msg']);
  938. }
  939. return false;
  940. } catch (e) {
  941. return false;
  942. }
  943. }
  944. /// 用户签到积分兑换商品
  945. Future<bool> signInExchange(GoodsBean goodsBean) async {
  946. Map data = {
  947. "userId": UserData().basicInfo.userId,
  948. "id": goodsBean.id,
  949. "score": goodsBean.s,
  950. };
  951. data['sign'] = TokenMgr().getSign(data);
  952. data['userId'] = UserData().basicInfo.userId;
  953. data['score'] = goodsBean.s;
  954. data['id'] = goodsBean.id;
  955. try {
  956. Response res =
  957. await HttpUtil().post('sign/in/score/exchange', data: data);
  958. Map resData = res.data;
  959. print('###signInExchange res.data ${res.data}');
  960. if (resData['code'] == 0) {
  961. return true;
  962. } else {
  963. showToast(resData['msg']);
  964. }
  965. return false;
  966. } catch (e) {
  967. return false;
  968. }
  969. }
  970. addFriends(
  971. BuildContext context, int friendId, String content, callback) async {
  972. Map data = {
  973. "userId": UserData().basicInfo.userId,
  974. "friendsUserId": friendId
  975. };
  976. data['sign'] = TokenMgr().getSign(data);
  977. data['content'] = content;
  978. Response res = await HttpUtil().post('friendship/add/friends', data: data);
  979. Map resData = res.data;
  980. print(resData);
  981. if (resData['code'] == 0) {
  982. showToast(resData['msg']);
  983. if (callback != null) callback();
  984. }
  985. }
  986. //付费人工翻译
  987. getPersonalTranslate(MsgModel msgModel) async {
  988. Map data = {
  989. "suserid": msgModel.from,
  990. "chatmsgid": msgModel.time,
  991. "tlanguage": UserData().language,
  992. "chattype": msgModel.msgType,
  993. "chatchanneltype": msgModel.channelType,
  994. "targetid": msgModel.sessionId
  995. };
  996. data['sign'] = TokenMgr().getSign(data);
  997. if (msgModel.msgType == 0) {
  998. data['content'] = base64Encode(msgModel.msgContent);
  999. } else {
  1000. if (msgModel.localFile == null) {
  1001. showToast('请稍后再试');
  1002. return;
  1003. }
  1004. data['content'] =
  1005. base64Encode(File(msgModel.localFile).readAsBytesSync());
  1006. }
  1007. data["tuserids"] = [UserData().basicInfo.userId];
  1008. data['duration'] =
  1009. msgModel.extraInfo != null ? msgModel.extraInfo ~/ 1000 : 0;
  1010. data['ispay'] = true;
  1011. if (msgModel.msgType == ChatType.TextChatType.value) {
  1012. int length = utf8.decode(msgModel.msgContent).length;
  1013. data['money'] = length ~/ 50 + 1; //每50个字耗费1H币
  1014. print('字数 $length 价格 ${length % 50 + 1}');
  1015. } else if (msgModel.msgType == ChatType.ShortVoiceChatType.value) {
  1016. //没20秒扣除1Hb
  1017. data['money'] =
  1018. msgModel.extraInfo != null ? msgModel.extraInfo ~/ 20000 + 1 : 0;
  1019. }
  1020. if (msgModel.translateContent != null &&
  1021. msgModel.translateContent.length > 0) {
  1022. data['mcontent'] = base64Encode(msgModel.enTranslateContent);
  1023. }
  1024. Response res =
  1025. await HttpUtil().post('service/paid/translation', data: data);
  1026. if (res == null) {
  1027. return false;
  1028. }
  1029. Map resData = res.data;
  1030. print('付费翻译请求$resData');
  1031. if (resData['code'] == 0) {
  1032. print('扣除 H 币 ${data['money']}');
  1033. return true;
  1034. }
  1035. print(resData['msg']);
  1036. showToast(resData['msg']);
  1037. return false;
  1038. }
  1039. //用户评价人工翻译,差评
  1040. Future<bool> rateTranslateResult(MsgModel msg, Function callback) async {
  1041. Map data = {
  1042. "userId": UserData().basicInfo.userId,
  1043. "chatUserId": msg.from,
  1044. "chatMsgId": msg.time,
  1045. "score": 1
  1046. };
  1047. data['sign'] = TokenMgr().getSign(data);
  1048. Response res = await HttpUtil().post('translate/user/score', data: data);
  1049. if (res == null) {
  1050. return false;
  1051. }
  1052. var resData = res.data;
  1053. if (resData['code'] == 0) {
  1054. msg.transTag = 10; //已评价过
  1055. if (callback != null) {
  1056. callback();
  1057. }
  1058. SqlUtil().updateUserTranslateRate(msg.sessionId, msg.time, msg.transTag);
  1059. return true;
  1060. }
  1061. return false;
  1062. }
  1063. //根据经纬度获取用户国家城市
  1064. getAddress(double lon, double lat) async {
  1065. Map data = {
  1066. "lon": lon.toString(),
  1067. "lat": lat.toString(),
  1068. };
  1069. data['sign'] = TokenMgr().getSign(data);
  1070. data['language'] = UserData().language;
  1071. Response res = await HttpUtil().post('user/get/address', data: data);
  1072. if (res == null) return;
  1073. Map resData = res.data;
  1074. if (resData['code'] == 0 && resData['data'] != null) {
  1075. print(resData['data']);
  1076. List address = resData['data'].split(',');
  1077. if (address.length != 2) return;
  1078. String country = address[0];
  1079. String city = address[1];
  1080. UserData().isInChina = false;
  1081. if (country == '越南') {
  1082. UserData().currentCity = 'VietNam-';
  1083. List citys = constData[3]['city'][0]['List'];
  1084. for (int i = 0; i < citys.length; i++) {
  1085. if (citys[i]['Value'] == city) {
  1086. UserData().currentCity += citys[i]['Key'];
  1087. break;
  1088. }
  1089. }
  1090. } else if (country == '中国') {
  1091. UserData().isInChina = true;
  1092. UserData().currentCity = 'China-ChinaRepeat';
  1093. } else {
  1094. UserData().currentCity = 'VietNam-HoChiMinhCIty';
  1095. }
  1096. if (UserData().currentCity != UserData().basicInfo.meetPlace) {
  1097. UserData().basicInfo.meetPlace = UserData().currentCity;
  1098. changeCurrentCity(lon, lat, () {});
  1099. }
  1100. MessageMgr().emit('change_currentcity');
  1101. }
  1102. }
  1103. //根据经纬度获取用户国家城市
  1104. changeCurrentCity(double lon, double lat, callback) async {
  1105. if (UserData().basicInfo.userId == null) return;
  1106. Map data = {
  1107. "userId": UserData().basicInfo.userId,
  1108. "lon": lon.toString(),
  1109. "lat": lat.toString(),
  1110. };
  1111. data['sign'] = TokenMgr().getSign(data);
  1112. Response res = await HttpUtil().post('user/update/meetPlace', data: data);
  1113. if (res == null) return;
  1114. Map resData = res.data;
  1115. print(resData);
  1116. if (resData['code'] == 0) {
  1117. callback();
  1118. }
  1119. }
  1120. //通过手机号查询用户
  1121. searchNewFrindsByPhone(String phone, callback) async {
  1122. Map data = {
  1123. "userId": UserData().basicInfo.userId,
  1124. "value": phone,
  1125. };
  1126. data['sign'] = TokenMgr().getSign(data);
  1127. Response res = await HttpUtil()
  1128. .post('/friendship/search/userPhone', data: data, isShowLoading: true);
  1129. if (res == null) return;
  1130. Map resData = res.data;
  1131. print(resData);
  1132. if (resData['code'] == 0) {
  1133. callback(resData['data']['UserId']);
  1134. }
  1135. }
  1136. //拉黑用户
  1137. blackUser(int userId, callback) async {
  1138. Map data = {
  1139. "userid": UserData().basicInfo.userId,
  1140. "type": 1,
  1141. "followUserId": userId,
  1142. };
  1143. data['sign'] = TokenMgr().getSign(data);
  1144. Response res =
  1145. await HttpUtil().post('userfollow/follow/insert', data: data);
  1146. Map resData = res.data;
  1147. showToast(resData['msg']);
  1148. if (resData['code'] == 0) {
  1149. BlacklistMgr.addMyBlackList(userId);
  1150. callback();
  1151. }
  1152. }
  1153. //取消拉黑用户
  1154. cancleBlackUser(int userId, callback) async {
  1155. Map data = {
  1156. "userid": UserData().basicInfo.userId,
  1157. "type": 1,
  1158. "followUserId": userId,
  1159. };
  1160. data['sign'] = TokenMgr().getSign(data);
  1161. Response res = await HttpUtil()
  1162. .post('userfollow/follow/cancel', data: data, isShowLoading: true);
  1163. Map resData = res.data;
  1164. showToast(resData['msg']);
  1165. if (resData['code'] == 0) {
  1166. BlacklistMgr.removeMyBalckList(userId);
  1167. callback();
  1168. }
  1169. }
  1170. //收藏用户
  1171. setLove(int userId, callback) async {
  1172. Map data = {
  1173. "userid": UserData().basicInfo.userId,
  1174. "type": 0,
  1175. "followUserId": userId,
  1176. };
  1177. data['sign'] = TokenMgr().getSign(data);
  1178. Response res = await HttpUtil()
  1179. .post('userfollow/follow/insert', data: data, isShowLoading: true);
  1180. Map resData = res.data;
  1181. if (resData['code'] == 0) {
  1182. showToast(resData['msg']);
  1183. callback();
  1184. }
  1185. }
  1186. //取消收藏用户
  1187. cancleLove(int userId, callback) async {
  1188. Map data = {
  1189. "userid": UserData().basicInfo.userId,
  1190. "type": 0,
  1191. "followUserId": userId,
  1192. };
  1193. data['sign'] = TokenMgr().getSign(data);
  1194. Response res = await HttpUtil()
  1195. .post('userfollow/follow/cancel', data: data, isShowLoading: true);
  1196. Map resData = res.data;
  1197. if (resData['code'] == 0) {
  1198. showToast(resData['msg']);
  1199. callback();
  1200. }
  1201. }
  1202. //向企业服务助手提交信息
  1203. Future<bool> commitInfoToCompany(MsgModel msgModel) async {
  1204. Map data = {
  1205. "userid": msgModel.from,
  1206. "msgType": msgModel.msgType,
  1207. };
  1208. data['sign'] = TokenMgr().getSign(data);
  1209. data['msgContent'] = base64Encode(msgModel.msgContent);
  1210. msgModel.state = MsgState.Sending;
  1211. print('commitInfoToCompany 参数 $data');
  1212. Response res = await HttpUtil().post('feedback/user/insert', data: data);
  1213. if (res == null) {
  1214. msgModel.state = MsgState.SendingFailed;
  1215. ChatDataMgr().updateMsgState(msgModel.sessionId, msgModel.time,
  1216. msgModel.channelType, msgModel.state);
  1217. return false;
  1218. }
  1219. Map resData = res.data;
  1220. print('commitInfoToCompany $resData');
  1221. if (resData['code'] == 0) {
  1222. msgModel.state = MsgState.SendingSuccess;
  1223. ChatDataMgr().updateMsgState(msgModel.sessionId, msgModel.time,
  1224. msgModel.channelType, msgModel.state);
  1225. return true;
  1226. }
  1227. showToast(resData['msg']);
  1228. return false;
  1229. }
  1230. //焚阅照片恢复
  1231. resetPhoto(callback) async {
  1232. Map data = {
  1233. "userId": UserData().basicInfo.userId,
  1234. };
  1235. data['sign'] = TokenMgr().getSign(data);
  1236. Response res = await HttpUtil()
  1237. .post('user/recover/photos', data: data, isShowLoading: true);
  1238. Map resData = res.data;
  1239. if (resData['code'] == 0) {
  1240. showToast(resData['msg']);
  1241. callback();
  1242. }
  1243. }
  1244. //获取好友校验值
  1245. checkFriends() async {
  1246. Map data = {
  1247. "userId": UserData().basicInfo.userId,
  1248. };
  1249. data['sign'] = TokenMgr().getSign(data);
  1250. Response res = await HttpUtil()
  1251. .post('friendship/check/userFriends', data: data);
  1252. Map resData = res.data;
  1253. if (resData['code'] == 0) {
  1254. FriendListMgr().checkFromServer(resData['data']);
  1255. }
  1256. }
  1257. //保存设备名称和编码
  1258. saveMobileInfo() async {
  1259. String mobileType = '';
  1260. DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  1261. if (Platform.isAndroid) {
  1262. AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
  1263. mobileType = androidInfo.model;
  1264. print('Running on ${androidInfo.model}'); // e.g. "Moto G (4)"
  1265. } else if (Platform.isIOS) {
  1266. IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
  1267. mobileType = iosInfo.utsname.machine;
  1268. }
  1269. Map data = {
  1270. "userId": UserData().basicInfo.userId,
  1271. };
  1272. data['sign'] = TokenMgr().getSign(data);
  1273. data['model'] = mobileType;
  1274. data['coding'] = UserData().deviceLanguageCode;
  1275. Response res =
  1276. await HttpUtil().post('user/save/modelAndCoding', data: data);
  1277. Map resData = res.data;
  1278. print(resData);
  1279. }
  1280. ///实时帮-翻译管家评价
  1281. evaluationTransalteHK(String orderNo,String value,bool isGood,Function callback) async {
  1282. Map data = {
  1283. "userId": UserData().basicInfo.userId,
  1284. "orderNo": orderNo,
  1285. "gradeStatus":isGood?1:2
  1286. };
  1287. data['sign'] = TokenMgr().getSign(data);
  1288. data['value'] = value;
  1289. Response res = await HttpUtil().post('steward/evaluation', data: data);
  1290. callback();
  1291. if (res == null) {
  1292. print('请求异常');
  1293. return;
  1294. }
  1295. var resData = res.data;
  1296. if (resData['code'] == 0) {
  1297. showToast('评价成功');
  1298. }else{
  1299. showToast(I18n.of(Constants.getCurrentContext()).net_error);
  1300. }
  1301. }
  1302. ///实时帮-用户测距
  1303. userRanging(int distance,String origin,String ending) async {
  1304. Map data = {
  1305. "userId": UserData().basicInfo.userId,
  1306. "distance": distance,
  1307. };
  1308. data['sign'] = TokenMgr().getSign(data);
  1309. data['origin'] = origin;
  1310. data['ending'] = ending;
  1311. Response res = await HttpUtil().post('steward/userRanging', data: data);
  1312. if (res == null) {
  1313. print('请求异常');
  1314. return;
  1315. }
  1316. var resData = res.data;
  1317. if (resData['code'] == 0) {
  1318. print('实时帮-用户测距提交 成功');
  1319. }else{
  1320. print('实时帮-用户测距提交 失败');
  1321. }
  1322. }
  1323. ///实时帮-翻译人员上线、下线
  1324. translateHKloginRecord(bool isLogin,Function callback) async {
  1325. Map data = {
  1326. "userId": UserData().basicInfo.userId,
  1327. "type": isLogin?1:2,
  1328. };
  1329. data['sign'] = TokenMgr().getSign(data);
  1330. print('请求data : $data');
  1331. Response res = await HttpUtil().post('steward/loginRecord', data: data);
  1332. if (res == null) {
  1333. print('请求异常');
  1334. return;
  1335. }
  1336. var resData = res.data;
  1337. if (resData['code'] == 0) {
  1338. callback();
  1339. print('翻译人员上线、下线 成功');
  1340. }else{
  1341. print('翻译人员上线、下线 失败 ${resData['msg']}');
  1342. }
  1343. }
  1344. }