import request from '@/utils/request'
const api = 'https://pbl.cocorobo.cn/api/cocoflow/'
// const api = 'http://localhost:7003/api/cocoflow/'

// 微信授权 - 用code换取access_token和用户信息
export function wechatAuth(data) {
  return request({
    url: api + 'wechat-get-user-info',
    method: 'POST',
    data,
    hideloading: false
  })
}

export function wechatRegister(data) {
  return request({
    url: api + 'wechat-register',
    method: 'POST',
    data,
    hideloading: false
  })
}

// 获取微信用户信息
export function getWechatUserInfo(openid) {
  return request({
    url: `/api/wechat/userinfo/${openid}`,
    method: 'GET',
    hideloading: true
  })
}

// 微信JS-SDK配置
export function getWechatJsConfig(url) {
  return request({
    url: api + 'api/wechat/jsconfig',
    method: 'POST',
    data: { url },
    hideloading: true
  })
}

// 微信分享配置
export function getWechatShareConfig(data) {
  return request({
    url: api + 'api/wechat/share',
    method: 'POST',
    data,
    hideloading: true
  })
}

// 微信支付
export function wechatPay(data) {
  return request({
    url: api + 'api/wechat/pay',
    method: 'POST',
    data,
    hideloading: false
  })
}

// 检查微信授权状态
export function checkWechatAuth(openid) {
  return request({
    url: api + `api/wechat/check-auth/${openid}`,
    method: 'GET',
    hideloading: true
  })
}
