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.
 
 
 
 
 
 

39 rivejä
1.6 KiB

  1. import wx from './weixin-js-sdk.js';
  2. export default {
  3. scanCodeFun() {
  4. const promise = new Promise((resolve, reject) => {
  5. this.HTTP_GET("weixinapi/getweixinwebaccess_token?url=" + encodeURIComponent(window.location.href)).then((success)=>{
  6. if(!success){
  7. resolve(false)
  8. return
  9. }
  10. wx.config({
  11. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  12. appId: success.appid, // 必填,公众号的唯一标识
  13. timestamp: success.timestamp, // 必填,生成签名的时间戳
  14. nonceStr: success.noncestr, // 必填,生成签名的随机串
  15. signature: success.certificate, // 必填,签名
  16. jsApiList: ["scanQRCode"] // 必填,需要使用的JS接口列表
  17. });
  18. wx.ready(() => {
  19. wx.scanQRCode({
  20. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  21. scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
  22. success: function (res) {
  23. var result = res.resultStr; // 当 needResult 为 1 时,扫码返回的结果
  24. var resultArr = result.split(','); // 扫描结果以逗号分割数组
  25. var codeContent = resultArr[resultArr.length - 1]; // 获取数组最后一个元素,也就是最终的内容
  26. resolve({result:codeContent})
  27. },
  28. fail: function (res) {
  29. this.TOAST("调用扫码失败")
  30. resolve(false)
  31. }
  32. });
  33. })
  34. })
  35. })
  36. return promise
  37. }
  38. }