更新云函数
This commit is contained in:
116
apis/index.js
Normal file
116
apis/index.js
Normal file
@@ -0,0 +1,116 @@
|
||||
|
||||
/**
|
||||
* Web唐明明
|
||||
* 匆匆数载恍如梦,岁月迢迢华发增。
|
||||
* 碌碌无为枉半生,一朝惊醒万事空。
|
||||
*/
|
||||
|
||||
import store from '@/store'
|
||||
|
||||
// 基础配置
|
||||
const config = {
|
||||
apiUrl : 'https://e-chain.cnskl.com/api/',
|
||||
timeout : 60000
|
||||
}
|
||||
|
||||
let loginHintState = false
|
||||
|
||||
// 网络请求
|
||||
const request = (parameter) => {
|
||||
// 检查url配置
|
||||
if(parameter.url === 'undefined' || parameter.url === ''){
|
||||
uni.showToast({
|
||||
title: '请求地址不能为空',
|
||||
icon : 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
// 注入header
|
||||
config.header = {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': store.getters.getToken || ''
|
||||
}
|
||||
// 请求实例
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url : config.apiUrl + parameter.url,
|
||||
timeout : config.timeout,
|
||||
header : config.header || {},
|
||||
data : parameter.data || {},
|
||||
method : parameter.method || 'GET',
|
||||
success : res => {
|
||||
if (res.header.Authorization){
|
||||
updateToken('token', res.header.Authorization)
|
||||
}
|
||||
if(res.statusCode === 200){
|
||||
const resolveData = res.data
|
||||
if(resolveData.status_code === 200) {
|
||||
resolve(resolveData.data)
|
||||
return
|
||||
}
|
||||
if(resolveData.status_code === 401) {
|
||||
loginHint()
|
||||
return
|
||||
}
|
||||
reject(resolveData)
|
||||
return
|
||||
}
|
||||
errToast(res.statusCode)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 处理一些http请求错误提示
|
||||
const errToast = (code) => {
|
||||
console.log(code)
|
||||
switch (code){
|
||||
case 404:
|
||||
uni.showToast({
|
||||
title: code + '接口不存在,请联系系统管理员',
|
||||
icon : 'none'
|
||||
})
|
||||
break;
|
||||
case 405:
|
||||
uni.showToast({
|
||||
title: code + '请检查接口请求方式错误',
|
||||
icon : 'none'
|
||||
})
|
||||
break;
|
||||
case 500:
|
||||
uni.showToast({
|
||||
title: code + '服务端错误,请检查服务器信息',
|
||||
icon : 'none'
|
||||
})
|
||||
break;
|
||||
case 401:
|
||||
console.log('重新登录')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新token
|
||||
const updateToken = (token) => {
|
||||
store.commit('setToken', token)
|
||||
}
|
||||
|
||||
// 处理登录提示
|
||||
const loginHint = () => {
|
||||
if( loginHintState ) return
|
||||
if(!loginHintState) loginHintState = true
|
||||
updateToken('')
|
||||
uni.showModal({
|
||||
title: '登录提示',
|
||||
content: '您的登录信息已过期,请重新登录',
|
||||
confirmColor: '#009B69',
|
||||
showCancel:false,
|
||||
success: res=> {
|
||||
loginHintState = false
|
||||
if (res.confirm) uni.reLaunch({
|
||||
url: '/pages/auth/login?type=overdue'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default request
|
||||
22
apis/interfaces/auth.js
Normal file
22
apis/interfaces/auth.js
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
/**
|
||||
* Web唐明明
|
||||
* 匆匆数载恍如梦,岁月迢迢华发增。
|
||||
* 碌碌无为枉半生,一朝惊醒万事空。
|
||||
* moduleName: 鉴权
|
||||
*/
|
||||
|
||||
import request from '../index'
|
||||
|
||||
// 一键登录
|
||||
const auth = (data) => {
|
||||
return request({
|
||||
url: 'user/socialite/login/unicloud/app',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
auth
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script>
|
||||
import { auth } from '@/apis/interfaces/auth'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -44,20 +45,19 @@
|
||||
}]
|
||||
}
|
||||
},
|
||||
success : auth => {
|
||||
uniCloud.callFunction({
|
||||
name: "phone-login",
|
||||
data: {
|
||||
access_token: auth.authResult.access_token,
|
||||
openid : auth.authResult.openid
|
||||
}
|
||||
}).then(res=>{
|
||||
success : result => {
|
||||
console.log(result)
|
||||
auth({
|
||||
access_token: result.authResult.access_token,
|
||||
openid : result.authResult.openid
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
}).catch(err=>{
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
fail : err => {
|
||||
uni.showToast({
|
||||
title: err.errMsg
|
||||
})
|
||||
console.log(err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
|
||||
/**
|
||||
* Web唐明明
|
||||
* 匆匆数载恍如梦,岁月迢迢华发增。
|
||||
* 碌碌无为枉半生,一朝惊醒万事空。
|
||||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
@@ -18,4 +25,4 @@ export default new Vuex.Store({
|
||||
uni.setStorageSync('token', tokenString)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,11 +1,37 @@
|
||||
'use strict';
|
||||
exports.main = async (event, context) => {
|
||||
return await uniCloud.getPhoneNumber({
|
||||
appid: '__UNI__CD19AAD',
|
||||
provider: 'univerify',
|
||||
apiKey : '16fa20236696596869759d3a81541901', // 在开发者中心开通服务并获取apiKey
|
||||
apiSecret: 'fca97287360c2e8f8259d8877a601887', // 在开发者中心开通服务并获取apiSecret
|
||||
access_token: event.access_token,
|
||||
openid: event.openid
|
||||
})
|
||||
|
||||
'use strict';
|
||||
|
||||
const crypto = require('crypto')
|
||||
|
||||
exports.main = async (event) => {
|
||||
const secret = 'Yuzhankeji2021.'
|
||||
const hmac = crypto.createHmac('sha256', secret);
|
||||
|
||||
let params = event.queryStringParameters
|
||||
const sign = params.sign
|
||||
delete params.sign
|
||||
|
||||
const signStr = Object.keys(params).sort().map(key => {
|
||||
return `${key}=${params[key]}`
|
||||
}).join('&')
|
||||
|
||||
hmac.update(signStr);
|
||||
|
||||
if (sign !== hmac.digest('hex')) {
|
||||
throw new Error('非法访问')
|
||||
}
|
||||
|
||||
const {
|
||||
access_token,
|
||||
openid
|
||||
} = params
|
||||
|
||||
return await uniCloud.getPhoneNumber({
|
||||
appid: '__UNI__CD19AAD',
|
||||
provider: 'univerify',
|
||||
apiKey: '16fa20236696596869759d3a81541901',
|
||||
apiSecret: 'fca97287360c2e8f8259d8877a601887',
|
||||
access_token: access_token,
|
||||
openid: openid,
|
||||
})
|
||||
};
|
||||
|
||||
7004
unpackage/dist/dev/app-plus/app-service.js
vendored
7004
unpackage/dist/dev/app-plus/app-service.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user