changePassword method

Future<JsonResult> changePassword(
  1. String? mobile,
  2. String? password
)

Implementation

Future<JsonResult> changePassword(String? mobile, String? password) async {
  Map<String, String> headers = {"Content-Type": "application/json"};

  var body =
      json.encode({"mobile": mobile, "password": password, "client": client});

  final initUrl = BytedeskUtils.getHostUri('/visitors/api/v1/change');
  final initResponse =
      await httpClient.post(initUrl, headers: headers, body: body);

  //解决json解析中的乱码问题
  Utf8Decoder utf8decoder = const Utf8Decoder(); // fix 中文乱码
  //将string类型数据 转换为json类型的数据
  final responseJson =
      json.decode(utf8decoder.convert(initResponse.bodyBytes));
  // final responseJson = json.decode(initResponse.body);
  // debugPrint("changePassword");
  // BytedeskUtils.printLog(responseJson);
  // 判断token是否过期
  if (responseJson.toString().contains('invalid_token')) {
    bytedeskEventBus.fire(InvalidTokenEventBus());
  }
  //
  return JsonResult.fromJson(responseJson);
}