微信公众号鉴权流程
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.
 
 
 

62 lines
2.0 KiB

<html>
<head>
<title>Express</title>
<link rel="stylesheet" href="/stylesheets/style.css">
<link rel="stylesheet" href="/stylesheets/base.css">
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script src="/javascripts/axios.min.js"></script>
<script src="/javascripts/vue.min.js"></script>
</head>
<body>
<div id="app">
<h1>Express</h1>
<p @click="scanCode">扫描二维码</p>
</div>
</body>
<script lang="javascript">
new Vue({
el: '#app',
mounted() {
this.wxconfig()
},
methods: {
wxconfig() {
var host = location.origin || 'http://gitea.huaxianli.com:3000' //'http://wxtest.huaxianli.com' //'http://huaxianli.gicp.net'
axios.get(host + '/jsapi?url=' + encodeURIComponent(location.href.split('#')[0]))
.then((result) => {
let { appid
, timestamp
, noncestr
, signature } = result.data
console.log('>>>data', result.data)
wx.config({
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: appid, // 必填,公众号的唯一标识
timestamp, // 必填,生成签名的时间戳
nonceStr: noncestr, // 必填,生成签名的随机串
signature,// 必填,签名
jsApiList: [
'scanQRCode'
] // 必填,需要使用的JS接口列表
})
})
},
scanCode() {
wx.scanQRCode({
needResult: 0, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: function (res) {
var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
}
})
}
}
})
</script>
</html>