丰都投票界面已完成
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import http from "./http";
|
||||
import Vue from "vue";
|
||||
import CryptoJS from "./crypto-js";
|
||||
import qs from 'query-string'
|
||||
|
||||
/**
|
||||
* 用户登录信息和方法
|
||||
@@ -136,6 +137,41 @@ export const user = {
|
||||
} else return Promise.reject(res.msg)
|
||||
})
|
||||
},
|
||||
getWechatToken({commit, dispatch}, params) {
|
||||
const encryptByDES = password => {
|
||||
let isIos = uni.getSystemInfoSync().system.toUpperCase == 'ios'
|
||||
let key = "thanks,villcloud"
|
||||
let iv = CryptoJS.enc.Latin1.parse(key)
|
||||
let encrypted = CryptoJS.AES.encrypt(password, iv, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.ZeroPadding
|
||||
})
|
||||
if (isIos) {
|
||||
return encodeURIComponent(encrypted.toString());
|
||||
} else {
|
||||
return encrypted.toString();
|
||||
}
|
||||
}
|
||||
let {module} = params, action = "/auth/wechat-mp/token"
|
||||
return http.post(action, params, {
|
||||
withoutToken: true,
|
||||
module,
|
||||
params: {
|
||||
...params, grant_type: 'password',
|
||||
password: encryptByDES(params.password)
|
||||
},
|
||||
headers: {
|
||||
Authorization: "Basic d3htcDp3eG1w"
|
||||
}
|
||||
}).then(res => {
|
||||
if (res?.access_token) {
|
||||
const token = [res?.token_type, res?.access_token].join(" ").trim()
|
||||
commit("setToken", token)
|
||||
return token
|
||||
} else return Promise.reject(res.msg)
|
||||
})
|
||||
},
|
||||
getAccount({dispatch, commit}, config) {
|
||||
//获取企业微信后台账号信息
|
||||
return http.post("/admin/user/detail-phone", null, config).then(res => {
|
||||
@@ -161,6 +197,20 @@ export const user = {
|
||||
* 企微jssdk功能
|
||||
*/
|
||||
let timer = {}
|
||||
/**
|
||||
* 微信oauth2跳转链接
|
||||
* https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&agentid=AGENTID#wechat_redirect
|
||||
* @param params
|
||||
*/
|
||||
const oauth2Weixin = params => qs.stringifyUrl({
|
||||
url: "https://open.weixin.qq.com/connect/oauth2/authorize",
|
||||
query: {
|
||||
response_type: 'code',
|
||||
url: encodeURIComponent(location.href),
|
||||
...params
|
||||
},
|
||||
fragmentIdentifier: "wechat_redirect"
|
||||
})
|
||||
export const wxwork = {
|
||||
state: () => ({
|
||||
agentSignURL: "",
|
||||
@@ -218,27 +268,34 @@ export const wxwork = {
|
||||
})
|
||||
}
|
||||
},
|
||||
getCode({state, dispatch}, tryAgentSign = false) {
|
||||
let {corpid: corpId, suiteId, agentid: agentId} = state.config, url = location.href, REDIRECT_URI = encodeURIComponent(url), scope = "snsapi_privateinfo"
|
||||
if (/AppForm/.test(location.pathname)) {
|
||||
scope = "snsapi_base"
|
||||
} else if (suiteId) {
|
||||
corpId = suiteId
|
||||
scope = "snsapi_privateinfo"
|
||||
getCode({state, dispatch}, params) {
|
||||
const excute = (tryAgentSign = false) => {
|
||||
if (!params.appid) {
|
||||
let {corpid: corpId, suiteId, agentid} = state.config, scope = "snsapi_privateinfo"
|
||||
if (/AppForm/.test(location.pathname)) {
|
||||
scope = "snsapi_base"
|
||||
} else if (suiteId) {
|
||||
corpId = suiteId
|
||||
scope = "snsapi_privateinfo"
|
||||
}
|
||||
params = {appid: corpId, agentid, scope}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (corpId && scope) {
|
||||
const oauthURL = oauth2Weixin(params)
|
||||
location.replace(oauthURL)
|
||||
} else if (!tryAgentSign && corpId) {
|
||||
dispatch("agentSign", {corpId, suiteId}).then(() => excute(true)).then(() => resolve())
|
||||
} else reject("URL缺少必要参数(corpId)")
|
||||
})
|
||||
} else new Promise((resolve, reject) => {
|
||||
const {appid} = params
|
||||
if (!!appid) {
|
||||
const oauthURL = oauth2Weixin(params)
|
||||
location.replace(oauthURL)
|
||||
} else reject("URL缺少必要参数(appid)")
|
||||
})
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (corpId && scope) {
|
||||
let oauthURL = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&agentid=AGENTID#wechat_redirect'
|
||||
.replace(/APPID/g, corpId)
|
||||
.replace(/REDIRECT_URI/g, REDIRECT_URI)
|
||||
.replace(/SCOPE/g, scope)
|
||||
.replace(/AGENTID/g, agentId)
|
||||
console.log(location, oauthURL)
|
||||
location.replace(oauthURL)
|
||||
} else if (!tryAgentSign && corpId) {
|
||||
dispatch("agentSign", {corpId, suiteId}).then(() => dispatch("getCode", true)).then(() => resolve())
|
||||
} else reject("URL缺少必要参数(corpId)")
|
||||
})
|
||||
return excute()
|
||||
},
|
||||
injectJWeixin({state, commit, rootState}, apis) {
|
||||
const inject = (jsApiList) => new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user