qr_address.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. var axios = require('axios');
  2. var fs = require('fs');
  3. module.exports = async (ctx, next) => {
  4. if (ctx.state.$wxInfo.loginState === 1) {
  5. /* async await和koa的执行顺序问题?????*/
  6. let secret = require('../config.js').appSecret,
  7. appId = require('../config.js').appId
  8. console.log('appId', appId)
  9. // let url_access_token = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appId+'&secret=' + secret, access_token
  10. // axios.get(url_access_token)
  11. // .then(function (res) {
  12. // access_token = res.data.access_token
  13. // console.log('access_token', access_token)
  14. // let url_qr = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=' + access_token
  15. // axios({
  16. // method: "POST",
  17. // url: url_qr,
  18. // data: { path: "pages/web_view/web_view" },
  19. // responseType: 'arraybuffer' //必须要写!
  20. // }).then((res) => {
  21. // console.log('res', res);
  22. // var originBuffer = res.data
  23. // console.log(Buffer.isBuffer(originBuffer));
  24. // fs.writeFile('./qr.jpg', originBuffer, function (err) { //此段代码写在本地吧,让图片在本地生成,在手工上传到服务器上
  25. // if (err) { console.log(err) }
  26. // });
  27. // });
  28. // })
  29. } else {
  30. ctx.state.code = -1
  31. }
  32. }