248 lines
9.5 KiB
Java
248 lines
9.5 KiB
Java
package com.arpa.hndahesudintocctmsdriver.request;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.PackageManager;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.os.Handler;
|
|
import android.provider.Settings;
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
import com.arpa.hndahesudintocctmsdriver.bean.AppInfoBean;
|
|
import com.arpa.hndahesudintocctmsdriver.event.VehicleEvent;
|
|
import com.arpa.hndahesudintocctmsdriver.ui.auth.CertificatesActivity;
|
|
import com.arpa.hndahesudintocctmsdriver.ui.business.Md5Util;
|
|
import com.google.gson.Gson;
|
|
import com.arpa.hndahesudintocctmsdriver.request.bean.LoginRegInputBean;
|
|
import com.arpa.hndahesudintocctmsdriver.ui.home.OrderAllActivity;
|
|
import com.arpa.hndahesudintocctmsdriver.ui.login.LoginActivity;
|
|
import com.arpa.hndahesudintocctmsdriver.ui.auth.VehicleAuthActivity;
|
|
import com.arpa.hndahesudintocctmsdriver.ui.my.WoDeFragment;
|
|
import com.arpa.hndahesudintocctmsdriver.util.map.MapUtil;
|
|
import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
|
|
import com.arpa.hndahesudintocctmsdriver.util.http.OkDate;
|
|
import com.arpa.hndahesudintocctmsdriver.util.http.OkHttpUtil;
|
|
import com.arpa.hndahesudintocctmsdriver.util.http.RequestUtil;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import okhttp3.Request;
|
|
|
|
public class UserRequset {
|
|
|
|
private Context con;
|
|
private Handler hd;
|
|
|
|
public UserRequset(Context con, Handler hd) {
|
|
this.con = con;
|
|
this.hd = hd;
|
|
}
|
|
|
|
private Gson gson = new Gson();
|
|
|
|
public String getToken(Context con) {
|
|
return SPUtil.getSP(con, LoginActivity.USER, LoginActivity.USER_TOKEN);
|
|
}
|
|
|
|
//获取全部代码表
|
|
public void getCodeData() {
|
|
Request re = OkHttpUtil.post(new OkDate(RequestConstant.getSendCodeUrl(), ""), con);
|
|
RequestUtil.start(1, "未知", re, con, hd);
|
|
}
|
|
|
|
//获取手机验证码
|
|
public void getPhoneCode(String phone) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("phone", phone);
|
|
map.put("sendType", 1);
|
|
Request re = OkHttpUtil.post(new OkDate(RequestConstant.getSendCodeUrl(), MapUtil.mapJson(map)), con);
|
|
RequestUtil.start(1, LoginActivity.CODE_RESULT, re, con, hd);
|
|
}
|
|
|
|
//账户注册
|
|
public void UserReg() {
|
|
Request re = OkHttpUtil.post(new OkDate(RequestConstant.getREGUrl(), ""), con);
|
|
RequestUtil.start(1, "", re, con, hd);
|
|
}
|
|
|
|
//账户登录
|
|
public void UserLogin(LoginRegInputBean lrib) {
|
|
Request re = OkHttpUtil.post(new OkDate(RequestConstant.getLoginUrl(), gson.toJson(lrib)), con);
|
|
RequestUtil.start(1, LoginActivity.LOGIN_RESULT, re, con, hd);
|
|
}
|
|
|
|
//账户信息
|
|
public void User() {
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getUserUrl(), ""), getToken(con), con);
|
|
RequestUtil.start(1, "userdata", re, con, hd);
|
|
}
|
|
|
|
//司机认证信息
|
|
public void driverAuthData() {
|
|
String mt = "{}";
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getDriverAuthInfoUrl(), mt), getToken(con), con);
|
|
RequestUtil.start(1, WoDeFragment.AUTH_DATA, re, con, hd);
|
|
}
|
|
|
|
//车辆列表
|
|
public void vehicleList(String type) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("type", type);
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getGetCarList(), MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, WoDeFragment.VEHICLE_LIST, re, con, hd);
|
|
}
|
|
|
|
//删除车辆
|
|
public void delVehicle(String id) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("carId", id);
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getDelCar(), MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, VehicleAuthActivity.DEL_CAR, re, con, hd);
|
|
}
|
|
|
|
//解绑车辆
|
|
public void relieveVehicle(String id) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("carId", id);
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getGetCarDel(), MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, WoDeFragment.VEHICLE_DEL, re, con, hd);
|
|
}
|
|
|
|
//车辆详情
|
|
public void vehicleDel(String id) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("carId", id);
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getGetCarDel(), MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, WoDeFragment.VEHICLE_DEL, re, con, hd);
|
|
}
|
|
|
|
//车辆详情
|
|
public void vehicleDelTwo(String id) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("carId", id);
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getGetCarDel(), MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, "onlyGetDetail", re, con, hd);
|
|
}
|
|
|
|
//司机身份证认证
|
|
public void driverIDAuth() {
|
|
String url = RequestConstant.BASE_URL + "/app/driver/auth/authInfo";
|
|
String mt = "";
|
|
Request re = OkHttpUtil.posts(new OkDate(url, mt), getToken(con), con);
|
|
RequestUtil.start(1, "", re, con, hd);
|
|
}
|
|
|
|
//司机运单列表
|
|
public void getListV2(int page, int limit) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("page", page);
|
|
map.put("limit", limit);
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getOrderList(), MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, OrderAllActivity.USER_ORDER_LIST, re, con, hd);
|
|
}
|
|
|
|
//app更新
|
|
public void upApp() {
|
|
String vs = "1.0.0";
|
|
try {
|
|
// isOpenAppNoRe();
|
|
vs = con.getPackageManager().getPackageInfo(con.getPackageName(), 0).versionName;
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
e.printStackTrace();
|
|
}
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("source", 0);
|
|
map.put("version", vs);
|
|
Request re = OkHttpUtil.post(new OkDate(RequestConstant.getVERSION(), MapUtil.mapJson(map)), con);
|
|
RequestUtil.start(1, "up_app", re, con, hd);
|
|
}
|
|
|
|
/**
|
|
* 判断是否开启未知应用安装权限
|
|
*/
|
|
private void isOpenAppNoRe() {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
boolean b = con.getPackageManager().canRequestPackageInstalls();
|
|
if (!b) {
|
|
startInstallPermissionSettingActivity();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 跳转到设置-允许安装未知来源-页面
|
|
*/
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
private void startInstallPermissionSettingActivity() {
|
|
//注意这个是8.0新API
|
|
Uri packageURI = Uri.parse("package:" + con.getPackageName());
|
|
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
con.startActivity(intent);
|
|
}
|
|
|
|
//党员认证
|
|
public void partyMember(String url) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("partyMemberUrl", url);
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getPartyMember(), MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, "partyMember", re, con, hd);
|
|
}
|
|
|
|
public void getImage(int type) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("type", type);
|
|
Request re;
|
|
if (getToken(con).equals("")) {
|
|
re = OkHttpUtil.post(new OkDate(RequestConstant.getGetImage(), MapUtil.mapJson(map)), con);
|
|
} else {
|
|
re = OkHttpUtil.posts(new OkDate(RequestConstant.getGetImage(), MapUtil.mapJson(map)), getToken(con), con);
|
|
}
|
|
RequestUtil.start(1, "getImage", re, con, hd);
|
|
}
|
|
|
|
//app/driver/auth/driverExpire
|
|
public void getDriverExpire() {
|
|
Request re = OkHttpUtil.posts(new OkDate(RequestConstant.getGetCertificateExpired(), ""), getToken(con), con);
|
|
RequestUtil.start(1, "driverExpire", re, con, hd);
|
|
}
|
|
|
|
|
|
public void getJtt(int id) {
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
map.put("waybillId", id);
|
|
Request re = OkHttpUtil.posts(new OkDate("http://app.dahehuoyun.com/api/traffic/getTrafficConfigByWaybillId", MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, "jttRes", re, con, hd);
|
|
}
|
|
|
|
public void getJtts(String id) {
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
map.put("waybillNum", id);
|
|
Request re = OkHttpUtil.posts(new OkDate("http://app.dahehuoyun.com/api/traffic/getTrafficConfigByWaybillNum", MapUtil.mapJson(map)), getToken(con), con);
|
|
RequestUtil.start(1, "jttRes", re, con, hd);
|
|
|
|
}
|
|
|
|
//获取燃油类型
|
|
public void carAudit(String carId) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("carId", carId);
|
|
Request re = OkHttpUtil.get(new OkDate(RequestConstant.getCarAudit(), "get", Md5Util.resNoUrl(map)), getToken(con));
|
|
RequestUtil.start(1, VehicleAuthActivity.CAR_AUDIO, re, con, hd);
|
|
}
|
|
|
|
public void postAppInfo(AppInfoBean appInfoBean, String type) {
|
|
// Request re = OkHttpUtil.get(new OkDate(RequestConstant.getCarAudit(),"get", gson.toJson(appInfoBean)),getToken(con));
|
|
Request re;
|
|
if ("put".equals(type)) {
|
|
re = OkHttpUtil.put(new OkDate(RequestConstant.postAppInfo(), type, gson.toJson(appInfoBean)), con);
|
|
} else {
|
|
re = OkHttpUtil.post(new OkDate(RequestConstant.postAppInfo(), type, gson.toJson(appInfoBean)), con);
|
|
}
|
|
RequestUtil.start(1, VehicleAuthActivity.APP_INFO, re, con, hd);
|
|
}
|
|
}
|