tools.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const util = require('../utils/util.js');
  2. // 登录状态
  3. const rzStatus = () => {
  4. return new Promise((resolve, reject) => {
  5. wx.login({
  6. success: (res) => {
  7. if (res.code) {
  8. wx.request({
  9. url: util.globalData.publicUrl + '/wx/getAppletOpenId',
  10. method: "GET",
  11. data: {
  12. cid: 'applet',
  13. code: res.code
  14. },
  15. success: res => {
  16. if (res.data.status == 200) {
  17. wx.setStorageSync('openId', res.data.data.openid)
  18. wx.request({
  19. url: util.globalData.publicUrl + '/applet/isExist',
  20. method: "GET",
  21. data: {
  22. appletsId: wx.getStorageSync('openId')
  23. },
  24. success: (res) => {
  25. console.log('是否绑定', res.data.code);
  26. resolve(res);
  27. },
  28. fail: (res) => {
  29. reject(res)
  30. }
  31. })
  32. }
  33. }
  34. });
  35. } else {
  36. console.log('获取用户登录态失败!' + res.errMsg);
  37. }
  38. }
  39. })
  40. })
  41. };
  42. const finishInfo = () => {
  43. return new Promise((resolve, reject) => {
  44. wx.request({
  45. url: util.globalData.publicUrl + '/user/isPerfect',
  46. method: "GET",
  47. header: {
  48. appletsId: wx.getStorageSync('openId')
  49. },
  50. success: (res) => {
  51. console.log(res.data)
  52. resolve(res)
  53. },
  54. fail: (re) => {
  55. reject(re)
  56. }
  57. })
  58. })
  59. };
  60. module.exports = {
  61. rzStatus,
  62. finishInfo
  63. }