星油企业版
This commit is contained in:
662
utils/amap-wx.130.js
Normal file
662
utils/amap-wx.130.js
Normal file
@@ -0,0 +1,662 @@
|
||||
function AMapWX(a) {
|
||||
this.key = a.key;
|
||||
this.requestConfig = {
|
||||
key: a.key,
|
||||
s: "rsx",
|
||||
platform: "WXJS",
|
||||
appname: a.key,
|
||||
sdkversion: "1.2.0",
|
||||
logversion: "2.0"
|
||||
};
|
||||
this.MeRequestConfig = {
|
||||
key: a.key,
|
||||
serviceName: "https://restapi.amap.com/rest/me"
|
||||
}
|
||||
}
|
||||
AMapWX.prototype.getWxLocation = function(a, b) {
|
||||
wx.getLocation({
|
||||
type: "gcj02",
|
||||
success: function(c) {
|
||||
c = c.longitude + "," + c.latitude;
|
||||
wx.setStorage({
|
||||
key: "userLocation",
|
||||
data: c
|
||||
});
|
||||
b(c)
|
||||
},
|
||||
fail: function(c) {
|
||||
wx.getStorage({
|
||||
key: "userLocation",
|
||||
success: function(d) {
|
||||
d.data && b(d.data)
|
||||
}
|
||||
});
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: c.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getMEKeywordsSearch = function(a) {
|
||||
if (!a.options) return a.fail({
|
||||
errCode: "0",
|
||||
errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"
|
||||
});
|
||||
var b = a.options,
|
||||
c = this.MeRequestConfig,
|
||||
d = {
|
||||
key: c.key,
|
||||
s: "rsx",
|
||||
platform: "WXJS",
|
||||
appname: a.key,
|
||||
sdkversion: "1.2.0",
|
||||
logversion: "2.0"
|
||||
};
|
||||
b.layerId && (d.layerId = b.layerId);
|
||||
b.keywords && (d.keywords = b.keywords);
|
||||
b.city && (d.city = b.city);
|
||||
b.filter && (d.filter = b.filter);
|
||||
b.sortrule && (d.sortrule = b.sortrule);
|
||||
b.pageNum && (d.pageNum = b.pageNum);
|
||||
b.pageSize && (d.pageSize = b.pageSize);
|
||||
b.sig && (d.sig =
|
||||
b.sig);
|
||||
wx.request({
|
||||
url: c.serviceName + "/cpoint/datasearch/local",
|
||||
data: d,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(e) {
|
||||
(e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
|
||||
errCode: "0",
|
||||
errMsg: e
|
||||
})
|
||||
},
|
||||
fail: function(e) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: e.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getMEIdSearch = function(a) {
|
||||
if (!a.options) return a.fail({
|
||||
errCode: "0",
|
||||
errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"
|
||||
});
|
||||
var b = a.options,
|
||||
c = this.MeRequestConfig,
|
||||
d = {
|
||||
key: c.key,
|
||||
s: "rsx",
|
||||
platform: "WXJS",
|
||||
appname: a.key,
|
||||
sdkversion: "1.2.0",
|
||||
logversion: "2.0"
|
||||
};
|
||||
b.layerId && (d.layerId = b.layerId);
|
||||
b.id && (d.id = b.id);
|
||||
b.sig && (d.sig = b.sig);
|
||||
wx.request({
|
||||
url: c.serviceName + "/cpoint/datasearch/id",
|
||||
data: d,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(e) {
|
||||
(e = e.data) && e.status && "1" === e.status &&
|
||||
0 === e.code ? a.success(e.data) : a.fail({
|
||||
errCode: "0",
|
||||
errMsg: e
|
||||
})
|
||||
},
|
||||
fail: function(e) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: e.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getMEPolygonSearch = function(a) {
|
||||
if (!a.options) return a.fail({
|
||||
errCode: "0",
|
||||
errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"
|
||||
});
|
||||
var b = a.options,
|
||||
c = this.MeRequestConfig,
|
||||
d = {
|
||||
key: c.key,
|
||||
s: "rsx",
|
||||
platform: "WXJS",
|
||||
appname: a.key,
|
||||
sdkversion: "1.2.0",
|
||||
logversion: "2.0"
|
||||
};
|
||||
b.layerId && (d.layerId = b.layerId);
|
||||
b.keywords && (d.keywords = b.keywords);
|
||||
b.polygon && (d.polygon = b.polygon);
|
||||
b.filter && (d.filter = b.filter);
|
||||
b.sortrule && (d.sortrule = b.sortrule);
|
||||
b.pageNum && (d.pageNum = b.pageNum);
|
||||
b.pageSize && (d.pageSize = b.pageSize);
|
||||
b.sig && (d.sig = b.sig);
|
||||
wx.request({
|
||||
url: c.serviceName + "/cpoint/datasearch/polygon",
|
||||
data: d,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(e) {
|
||||
(e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
|
||||
errCode: "0",
|
||||
errMsg: e
|
||||
})
|
||||
},
|
||||
fail: function(e) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: e.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getMEaroundSearch = function(a) {
|
||||
if (!a.options) return a.fail({
|
||||
errCode: "0",
|
||||
errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"
|
||||
});
|
||||
var b = a.options,
|
||||
c = this.MeRequestConfig,
|
||||
d = {
|
||||
key: c.key,
|
||||
s: "rsx",
|
||||
platform: "WXJS",
|
||||
appname: a.key,
|
||||
sdkversion: "1.2.0",
|
||||
logversion: "2.0"
|
||||
};
|
||||
b.layerId && (d.layerId = b.layerId);
|
||||
b.keywords && (d.keywords = b.keywords);
|
||||
b.center && (d.center = b.center);
|
||||
b.radius && (d.radius = b.radius);
|
||||
b.filter && (d.filter = b.filter);
|
||||
b.sortrule && (d.sortrule = b.sortrule);
|
||||
b.pageNum && (d.pageNum = b.pageNum);
|
||||
b.pageSize &&
|
||||
(d.pageSize = b.pageSize);
|
||||
b.sig && (d.sig = b.sig);
|
||||
wx.request({
|
||||
url: c.serviceName + "/cpoint/datasearch/around",
|
||||
data: d,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(e) {
|
||||
(e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
|
||||
errCode: "0",
|
||||
errMsg: e
|
||||
})
|
||||
},
|
||||
fail: function(e) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: e.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getGeo = function(a) {
|
||||
var b = this.requestConfig,
|
||||
c = a.options;
|
||||
b = {
|
||||
key: this.key,
|
||||
extensions: "all",
|
||||
s: b.s,
|
||||
platform: b.platform,
|
||||
appname: this.key,
|
||||
sdkversion: b.sdkversion,
|
||||
logversion: b.logversion
|
||||
};
|
||||
c.address && (b.address = c.address);
|
||||
c.city && (b.city = c.city);
|
||||
c.batch && (b.batch = c.batch);
|
||||
c.sig && (b.sig = c.sig);
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/geocode/geo",
|
||||
data: b,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(d) {
|
||||
(d = d.data) && d.status && "1" === d.status ? a.success(d) : a.fail({
|
||||
errCode: "0",
|
||||
errMsg: d
|
||||
})
|
||||
},
|
||||
fail: function(d) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: d.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getRegeo = function(a) {
|
||||
function b(d) {
|
||||
var e = c.requestConfig;
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/geocode/regeo",
|
||||
data: {
|
||||
key: c.key,
|
||||
location: d,
|
||||
extensions: "all",
|
||||
s: e.s,
|
||||
platform: e.platform,
|
||||
appname: c.key,
|
||||
sdkversion: e.sdkversion,
|
||||
logversion: e.logversion
|
||||
},
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(g) {
|
||||
if (g.data.status && "1" == g.data.status) {
|
||||
g = g.data.regeocode;
|
||||
var h = g.addressComponent,
|
||||
f = [],
|
||||
k = g.roads[0].name + "\u9644\u8fd1",
|
||||
m = d.split(",")[0],
|
||||
n = d.split(",")[1];
|
||||
if (g.pois &&
|
||||
g.pois[0]) {
|
||||
k = g.pois[0].name + "\u9644\u8fd1";
|
||||
var l = g.pois[0].location;
|
||||
l && (m = parseFloat(l.split(",")[0]), n = parseFloat(l.split(",")[1]))
|
||||
}
|
||||
h.provice && f.push(h.provice);
|
||||
h.city && f.push(h.city);
|
||||
h.district && f.push(h.district);
|
||||
h.streetNumber && h.streetNumber.street && h.streetNumber.number ? (f.push(h
|
||||
.streetNumber.street), f.push(h.streetNumber.number)) : f.push(g.roads[0]
|
||||
.name);
|
||||
f = f.join("");
|
||||
a.success([{
|
||||
iconPath: a.iconPath,
|
||||
width: a.iconWidth,
|
||||
height: a.iconHeight,
|
||||
name: f,
|
||||
desc: k,
|
||||
longitude: m,
|
||||
latitude: n,
|
||||
id: 0,
|
||||
regeocodeData: g
|
||||
}])
|
||||
} else a.fail({
|
||||
errCode: g.data.infocode,
|
||||
errMsg: g.data.info
|
||||
})
|
||||
},
|
||||
fail: function(g) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: g.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
var c = this;
|
||||
a.location ? b(a.location) : c.getWxLocation(a, function(d) {
|
||||
b(d)
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getWeather = function(a) {
|
||||
function b(g) {
|
||||
var h = "base";
|
||||
a.type && "forecast" == a.type && (h = "all");
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/weather/weatherInfo",
|
||||
data: {
|
||||
key: d.key,
|
||||
city: g,
|
||||
extensions: h,
|
||||
s: e.s,
|
||||
platform: e.platform,
|
||||
appname: d.key,
|
||||
sdkversion: e.sdkversion,
|
||||
logversion: e.logversion
|
||||
},
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(f) {
|
||||
if (f.data.status && "1" == f.data.status)
|
||||
if (f.data.lives) {
|
||||
if ((f = f.data.lives) && 0 < f.length) {
|
||||
f = f[0];
|
||||
var k = {
|
||||
city: {
|
||||
text: "\u57ce\u5e02",
|
||||
data: f.city
|
||||
},
|
||||
weather: {
|
||||
text: "\u5929\u6c14",
|
||||
data: f.weather
|
||||
},
|
||||
temperature: {
|
||||
text: "\u6e29\u5ea6",
|
||||
data: f.temperature
|
||||
},
|
||||
winddirection: {
|
||||
text: "\u98ce\u5411",
|
||||
data: f.winddirection + "\u98ce"
|
||||
},
|
||||
windpower: {
|
||||
text: "\u98ce\u529b",
|
||||
data: f.windpower + "\u7ea7"
|
||||
},
|
||||
humidity: {
|
||||
text: "\u6e7f\u5ea6",
|
||||
data: f.humidity + "%"
|
||||
}
|
||||
};
|
||||
k.liveData = f;
|
||||
a.success(k)
|
||||
}
|
||||
} else f.data.forecasts && f.data.forecasts[0] && a.success({
|
||||
forecast: f.data.forecasts[0]
|
||||
});
|
||||
else a.fail({
|
||||
errCode: f.data.infocode,
|
||||
errMsg: f.data.info
|
||||
})
|
||||
},
|
||||
fail: function(f) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: f.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function c(g) {
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/geocode/regeo",
|
||||
data: {
|
||||
key: d.key,
|
||||
location: g,
|
||||
extensions: "all",
|
||||
s: e.s,
|
||||
platform: e.platform,
|
||||
appname: d.key,
|
||||
sdkversion: e.sdkversion,
|
||||
logversion: e.logversion
|
||||
},
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(h) {
|
||||
if (h.data.status && "1" == h.data.status) {
|
||||
h = h.data.regeocode;
|
||||
if (h.addressComponent) var f = h.addressComponent.adcode;
|
||||
else h.aois && 0 < h.aois.length && (f = h.aois[0].adcode);
|
||||
b(f)
|
||||
} else a.fail({
|
||||
errCode: h.data.infocode,
|
||||
errMsg: h.data.info
|
||||
})
|
||||
},
|
||||
fail: function(h) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: h.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
var d = this,
|
||||
e = d.requestConfig;
|
||||
a.city ? b(a.city) : d.getWxLocation(a, function(g) {
|
||||
c(g)
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getPoiAround = function(a) {
|
||||
function b(e) {
|
||||
e = {
|
||||
key: c.key,
|
||||
location: e,
|
||||
s: d.s,
|
||||
platform: d.platform,
|
||||
appname: c.key,
|
||||
sdkversion: d.sdkversion,
|
||||
logversion: d.logversion
|
||||
};
|
||||
a.querytypes && (e.types = a.querytypes);
|
||||
a.querykeywords && (e.keywords = a.querykeywords);
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/place/around",
|
||||
data: e,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(g) {
|
||||
if (g.data.status && "1" == g.data.status) {
|
||||
if ((g = g.data) && g.pois) {
|
||||
for (var h = [], f = 0; f < g.pois.length; f++) {
|
||||
var k = 0 ==
|
||||
f ? a.iconPathSelected : a.iconPath;
|
||||
h.push({
|
||||
latitude: parseFloat(g.pois[f].location.split(",")[1]),
|
||||
longitude: parseFloat(g.pois[f].location.split(",")[0]),
|
||||
iconPath: k,
|
||||
width: 22,
|
||||
height: 32,
|
||||
id: f,
|
||||
name: g.pois[f].name,
|
||||
address: g.pois[f].address
|
||||
})
|
||||
}
|
||||
a.success({
|
||||
markers: h,
|
||||
poisData: g.pois
|
||||
})
|
||||
}
|
||||
} else a.fail({
|
||||
errCode: g.data.infocode,
|
||||
errMsg: g.data.info
|
||||
})
|
||||
},
|
||||
fail: function(g) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: g.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
var c = this,
|
||||
d = c.requestConfig;
|
||||
a.location ? b(a.location) : c.getWxLocation(a, function(e) {
|
||||
b(e)
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getStaticmap = function(a) {
|
||||
function b(e) {
|
||||
c.push("location=" + e);
|
||||
a.zoom && c.push("zoom=" + a.zoom);
|
||||
a.size && c.push("size=" + a.size);
|
||||
a.scale && c.push("scale=" + a.scale);
|
||||
a.markers && c.push("markers=" + a.markers);
|
||||
a.labels && c.push("labels=" + a.labels);
|
||||
a.paths && c.push("paths=" + a.paths);
|
||||
a.traffic && c.push("traffic=" + a.traffic);
|
||||
e = "https://restapi.amap.com/v3/staticmap?" + c.join("&");
|
||||
a.success({
|
||||
url: e
|
||||
})
|
||||
}
|
||||
var c = [];
|
||||
c.push("key=" + this.key);
|
||||
var d = this.requestConfig;
|
||||
c.push("s=" + d.s);
|
||||
c.push("platform=" + d.platform);
|
||||
c.push("appname=" + d.appname);
|
||||
c.push("sdkversion=" + d.sdkversion);
|
||||
c.push("logversion=" + d.logversion);
|
||||
a.location ? b(a.location) : this.getWxLocation(a, function(e) {
|
||||
b(e)
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getInputtips = function(a) {
|
||||
var b = Object.assign({}, this.requestConfig);
|
||||
a.location && (b.location = a.location);
|
||||
a.keywords && (b.keywords = a.keywords);
|
||||
a.type && (b.type = a.type);
|
||||
a.city && (b.city = a.city);
|
||||
a.citylimit && (b.citylimit = a.citylimit);
|
||||
if(a.page && a.offset){
|
||||
b.page=a.page;
|
||||
b.offset=a.offset ;
|
||||
}
|
||||
wx.request({
|
||||
url: a.page?"https://restapi.amap.com/v3/place/text?parameters":"https://restapi.amap.com/v3/assistant/inputtips",
|
||||
data:b,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(c) {
|
||||
c && c.data && c.data.tips && a.success({
|
||||
tips: c.data.tips
|
||||
})
|
||||
},
|
||||
fail: function(c) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: c.errMsg ||
|
||||
""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getDrivingRoute = function(a) {
|
||||
var b = Object.assign({}, this.requestConfig);
|
||||
a.origin && (b.origin = a.origin);
|
||||
a.destination && (b.destination = a.destination);
|
||||
a.strategy && (b.strategy = a.strategy);
|
||||
a.waypoints && (b.waypoints = a.waypoints);
|
||||
a.avoidpolygons && (b.avoidpolygons = a.avoidpolygons);
|
||||
a.avoidroad && (b.avoidroad = a.avoidroad);
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/direction/driving",
|
||||
data: b,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(c) {
|
||||
c && c.data && c.data.route && a.success({
|
||||
paths: c.data.route.paths,
|
||||
taxi_cost: c.data.route.taxi_cost || ""
|
||||
})
|
||||
},
|
||||
fail: function(c) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: c.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getWalkingRoute = function(a) {
|
||||
var b = Object.assign({}, this.requestConfig);
|
||||
a.origin && (b.origin = a.origin);
|
||||
a.destination && (b.destination = a.destination);
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/direction/walking",
|
||||
data: b,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(c) {
|
||||
c && c.data && c.data.route && a.success({
|
||||
paths: c.data.route.paths
|
||||
})
|
||||
},
|
||||
fail: function(c) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: c.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getTransitRoute = function(a) {
|
||||
var b = Object.assign({}, this.requestConfig);
|
||||
a.origin && (b.origin = a.origin);
|
||||
a.destination && (b.destination = a.destination);
|
||||
a.strategy && (b.strategy = a.strategy);
|
||||
a.city && (b.city = a.city);
|
||||
a.cityd && (b.cityd = a.cityd);
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/direction/transit/integrated",
|
||||
data: b,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(c) {
|
||||
c && c.data && c.data.route && (c = c.data.route, a.success({
|
||||
distance: c.distance || "",
|
||||
taxi_cost: c.taxi_cost ||
|
||||
"",
|
||||
transits: c.transits
|
||||
}))
|
||||
},
|
||||
fail: function(c) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: c.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
AMapWX.prototype.getRidingRoute = function(a) {
|
||||
var b = Object.assign({}, this.requestConfig);
|
||||
a.origin && (b.origin = a.origin);
|
||||
a.destination && (b.destination = a.destination);
|
||||
wx.request({
|
||||
url: "https://restapi.amap.com/v3/direction/riding",
|
||||
data: b,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
success: function(c) {
|
||||
c && c.data && c.data.route && a.success({
|
||||
paths: c.data.route.paths
|
||||
})
|
||||
},
|
||||
fail: function(c) {
|
||||
a.fail({
|
||||
errCode: "0",
|
||||
errMsg: c.errMsg || ""
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
module.exports.AMapWX = AMapWX;
|
||||
54
utils/encode.js
Normal file
54
utils/encode.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
import md5 from 'js-md5'
|
||||
|
||||
// import { JSEncrypt } from 'jsencrypt'
|
||||
var keyStr = 'qDfajQ*v@W1mCruZ'
|
||||
|
||||
export default {
|
||||
/**
|
||||
* @param {*需要加密的字符串 注:对象转化为json字符串再加密} word
|
||||
* @param {*aes加密需要的key值,这个key值后端同学会告诉你} keyStr
|
||||
*/
|
||||
encrypt(word) { // 加密
|
||||
var key = CryptoJS.enc.Utf8.parse(keyStr)
|
||||
var srcs = CryptoJS.enc.Utf8.parse(word)
|
||||
var encrypted = CryptoJS.AES.encrypt(srcs, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}) // 加密模式为ECB,补码方式为PKCS5Padding(也就是PKCS7)
|
||||
return encrypted.toString()
|
||||
},
|
||||
decrypt(word) { // 解密
|
||||
var key = CryptoJS.enc.Utf8.parse(keyStr)
|
||||
// var srcs = CryptoJS.enc.Utf8.parse(word)
|
||||
if (word) {
|
||||
word = word.replace(/[\r\n]/g, "")
|
||||
}
|
||||
var decrypt = CryptoJS.AES.decrypt(word, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
})
|
||||
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
|
||||
},
|
||||
|
||||
md5Salt(str) {
|
||||
return md5(str + 'kdq*&qflbn1gga?aDq')
|
||||
},
|
||||
md5NoSalt(str) {
|
||||
return md5(str)
|
||||
},
|
||||
uuid() { // 获取uuid
|
||||
var s = []
|
||||
var hexDigits = '0123456789abcdef'
|
||||
for (var i = 0; i < 36; i++) {
|
||||
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
|
||||
}
|
||||
s[14] = '4'
|
||||
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1)
|
||||
s[8] = s[13] = s[18] = s[23] = '-'
|
||||
|
||||
var uuid = s.join('')
|
||||
return uuid
|
||||
}
|
||||
|
||||
}
|
||||
1122
utils/qqmap-wx-jssdk.js
Normal file
1122
utils/qqmap-wx-jssdk.js
Normal file
File diff suppressed because it is too large
Load Diff
173
utils/request.js
Normal file
173
utils/request.js
Normal file
@@ -0,0 +1,173 @@
|
||||
import axios from 'axios'
|
||||
import utils from '@/utils/encode'
|
||||
// const env = process.env.NODE_ENV
|
||||
// const env = 'production'/* */
|
||||
const env = 'test'
|
||||
// const env = 'production'
|
||||
// 45
|
||||
const testUrl = 'http://192.168.0.46:38080'
|
||||
const productUrl = 'https://www.xingoil.com/adminapi'
|
||||
|
||||
// const productUrl = 'http://uat.xingoil.com/adminapi'
|
||||
// const productUrl = 'http://192.168.0.191:38080'
|
||||
// const productUrl = 'http://121.196.213.68/adminapi'
|
||||
const service = axios.create({
|
||||
baseURL: env == 'production' ? productUrl : testUrl,
|
||||
// baseURL: testUrl,
|
||||
timeout: 5000
|
||||
})
|
||||
|
||||
var url = ''
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
// 拦截请求
|
||||
uni.showLoading({
|
||||
title: '加载中...',
|
||||
mask:true
|
||||
})
|
||||
const token = uni.getStorageSync('Authorization')
|
||||
const unionId = uni.getStorageSync('unionid')
|
||||
const openId = uni.getStorageSync('openid')
|
||||
// const accountSources = 'WE_CHAT_PROGRAM'
|
||||
const accountSources = 'LOGIN_MP_WECHAT'
|
||||
// console.log('取出来缓存', token, openid)
|
||||
config.headers['openId'] = openId
|
||||
config.headers['Authorization'] = token
|
||||
config.headers['accountSources'] = accountSources
|
||||
config.headers['imei'] = unionId
|
||||
config.headers['dataSources'] = 'MP'
|
||||
|
||||
if (env === 'production') {
|
||||
console.log("这里是生产")
|
||||
// 生产环境,加密,不输出任何东西
|
||||
// 设置jsessionid和token
|
||||
const JSESSIONID = utils.uuid()
|
||||
config.headers['JSESSIONID'] = JSESSIONID
|
||||
config.headers['token'] = utils.md5Salt(JSESSIONID)
|
||||
// if ( encryptWhite.indexOf(config.url) < 0) {
|
||||
// if (!notEncrypt && encryptWhite.indexOf(config.url) < 0) {
|
||||
// 这是定义在哪的
|
||||
const data = { // 用于存储加密
|
||||
params: '' // 加密后的密文
|
||||
}
|
||||
// 要加密
|
||||
data.params = utils.encrypt(JSON.stringify(config.data))
|
||||
console.log('参数', config.url, '参数加密前',config.data,'加密:',data)
|
||||
config.data = data
|
||||
// }
|
||||
} else {
|
||||
console.log("这里是测试")
|
||||
console.log('\n\n-----------------------')
|
||||
console.log('参数', config.url, '参数加密前', config.data)
|
||||
url = config.url
|
||||
}
|
||||
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '网络超时',
|
||||
icon: "none"
|
||||
})
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
if (env === 'production') {
|
||||
// 生产环境,进行加密解密,不输出日志
|
||||
if (res.encrypt == 1) {
|
||||
// 加密的数据,需要解密
|
||||
const dataParam = JSON.parse(utils.decrypt(res.data))
|
||||
res.data = JSON.stringify(dataParam) === '{}' ? null : dataParam
|
||||
console.log(res.data)
|
||||
// console.log('返回', response.config.url, '返回结果',res)
|
||||
}
|
||||
} else {
|
||||
console.log('返回', response.config.url, '返回结果未加密', res)
|
||||
// console.log('-------------------------------------------\n\n')
|
||||
}
|
||||
|
||||
uni.hideLoading()
|
||||
if(response.config.url.indexOf('/oil-site/oilSiteOrderInfo/getOrderQrCode') === -1){
|
||||
if(response.config.url.indexOf('/oil-site/oilSiteAppInfo/getSiteDetails') != -1){
|
||||
console.log('这里是getSiteDetails 拦截处')
|
||||
// if (res.code != 20000&&res.msg!='令牌为空,不允许操作'&&res.msg!='您的ip已经更改,请重新登录'&&res.msg!='登录与操作设备不同') {
|
||||
// uni.showToast({
|
||||
// title: res.msg,
|
||||
// icon: "none"
|
||||
// })
|
||||
// }
|
||||
}else{
|
||||
if (res.code != 20000&&res.msg!='令牌为空,不允许操作'&&res.msg!='您的ip已经更改,请重新登录'&&res.msg!='登录与操作设备不同') {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: "none"
|
||||
});
|
||||
if(response.config.url.indexOf('/oil-user/oilCompanyInfo/getQrCodeType') != -1){
|
||||
setTimeout(()=>{
|
||||
uni.redirectTo({
|
||||
url: '/BagAuth/pages/login/login'
|
||||
})
|
||||
},2000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
},
|
||||
error => {
|
||||
uni.hideLoading()
|
||||
uni.getNetworkType({
|
||||
success: function(res) {
|
||||
console.log(res.networkType);
|
||||
if (res.networkType === 'none') {
|
||||
uni.showToast({
|
||||
title: '没有网啦!',
|
||||
icon: "none"
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '请求失败!',
|
||||
icon: "none"
|
||||
})
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// #ifndef H5
|
||||
service.defaults.adapter = function(config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var settle = require('axios/lib/core/settle');
|
||||
var buildURL = require('axios/lib/helpers/buildURL');
|
||||
uni.request({
|
||||
method: config.method.toUpperCase(),
|
||||
url: config.baseURL + buildURL(config.url, config.params, config.paramsSerializer),
|
||||
header: config.headers,
|
||||
data: config.data,
|
||||
dataType: config.dataType,
|
||||
responseType: config.responseType,
|
||||
sslVerify: config.sslVerify,
|
||||
complete: function complete(response) {
|
||||
response = {
|
||||
data: response.data,
|
||||
status: response.statusCode,
|
||||
errMsg: response.errMsg,
|
||||
header: response.header,
|
||||
config: config
|
||||
};
|
||||
settle(resolve, reject, response);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
|
||||
export default service
|
||||
74
utils/tools.js
Normal file
74
utils/tools.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import oilIdentityApi from '@/api/oil-identity'
|
||||
export default {
|
||||
async WXlogin(e) {
|
||||
return new Promise((re, rj) => {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: async (loginRes) => {
|
||||
const code = loginRes.code
|
||||
oilIdentityApi.sendCode(loginRes.code).then(res => {
|
||||
if (res.code === 20000) {
|
||||
uni.setStorageSync('sessionKey', res.data.sessionKey);
|
||||
uni.setStorageSync('openid', res.data.openId);
|
||||
uni.setStorageSync('unionid', res.data.unionId);
|
||||
const data1 = {
|
||||
...e.detail,
|
||||
sessionKey: uni.getStorageSync('sessionKey'),
|
||||
unionId: uni.getStorageSync('unionid'),
|
||||
openId: uni.getStorageSync('openid'),
|
||||
appId: 'wx7a939c19b270cc3d'
|
||||
}
|
||||
oilIdentityApi.getPhone(data1).then(resj => {
|
||||
re(resj.data.phoneNumber)
|
||||
});
|
||||
} else if (res.code == 1002) {
|
||||
uni.showModal({
|
||||
title: '微信登录失败提醒',
|
||||
content: `${res.msg}如有疑问,请联系客服处理`
|
||||
})
|
||||
|
||||
}
|
||||
}).catch(err => {
|
||||
uni.showToast({
|
||||
title: '登陆失败',
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
},
|
||||
fail: err => {},
|
||||
})
|
||||
})
|
||||
},
|
||||
overallInterceptor(callBack) {
|
||||
uni.addInterceptor('redirectTo', {
|
||||
invoke(e) {
|
||||
console.log('拦截redirectTo');
|
||||
setTimeout(() => {
|
||||
callBack('redirectTo')
|
||||
}, 0)
|
||||
return false;
|
||||
},
|
||||
success(e) {
|
||||
taht.$nextTick(function() {
|
||||
console.log('跳转页面加载成功')
|
||||
})
|
||||
}
|
||||
});
|
||||
uni.addInterceptor('switchTab', {
|
||||
invoke(e) {
|
||||
console.log('拦截switchTab')
|
||||
setTimeout(() => {
|
||||
callBack('switchTab')
|
||||
}, 0)
|
||||
return false;
|
||||
},
|
||||
success(e) {
|
||||
taht.$nextTick(function() {
|
||||
console.log('跳转页面加载成功')
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user