官方網站: https://open.weixin.qq.com
(一定要看官方API,能讓你少走十萬八千里的彎路!!!!自我警告⚠️)
代碼如下:
1.1在index.html中引入wxLogin.js
<script type='text/javascript' src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
2.2根據需求,在點擊的時候出現二維碼,在methods中單獨寫了二維碼的方法並在點擊事件中執行。二維碼代碼如下:
var obj=new WxLogin({
self_redirect:false,
id:'qrcode',
appid:'wxe19e3e2415e89353',
scope:'snsapi_login',
redirect_uri:encodeURIComponent('http://www.coolarch.net/Mingzhu/wechat/callBack'),
state:'1211111',
style:'black',
href:'',
})
tips:
- 出現了redirect_uri 參數錯誤
出現很多解決方法,其中包括不需要寫http://的,實踐證明,去掉http://是不行的。
2.self_redirect爲true的時候,出現了很'魔幻'的事情