let mpi = {}

// 微信登陆
mpi.wxLogin = () => {
  return new Promise((resolve, reject)=>{
    uni.login({
      success: function (res) {
        resolve(res)
      },
      fail: function (err) {
        console.warn(err)
        reject(err)
      }
    })
  })
}

/**
 * 订阅认证信息
 */
mpi.subscribe=(tmplIds)=>{
	return new Promise((resolve, reject)=>{
	  uni.requestSubscribeMessage({
		tmplIds,
		success(res) {
		  resolve(res)
		},
		fail(err) {
		  reject(err)
		}
	  })
	})
},

mpi.changeBase64 = (filePath) => {
	return new Promise((resolve, reject) => {
		uni.getFileSystemManager().readFile({
			filePath,//选择图片返回的相对路径
			encoding: 'base64',//编码格式
			success:function(res){
				resolve(res)
			},
		    fail: function(err) {
			    reject(err)
		    },
		})
	})
}

// 获取用户信息
mpi.wxGetUserInfo = () => {
  return new Promise((resolve, reject) => {
    uni.getUserInfo({
      withCredentials: true,
      success: function(res) {
        resolve(res)
      },
      fail: function(err) {
        reject(err)
      },
    })
  })
}

export default mpi
