123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- import { appId, envs } from "./api";
- import { encryption, sign, arrayToJson } from "./encryption";
- import { setItem, getItem, StorageKeys, removeItem } from "../storage";
- import { sm4Key } from "../network/api.js";
- const tools = require("../../static/etcUtil/tools.js");
- import SM4Util from "../util/sm4.js";
- import { agentId, channelId } from "@/utils/network/difference";
- import { updateToken, updateTokenNew } from "@/utils/network/api";
- import orderJump from "@/composables/order/orderJump";
- const { getOrderList } = orderJump();
- import { jump } from "@/datas/9901Jump.js";
- const s4 = new SM4Util();
-
- /* 刷新token */
- function updateGetToken() {
- const options = {
- type: 2,
- data: {
- openId: getItem("openId"),
- accessToken: getItem(StorageKeys.Token),
- },
- method: "POST",
- showLoading: false,
- };
- //刷新token
- return new Promise(async (resolve, reject) => {
- const res = await request(updateToken, options);
- const data = JSON.parse(res.bizContent);
- console.log("data", data);
- setItem("accessToken", data.accessToken);
- setItem(StorageKeys.Token, data.accessToken);
- setItem("openId", data.openId);
- resolve(data);
- }).catch((error) => {
- reject(error);
- });
- }
-
- //请求
- export function request(code, options = {}, start = false) {
- //公参
- const Common = {
- agentId: agentId,
- channelId: channelId,
- channelType: "1",
- staffId: "54623263cb4d4a289dccbc983b22a4af",
- terminalId: "999999999999",
- loginSource: getItem("loginSource"),
- rbacSource: "MINI_PROGRAM",
- accessToken: getItem(StorageKeys.Token),
- openId: getItem(StorageKeys.OpenId),
- opId: getItem(StorageKeys.OpenId),
- };
-
- // options.url = envs[process.env.NODE_ENV].baseUrl + '/api/interfaceMidGroundIn'
- options.url =
- envs[process.env.NODE_ENV].baseUrl + "/ndev/api/interfaceMidGroundIn";
- //默认json数据格式提交`
- let contentType = "application/x-www-form-urlencoded";
-
- //判断baseUri是否为空
- if (options.baseUrl) {
- options.url = options.baseUrl;
- }
- //根据type判断数据传输格式
- if (options.type && options.type === 2) {
- contentType = "application/json;charset=UTF-8";
- }
- //默认POST提交
- options.method = options.method ? options.method : "POST";
-
- //设置请求超时时间
- options.timeout = 60000;
-
- options.header = {
- "content-type": contentType,
- "Access-Token": getItem(StorageKeys.Token),
- };
- if (!start) {
- //判断code不为空
- if (code) {
- options.data = encryption(
- code,
- Object.assign(Common, {
- ...options.data,
- appId: appId,
- }),
- 2
- );
- }
- }
- console.log("code", code, options.data);
- //是否显示加载中
- if (options.showLoading) {
- uni.showLoading({
- title: "请稍后",
- mask: true,
- });
- }
- //参数返回
- return new Promise((resolve, reject) => {
- options.success = (res) => {
- // 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
- if (options.showLoading) {
- uni.hideLoading();
- }
- if (res.data.statusCode !== 0) {
- if (res.data.statusCode == 600) {
- resolve(res.data);
- } else if (res.data.statusCode == 401) {
- uni.showModal({
- title: "提示",
- content: res.data.errorMsg,
- confirmText: "去登录",
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- removeItem(StorageKeys.Token);
- removeItem(StorageKeys.OpenId);
- uni.reLaunch({
- url: "/login/login",
- });
- }
- },
- });
- } else if (
- res.data.statusCode == 99999 &&
- res.data.errorMsg == "客户端登录凭证为空"
- ) {
- console.log("11====", res.data.errorMsg);
- jump("17", "");
- } else if (res.data.statusCode == 99999) {
- if (!start) {
- updateGetToken().then((data) => {
- console.log("token刷新", data);
- request(code, options, true);
- });
- } else {
- uni.showModal({
- title: "提示",
- content: res.data.errorMsg,
- success: function (res) {
- if (res.confirm) {
- console.log("用户点击确定1");
- } else if (res.cancel) {
- console.log("用户点击取消1");
- }
- },
- });
- }
- } else if (res.data.statusCode == 7041) {
- let orderId = res.data.errorMsg;
- uni.showModal({
- title: "提示",
- content: "继续申办",
- // cancelText: '解除车牌', //前往解除车牌占用
- success: function (res) {
- if (res.confirm) {
- console.log("继续申办2", orderId);
- getOrderList(orderId);
- } else if (res.cancel) {
- }
- },
- });
- } else if (res.data.statusCode == 7042) {
- uni.showModal({
- title: "提示",
- content: res.data.errorMsg,
- confirmText: "去激活",
- success: function (res) {
- if (res.confirm) {
- uni.redirectTo({
- url: "/subpackage/personal-center/install-activation-order",
- });
- } else if (res.cancel) {
- }
- },
- });
- } else if (res.data.statusCode == 7043) {
- // 非小程序 非当前用户 提示内容即可
- uni.showModal({
- title: "提示",
- content: res.data.errorMsg,
- success: function (res) {
- if (res.confirm) {
- uni.redirectTo({
- url: "/subpackage/after-sale/onlineService",
- });
- } else if (res.cancel) {
- }
- },
- });
- } else {
- // 当前车辆已存在订单,无法再次创建订单
- if (code == 6 && res.data.statusCode == 704) {
- console.log(code == 6, res.data.statusCode == 704);
- uni.showModal({
- title: "提示",
- content: res.data.errorMsg,
- cancelText: "解除车牌", //前往解除车牌占用
- success: function (res) {
- if (res.confirm) {
- console.log("用户点击确定2");
- } else if (res.cancel) {
- uni.redirectTo({
- url: "/subpackage/after-sale/rescind-carId/rescind-carId-select",
- });
- }
- },
- });
- } else if (
- (code == "abaf0013caa24dafad12b0f571e8ee40" &&
- res.data.statusCode == 704) ||
- (code == "36" && res.data.statusCode == 200)
- ) {
- // 从九州过来的无感登录
- console.log(code == 6, res.data.statusCode == 704);
- uni.showModal({
- title: "提示",
- content: res.data.errorMsg,
- confirmText: "去登录",
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- uni.navigateTo({
- url: `/login/login`,
- });
- }
- },
- });
- } else {
- if (options.showLoading) {
- tools.hideLoadingAlert();
- uni.hideToast();
- }
- console.log("请求失败返回参数", code, res);
- uni.showModal({
- title: "提示",
- content: res.data.errorMsg,
- success: function (res) {
- if (res.confirm) {
- console.log("用户点击确定2");
- } else if (res.cancel) {
- console.log("用户点击取消2");
- }
- },
- });
- }
- }
- reject(res.data.errorMsg);
- return;
- } else {
- console.log("res===", res);
- let content = s4.decryptData_CBC(res, sm4Key);
- console.log("请求成功返回参数:", code, content.data);
- resolve(content.data);
- }
- };
- options.fail = (err) => {
- uni.hideLoading();
- console.log("请求错误", err);
- //处理请求错误
- reject(err);
- };
- uni.getNetworkType({
- success: function (res) {
- if (res.networkType == "none") {
- uni.showModal({
- title: "提示",
- content: "网络异常",
- success: function (res) {
- if (res.confirm) {
- console.log("用户点击确定");
- } else if (res.cancel) {
- console.log("用户点击取消");
- }
- },
- });
- } else {
- uni.request(options);
- }
- console.log("res.networkType", res.networkType);
- },
- });
- });
- }
- /* 刷新token */
- function updateGetTokenNew() {
- const options = {
- type: 2,
- data: {
- openId: getItem("openId"),
- accessToken: getItem(StorageKeys.Token),
- },
- method: "POST",
- showLoading: false,
- };
- //刷新token
- return new Promise(async (resolve, reject) => {
- const res = await requestNew(updateTokenNew, options);
- const data = res;
- console.log("data", data);
- setItem("accessToken", data.accessToken);
- setItem(StorageKeys.Token, data.accessToken);
- setItem("openId", data.openId);
- resolve(data);
- }).catch((error) => {
- reject(error);
- });
- }
- //请求
- export function requestNew(code, options = {}, start = false, clie = () => {}) {
- //公参
- const Common = {
- loginSource: getItem("loginSource"),
- // <<<<<<< HEAD
- // customerId: getItem("customerObj").customerId,
- // accessToken: getItem(StorageKeys.Token)
- // =======
- accessToken: getItem(StorageKeys.Token),
- customerId: getItem('userInfo') ? (getItem('userInfo')['customerId'] || '' ) : "",
- // >>>>>>> 2bd4fd2288160c9b41c882d376c6debd9051e296
- };
- console.log("Common", Common, getItem("customerObj"));
- // options.url = envs[process.env.NODE_ENV].baseUrl+'/prod' + code
- options.url = envs[process.env.NODE_ENV].baseUrl + "/newDev/ndev" + code;
- //默认json数据格式提交`
- let contentType = "application/json";
-
- //判断baseUri是否为空
- if (options.baseUrlNew) {
- options.url = options.baseUrlNew;
- }
- //根据type判断数据传输格式
- if (options.type && options.type === 2) {
- contentType = "application/json;charset=UTF-8";
- }
- //默认POST提交
- options.method = options.method ? options.method : "POST";
-
- //设置请求超时时间
- options.timeout = 60000;
- console.log("getItem(StorageKeys.Token)", getItem(StorageKeys.Token));
- options.header = {
- "content-type": contentType,
- "Access-Token": getItem(StorageKeys.Token),
- };
- if (!start) {
- //判断code不为空
- if (code) {
- options.data = Object.assign(Common, {
- ...options.data,
- });
- }
- }
- console.log("code", code, options.data);
- //是否显示加载中
- if (options.showLoading) {
- uni.showLoading({
- title: "请稍后",
- mask: true,
- });
- }
- //参数返回
- return new Promise((resolve, reject) => {
- options.success = (res) => {
- // 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
- if (options.showLoading) {
- uni.hideLoading();
- }
- console.log(
- "返回结果" + code,
- res,
- res.statusCode,
- res.data.code,
- res.statusCode == 200 && res.data.code == 0
- );
-
- if (res.statusCode == 200 && res.data.code == 0) {
- resolve(res.data.data);
- } else {
- if (res.data.code == 401002) {
- // updateGetTokenNew().then((data) => {
- // console.log("token刷新", data);
- // clie(data)
- // requestNew(code, options, true)
- // })
- if (!getItem("IsLogin") || getItem("IsLogin") == false) {
- setItem("IsLogin", true);
- uni.showModal({
- title: "提示",
- content: "登录失效,请重新登录!",
- confirmText: "去登录",
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- setTimeout(() => {
- setItem("IsLogin", false);
- }, 3000);
-
- uni.navigateTo({
- url: `/login/login`,
- });
- }
- },
- });
- }
- } else if (
- res.data.code == 403001 ||
- res.data.code == 403004 ||
- res.data.code == 403003
- ) {
- // 会详细列出具体字段的错误信息。
- uni.showModal({
- title: "提示",
- content: res.data.message,
- success: function (res) {
- if (res.confirm) {
- console.log("用户点击确定2");
- } else if (res.cancel) {
- console.log("用户点击取消2");
- }
- },
- });
- } else {
- uni.showModal({
- title: "提示",
- content: res.data.message,
- success: function (res) {
- if (res.confirm) {
- console.log("用户点击确定2");
- } else if (res.cancel) {
- console.log("用户点击取消2");
- }
- },
- });
- }
-
- reject(res.data.message);
- return;
- }
- };
- options.fail = (err) => {
- uni.hideLoading();
- console.log("请求错误", err);
- //处理请求错误
- reject(err);
- };
- uni.getNetworkType({
- success: function (res) {
- if (res.networkType == "none") {
- uni.showModal({
- title: "提示",
- content: "网络异常",
- success: function (res) {
- if (res.confirm) {
- console.log("用户点击确定");
- } else if (res.cancel) {
- console.log("用户点击取消");
- }
- },
- });
- } else {
- uni.request(options);
- }
- console.log("res.networkType", res.networkType);
- },
- });
- });
- }
-
- export function corefn(urlcode, subdata, backfn) {
- var requestUrl = "https://zeus.etcjz.cn/api/common/transmit/v1/send/zt";
-
- var requestData = new Array();
- requestData["requestId"] = getDate() + generateMixed(10);
- requestData["accessCode"] = "etc";
- requestData["distinction"] = urlcode;
- requestData["data"] = JSON.stringify(subdata);
- requestData["sign"] = sign(requestData, "etc123456");
- var requestData = arrayToJson(requestData);
- sendPostv2(requestUrl, requestData, function (res) {
- uni.hideLoading();
- backfn(res);
- });
- }
-
- function sendPostv2(url, requestData, callback, contentType = null) {
- console.log("请求入参:", requestData, url);
-
- var type = "";
- if (contentType == "1") {
- type = "application/json";
- } else {
- type = "application/x-www-form-urlencoded";
- }
- wx.request({
- url: url, //请求接口的url
- method: "POST", //请求方式
- data: requestData, //请求参数
- header: {
- "Content-Type": type,
- },
- complete: function (response) {
- //请求结束后隐藏 loading 提示框
- // wx.hideToast();
- },
- success: function (response) {
- if (response.statusCode != "200") {
- callback({
- rc: "99",
- rm: "请求服务器异常_状态" + response.statusCode,
- rd: "",
- });
- return;
- }
- console.log(response.data);
- console.log("返回结果:", response.data);
- callback(response.data);
- },
-
- fail: function (response) {
- //console.log('========发送请求失败_fai',response);
- callback({
- rc: "98",
- rm: "发送请求失败_fail",
- rd: "",
- });
- },
- });
- }
-
- //获取时间ymdHis
- function getDate() {
- var date = new Date();
- return (
- date.getFullYear().toString() +
- pad2(date.getMonth() + 1) +
- pad2(date.getDate()) +
- pad2(date.getHours()) +
- pad2(date.getMinutes()) +
- pad2(date.getSeconds())
- );
- }
-
- function pad2(n) {
- return n < 10 ? "0" + n : n;
- }
- /**
- * 获取随机数
- */
- function generateMixed(n) {
- var chars = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
- var res = "";
- for (var i = 0; i < n; i++) {
- var id = Math.ceil(Math.random() * 8);
- res += chars[id];
- }
- return res;
- }
|