other_login_provider.dart
3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/check_seller_acc_model.dart';
import 'package:one_key/models/checkbind_phone_model.dart';
import 'package:one_key/models/phone_code_model.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
import 'package:one_key/utils/utils.dart';
import 'dart:convert';
/**
* 第三方登陆
*/
class OtherLoginProvider extends ChangeNotifier {
String? code; //验证码
PhoneCodeSunModel? phoneCodeSunModel;
PageState pageState = PageState.Loading; //是否有店铺
List<CheckSellerAccSunModel>? sellerList = []; //绑定微信或者手机号码的商家列表
/// 给手机发送短信验证码
Future<bool> getPhoneCode(BuildContext context, Map<String, String?> params,
{isShowLoading = true}) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.send_vc_code,
data: params, showLoading: false);
if (baseResp.code == Constant.status_success) {
if (baseResp.data.isEmpty) {
return false;
} else {
Map<String, dynamic> data = jsonDecode(baseResp.data);
//解析解析
if (data['status'] == 'success') {
return true;
}
// phoneCodeSunModel = PhoneCodeModel.fromJson(jsonDecode(baseResp.data)).data;
return false;
}
} else {
Utils.showToast(baseResp.msg ?? "");
return false;
}
} catch (error) {}
return false;
}
/// APP微信登录后检测是否存在商家
Future<List<CheckSellerAccSunModel>?> checkSellerAcc(
BuildContext context, Map<String, String?> params,
{isShowLoading = true, showLoading = false}) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.check_seller_acc,
data: params,
showLoading: pageState == PageState.Loading ? false : showLoading);
if (baseResp.code == Constant.status_success) {
if (baseResp.data != null) {
//解析解析
pageState = PageState.Success;
sellerList = CheckSellerAccModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data!
.cast<CheckSellerAccSunModel>();
} else {
pageState = PageState.Empty;
}
} else {
Utils.showToast(baseResp.msg ?? "");
pageState = PageState.ConnectivityError;
}
notifyListeners();
return sellerList;
} catch (error) {
print(error);
}
return null;
}
/// APP微信登录后检测是否绑定过手机号
Future<CheckbindPhoneSunModel?> checkbindPhone(
BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
try {
BaseResp<Map<String, dynamic>?> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.post, HttpUrl.check_bind_phone,
data: params, showLoading: false);
CheckbindPhoneSunModel? checkbindPhoneSunModel;
if (baseResp.code == Constant.status_success) {
if (baseResp.data == null) {
return checkbindPhoneSunModel;
} else {
//解析解析
checkbindPhoneSunModel = CheckbindPhoneModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
return checkbindPhoneSunModel;
}
} else {
Utils.showToast(baseResp.msg ?? "");
return checkbindPhoneSunModel;
}
} catch (error) {}
return null;
}
}