App.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <div id="app">
  3. <router-view></router-view>
  4. </div>
  5. </template>
  6. <script>
  7. import API from './api/index'
  8. import wx from 'weixin-js-sdk'
  9. import util from './util/index'
  10. export default {
  11. name: 'app',
  12. mounted(){
  13. // window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx307150d9062ebdf4&redirect_uri=http%3A%2F%2Fwww.qingyingtech.com%2Fmobile&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'
  14. this.checkUserAuth();
  15. },
  16. methods:{
  17. // 检查用户是否授权过
  18. checkUserAuth(){
  19. let openId = this.$cookie.get('openId');
  20. if(!openId){
  21. window.location.href = API.wechatRedirect;
  22. }else{
  23. this.getWechatConfig();
  24. }
  25. },
  26. // 获取微信配置信息
  27. getWechatConfig(){
  28. this.$http.get(API.wechatConfig+'?url='+location.href.split('#')[0]).then(function(response){
  29. let res = response.data;
  30. if(res.code == 0){
  31. let data = res.data;
  32. wx.config({
  33. debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  34. appId: data.appId, // 必填,公众号的唯一标识
  35. timestamp: data.timestamp, // 必填,生成签名的时间戳
  36. nonceStr: data.nonceStr, // 必填,生成签名的随机串
  37. signature: data.signature,// 必填,签名
  38. jsApiList: data.jsApiList // 必填,需要使用的JS接口列表
  39. })
  40. wx.ready(()=>{
  41. util.initShareInfo(wx);
  42. })
  43. }
  44. })
  45. }
  46. }
  47. }
  48. </script>
  49. <style>
  50. </style>