wxLogin.js 983 B

12345678910111213141516171819202122232425
  1. import store from '@/store/index.js'
  2. import authorize from '@/common/config/authorize.js'
  3. import { userInfoLogin } from "@/api/use.js"
  4. // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  5. const wxLoginAuthorize = function(){
  6. authorize.getCode('weixin').then(wechatcode =>{
  7. authorize.getUserInfo('weixin').then(wxResponse =>{
  8. userInfoLogin({code:wechatcode,encryptedData:wxResponse.encryptedData,iv:wxResponse.iv}).then(response =>{
  9. store.commit('updateStatus',response.data)
  10. store.commit('login',response.data);
  11. uni.setStorageSync('token',response.data.token)
  12. uni.removeStorageSync('sessionid')
  13. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  14. }).catch(response =>{
  15. uni.removeStorageSync('sessionid')
  16. uni.setStorageSync('sessionid','JSESSIONID='+response.data)
  17. store.commit('logout',response.data)
  18. store.commit('updateStatus',response.data)
  19. })
  20. })
  21. })
  22. }
  23. export default{
  24. wxLoginAuthorize
  25. }