const useAjax = (url, data, method) => {
  return new Promise((resolve, reject) => {
    $.ajax({
      url,
      data,
      type: method,
      dataType: "json",
    })
      .done((res, status, req) => resolve({res, status, req}))
      .fail((err) => reject(err))
  })
}

const getCustomerService = async () => {
  let url = testurl + '/mobile-api/origin/customerService.html'
  return await useAjax(url, null, "GET")
}

const postInitCaptcha = async () => {
  let url = `${testurl}/mobile-api/v5/captcha/initWithoutSwitch.html`
  let data = {
    "locale": "zh_CN",
    "terminal": "pc",
    "is_native": false,
    "version": "v3055",
    "resolution": "2x",
    "type": "login"
  }
  return await useAjax(url, data, "POST")
}

const postCheckCode = async (data) => {
  let url = `${testurl}/mobile-api/v5/captcha/checkCode.html`
  return await useAjax(url, data, "POST")
}
