openPlatform.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // 登录
  2. // import third from '@/sheep/api/third';
  3. import SocialApi from '@/sheep/api/member/social';
  4. // TODO 非繁人:等后面搞 App 再弄
  5. const socialType = 32; // 社交类型 - 微信开放平台
  6. const load = async () => {};
  7. // 微信开放平台移动应用授权登陆
  8. const login = () => {
  9. return new Promise(async (resolve, reject) => {
  10. const loginRes = await uni.login({
  11. provider: 'weixin',
  12. onlyAuthorize: true,
  13. });
  14. debugger
  15. if (loginRes.errMsg == 'login:ok') {
  16. const res = await third.wechat.login({
  17. platform: 'openPlatform',
  18. shareInfo: uni.getStorageSync('shareLog') || {},
  19. payload: encodeURIComponent(
  20. JSON.stringify({
  21. code: loginRes.code,
  22. }),
  23. ),
  24. });
  25. if (res.error === 0) {
  26. resolve(true);
  27. }
  28. } else {
  29. uni.showToast({
  30. icon: 'none',
  31. title: loginRes.errMsg,
  32. });
  33. }
  34. resolve(false);
  35. });
  36. };
  37. // 微信 App 解除绑定
  38. const unbind = async (openid) => {
  39. const { code } = await SocialApi.socialUnbind(socialType, openid);
  40. return code === 0;
  41. };
  42. // 获得社交信息
  43. async function getInfo() {
  44. const { code, data } = await SocialApi.getSocialUser(socialType);
  45. if (code !== 0) {
  46. return undefined;
  47. }
  48. return data;
  49. }
  50. export default {
  51. load,
  52. login,
  53. getInfo
  54. };