完成XGL微信授权

This commit is contained in:
Andy Leong 2022-07-28 19:26:05 +08:00
parent 30727f4f65
commit 0be21f0195
12 changed files with 403 additions and 82 deletions

View File

@ -1,6 +1,17 @@
// 生产环境
NODE_ENV = 'production' NODE_ENV = 'production'
// 入口地址
VUE_APP_BASE_URL = 'https://cdn.xglpa.com/tcubic/pdf/' VUE_APP_BASE_URL = 'https://cdn.xglpa.com/tcubic/pdf/'
// 业务接口
VUE_APP_API = 'https://cdn.xglpa.com/tcubic/pdf/' VUE_APP_API = 'https://cdn.xglpa.com/tcubic/pdf/'
// CDN地址
VUE_APP_CDN = 'https://cdn.xglpa.com/tcubic/pdf/' VUE_APP_CDN = 'https://cdn.xglpa.com/tcubic/pdf/'
VUE_APP_APPID = '1aeedce2a31340e591a5d64080d6105b'
VUE_APP_ACTIVITYID = '20220510563146' // XGL授权接口
VUE_APP_XGL_DOMAIN = https://wealth.newone.com.cn
// 招商证券授权接口
VUE_APP_ZS_DOMAIN = https://wealth.newone.com.cn

View File

@ -1,6 +1,17 @@
// 测试环境
NODE_ENV = 'test' NODE_ENV = 'test'
VUE_APP_BASE_URL = 'https://hd.xglpa.com/zszq-celebration/activity/'
// 入口地址
VUE_APP_BASE_URL = 'https://test.szxgl.cn/zszq-celebration/activity/'
// 业务接口
VUE_APP_API = 'https://test.szxgl.cn/zszq-celebration' VUE_APP_API = 'https://test.szxgl.cn/zszq-celebration'
// CDN地址
VUE_APP_CDN = 'https://test.szxgl.cn/zszq-celebration/activity/' VUE_APP_CDN = 'https://test.szxgl.cn/zszq-celebration/activity/'
VUE_APP_APPID = '1aeedce2a31340e591a5d64080d6105b'
VUE_APP_ACTIVITYID = '20220510563146' // XGL授权接口
VUE_APP_XGL_DOMAIN = 'https://test.szxgl.cn/zszq-celebration/zsApi/xfhdAuthorize'
// 招商证券授权接口
VUE_APP_ZS_DOMAIN = 'https://wealth.newone.com.cn'

View File

@ -10,7 +10,7 @@ module.exports = {
host: '39.108.110.167', // 服务器地址 host: '39.108.110.167', // 服务器地址
port: 22, // 服务器端口号 port: 22, // 服务器端口号
username: 'root', // 服务器登录用户名 username: 'root', // 服务器登录用户名
password: 'XfhdTest123', // 服务器登录密码 password: 'xFhD@Test123', // 服务器登录密码
distPath: 'dist', // 本地打包生成目录 distPath: 'dist', // 本地打包生成目录
webDir: "/mnt/services/tomcat-8090-test/webapps/zszq-celebration/activity", // test替换自己实际项目目录 服务器部署路径(不可为空或'/' webDir: "/mnt/services/tomcat-8090-test/webapps/zszq-celebration/activity", // test替换自己实际项目目录 服务器部署路径(不可为空或'/'
isRemoveRemoteFile: true // 是否删除远程文件默认true isRemoveRemoteFile: true // 是否删除远程文件默认true

BIN
dist.zip

Binary file not shown.

127
src/api/authorize-api.js Normal file
View File

@ -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,
}

View File

