{"size": 2019, "ext": "js", "max_stars_repo_path": "src/assets/utils/wechat.js", "max_stars_repo_name": "iamjoel/mobile-codes-collection", "max_stars_repo_stars_event_min_datetime": "2018-08-13T02:55:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-11T01:31:26.000Z", "max_issues_repo_path": "src/assets/utils/wechat.js", "max_issues_repo_name": "iamjoel/mobile-codes-collection", "max_issues_repo_issues_event_min_datetime": "2019-01-11T07:20:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T08:06:02.000Z", "max_forks_repo_path": "src/assets/utils/wechat.js", "max_forks_repo_name": "iamjoel/mobile-codes-collection", "max_forks_repo_forks_event_min_datetime": "2018-08-07T02:33:42.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-07T02:33:42.000Z"}
{"max_stars_count": 6, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 26.92, "max_line_length": 109, "alphanum_fraction": 0.5052005944}
import axios from 'axios'
import { urls } from '@/setting'

function registerSDK (opts = {}, successFn = function () {}) {
  // opts.registerURL = opts.registerURL || location.origin + location.pathname
  // opts.registerURL = 'http://zhixingclub.com/sanqianfang/mobile/?a=3'//location.origin + location.pathname
  opts.registerURL = location.href.split('#')[0] //location.origin + location.pathname
  axios
    .post(urls.wechat.registerWechat, {
      url: opts.registerURL
    })
    .then(({ data }) => {
      var info = data.data
      wx.config({
        // debug: true,
        ...info
      })

      wx.ready(() => {
        if (opts.hideShare) {
          wx.hideMenuItems({
            menuList: [
              'menuItem:share:appMessage',
              'menuItem:share:timeline',
              'menuItem:share:qq',
              'menuItem:share:weiboApp',
              'menuItem:favorite',
              'menuItem:share:facebook',
              'menuItem:share:QZone'
            ]
          })
        } else {
          wx.showMenuItems({
            menuList: [
              'menuItem:share:appMessage',
              'menuItem:share:timeline',
              'menuItem:share:qq',
              'menuItem:share:weiboApp',
              'menuItem:favorite',
              'menuItem:share:facebook',
              'menuItem:share:QZone'
            ]
          })
        }
        successFn && successFn()
      })

      wx.error(res => {
        // alert('微信jssdk 注册失败:' + JSON.stringify(res))
      })
    })
}

import { Toast } from 'vant'
export function pay (payInfo, successFn, failFn) {
  axios.post(urls.wechat.getPayInfo, payInfo).then(({ data }) => {
    registerSDK({}, function () {
      wx.chooseWXPay(
        Object.assign(data.data, {
          success () {
            Toast('支付成功')
            successFn && successFn()
          },
          fail () {
            Toast('支付失败')
            failFn && failFn()
          }
        })
      )
    })
  })
}

export default registerSDK
