Commit ee7458d0 authored by xulili's avatar xulili

二维码生成

parent 60e16ded
......@@ -7,6 +7,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>亿百分</title>
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>
<body>
......
This diff is collapsed.
......@@ -20,7 +20,7 @@
<!-- <button class="testButton" @click="zTestPreAuthCode">preAuthCodeUrl</button>
<div class="fkwindow">{{zcache.preAuthCodeUrl}}</div> -->
<!--
<!--
<button class="testButton" @click="zTestGetNowUrlInfo">nowUrlInfo</button>
<div class="fkwindow">{{zcache.nowUrl}}</div> -->
......@@ -106,7 +106,7 @@ export default {
);
if (this.$route.query.code === undefined) {
this.zTestPreAuthCode();
// this.zTestPreAuthCode();
} else {
this.zTestGetNowUrlInfo()
this.zTestGetUserInfoByOldToken()
......@@ -365,4 +365,4 @@ export default {
font-size: 14px;
word-wrap: break-word;
}
</style>
\ No newline at end of file
</style>
<template>
<div class="qr-code">
<canvas id="QRCode_header"></canvas>
<img id="image" src="" alt="">
</div>
</template>
<script>
import QRCode from 'qrcode'
import axios from 'axios'
export default {
name: 'index',
data(){
return{
QRCodeMsg:''
data() {
return {
accessToken: ""
}
},
mounted(){
this.creatQrCode()
mounted() {
this.getAcessToken()
this.createCode()
},
methods:{
creatQrCode(){
let opts = {
errorCorrectionLevel: "H",//容错级别
type: "image/png",//生成的二维码类型
quality: 0.3,//二维码质量
margin: 12,//二维码留白边距
width: 200,//宽
height: 180,//高
color: {
dark: "#333333",//前景色
light: "#fff"//背景色
methods: {
getAcessToken(){
let _this = this
axios({
url: "http://139.155.48.151:8085/workWx/auth/oauth2/getAccessToken",
method: "get",
}).then(res=>{
_this.accessToken = res.data.data
_this.createCode()
})
},
createCode() {
let pageUrl = `/wxx/cgi-bin/wxaapp/createwxaqrcode?access_token=${this.accessToken}`
$.ajax({
type: "POST",
url: pageUrl,
data: JSON.stringify({"path": "pages/signIn/signIn"}),
xhrFields: { responseType: "arraybuffer" },
success: function (res) {
let imgUrl = 'data:image/png;base64,' + btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''))
$('#image').attr('src',imgUrl)
},
error: function (data) {
console.log(data)
}
};
// this.QRCodeMsg = window.location.href; //生成的二维码为URL地址js
// this.QRCodeMsg = window.location.href; //生成的二维码为URL地址js
alert(`${window.location.origin}/voucherInfo`)
this.QRCodeMsg = `${window.location.origin}/voucherInfo`; //生成的二维码为URL地址js
let msg = document.getElementById("QRCode_header");
// 将获取到的数据(val)画到msg(canvas)上
QRCode.toCanvas(msg, this.QRCodeMsg, opts, function (error) {
console.log(error)
});
},
}
}
}
</script>
<style scoped lang="scss">
.qr-code{
text-align: center;
padding-top: 50px;
#image {
display: inline-block;
width: 60%;
}
}
</style>
......@@ -22,6 +22,14 @@ module.exports = {
'^/api': ''
}
},
'/wxx': {
ws: false,
target: 'https://api.weixin.qq.com',
changeOrigin: true,
pathRewrite: {
'^/wxx': ''
}
},
}
},
css: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment