import 'dart:convert'; import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/utils.dart'; import 'package:huixiang/constant.dart'; import 'package:huixiang/data/achivement_detail_list.dart'; import 'package:huixiang/data/activity.dart'; import 'package:huixiang/data/activity_pos.dart'; import 'package:huixiang/data/address.dart'; import 'package:huixiang/data/app_update.dart'; import 'package:huixiang/data/article.dart'; import 'package:huixiang/data/banner.dart'; import 'package:huixiang/data/base_data.dart'; import 'package:huixiang/data/base_list_data.dart'; import 'package:huixiang/data/brand_data.dart'; import 'package:huixiang/data/captcha_data.dart'; import 'package:huixiang/data/category_select.dart'; import 'package:huixiang/data/channels.dart'; import 'package:huixiang/data/chapter.dart'; import 'package:huixiang/data/collect_class.dart'; import 'package:huixiang/data/comunity_comment.dart'; import 'package:huixiang/data/coupon.dart'; import 'package:huixiang/data/coupon_detail.dart'; import 'package:huixiang/data/course.dart'; import 'package:huixiang/data/course_details.dart'; import 'package:huixiang/data/exchange_order.dart'; import 'package:huixiang/data/farmers.dart'; import 'package:huixiang/data/follow.dart'; import 'package:huixiang/data/goods.dart'; import 'package:huixiang/data/goods_category.dart'; import 'package:huixiang/data/headlines.dart'; import 'package:huixiang/data/headlines_details.dart'; import 'package:huixiang/data/home_rank.dart'; import 'package:huixiang/data/im_user.dart'; import 'package:huixiang/data/invitation.dart'; import 'package:huixiang/data/invoice_list.dart'; import 'package:huixiang/data/invoices_detail_info.dart'; import 'package:huixiang/data/invoices_history_list.dart'; import 'package:huixiang/data/login_info.dart'; import 'package:huixiang/data/logistics.dart'; import 'package:huixiang/data/member_comment.dart'; import 'package:huixiang/data/member_infor.dart'; import 'package:huixiang/data/message.dart'; import 'package:huixiang/data/msg_stats.dart'; import 'package:huixiang/data/order_info.dart'; import 'package:huixiang/data/page.dart'; import 'package:huixiang/data/rank.dart'; import 'package:huixiang/data/recharge_act.dart'; import 'package:huixiang/data/second_card.dart'; import 'package:huixiang/data/sign_info.dart'; import 'package:huixiang/data/social_info.dart'; import 'package:huixiang/data/store.dart'; import 'package:huixiang/data/store_info.dart'; import 'package:huixiang/data/title_info_list.dart'; import 'package:huixiang/data/upload_result.dart'; import 'package:huixiang/data/user_bill.dart'; import 'package:huixiang/data/user_info.dart'; import 'package:huixiang/data/vip_badges.dart'; import 'package:huixiang/data/vip_benefit.dart'; import 'package:huixiang/data/vip_card.dart'; import 'package:huixiang/data/vip_card_home.dart'; import 'package:huixiang/data/vip_rule_details.dart'; import 'package:huixiang/data/wx_pay.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/utils/flutter_utils.dart'; import 'package:huixiang/view_widget/login_tips_dialog.dart'; import 'package:retrofit/retrofit.dart'; part 'retrofit_api.g.dart'; @RestApi(baseUrl: kDebugMode ? serviceBaseUrl : localBaseUrl) abstract class ApiService { factory ApiService( Dio dio, { String? baseUrl, BuildContext? context, String? token, bool showLoading = false, bool isIp = false, bool pay = true, ParseErrorLogger? errorLogger, }) { Map headers = (token == null || token == "") ? {} : {'token': "Bearer $token"}; if (pay) { headers["Environment"] = "app"; } print("软件当前运行的模式 kReleaseMode:" + (kReleaseMode ? "发布模式" : "调试模式")); baseUrl = kDebugMode ? serviceBaseUrl : localBaseUrl; if (kDebugMode) baseUrl = serviceBaseUrl; if (isIp) baseUrl = ipBaseUrl; dio.options = BaseOptions( connectTimeout: 30000.milliseconds, receiveTimeout: 30000.milliseconds, headers: headers, responseType: ResponseType.json, ); if (dio.interceptors.length <= 1) { dio.interceptors.add( InterceptorsWrapper(onRequest: ( RequestOptions options, RequestInterceptorHandler handler, ) { try { debugPrint("\n======================= 请求数据 ======================="); debugPrint("method = ${options.method.toString()}"); debugPrint("url = ${options.uri.toString()}"); debugPrint("headers = ${options.headers}"); if (context != null && showLoading && !SmartDialog.checkExist(dialogTypes: {SmartAllDialogType.loading})) { AppUtils.cancelCloseLoading(); //是否显示loading S.current.zhengzaijiazai.loading; } if (options.data is FormData) { debugPrint("params data = FormData"); } else { debugPrint("params data = ${jsonEncode(options.data)}"); } debugPrint("params queryParameters = ${options.queryParameters}"); } catch (e1) {} handler.next(options); }, onResponse: ( Response response, ResponseInterceptorHandler handler, ) { try { debugPrint("\n======================= 响应数据开始 ======================="); if (SmartDialog.checkExist(dialogTypes: {SmartAllDialogType.loading})) { AppUtils.timerCloseLoading(); } debugPrint("code = ${response.statusCode}"); p(jsonEncode(response.data)); if (response.data is Map) { Map map = response.data; if (map["code"] == 40005 || map["code"] == 40001) { if (context != null) { LoginTipsDialog.instance.show(context); } } debugPrint("======================= 响应数据结束 =======================\n"); if (map["code"] == 0 || map["code"] == 200) {} } } catch (e2) { print("respon: ${e2}"); } handler.next(response); }, onError: ( DioException e, ErrorInterceptorHandler handler, ) { if (SmartDialog.checkExist(dialogTypes: {SmartAllDialogType.loading})) { AppUtils.closeLoading(); } debugPrint("\n======================= 错误响应数据 ======================="); debugPrint("type = ${e.type}"); debugPrint("message = ${e.message}"); debugPrint("\n"); handler.next(e); }), ); } return _ApiService(dio, baseUrl: baseUrl, errorLogger: errorLogger); } static void p(String msg) { //因为String的length是字符数量不是字节数量所以为了防止中文字符过多, // 把4*1024的MAX字节打印长度改为1000字符数 if (msg.length > 10000) return; int maxStrLength = 900; //大于1000时 while (msg.length > maxStrLength) { debugPrint(msg.substring(0, maxStrLength), wrapWidth: maxStrLength); msg = msg.substring(maxStrLength); } //剩余部分 debugPrint(msg, wrapWidth: maxStrLength); } ///文件上传 @POST("/file/upload") @MultiPart() Future> upload(@Part(name: "file") File data, @Part(name: "folderId") int folderId, bool isVideo); /// 周边搜索 @GET( "https://restapi.amap.com/v3/place/around?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&keywords={keywords}&offset={size}&page={page}&extensions=all") Future searchPoi(@Path("lat") String lat, @Path("lng") String lng, @Path("keywords") String keywords, int size, int page); /// 逆地理编码 @GET( "https://restapi.amap.com/v3/geocode/regeo?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&extensions=base") Future geocodeRegeo( @Path("lat") String lat, @Path("lng") String lng); /// 用户登录 @POST("/auth/platform/memberLogin") Future?> memberLogin(@Body() Map param); ///获取APP门店推广渠道 @GET("/auth/appChannels") Future> appChannels(); ///发送验证码 @POST("/auth/sendVerify") Future> sendVerify(@Body() Map param); ///积分商城商品列表 @POST("/creditGoods/list") Future>> creditGoods( @Body() Map param); ///积分商城商品分類列表 @POST("/creditGoodsCategory/page") Future>> goodsCategory( @Body() Map param); ///积分商城商品详情 @GET("/creditGoods/{id}") Future> creditGoodsById(@Path("id") String id); ///查询用户信息 @GET("/member/info") Future?> queryInfo(); ///编辑用户信息 @POST("/member/editMemberInfo") Future editInfo(@Body() Map param); ///用户签到信息 @GET("/member/signInInfo") Future> signInInfo(); ///用户签到 @GET("/member/signIn") Future signIn(); ///平台充值 @POST("/wallet/recharge") Future> recharge(@Body() Map param); ///充值活动列表 @GET("/wallet/rechargeActList?tenantCode={tenantCode}") Future> rechargeActList( @Path("tenantCode") String tenantCode); ///领取优惠券 @GET("/coupon/receive?couponId={couponId}") Future receiveCoupon(@Path("couponId") String couponId); ///兑换订单列表 @POST("/creditOrder/list") Future>> creditOrderList( @Body() Map param); ///创建积分订单 @POST("/creditOrder/create") Future creditOrder(@Body() Map param); ///保存收货地址 @POST("/address/add") Future addAddress(@Body() Map param); ///删除收货地址 @POST("/address/delete") Future deleteAddress(@Body() Map param); ///查询收货地址 @GET("/address/detail/{id}") Future queryAddress(@Path("id") String id); ///查询用户所有的收货地址 @GET("/address/queryMemberAddress") Future> queryMemberAddress(); ///更新收货地址 @POST("/address/update") Future updateAddress(@Body() Map param); ///查询领券列表 @POST("/coupon/centreList") Future>> queryCoupon( @Body() Map param); ///查询卡包列表 @POST("/coupon/packageList") Future>> queryCard( @Body() Map param); ///门店地址列表 @POST("/store/list") Future> queryStore(@Body() Map param); ///分页查看资讯列表 @POST("/information/list") Future>> informationList( @Body() Map param); ///查看资讯详情 @GET("/information/{id}") Future> informationInfo(@Path("id") String id); ///查看活动详情 @GET("/information/{id}") Future> activityInfo(@Path("id") String id); ///积分订单兑换到券包 @GET("/creditOrder/receive/{id}") Future creditOrderReceive(@Path("id") String id); ///首页数据 @GET("/home/home") Future> queryHome(); ///查询店铺商家详情 @GET("/store/{id}") Future> queryStoreInfo(@Path("id") String id); ///分页查看资讯列表 @POST("/information/list") Future>> queryArticle( @Body() Map param); ///banner查询 @POST("/banner/page") Future>> queryBanner( @Body() Map param); ///品牌信息 @GET("/home/brand") Future queryHomeBrand(); /// 小程序会员登录 @GET("/auth/mini/login/{storeId}") Future minLogin(@Path("storeId") String storeId); /// 各种消费记录 @POST("/member/listBill") Future>> queryBillInfo( @Body() Map param); ///会员等级列表 @GET("/member/rankList") Future> rankList(); ///订单列表 @POST("/order/list") Future>> orderList( @Body() Map param); ///订单详情 @GET("/order/orderDetail?id={id}") Future> orderDetail(@Path("id") String id); ///继续付款 @POST("/order/continuePay") Future continuePay(@Body() Map param); ///积分订单兑换到券包 @GET("/creditOrder/receive/{id}") Future receiveToCard(@Path("id") String id); ///会员卡列表 @POST("/member/vipList") Future> vipList(@Body() Map param); ///会员卡详情 @POST("/member/vipDetail") Future> vipDetail(@Body() Map param); ///分页查询App消息列表 @POST("/app-msg/list") Future>> msgList( @Body() Map param); ///加载验证码 @POST("/captcha/get") Future captchaGet(@Body() Map param); ///校验验证码 @POST("/captcha/check") Future captchaCheck(@Body() Map param); ///App消息详情 @GET("/app-msg/{id}") Future queryMsg(@Path("id") String id); ///App消息 统计各类消息数量 @GET("/app-msg/stats") Future> stats(); ///给文章/活动点赞 @GET("/information/likes/{id}") Future informationLikes(@Path("id") String id); ///发布评论 @POST("/memberComment") Future memberComment(@Body() Map param); ///查询评论列表 @POST("/memberComment/list") Future>> memberCommentList( @Body() Map param); ///评论点赞 @GET("/memberComment/likes/{id}") Future commentLike(@Path("id") String id); ///评论删除 @DELETE("/memberComment/{id}") Future delComment(@Path("id") String id); ///查询物流轨迹 @GET("/order/getShippingTrace/{shipperCode}/{logisticCode}") Future> shippingTrace( @Path("shipperCode") String shipperCode, @Path("logisticCode") String logisticCode); // ///反馈 // @POST("/other/report") // Future> report(@Body() Map map); ///取消订单 @GET("/order/cancel/{id}") Future> orderCancel(@Path("id") String id); ///继续付款? @POST("/order/settlement") Future> settlement(@Body() Map map); /// 发表动态 @POST("/information/trend") Future> trend(@Body() Map map); /// 动态列表 @POST("/information/trend-list") Future>> trendList( @Body() Map map); /// 我关注/粉丝的会员列表 @POST("/member/follow/list") Future>> followList( @Body() Map map); /// 好友列表 @POST("/member/mutualFollow/list") Future>> mutualFollowList( @Body() Map map); ///关注/取关会员 @PUT("/member/follow/{followId}") Future follow(@Path("followId") String followId); ///删除动态 @DELETE("/information/trend/{id}") Future deleteTrend(@Path("id") String id); ///个人社交信息(粉丝/关注数量/成就数量/好友数量) @GET("/member/socialInfo") Future> socialInfo(); ///课程分类列表 @GET("/course/categoryList") Future> categoryList(); ///课程章节列表 @GET("/course/catalogList/{courseId}") Future> catalogList(@Path("courseId") String courseId); /// 课程列表 @POST("/course/list") Future>> courseList( @Body() Map map); ///课程的合集列表 @GET("/course/collectList") Future> collectList(); ///合集包含的课程列表 @GET("/course/collect/{collectId}") Future> collect(@Path("collectId") String collectId); ///课程详情 @GET("/course/{id}") Future> course(@Path("id") String id); ///给文章/活动点赞 @GET("/course/likes/{courseId}") Future courseLikes(@Path("courseId") String courseId); /// APP查询所有成就徽章 并显示会员完成的 @POST("/app-memberAchievement/findBadges") Future> findBadges(@Body() Map map); ///查看一个成就大类详情 @GET( "/app-memberAchievement/getAchievementDetail?achievementCategoryId={achievementCategoryId}") Future> getAchievementDetail( @Path("achievementCategoryId") String achievementCategoryId); ///会员的权益列表 @GET("/member/benefitList") Future> benefitList(); ///会员权益 @GET("/home/vipBenefit") Future> vipBenefit(); ///查询副卡列表 @GET("/member/secondCardList") Future> secondCardList(); ///绑定副卡 @GET("/member/bindSecondCard/{phone}") Future bindSecondCard(@Path("phone") String phone); ///解绑副卡 @GET("/member/unbindSecondCard/{phone}") Future unbindSecondCard(@Path("phone") String phone); ///查看积分订单物流 @GET("/creditOrder/getAppShippingTrace?orderId={orderId}") Future> getAppShippingTrace( @Path("orderId") String orderId); ///购买会员等级 @POST("/member/rankBuy") Future> rankBuy(@Body() Map param); ///文章合集列表 @GET("/information/categoryList") Future> headlinesList(); ///文章合集详情 @GET("/information/category/{id}") Future> headlinesDetails(@Path("id") String id); /// 我的邀请会员列表 @POST("/member/inviteMemberList") Future>> inviteMemberList( @Body() Map map); ///核销优惠券 @GET("/coupon/wiped/{memberCouponId}") Future wiped(@Path("memberCouponId") String memberCouponId); ///查询优惠券详情 @GET("/coupon/detail/{memberCouponId}") Future> couponDetail(@Path("") String memberCouponId); ///查询会员信息 @GET("/member/detail/{id}") Future> memberDetail(@Path("id") String id); ///活动弹窗 @GET("/home/appPopup") Future> appPopup(); ///注销会员 @GET("/member/deleteMine") Future deleteMine(); ///投诉资讯/动态 @POST("/information/complaint") Future complaint(@Body() Map param); ///app自动更新 @GET("/home/version") Future> appVersion(); ///App推荐排行 @GET("/home/recommendRank") Future> recommendRank(); ///发送修改支付密码的短信验证 @GET("/member/sendVerifyByUpdatePayPwd") Future sendVerifyByUpdatePayPwd(); ///修改支付密码 @POST("/member/updatePayPwd") Future updatePayPwd(@Body() Map param); ///验证验证码 @POST("/member/verifyByUpdatePayPwd") Future verifyByUpdatePayPwd(@Body() Map param); ///VIP首页 @GET("/vipCard/index") Future> vipCardIndex(); ///VIP订阅/购买 @POST("/vipCard/orderVip") Future> orderVip(@Body() Map param); ///通过code获取设置/助农列表 @GET("/raise/products") Future> getConfig(); ///更换账户手机号码 @POST("/auth/changePhone") Future changePhone(@Body() Map param); ///修改手机号-发送验证码 @GET("/auth/sendVerify/{mobile}") Future changeSendVerify(@Path("mobile") String mobile); ///兑换积分门店列表 @GET("/store/storeListByCreditId/{creditGoodsId}") Future> storeListByCreditId( @Path("creditGoodsId") String creditGoodsId); ///获取APP门店推广渠道 @GET("/ipJson.jsp") Future getIpInfo(); // Future getUrlFile(String url); ///查询订单状态完成的并且可以开发票的订单列表 @POST("order/invoiceOrderList") Future> invoiceOrderList( @Body() Map param); ///新增发票抬头 @POST("invoiceHeader") Future invoiceHeader(@Body() Map param); ///修改发票抬头 @PUT("invoiceHeader") Future invoiceHeaders(@Body() Map param); ///抬头信息列表 @POST("invoiceHeader/page") Future> invoiceHeaderList( @Body() Map param); ///删除抬头信息 @DELETE("invoiceHeader?ids[]={ids}") Future delInvoiceHeader(@Path("ids") String ids); ///提交发票审核 @POST("invoice") Future invoiceSubmit(@Body() Map param); ///开票历史 @POST("invoice/page") Future> invoicePage( @Body() Map param); ///发票详情 @GET("invoice/detail{id}") Future> invoiceDetail(@Path("id") String id); ///消息页批量查询用户信息 @POST("/member/memberInfoByIds") Future> memberInfoByIds( @Body() Map param); ///Im关键字搜索 @GET("/member/memberSearch?keyword={keyword}") Future> memberSearch(@Path("keyword") String keyword); @GET("/config/qiniuToken") Future> getQiniuToken(); }