| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- // 预发布地址
- let httpTrackLog = 'https://hyperion-track-app.mokamrp.com';
- let httpServiceURL = '';
- let version = __wxConfig.envVersion;
- switch (version) {
- case 'develop':
- httpServiceURL = 'https://hyperion-novel-qa-app.mokamrp.com';
- // httpServiceURL = "http://172.16.24.193:10111";
- // httpServiceURL = 'https://iaa-app.mokamrp.com';
- break;
- case 'trial':
- httpServiceURL = 'https://test-iaa-app.mokamrp.com';
- // httpServiceURL = 'https://iaa-app.mokamrp.com';
- break;
- case 'release': //正式版
- httpServiceURL = 'https://iaa-app.mokamrp.com';
- break;
- default: //未知,默认调用正式版
- httpServiceURL = 'https://iaa-app.mokamrp.com';
- break;
- }
- // 普通POST请求
- export const post = (url, body = {}) => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: url,
- data: body,
- method: 'POST',
- dataType: 'json',
- success: (res) => {
- if (res.statusCode == 200 && res.data.code == 200) {
- resolve(res.data.data);
- } else {
- reject(res);
- }
- },
- fail: (res) => {
- console.log(url, 'error--------', res);
- reject(res);
- },
- });
- });
- };
- // 普通Get请求
- export const get = (url) => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: url,
- method: 'GET',
- success: (res) => {
- if (res.statusCode == 200 && res.data.code == 200) {
- resolve(res.data);
- } else {
- reject(res);
- }
- },
- fail: (res) => {
- reject(res);
- },
- });
- });
- };
- /**
- * 打点请求
- */
- export function uploadTrackLog(url, body) {
- if (!body) {
- body = {};
- }
- return post(httpTrackLog + url, body);
- }
- export const requestLogin = (data) => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: httpServiceURL + '/user/loginWx',
- data: data,
- method: 'POST',
- dataType: 'json',
- header: {},
- success: function (res) {
- if (res.data.code == 200) {
- console.log(res);
- resolve(res.data.data);
- } else {
- wx.showToast({
- title: res.data.msg || res.data.error || '登录失败...',
- icon: 'none',
- });
- console.log('login fail', res);
- reject(res.data);
- }
- },
- fail: function (res) {
- console.log('login fail', res);
- wx.showToast({
- title: '登录失败...',
- icon: 'none',
- });
- },
- });
- });
- };
- export const requestAll = (requestUrl, body, method = 'POST', customHeaders = {}) => {
- console.log("body",body)
- let app = getApp().globalData;
- let url = httpServiceURL + requestUrl;
- if (method === 'GET') {
- if (body) {
- url += '?';
- for (const k in body) {
- url += `&${k}=${body[k]}`;
- }
- }
- }
- return new Promise((resolve, reject) => {
- wx.request({
- url: url,
- data: body,
- method: method,
- dataType: 'json',
- header: {
- ...customHeaders,
- token: customHeaders.token || app.token || '',
- },
- success: function (res) {
- if (res.data.code == 200) {
- // 是否需要解密
- console.log(url, '<------>', res.data.data);
- if (typeof res.data.data === 'number') {
- resolve(res.data.data);
- } else {
- resolve(res.data.data || []);
- }
- } else {
- console.log('error:', res.data, url);
- reject(res.data);
- }
- },
- fail: function (res) {
- wx.showToast({
- title: '网络出错,请重试...',
- icon: 'none',
- });
- },
- });
- });
- };
- /**
- * 图文服务
- */
- export function tuwenRequest(url, body) {
- if (!body) {
- body = {};
- }
- return tuwenPost('https://kratos.mokamrp.com' + url, body);
- }
- export const tuwenPost = (url, body = {}) => {
- const app = getApp()
- return new Promise((resolve, reject) => {
- wx.request({
- url: url,
- data: body,
- method: 'POST',
- dataType: 'json',
- header: {
- 'Authorization': 'tanlongjiefuckdick'
- },
- success: (res) => {
- if (res.statusCode == 200 && res.data.code == 200) {
- let result = JSON.parse(res.data.data)
- resolve(result)
- } else {
- reject(res)
- }
- },
- fail: (res) => {
- console.log(url, 'error--------', res)
- reject(res)
- }
- })
- })
- }
- /**
- * 投诉
- */
- export function workGet(url, body) {
- if (!body) {
- body = {}
- }
- return get('https://moka-volta-kratos-workwx-h5.mokamrp.com' + url, body)
- }
- export function workPost(url, body) {
- if (!body) {
- body = {}
- }
- return post('https://moka-volta-kratos-workwx-h5.mokamrp.com' + url, body)
- }
|