# 导入依赖包
npm i -S weixin-js-sdk
1
# 前端页面使用
import wx from 'weixin-js-sdk'
this.axios({
method: 'post',
url: 'http://my.service.com/index.php/opcode/6002',
data:{ url:location.href.split('#')[0] } //向服务端提供授权url参数,并且不需要#后面的部分
}).then((res)=>{
wx.config({
debug: true, // 开启调试模式,
appId: res.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
timestamp: res.timestamp, // 必填,生成签名的时间戳
nonceStr: res.nonceStr, // 必填,生成签名的随机串
signature: res.signature,// 必填,签名,见附录1
jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15