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.
205 lines
7.1 KiB
205 lines
7.1 KiB
/**
|
|
* Copyright © 2020-present LiuDanYang. All rights Reserved.
|
|
*/
|
|
import { mGet, mPost } from "./request"
|
|
import { mconfig } from "./moment"
|
|
import { pconfig } from "./payment"
|
|
import { sconfig } from "./saas"
|
|
import { zconfig } from "./ztb"
|
|
const util = require('../utils/util')
|
|
const storage = require('../utils/storage')
|
|
const app = getApp()
|
|
const urls = ['https://api-client-uec-dev.qniao.cn', 'https://api-client-uec-test.qniao.cn', 'https://api-client-uec.qniao.cn']
|
|
|
|
const config = {
|
|
baseUrl: urls[app.evn]
|
|
}
|
|
const wechatApplet = (params) => mPost('/uec/get/wechat-applet-session', params, config)
|
|
const loginCaptcha = (params) => mPost(`/uec/authorize/by-captcha`, params, config)
|
|
const loginPwd = (params) => mPost(`/uec/authorize/by-password`, params, config)
|
|
const postCaptcha = (params) => mPost(`/uec/get/auth-captcha`, params, config)
|
|
const setPassword = (params) => mPost(`/uec/user/set/sign-in-password`, params, config)
|
|
const modifyMobile = (params) => mPost(`/uec/user/modify/mobile`, params, config)
|
|
const getUserInfo = (params) => mGet('/uec/get/user-info', params, config)
|
|
const updateUserInfo = (params) => mPost('/uec/user/update/user-info', params, config)
|
|
const getAuthSession = () => mGet('/uec/create/identity-auth-session', null, config)
|
|
const certificateImage = (params) => mPost('/uec/recognize/certificate-img', params, config)
|
|
const certificateIdentity = (params) => mPost('/uec/identify/identity', params, config)
|
|
const ocrLicense = (params) => mPost('/uec/recognize/business-license', params, config)
|
|
const checkLicense = (params) => mPost('/uec/identify/enterprise/by-three-keys', params, config)
|
|
|
|
// ****************************************************************************************************************************************
|
|
// /authorize/by-wechat-applet小程序登录
|
|
function loginWechat(form) {
|
|
let promise = new Promise(function (resolve, reject) {
|
|
if (!form.encryptedData) {
|
|
util.showToast('授权被拒绝,获取微信用户失败')
|
|
reject('授权被拒绝,获取微信用户失败')
|
|
return
|
|
}
|
|
wx.showLoading({ title: '登录中', mask: true })
|
|
var tempToken = storage.get('tmpAuthToken')
|
|
if(!util.isEmpty(tempToken)){
|
|
form.tmpAuthToken = tempToken
|
|
unionWechat(form, resolve, reject)
|
|
} else {
|
|
wx.login({
|
|
success: res => {
|
|
// 获取openId
|
|
wx.request({
|
|
header: { 'X-APP-ID': app.xAppId },
|
|
url: config.baseUrl + '/uec/get/wechat-applet-session',
|
|
data: { authCode: res.code },
|
|
method: 'POST',
|
|
success: function (result) {
|
|
if (result.data.code == 0) {
|
|
form.tmpAuthToken = result.data.data.tmpAuthToken
|
|
storage.put('tmpAuthToken', form.tmpAuthToken, 98)
|
|
// 微信登录,获取unionId
|
|
unionWechat(form, resolve, reject)
|
|
} else {
|
|
wx.hideLoading()
|
|
util.showToast('登录失败,请稍后再试')
|
|
reject('登录失败,请稍后再试')
|
|
}
|
|
},
|
|
fail: function (err) {
|
|
wx.hideLoading()
|
|
util.showToast('登录失败,请稍后再试')
|
|
reject('登录失败,请稍后再试')
|
|
}
|
|
})
|
|
},
|
|
fail: function (err) {
|
|
wx.hideLoading()
|
|
util.showToast('登录失败,请稍后再试')
|
|
reject('登录失败,请稍后再试')
|
|
}
|
|
})
|
|
}
|
|
})
|
|
return promise
|
|
}
|
|
|
|
// POST /uec/authorize/by-wechat-applet 通过小程序的方式进行认证
|
|
function unionWechat(form, resolve, reject) {
|
|
wx.request({
|
|
header: { 'X-APP-ID': app.xAppId },
|
|
url: config.baseUrl + '/uec/authorize/by-wechat-applet',
|
|
data: form,
|
|
method: 'POST',
|
|
success: function (result) {
|
|
if (result.data.code == 0) {
|
|
storage.remove('tempToken')
|
|
resolve(result.data)
|
|
} else {
|
|
reject(result.data)
|
|
}
|
|
},
|
|
fail: function () {
|
|
wx.hideLoading()
|
|
wx.showToast({ title: '获取用户信息,请稍后再试', icon: "none" })
|
|
reject('请求错误!')
|
|
}
|
|
})
|
|
}
|
|
// ****************************************************************************************************************************************
|
|
// 通过微信的方式登录,onGotPhoneNumber中统一处理/uec/decrypt/wechat-applet-mobile
|
|
function gotPhoneNumber(form, resolve, reject) {
|
|
// 获取手机号码 /authorize/encrypt/mobile
|
|
wx.request({
|
|
header: { 'X-APP-ID': app.xAppId },
|
|
url: config.baseUrl + '/uec/decrypt/wechat-applet-mobile',
|
|
data: form,
|
|
method: 'POST',
|
|
success: function (result) {
|
|
// 绑定手机号码,进行登录
|
|
wx.hideLoading()
|
|
if (result.data.code != 0) {
|
|
wx.showToast({ title: '登录失败,请稍后再试', icon: "none" })
|
|
reject('登录失败,请稍后再试')
|
|
return
|
|
}
|
|
result.data.tmpAuthToken = form.tmpAuthToken
|
|
resolve(result.data)
|
|
},
|
|
fail: function (res) {
|
|
wx.hideLoading()
|
|
wx.showToast({ title: '登录失败,请稍后再试', icon: "none" })
|
|
reject('登录失败,请稍后再试')
|
|
}
|
|
})
|
|
}
|
|
|
|
function phoneWechat(form) {
|
|
let promise = new Promise(function (resolve, reject) {
|
|
if (!form.encryptedData) {
|
|
wx.showToast({ title: '授权被拒绝,登录失败', icon: "none" })
|
|
reject('授权被拒绝,登录失败')
|
|
return
|
|
}
|
|
wx.showLoading({ title: '登录中', mask: true })
|
|
// 没有获取到openId,获取之后进行登录
|
|
wx.login({
|
|
success: res => {
|
|
// 获取openId
|
|
wx.request({
|
|
header: { 'X-APP-ID': app.xAppId },
|
|
url: config.baseUrl + '/uec/get/wechat-applet-session',
|
|
data: { authCode: res.code },
|
|
method: 'POST',
|
|
success: function (result) {
|
|
if (result.data.code == 0) {
|
|
form.tmpAuthToken = result.data.data.tmpAuthToken
|
|
// 获取手机号码
|
|
gotPhoneNumber(form, resolve, reject)
|
|
} else {
|
|
wx.hideLoading()
|
|
wx.showToast({ title: '登录失败,请稍后再试', icon: "none" })
|
|
reject('登录失败,请稍后再试')
|
|
}
|
|
},
|
|
fail: function (res) {
|
|
wx.hideLoading()
|
|
wx.showToast({ title: '登录失败,请稍后再试', icon: "none" })
|
|
reject('登录失败,请稍后再试')
|
|
}
|
|
})
|
|
},
|
|
fail: function (res) {
|
|
wx.hideLoading()
|
|
wx.showToast({ title: '登录失败,请稍后再试', icon: "none" })
|
|
reject('登录失败,请稍后再试')
|
|
}
|
|
})
|
|
})
|
|
return promise
|
|
}
|
|
|
|
function finalizeToken(){
|
|
config.header = null
|
|
mconfig.header = null
|
|
pconfig.header = null
|
|
sconfig.header = null
|
|
zconfig.header = null
|
|
}
|
|
|
|
export {
|
|
config,
|
|
finalizeToken,
|
|
wechatApplet,
|
|
getUserInfo,
|
|
updateUserInfo,
|
|
postCaptcha,
|
|
loginPwd,
|
|
loginCaptcha,
|
|
getAuthSession,
|
|
certificateImage,
|
|
certificateIdentity,
|
|
phoneWechat,
|
|
loginWechat,
|
|
setPassword,
|
|
modifyMobile,
|
|
ocrLicense,
|
|
checkLicense
|
|
}
|