@ -1,63 +1,144 @@
<template> <template>
<div class="welcomePage"> <div class="indexPage">
<div @click="btn">招商证券88司庆活动</div> <div>招商证券88司庆活动</div>
<div @click="auth">点击授权</div>
<div>授权信息{{ authData }}</div>
</div> </div>
</template> </template>
<script setup> <script setup>
import { onBeforeMount, onMounted, defineEmits, defineProps, reactive, ref, toRefs } from 'vue' import { onBeforeMount, onMounted, defineEmits, defineProps, reactive, ref, toRefs, getCurrentInstance, computed } from 'vue'
import gsap from "gsap"; import gsap from "gsap";
import axios from 'axios' import axios from 'axios'
import { Toast } from 'vant'; import { Toast, Dialog } from 'vant';
import { useStore } from "vuex";
import { get_authorize, get_jssdk } from '@/api/authorize-api'
import service from "@/api/httpServe"
import qs from 'qs'
import h5plugin from '@/utils/plugin'
// //
const emit = defineEmits(["welcomePage"]); // const emit = defineEmits(["indexPage"]); //
const props = defineProps({ sendMessage: Object }); // props const props = defineProps({ sendMessage: Object }); // props
const store = useStore() //vuex
const { proxy } = getCurrentInstance(); //plugin
const authData = ref('')
const authCode = ref('')
// //
onBeforeMount(() => { }) onBeforeMount(() => { })
// //
onMounted(() => { }) onMounted(() => {
console.log("用户活动信息:", store.state.userAccount);
console.log("api:", process.env.VUE_APP_XGL_DOMAIN);
console.log('code:', h5plugin.getQueryString('code'));
if (h5plugin.getQueryString('code')) {
authCode.value = h5plugin.getQueryString('code')
console.log("存在code");
getOpenId(authCode.value)
} else {
getCode()
}
})
const btn = () => { const btn = () => {
Toast('项目开发中'); // Toast('');
emit('indexPage', 'hello')
Dialog.alert({
title: '招商证券88司庆活动',
message: '项目开发中',
confirmButtonText: '确定',
showCancelButton: true,
}).then((e) => {
// openid
store.commit({ type: 'updateOpenid', openid: 'openid110' })
console.log(e, store.state.userAccount);
}).catch((e) => {
console.log(e);
});
} }
const auth = () => {
// get_authorize()
// let api = get_jssdk(process.env.VUE_APP_XGL_AUTHORIZE_DOMAIN)
// service.get('/zsApi/xfhdAuthorize')
// .then((res) => {
// console.log("", res);
// authData.value = res.data
// })
getCode()
}
// getCode
const getCode = () => {
// let redirect_uri = `${window.location.protocol}//${window.location.host + window.location.pathname}?activityId=${activityId}&gameId=${gameId}&rankType=${rankType}`;
let redirect_uri = window.location.href;
service.post(process.env.VUE_APP_API + '/zsApi/xfhdAuthorize', qs.stringify({
redirect_uri: redirect_uri
})).then((res) => {
let code = res.data.data
authCode.value = res.data.data
window.location.href = res.data.data
})
}
// getOpenid
const getOpenId = (code) => {
service.post(process.env.VUE_APP_API + '/zsApi/oauthInfo', qs.stringify({
code: code
})).then((res) => {
})
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.welcomePage { .indexPage {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
color: #000; color: #000;
flex-wrap: wrap;
flex-direction: column;
.video_container {
width: 80%;
.video {
width: 100%;
}
} }
span {
color: rgb(255, 0, 0);
font-weight: 700;
} }
</style> </style>

View File

@ -0,0 +1,63 @@
<template>
<div class="myPrizeCon">
</div>
</template>
<script setup>
import { onBeforeMount, onMounted, defineEmits, defineProps, reactive, ref, toRefs } from 'vue'
import gsap from "gsap";
import axios from 'axios'
import { Toast } from 'vant';
import { useStore } from "vuex";
//
const emit = defineEmits(["welcomePage"]); //
const props = defineProps({ sendMessage: Object }); // props
const store = useStore()
//
onBeforeMount(() => { })
//
onMounted(() => {
})
</script>
<style lang="scss" scoped>
.welcomePage {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
color: #000;
.video_container {
width: 80%;
.video {
width: 100%;
}
}
}
</style>

View File

@ -1,6 +1,9 @@
<template> <template>
<div class="homePage"> <div class="homePage">
<Index /> <!-- 加载页 -->
<!-- 首页 -->
<Index @indexPage="indexPage" />
</div> </div>
</template> </template>
@ -18,17 +21,14 @@ import Index from "@/components/Index"
onBeforeMount(() => { }); onBeforeMount(() => { });
// //
onMounted(() => { onMounted(() => { });
//
const optionShare = { //
title: '2022中国中产女性财富管理及幸福指数报告', // const indexPage = (actions) => {
desc: ' ', // console.log("来自index组件", actions);
link: process.env.VUE_APP_BASE_URL + 'index.html', //
imgUrl: process.env.VUE_APP_CDN + 'share.jpg', //
} }
wxShare(optionShare)
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -5,15 +5,26 @@ import App from './Home.vue'
import Vue from 'vue' import Vue from 'vue'
import store from '@/store' import store from '@/store'
import "amfe-flexible" import "amfe-flexible"
import h5plugin from '@/utils/plugin'
import VConsole from 'vconsole' import VConsole from 'vconsole'
const vConsole = new VConsole();
// 注册全局方法 // 注册全局方法
const app = createApp(App); const app = createApp(App);
app.config.globalProperties.$H5Plugin = h5plugin;
// 测试环境微信端才展示vconsole
if (h5plugin.isMobile() && h5plugin.isWX() && process.env.NODE_ENV == "test") {
const vConsole = new VConsole();
}
console.log("环境:", process.env.NODE_ENV)
// app.use(router) // app.use(router)
app.use(store) app.use(store)
app.mount('#app') app.mount('#app')

View File

@ -2,37 +2,33 @@ import { createStore } from 'vuex';
import h5plugin from "@/utils/plugin.js" import h5plugin from "@/utils/plugin.js"
export default createStore({ export default createStore({
// 数据源
state: { state: {
userProgress: { userAccount: {
pass1IsComplete: 0, //第一题完成情况 openid: 'openid12138', //用户openid
pass2IsComplete: 0, //第二题完成情况 token: 'token12138', //用户token
pass3IsComplete: 0, //第三题完成情况 isDraw: false, //是否抽过奖
pass1IsDraw: 0, //第一题抽奖情况 isHasAccount: false, //是否存在牛卡号
pass2IsDraw: 0, //第二题抽奖情况 isAddCustomer: false, //是否添加过服务人员
pass3IsDraw: 0, //第三题抽奖情况 isHasPrize: [], //是否存在奖品
pass1Prize: '', //第一题抽奖结果
pass2Prize: '', //第二题抽奖结果
pass3Prize: '', //第三题抽奖结果
}, //用户进度
openId: '', //用户openid
openToken: '', //用户openToken
pass1IsComplete: '', //第一题完成情况
pass1IsDraw: '', //第一题抽奖情况
pass1Prize: '', //第一题抽奖结果
pass2IsComplete: '', //第二题完成情况
pass2IsDraw: '', //第二题抽奖情况
pass2Prize: '', //第二题抽奖结果
pass3IsComplete: '', //第三题完成情况
pass3IsDraw: '', //第三题抽奖情况
pass3Prize: '', //第三题抽奖结果
}, },
// 改变方法
},
// 计算
getters: {},
// 改变方法(同步):每个 mutation 都有一个字符串的事件类型 (type)和一个回调函数 (handler)
mutations: { mutations: {
updateOpenid(state) { // 更新openid
// state.openid = changVal updateOpenid(state, val) {
// console.log(state.openid); console.log("update");
state.userAccount.openid = val.openid
} }
}, },
// 改变方法:异步
actions: {}, actions: {},
// 模块化
modules: {}, modules: {},
}) })

View File

@ -5,13 +5,23 @@ const h5plugin = {
isWX() { isWX() {
var ua = window.navigator.userAgent.toLowerCase(); var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger') { if (ua.match(/MicroMessenger/i) == 'micromessenger') {
console.log("微信环境");
return true; return true;
} else { } else {
console.log("非微信环境");
return false; return false;
} }
}, },
// 判断是否移动端
isMobile() {
let userAgentInfo = navigator.userAgent;
let Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
let getArr = Agents.filter(i => userAgentInfo.includes(i));
return getArr.length ? true : false;
},
// 判断微博环境 // 判断微博环境
isWeibo() { isWeibo() {
var ua = window.navigator.userAgent.toLowerCase(); var ua = window.navigator.userAgent.toLowerCase();
@ -260,6 +270,8 @@ const h5plugin = {
} }
export default h5plugin; export default h5plugin;

View File

@ -49,7 +49,18 @@ module.exports = {
// 开启gzip压缩 // 开启gzip压缩
configureWebpack: config => { configureWebpack: config => {
const plugins = []; const plugins = [];
if (IS_PROD) { // if (IS_PROD) {
// plugins.push(
// new CompressionWebpackPlugin({
// filename: "[path].gz[query]",
// algorithm: "gzip",
// test: productionGzipExtensions,
// threshold: 10240,
// minRatio: 0.8
// })
// );
// }
plugins.push( plugins.push(
new CompressionWebpackPlugin({ new CompressionWebpackPlugin({
filename: "[path].gz[query]", filename: "[path].gz[query]",
@ -59,8 +70,6 @@ module.exports = {
minRatio: 0.8 minRatio: 0.8
}) })
); );
}
config.plugins = [...config.plugins, ...plugins]; config.plugins = [...config.plugins, ...plugins];
}, },