openPlatform.js 873 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // 登录
  2. import { isEmpty } from 'lodash';
  3. import third from '@/sheep/api/third';
  4. const load = async () => {};
  5. // 微信开放平台移动应用授权登陆
  6. const login = () => {
  7. return new Promise(async (resolve, reject) => {
  8. const loginRes = await uni.login({
  9. provider: 'weixin',
  10. onlyAuthorize: true,
  11. });
  12. if (loginRes.errMsg == 'login:ok') {
  13. const res = await third.wechat.login({
  14. platform: 'openPlatform',
  15. shareInfo: uni.getStorageSync('shareLog') || {},
  16. payload: encodeURIComponent(
  17. JSON.stringify({
  18. code: loginRes.code,
  19. }),
  20. ),
  21. });
  22. if (res.code === 1) {
  23. resolve(true);
  24. }
  25. } else {
  26. uni.showToast({
  27. icon: 'none',
  28. title: loginRes.errMsg,
  29. });
  30. }
  31. resolve(false);
  32. });
  33. };
  34. export default {
  35. load,
  36. login,
  37. };