You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.5 KiB

import {appConfig} from '../config'
const openid_info_key = appConfig.openidInfoKey
const user_info_key = 'user_info_yunyubang'
export const weixin = {
getOpenidInfo: (cb, refresh) => {
cb = cb || function () {}
refresh = refresh || false
if (!refresh) {
let openid_info = uni.getStorageSync(openid_info_key)
if (openid_info && openid_info.openid && openid_info.session_key) {
cb(openid_info)
return
}
}
uni.login({
provider: 'weixin',
success: (res) => {
uni.request({
url: appConfig.baseUrl + '/api/member/login-by-code',
method: 'POST',
data: {code: res.code},
success: result => {
console.log(result)
uni.setStorageSync(openid_info_key, result.data.data.user_info)
cb(result.data.data.user_info)
}
});
}
});
},
getUserProfile: (cb) => {
cb = cb || function () {}
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
uni.setStorageSync(user_info_key, res.userInfo)
cb(res.userInfo)
}
})
},
getUserInfoCache: () => {
return uni.getStorageSync(user_info_key)
}
}
export function login() {
uni.login({
provider: 'weixin',
success: res => {
uni.request({
url: appConfig.baseUrl + '/api/wechat/user-login',
method: 'POST',
data: {
code: res.code,
iv: '',
},
success: result => {
}
})
}
});
}