1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- let baseUrl = null
- let oldUrl = null
- const {
- miniProgram: {
- envVersion
- }
- } = wx.getAccountInfoSync();
- /* if (envVersion == 'develop') {
- baseUrl = 'https://reader-api.efunbox.cn/wx'
- oldUrl = 'https://reader-api.efunbox.cn'
- } else { */
- baseUrl = 'https://reader-api.ai160.com/wx'
- oldUrl = 'https://reader-api.ai160.com'
- // }
- function request(url, method, data, oldBaseUrl = false, intercept = true) {
- let header = {
- 'uid': wx.getStorageSync('uid') || '',
- // 'channelCode': wx.getStorageSync('user').channel == '4001' ? '4001' : '3001'
- 'channelCode': wx.getStorageSync('channelCode')
- }
- return new Promise((reslove, reject) => {
- wx.request({
- url: oldBaseUrl ? oldUrl + url : baseUrl + url,
- method: method,
- data: data,
- header: header,
- success: (result) => {
- let {
- data: {
- code,
- data = {},
- message
- }
- } = result
- if (intercept) {
- if (code == '200') {
- reslove(data)
- } else if (code == '1102') {
- console.log(code, '<=====code1', message);
- wx.clearStorage()
- } else if (code) {
- console.log(code, '<=====code2', message);
- wx.showToast({
- title: message,
- icon: "none",
- duration: 3000
- })
- }
- } else {
- reslove(result.data)
- }
- },
- fail: (res) => {
- console.log(res)
- reject(res)
- },
- })
- })
- }
- function aiRequest(url, method, data) {
- return new Promise((reslove, reject) => {
- wx.request({
- url: 'https://ai.wx.aidomore.com/v3' + url,
- method,
- data,
- timeout: 60000,
- header: {
- 'uid': wx.getStorageSync('uid') || '',
- },
- success: (result) => {
- let {
- statusCode,
- data
- } = result
- if (statusCode == '200') {
- reslove(data)
- } else {
- wx.showToast({
- title: '服务异常请稍后重试',
- icon: "none",
- duration: 3000
- })
- }
- },
- fail: (res) => {
- console.error(res)
- reject(res)
- },
- })
- })
- }
- module.exports = {
- request,
- aiRequest
- }
|