You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
7.6 KiB
243 lines
7.6 KiB
import 'dart:convert'; |
|
import 'dart:io'; |
|
|
|
import 'package:dio/dio.dart'; |
|
import 'package:flutter/foundation.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:huixiang/login/login_page.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:retrofit/retrofit.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
part 'retrofit_api.g.dart'; |
|
|
|
// @RestApi(baseUrl: "http://192.168.10.236:8766/app/") |
|
@RestApi(baseUrl: "http://platform.test.api.lotus-wallet.com/app/") |
|
// @RestApi(baseUrl: "http://192.168.10.129:8766/app/") |
|
abstract class ApiService { |
|
factory ApiService(Dio dio, |
|
{String baseUrl, BuildContext context, 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}"); |
|
if (options.data is FormData) { |
|
print("params data = FormData"); |
|
} else { |
|
print("params data = ${jsonEncode(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)); |
|
Map map = response.data; |
|
if (map["code"] == 40005 || map["code"] == 40001) { |
|
SharedPreferences.getInstance().then((value) => value.clear()); |
|
Navigator.pushAndRemoveUntil(context, MaterialPageRoute( |
|
builder: (BuildContext context) { |
|
return LoginPage(); |
|
}, |
|
), (route) => route == null); |
|
} |
|
print("======================= 响应数据结束 =======================\n"); |
|
}, onError: (DioError e) { |
|
print("\n=======================错误响应数据 ========================"); |
|
print("type = ${e.type}"); |
|
print("message = ${e.message}"); |
|
print("\n"); |
|
}), |
|
); |
|
|
|
if(kReleaseMode) { |
|
baseUrl = "http://platform.test.api.lotus-wallet.com/app/"; |
|
} |
|
|
|
|
|
return _ApiService(dio, baseUrl: baseUrl); |
|
} |
|
|
|
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") |
|
@MultiPart() |
|
Future<BaseData> upload( |
|
@Part(name: "file") File data, @Part(name: "folderId") int folderId); |
|
|
|
/// 周边搜索 |
|
@GET( |
|
"https://restapi.amap.com/v3/place/around?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&keywords={keywords}&offset={size}&page={page}&extensions=all") |
|
Future<dynamic> searchPoi(@Path("lat") String lat, @Path("lng") String lng, |
|
@Path("keywords") String keywords, int size, int page); |
|
|
|
/// 用户登录 |
|
@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); |
|
|
|
///领取优惠券 |
|
@GET("/coupon/receive?couponId={couponId}") |
|
Future<BaseData> receiveCoupon(@Path("couponId") String couponId); |
|
|
|
///订单列表 |
|
@POST("/creditOrder/list") |
|
Future<BaseData> creditOrderList(@Body() Map<String, dynamic> param); |
|
|
|
///创建积分订单 |
|
@POST("/creditOrder/create") |
|
Future<BaseData> creditOrder(@Body() Map<String, dynamic> param); |
|
|
|
///保存收货地址 |
|
@POST("/address/add") |
|
Future<BaseData> addAddress(@Body() Map<String, dynamic> param); |
|
|
|
///删除收货地址 |
|
@POST("/address/delete") |
|
Future<BaseData> deleteAddress(@Body() Map<String, dynamic> param); |
|
|
|
///查询收货地址 |
|
@GET("/address/detail/{id}") |
|
Future<BaseData> queryAddress(@Path("id") String id); |
|
|
|
///查询用户所有的收货地址 |
|
@GET("/address/queryMemberAddress") |
|
Future<BaseData> queryMemberAddress(); |
|
|
|
///更新收货地址 |
|
@POST("/address/update") |
|
Future<BaseData> updateAddress(@Body() Map<String, dynamic> param); |
|
|
|
///查询领券列表 |
|
@POST("/coupon/centreList") |
|
Future<BaseData> queryCoupon(@Body() Map<String, dynamic> param); |
|
|
|
///查询卡包列表 |
|
@POST("/coupon/packageList") |
|
Future<BaseData> queryCard(@Body() Map<String, dynamic> param); |
|
|
|
///门店地址列表 |
|
@POST("/store/list") |
|
Future<BaseData> queryStore(@Body() Map<String, dynamic> param); |
|
|
|
///分页查看资讯列表 |
|
@POST("/information/list") |
|
Future<BaseData> informationList(@Body() Map<String, dynamic> param); |
|
|
|
///查看资讯详情 |
|
@POST("/information/{id}") |
|
Future<BaseData> informationInfo(@Body() Map<String, dynamic> param); |
|
|
|
///积分订单兑换到券包 |
|
@GET("/creditOrder/receive/{id}") |
|
Future<BaseData> creditOrderReceive(@Path("id") String id); |
|
|
|
///首页数据 |
|
@GET("/home/home") |
|
Future<BaseData> queryHome(); |
|
|
|
///查询店铺商家详情 |
|
@GET("/store/{id}") |
|
Future<BaseData> queryStoreInfo(@Path("id") String id); |
|
|
|
///分页查看资讯列表 |
|
@POST("/information/list") |
|
Future<BaseData> queryArticle(@Body() Map<String, dynamic> param); |
|
|
|
///banner查询 |
|
@POST("/banner/page") |
|
Future<BaseData> queryBanner(@Body() Map<String, dynamic> param); |
|
|
|
///品牌信息 |
|
@GET("/home/brand") |
|
Future<BaseData> queryHomeBrand(); |
|
|
|
///小程序会员登录 |
|
@GET("/auth/mini/login/{storeId}") |
|
Future<BaseData> minLogin(@Path("storeId") String storeId); |
|
|
|
///小程序会员登录 |
|
@POST("/member/listBill") |
|
Future<BaseData> queryBillInfo(@Body() Map<String, dynamic> param); |
|
|
|
///会员等级列表 |
|
@GET("/member/rankList") |
|
Future<BaseData> rankList(); |
|
|
|
///订单列表 |
|
@POST("/order/list") |
|
Future<BaseData> orderList(@Body() Map<String, dynamic> param); |
|
|
|
///订单详情 |
|
@GET("/order/orderDetail?id={id}") |
|
Future<BaseData> orderDetail(@Path("id") String id); |
|
|
|
///继续付款 |
|
@POST("/order/continuePay") |
|
Future<BaseData> continuePay(@Body() Map<String, dynamic> param); |
|
|
|
///积分订单兑换到券包 |
|
@GET("/creditOrder/receive/{id}") |
|
Future<BaseData> receiveToCard(@Path("id") String id); |
|
|
|
///会员卡列表 |
|
@GET("/member/vipList") |
|
Future<BaseData> vipList(); |
|
|
|
///会员卡详情 |
|
@GET("/member/vipDetail/{id}") |
|
Future<BaseData> vipDetail(@Path("id") String id); |
|
|
|
}
|
|
|