bindWeChatMobile method
Implementation
Future<UserJsonResult> bindWeChatMobile(
String? mobile, String? unionid) async {
//
Map<String, String> headers = {
HttpHeaders.contentTypeHeader: "application/json"
};
//
var body =
json.encode({"mobile": mobile, "unionid": unionid, "client": client});
//
// final initUrl = '$baseUrl/visitor/api/bind/wechat/mobile';
final initUrl = BytedeskUtils.getHostUri('/visitor/api/bind/wechat/mobile');
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));
debugPrint("responseJson $responseJson");
//
UserJsonResult userJsonResult = UserJsonResult.fromJson(responseJson);
if (userJsonResult.statusCode == 200) {
SpUtil.putString(BytedeskConstants.mobile, mobile!);
SpUtil.putString(BytedeskConstants.unionid, unionid!);
SpUtil.putBool(BytedeskConstants.isAuthenticated, true);
}
//
return userJsonResult;
}