app.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const util = require('./utils/util.js');
  2. App({
  3. globalData: {
  4. showAnimation: true,
  5. id: null,
  6. name: null,
  7. },
  8. onError(msg) {
  9. console.log(msg)
  10. },
  11. getAuthKey: function () {
  12. console.log("apppppppjsjsjsjsjjsjsj");
  13. return new Promise(function (resolve, reject) {
  14. wx.login({
  15. success: function (res) {
  16. if (res.code) {
  17. wx.request({
  18. url: util.globalData.publicUrl + '/wx/getAppletOpenId',
  19. method: "GET",
  20. data: {
  21. cid: 'applet',
  22. code: res.code
  23. },
  24. success: res => {
  25. // 获取到用户的 openid
  26. if (res.data.status == 200) {
  27. wx.setStorageSync('openId', res.data.data.openid)
  28. wx.request({
  29. url: util.globalData.publicUrl + '/applet/isExist',
  30. method: "GET",
  31. data: {
  32. appletsId: wx.getStorageSync('openId')
  33. },
  34. success: (res) => {
  35. console.log('app登录是否绑定的', res.data.code);
  36. if (res.data.code == 0) {
  37. if (res.data.data) {
  38. wx.setStorageSync('user', 'user');
  39. }
  40. resolve(res);
  41. }else{
  42. wx.clearStorageSync();
  43. }
  44. }
  45. })
  46. }
  47. }
  48. });
  49. } else {
  50. console.log('获取用户登录态失败!' + res.errMsg);
  51. var res = {
  52. status: 300,
  53. data: '错误'
  54. }
  55. reject('error');
  56. }
  57. }
  58. })
  59. });
  60. },
  61. })