client-meta.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import appSettings from '@/core/config/app-settings'
  2. // #ifdef H5
  3. import { runningInsideWeChat } from '@/platform/h5-wechat'
  4. // #endif
  5. const FALLBACK_CLIENT = {
  6. app: 'app-hl88live',
  7. wechat: 'wechat-hl88live',
  8. h5: 'h5-hl88live',
  9. mp: 'mp-hl88live'
  10. }
  11. function resolveClientId() {
  12. const map = appSettings.httpAppClient || {}
  13. // #ifdef APP-PLUS
  14. return map.app || FALLBACK_CLIENT.app
  15. // #endif
  16. // #ifdef H5
  17. return runningInsideWeChat()
  18. ? (map.wechat || FALLBACK_CLIENT.wechat)
  19. : (map.h5 || FALLBACK_CLIENT.h5)
  20. // #endif
  21. // #ifdef MP
  22. return map.mp || FALLBACK_CLIENT.mp
  23. // #endif
  24. return FALLBACK_CLIENT.h5
  25. }
  26. export function applyClientHeaders(headers = {}) {
  27. const next = { ...headers }
  28. next['App-Client'] = resolveClientId()
  29. next['Accept-Language'] = 'zh-CN,zh;q=0.9'
  30. next.language = uni.getLocale()
  31. // #ifdef APP-PLUS
  32. next.uuid = plus.device.uuid
  33. next['App-Version'] = plus.runtime.version
  34. // #endif
  35. return next
  36. }
  37. export function readSessionToken() {
  38. const cached = uni.getStorageSync('hl88app:user')
  39. return cached && cached.token ? cached.token : ''
  40. }