From 874d34f6df838341734940e0d700b8e0cd540ac0 Mon Sep 17 00:00:00 2001 From: tcubic <123456> Date: Mon, 1 Aug 2022 15:54:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/authorize-api-old.js | 127 +++++++++++++++++++++++++++++++++++ src/api/authorize-api.js | 100 +++------------------------ src/components/Index.vue | 21 +++++- src/page/Home/Home.vue | 8 ++- 4 files changed, 161 insertions(+), 95 deletions(-) create mode 100644 src/api/authorize-api-old.js diff --git a/src/api/authorize-api-old.js b/src/api/authorize-api-old.js new file mode 100644 index 0000000..5558fc5 --- /dev/null +++ b/src/api/authorize-api-old.js @@ -0,0 +1,127 @@ +import axios from 'axios' +import qs from 'qs' + +const domain_zs = process.env.VUE_APP_ZS_AUTHORIZE_DOMAIN; +const domain_xgl = process.env.VUE_APP_XGL_AUTHORIZE_DOMAIN; +/////////////////////////// + +// get || post 请求方法封装 +function get(url, params = {}) { + return new Promise((resolve, reject) => { + axios + .get(url, { + params: params + }) + .then(res => { + resolve(res.data) + }) + .catch(err => { + reject(err) + }) + }) + // 或者return axios.get(); +} +/** + * post方法,对应post请求 + * @param {String} url [请求的url地址] + * @param {Object} params [请求时携带的参数] + */ +function post(url, params) { + return new Promise((resolve, reject) => { + axios + .post(url, qs.stringify(params)) + .then(res => { + resolve(res.data) + }) + .catch(err => { + reject(err) + }) + }) + // 或者return axios.post(); +} + + + +// 1.公众号网页授权 +// 请求方法:get请求 +// 请求链接:/wxauth/official/account/authorize +// 请求参数: +// redirectUrl 请求链接 +// scope 授权类型:0用户授权,1静默授权 +// 返回值:无 +// 备注:回调页面URL后可能携带参数:token、userid、forceauth。 +// 先取token,如有,表示登录成功(登录成功userid会有值), +// 如token无值,取forceauth,为1时表示需要进行0-用户授权跳转。 +function get_authorize() { + let href = window.location.href + let h_idx = window.location.href.indexOf('#') + let out_href = href.slice(0, h_idx) + + window.location.href = `${domain_xgl}/wxauth/official/account/authorize?redirectUrl=${out_href}&scope=${1}"` +} + + +// 2.获取微信公众号jssdk +// 请求方法:get请求 +// 请求链接:/wxauth/official/account/jssdk/get +// 请求参数: +// url 请求链接 +function get_jssdk(url, params) { + // Bus.debug && (params.openid = Bus.testOpenId) + // return readyGet(domain_zs + "/wxauth/official/account/jssdk/get", params) + return new Promise((resolve, reject) => { + axios + .get(url, { + params: params + }) + .then(res => { + resolve(res.data) + }) + .catch(err => { + reject(err) + }) + }) + +} + +function getOpenId(code) { + return new Promise((reslove, reject) => { + utils.rebuildAjax.post(process.env.VUE_APP_BASE_URL + 'cott-acts/api/wx/oauthInfo', { + code + }).then((res) => { + if (res.ret == 0) { + Vue.prototype.$userInfo = { + openid: res.data.openid, + nickname: res.data.nickname, + headimgurl: res.data.headimgurl + }; + reslove(); + } else { + location.replace(window.location.protocol + '//' + window.location.host + window.location.pathname) + } + }) + }) + +} + +// 获取wx 授权 code +function getCode(activityId, gameId, rankType) { + let redirect_uri = `${window.location.protocol}//${window.location.host + window.location.pathname}?activityId=${activityId}&gameId=${gameId}&rankType=${rankType}`; + utils.rebuildAjax.post(process.env.VUE_APP_BASE_URL + 'cott-acts/api/wx/getOAuthUrl', { + redirect_uri + }).then((res) => { + if (res.ret == 0) { + console.log(res.url) + location.replace(res.url); + } + }) +} + + + + + +export { + get_authorize, + get_jssdk, +} diff --git a/src/api/authorize-api.js b/src/api/authorize-api.js index 5558fc5..2075a8b 100644 --- a/src/api/authorize-api.js +++ b/src/api/authorize-api.js @@ -1,46 +1,10 @@ -import axios from 'axios' -import qs from 'qs' +import Bus from "../bus.js"; +import {readyPost,readyGet} from "./base.js" -const domain_zs = process.env.VUE_APP_ZS_AUTHORIZE_DOMAIN; -const domain_xgl = process.env.VUE_APP_XGL_AUTHORIZE_DOMAIN; +const domain_zs = process.env.VUE_APP_ZS_AUTHORIZE_DOMAIN ; +const domain_xgl = process.env.VUE_APP_XGL_AUTHORIZE_DOMAIN ; /////////////////////////// -// get || post 请求方法封装 -function get(url, params = {}) { - return new Promise((resolve, reject) => { - axios - .get(url, { - params: params - }) - .then(res => { - resolve(res.data) - }) - .catch(err => { - reject(err) - }) - }) - // 或者return axios.get(); -} -/** - * post方法,对应post请求 - * @param {String} url [请求的url地址] - * @param {Object} params [请求时携带的参数] - */ -function post(url, params) { - return new Promise((resolve, reject) => { - axios - .post(url, qs.stringify(params)) - .then(res => { - resolve(res.data) - }) - .catch(err => { - reject(err) - }) - }) - // 或者return axios.post(); -} - - // 1.公众号网页授权 // 请求方法:get请求 @@ -55,9 +19,9 @@ function post(url, params) { function get_authorize() { let href = window.location.href let h_idx = window.location.href.indexOf('#') - let out_href = href.slice(0, h_idx) + let out_href = href.slice(0,h_idx) - window.location.href = `${domain_xgl}/wxauth/official/account/authorize?redirectUrl=${out_href}&scope=${1}"` + window.location.href = `${domain_zs}/wxauth/official/account/authorize?redirectUrl=${out_href}&scope=${1}"` } @@ -65,56 +29,10 @@ function get_authorize() { // 请求方法:get请求 // 请求链接:/wxauth/official/account/jssdk/get // 请求参数: -// url 请求链接 -function get_jssdk(url, params) { +// url 请求链接 +function get_jssdk(params) { // Bus.debug && (params.openid = Bus.testOpenId) - // return readyGet(domain_zs + "/wxauth/official/account/jssdk/get", params) - return new Promise((resolve, reject) => { - axios - .get(url, { - params: params - }) - .then(res => { - resolve(res.data) - }) - .catch(err => { - reject(err) - }) - }) - -} - -function getOpenId(code) { - return new Promise((reslove, reject) => { - utils.rebuildAjax.post(process.env.VUE_APP_BASE_URL + 'cott-acts/api/wx/oauthInfo', { - code - }).then((res) => { - if (res.ret == 0) { - Vue.prototype.$userInfo = { - openid: res.data.openid, - nickname: res.data.nickname, - headimgurl: res.data.headimgurl - }; - reslove(); - } else { - location.replace(window.location.protocol + '//' + window.location.host + window.location.pathname) - } - }) - }) - -} - -// 获取wx 授权 code -function getCode(activityId, gameId, rankType) { - let redirect_uri = `${window.location.protocol}//${window.location.host + window.location.pathname}?activityId=${activityId}&gameId=${gameId}&rankType=${rankType}`; - utils.rebuildAjax.post(process.env.VUE_APP_BASE_URL + 'cott-acts/api/wx/getOAuthUrl', { - redirect_uri - }).then((res) => { - if (res.ret == 0) { - console.log(res.url) - location.replace(res.url); - } - }) + return readyGet(domain_zs + "/wxauth/official/account/jssdk/get", params) } diff --git a/src/components/Index.vue b/src/components/Index.vue index 91f51f0..ba98328 100644 --- a/src/components/Index.vue +++ b/src/components/Index.vue @@ -77,7 +77,7 @@ import gsap from "gsap"; import axios from 'axios' import { Toast, Dialog } from 'vant'; import { useStore } from "vuex"; -import { get_authorize, get_jssdk } from '@/api/authorize-api' +// import { get_authorize, get_jssdk } from '@/api/authorize-api' import service from "@/api/httpServe" import qs from 'qs' import h5plugin from '@/utils/plugin' @@ -180,6 +180,8 @@ const btn = () => { // 抽奖按钮 const drawBtn = ()=>{ console.log("抽奖:"); + console.log("授权:",getAuthorize()); + } @@ -216,6 +218,23 @@ const hideServicePop = () => { } +// 招商证券授权 +const getAuthorize = ()=> { + // let href = window.location.href + // let h_idx = window.location.href.indexOf('#') + // let out_href = href.slice(0,h_idx) + + // window.location.href = `${process.env.VUE_APP_ZS_DOMAIN}/wxauth/official/account/authorize?redirectUrl=${out_href}&scope=${1}"` + + + let href = window.location.href; + let h_idx = window.location.href.indexOf("#"); + let out_href = href.slice(0, h_idx); + + return `${process.env.VUE_APP_ZS_DOMAIN}/wxauth/official/account/authorize?redirectUrl=${out_href}&scope=${1}"`; +} + +