Today Task
Usage Of Charles Proxy—
Charles抓包工具的使用(软件破解,https抓包设置,二级域名)
Usage Of UviewUI Components
Uniapp基础页面的组件的编写以及使用;(二手车小程序demo)
API Registration On Uniapp
Uniapp(VUE3.0)接口的注册
Charlesproxy What is Charlesproxy? Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).
Download Enter the official web of CharlesProxy .
Crack https://www.zzzmode.com/mytools/charles/
Installation Of Certificate Help–>SSL Proxying–>Install Charles Root Certificate
PS: There may be some errors sometimes during installation.Just throw the issues on the Internet then solve it.
Setting Of HTTPS Proxy Proxy–>SSL Proxying Settings, enter the domains you want to visit and set the port number as 443.
Usage Of UviewUI Components Documentation———uView .
API Registration On Uniapp
Define fomate of HTTP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 export default { baseUrl : 'https://wx.kxjdc.com' , data : {}, header : { 'Content-Type' : 'application/json' }, method : 'POST' , success ( ) {}, fail ( ) {}, complete ( ) {}, }
Import the information of HTTP and build the common functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 import _config from './apiConfig' import { ignoreNull, convertUrlQuery } from '@/utils/utils' function _error (res, error = true ) { if (res.code === 401 ) { uni.redirectTo ({ url : '/pages/auth/login/login' }) } else { if (error) { uni.showToast ({ icon : 'none' , title : res.message || '接口异常,请联系管理员' }) } } }export const https = (options, error = true ) => { options.url = _config.baseUrl + options.url options.data = ignoreNull (options.data ) _config.header ['X-Access-Token' ] = uni.getStorageSync ('X-Access-Token' ) return new Promise ((resolve, reject ) => { _config.complete = response => { if (options.handle ) { resolve (response.data ) } else { if (response.statusCode === 200 ) { if (response.data .code === 200 || response.data .code === 10000 ) { resolve (response.data ) } else { _error (response.data , error) } } else { try { Promise .reject (response).catch (err => { _error (response.data , error) }) } catch (e) { uni.hideLoading () } } } } uni.request (Object .assign ({}, _config, options)) }) }export const upload = (options, error = true ) => { options.url = _config.baseUrl + options.url return new Promise ((resolve, reject ) => { options.complete = response => { console .log ('上传返回:' , response) if (response.statusCode === 200 ) { resolve (JSON .parse (response.data )) } else { if (options.handle ) { reject (response) } else { try { Promise .reject (response).catch (err => { _error (JSON .parse (response.data ), error) }) } catch (e) { uni.hideLoading () } } } } uni.uploadFile (options) }) }
Then import https function in appointed customed api to build new HTTP function
1 2 3 4 5 6 7 8 9 10 11 12 import { https } from '@/common/interface' export default { homePage : () => { return https ({ url : '/api/index/home_res' , }) }, }
Put all customed APIs to a common.js such as index.js together
1 2 3 4 5 6 export { default as authApi } from './api/auth' export { default as booksApi } from './api/books' export { default as userApi } from './api/user' export { default as commonApi } from './api/common' export { default as homeApi } from './api/home'
Finally, import in vue file to use the functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import { homeApi } from '@/common' onLoad ( ) { this .init ; }, methods : { init ( ) { homeApi.homePage ().then (res => { }) } }