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.
83 lines
1.9 KiB
83 lines
1.9 KiB
import config from '../../config.js';
|
|
import request from '../request.js'
|
|
import common from '../common.js'
|
|
|
|
let mpAlipay = {}
|
|
|
|
/*
|
|
* 支付宝小程序获取OPENID
|
|
* 2022-03-24
|
|
*/
|
|
mpAlipay.getOpenid = function() {
|
|
let openid = uni.getStorageSync('openid')
|
|
let user_id = uni.getStorageSync('user_id')
|
|
|
|
return new Promise((resolve, reject) => {
|
|
if (!openid) {
|
|
// 获取授权登录的服务供应商
|
|
uni.getProvider({
|
|
service: 'oauth',
|
|
success: (res) => {
|
|
if (~res.provider.indexOf('alipay')) {
|
|
|
|
// 登录
|
|
uni.login({
|
|
provider: 'alipay',
|
|
scopes: ['auth_base'],
|
|
success: (loginRes) => {
|
|
console.log(loginRes.code)
|
|
|
|
request.getData(
|
|
'base/mpalipay/api/Auth/getAlipayUserId', {
|
|
code: loginRes.code
|
|
}, {
|
|
loading: 1
|
|
}).then(res => {
|
|
uni.setStorageSync('openid', res
|
|
.data.openid)
|
|
uni.setStorageSync('user_id', res
|
|
.data.user_id)
|
|
uni.setStorageSync('access_token',
|
|
res.data.access_token)
|
|
uni.setStorageSync(
|
|
'access_token_expire_time',
|
|
res.data
|
|
.access_token_expire_time)
|
|
|
|
resolve({
|
|
openid: uni
|
|
.getStorageSync(
|
|
'openid'),
|
|
user_id: uni
|
|
.getStorageSync(
|
|
'user_id'),
|
|
})
|
|
console.log('生产环境刚获得 缓存:openid = ' +
|
|
uni.getStorageSync(
|
|
'openid') +
|
|
' user_id = ' +
|
|
uni.getStorageSync(
|
|
'user_id'))
|
|
}, err => {
|
|
console.log(err)
|
|
reject()
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
} else {
|
|
resolve({
|
|
openid: uni.getStorageSync('openid'),
|
|
user_id: uni.getStorageSync('user_id'),
|
|
})
|
|
console.log('生产环境 缓存:openid = ' + uni.getStorageSync('openid') + ' user_id = ' + uni
|
|
.getStorageSync('user_id'))
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
export default mpAlipay
|