|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart';
|
|
|
|
import 'package:retrofit/retrofit.dart';
|
|
|
|
|
|
|
|
part 'retrofit_api.g.dart';
|
|
|
|
|
|
|
|
@RestApi(baseUrl: "http://192.168.10.236:8766/app")
|
|
|
|
abstract class ApiService {
|
|
|
|
factory ApiService(Dio dio, {String baseUrl, String token}) {
|
|
|
|
Map<String, dynamic> headers =
|
|
|
|
token == null || token == "" ? {} : {'token': "Bearer $token"};
|
|
|
|
dio.options = BaseOptions(
|
|
|
|
connectTimeout: 60000,
|
|
|
|
receiveTimeout: 60000,
|
|
|
|
headers: headers,
|
|
|
|
responseType: ResponseType.json);
|
|
|
|
dio.interceptors.add(
|
|
|
|
InterceptorsWrapper(onRequest: (RequestOptions options) {
|
|
|
|
print("\n====================== 请求数据 =======================");
|
|
|
|
print("method = ${options.method.toString()}");
|
|
|
|
print("url = ${options.uri.toString()}");
|
|
|
|
print("headers = ${options.headers}");
|
|
|
|
print("params data = ${options.data}");
|
|
|
|
print("params queryParameters = ${options.queryParameters}");
|
|
|
|
}, onResponse: (Response response) {
|
|
|
|
print("\n====================== 响应数据开始 =====================");
|
|
|
|
print("code = ${response.statusCode}");
|
|
|
|
// print("data = ${jsonEncode(response.data)}");
|
|
|
|
p(jsonEncode(response.data));
|
|
|
|
print("======================= 响应数据结束 =======================\n");
|
|
|
|
}, onError: (DioError e) {
|
|
|
|
print("\n=======================错误响应数据 ========================");
|
|
|
|
print("type = ${e.type}");
|
|
|
|
print("message = ${e.message}");
|
|
|
|
print("\n");
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
return _ApiService(dio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void p(String msg) {
|
|
|
|
//因为String的length是字符数量不是字节数量所以为了防止中文字符过多,
|
|
|
|
// 把4*1024的MAX字节打印长度改为1000字符数
|
|
|
|
int maxStrLength = 900;
|
|
|
|
//大于1000时
|
|
|
|
while (msg.length > maxStrLength) {
|
|
|
|
print(msg.substring(0, maxStrLength));
|
|
|
|
msg = msg.substring(maxStrLength);
|
|
|
|
}
|
|
|
|
//剩余部分
|
|
|
|
print(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
///文件上传
|
|
|
|
@POST("/file/upload")
|
|
|
|
Future<BaseData> upload(
|
|
|
|
@Part(value: "file") File file, @Part(value: "folderId") int param);
|
|
|
|
|
|
|
|
/// 用户登录
|
|
|
|
@POST("/auth/platform/memberLogin")
|
|
|
|
Future<BaseData> memberLogin(@Body() Map<String, dynamic> param);
|
|
|
|
|
|
|
|
///发送验证码
|
|
|
|
@GET("/auth/sendVerify/{mobile}")
|
|
|
|
Future<BaseData> sendVerify(@Path("mobile") String mobile);
|
|
|
|
|
|
|
|
///积分商城商品列表
|
|
|
|
@POST("/creditGoods/list")
|
|
|
|
Future<BaseData> creditGoods(@Body() Map<String, dynamic> param);
|
|
|
|
|
|
|
|
///积分商城商品详情
|
|
|
|
@GET("/creditGoods/{id}")
|
|
|
|
Future<BaseData> creditGoodsById(@Path("id") String id);
|
|
|
|
|
|
|
|
///查询用户信息
|
|
|
|
@GET("/member/info")
|
|
|
|
Future<BaseData> queryInfo();
|
|
|
|
|
|
|
|
///编辑用户信息
|
|
|
|
@POST("/member/editMemberInfo")
|
|
|
|
Future<BaseData> editInfo(@Body() Map<String, dynamic> param);
|
|
|
|
|
|
|
|
///用户签到信息
|
|
|
|
@GET("/member/signInInfo")
|
|
|
|
Future<BaseData> signInInfo();
|
|
|
|
|
|
|
|
///用户签到
|
|
|
|
@GET("/member/signIn")
|
|
|
|
Future<BaseData> signIn();
|
|
|
|
|
|
|
|
///会员充值
|
|
|
|
@POST("/member/recharge")
|
|
|
|
Future<BaseData> recharge(@Body() Map<String, dynamic> param);
|
|
|
|
|
|
|
|
///领取优惠券
|
|
|
|
@POST("/member/receiveCoupon")
|
|
|
|
Future<BaseData> receiveCoupon(@Body() Map<String, dynamic> param);
|
|
|
|
|
|
|
|
///订单列表
|
|
|
|
@POST("/creditOrder/list")
|
|
|
|
Future<BaseData> creditOrderList(@Body() Map<String, dynamic> param);
|
|
|
|
|
|
|
|
///创建积分订单
|
|
|
|
@POST("/creditOrder/create")
|
|
|
|
Future<BaseData> creditOrder(@Body() Map<String, dynamic> param);
|
|
|
|
}
|