import request from '../api/request'
import wx from 'weixin-js-sdk'

const wxJs = () => request({
  method: 'GET',
  url: '/api/wechat/account/config',
  params: {
    url: location.href,
    official_account_code: 'tingbang' //  写死
  }
})

export const WxConfig = async () => {
  const { data } = await wxJs()
  const wxParam = {
    debug: false,
    appId: data.app_id,
    timestamp: data.timestamp,
    nonceStr: data.nonce_str,
    signature: data.signature,
    jsApiList: [
      'checkJsApi',
      'openLocation',
      'getLocation',
      'updateAppMessageShareData',
      'updateTimelineShareData',
      'onMenuShareAppMessage',
      'onMenuShareTimeline',
      'hideMenuItems',
      'scanQRCode']
  }
  wx.config(wxParam)
  return wx
}
