Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WooCommerceAPI.prototype._request = async function(method, endpoint, data) {
- const url = this.url + endpoint
- const params = {
- url,
- method,
- encoding: this.encoding,
- timeout: this.timeout,
- }
- // if (this.isSsl) {
- // if (this.queryStringAuth) {
- // params.qs = {
- // consumer_key: this.consumerKey,
- // consumer_secret: this.consumerSecret,
- // ...data,
- // }
- // } else {
- // params.auth = {
- // user: this.consumerKey,
- // pass: this.consumerSecret,
- // }
- // }
- // if (this.verifySsl) {
- // params.strictSSL = this.verifySsl
- // }
- // } else if (method == 'GET') {
- // params.qs = this._getOAuth().authorize({
- // url,
- // method,
- // data,
- // })
- // } else if (method == 'POST') {
- // params.qs = this._getOAuth().authorize({
- // url,
- // method,
- // })
- // }
- // console.log(params.url);
- // encode the oauth_signature to make sure it not remove + charactor
- // params.qs.oauth_signature = encodeURIComponent(params.qs.oauth_signature)
- params.url = `${params.url}`
- if (method == 'GET') {
- let paramsArray = [];
- //拼接参数
- if (data) {
- Object.keys(data).forEach(key => paramsArray.push(key + '=' + data[key]))
- if (params.url.search(/\?/) === -1) {
- params.url += '?' + paramsArray.join('&')
- } else {
- params.url += '&' + paramsArray.join('&')
- }
- }
- params.headers = { 'Cache-Control': 'no-cache' }
- } else if (method == 'POST') {
- params.headers = {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- }
- params.body = JSON.stringify(data)
- }
- // console.log(params.url);
- return await fetch(params.url, params)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement