initALI.js 946 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import carhelp from '@/apis/utils/mixin.js'
  2. import * as API_WeiXin from '@/apis/weixin.js'
  3. import {
  4. getUrlParam,
  5. getAlipayRedirectURI,
  6. } from '@/apis/utils'
  7. var checkOpenId = true; //是否需要获取openId
  8. var openId = carhelp.getOpenIdALI();
  9. var app = {
  10. init: function() {
  11. if (!openId) {
  12. this.getOpenId();
  13. }
  14. },
  15. getOpenId() {
  16. const code = getUrlParam('auth_code');
  17. var openId= carhelp.getOpenIdALI()
  18. if (!openId) {
  19. if (!code) {
  20. var authUrl = document.URL//.replace('pages/parking/search', 'pages/parking/auth');
  21. window.location.href = getAlipayRedirectURI(process.car.VUE_APP_ALIAPPID, authUrl );
  22. } else {
  23. API_WeiXin.getDataByCodeALI(code).then(response => {
  24. carhelp.setOpenIdALI(response.data.openid)
  25. location.reload();
  26. }).catch(error => {
  27. console.log(error);
  28. });
  29. }
  30. }
  31. }
  32. }
  33. module.exports = app