Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('userInfoResponse', userInfoResponse);
//
// ------------------------------------
let decryptDataResponse;
try {
const sendData = {
encryptedData: userInfoResponse.encryptedData,
iv: userInfoResponse.iv,
sessionKey: Taro.getStorageSync('sessionKey'),
platform: 'wechatminiprogram',
};
decryptDataResponse = await Taro.request({
method: 'POST',
url: `${envConfig.WECHAT_HOST}/oauth/wechat/decrypt-data`,
data: sendData,
});
Taro.setStorageSync('userInfo', decryptDataResponse.data);
if (props.onLoginCallback) {
props.onLoginCallback(new Date().getTime());
}
} catch (e) {
setLoginLoading(false);
await Taro.showToast({ title: '获取 Decrypt Data 失败' });
}
console.log('decryptDataResponse', decryptDataResponse);
baseOptions(params, method = "GET") {
let { url, data } = params;
let contentType = "application/json";
contentType = params.contentType || contentType;
const option = {
url: url.indexOf("http") !== -1 ? url : BASE_URL + url,
data: data,
method: method,
header: {
"content-type": contentType
// Authorization: Taro.getStorageSync("Authorization")
}
};
return Taro.request(option);
},
get(url, data = "") {
export default async (options = {}) => {
options.method = (options.method || 'GET').toUpperCase()
options.timestamp = +new Date()
options.proxy = options.proxy !== false
try {
let response
if (options.url) {
response = await Taro.request({
url: getReqUrl(options),
data: getReqData(options),
header: getReqHeader(options),
method: options.method,
})
} else {
options.url = '/xxx'
response = await uploadFile({
url: getReqUrl(options),
filePath: options.data,
fileType: 'image',
name: 'file',
// header: getReqHeader('upload'),
})
if (response.data) {
response.data = JSON.parse(response.data)
getFutureMovies(){
let self = this;
let offset = this.state.offset;
let expectData = self.state.expectData
let ci = self.state.id;
Taro.request({
url:`https://m.maoyan.com/ajax/mostExpected?ci=${ci}&limit=10&offset=${offset}&token=`,
method:'GET'
}).then(res=>{
if(res.statusCode == 200){
let data = res.data.coming;
offset +=10;
data.forEach(value=>{
let arr = value["img"].split("w.h");
value['img'] = arr[0]+'128.180'+arr[1]
})
self.setState({
expectData:expectData.concat(data),
offset:offset
});
}
})
export default (options = { method: 'GET', data: {} }) => {
if (!noConsole) {
console.log(
`${new Date().toLocaleString()}【 M=${options.url} 】P=${JSON.stringify(
options.data
)}`
);
}
return Taro.request({
url: baseUrl + options.url,
data: {
...request_data,
...options.data,
},
header: {
'Content-Type': 'application/json',
},
method: options.method.toUpperCase(),
}).then(res => {
const { statusCode, data } = res;
if (statusCode >= 200 && statusCode < 300) {
if (!noConsole) {
console.log(
`${new Date().toLocaleString()}【 M=${options.url} 】【接口响应:】`,
res.data
getCities() {
Taro.request({
url:
"https://www.easy-mock.com/mock/5ba0a7f92e49497b37162e32/example_copy/cities_copy_1541385673090",
method: "GET",
header: {
Accept: "application/json, */*",
"Content-Type": "application/json"
}
}).then(res => {
if (res.statusCode == 200) {
let data = res.data.data.data.data;
Taro.setStorageSync("cities", data);
}
});
}
render() {
request(options: any, method: string = 'GET') {
const {url} = options;
Taro.showNavigationBarLoading();
return Taro.request({
...options,
method: method,
url: `${API_URL}${url}`,
header: {
...options.header
},
}).then((res) => {
Taro.stopPullDownRefresh();
Taro.hideNavigationBarLoading();
if (res.statusCode === 200) {
return res.data
}
throw new Error('[' + res.statusCode + ']网络请求异常')
})
.catch(err => {
Taro.hideNavigationBarLoading();
getHotDate(showDate){
let now = new Date();
if(new Date(showDate) < now){
showDate = this.getDate();
this.setState({
showDate:showDate
});
}
Taro.showLoading({
title:"加载数据中"
});
Taro.request({
url:`https://m.maoyan.com/ajax/movie?forceUpdate=${Date.now()}`,
method:'POST',
data:{
movieId:this.state.params.id,
day:showDate,
offset: this.state.offset,
limit: 20,
districtId: -1,
lineId: -1,
hallType: -1,
brandId: -1,
serviceId: -1,
areaId: -1,
stationId: -1,
item:"",
updateShowDay: true,
fetch: (url, options) => Taro.request({
url,
method: options.method,
data: options.body,
header: options.headers,
}).then(({data, statusCode}) => {
return {
ok: () => {
return statusCode >= 200 && statusCode < 300;
},
text: () => {
return Promise.resolve(JSON.stringify(data));
}
}
})
});
getCinemasList(){
let reqList = this.state.reqList;
let cityObj = Taro.getStorageSync('cities');
let self = this;
Taro.showLoading({
title:"加载中"
});
Taro.request({
method:'GET',
url:`https://m.maoyan.com/ajax/cinemaList?day=${reqList.day}&offset=${reqList.offset}&limit=20&districtId=${reqList.districtId}&lineId=${reqList.lineId}&hallType=${reqList.hallType}&brandId=${reqList.brandId}&serviceId=${reqList.serviceId}&areaId=${reqList.areaId}&stationId=${reqList.stationId}&item=&updateShowDay=true&reqId=${reqList.reqId}&cityId=${cityObj.geoCity.id}`,
}).then(res=>{
if(res.statusCode == 200){
Taro.hideLoading();
let data = res.data;
self.setState({
cinemas:self.state.cinemas.concat(data.cinemas)
});
}
})
}
loadMore(){