accredit.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var urlRedirectTo = "";
  5. Page({
  6. data: {
  7. ShowNotice:false,
  8. },
  9. onLoad: function (options) {
  10. urlRedirectTo = options.url;
  11. this.setData({
  12. Containnerheight: main.getWindowHeight(),
  13. });
  14. },
  15. onUnload: function () {
  16. },
  17. goto: function () {
  18. var that = this;
  19. wx.getSetting({
  20. success(res) {
  21. if (!res.authSetting['scope.userInfo']) {
  22. wx.authorize({
  23. scope: 'scope.userInfo',
  24. success() {
  25. that.getUserInfo();
  26. },
  27. fail() {
  28. }
  29. })
  30. }
  31. else {
  32. that.getUserInfo();
  33. }
  34. }
  35. });
  36. },
  37. //得到用户信息
  38. getUserInfo: function () {
  39. var that = this
  40. //调用登录接口
  41. wx.login({
  42. success: function (res0) {
  43. wx.getUserInfo({
  44. withCredentials: true,
  45. success: function (res) {
  46. app.globalData.userInfo.Code = res0.code;
  47. app.globalData.userInfo.iv = res.iv;
  48. app.globalData.userInfo.encryptedData = res.encryptedData;
  49. app.globalData.userInfo.NickName = res.userInfo.nickName;
  50. app.globalData.userInfo.AvatarUrl = res.userInfo.avatarUrl;
  51. that.login(app.globalData.userInfo, res.userInfo);
  52. },
  53. fail: function (res) {
  54. wx.navigateBack({
  55. delta: 1
  56. });
  57. }
  58. });
  59. },
  60. fail: function () {
  61. }
  62. });
  63. },
  64. login: function (param, param2) {
  65. var that = this;
  66. var url = "MiaoguoLogin";
  67. main.postData(url, {
  68. Code: param.Code,
  69. NickName: param2.nickName,
  70. AvatarUrl: param2.avatarUrl,
  71. Language: param2.language,
  72. Gender: param2.gender,
  73. City: param2.city,
  74. Province: param2.province,
  75. Country: param2.country,
  76. ProgramVersion: app.globalData.Version,
  77. Introducer: app.globalData.introducer,
  78. UserSource: app.globalData.userSource,
  79. SourceID: app.globalData.SourceID,
  80. LastUserSource: app.globalData.userSource,
  81. iv: param.iv,
  82. encryptedData: param.encryptedData,
  83. }, function (data) {
  84. app.globalData.userInfo.NickName = data.NickName;
  85. app.globalData.userInfo.AvatarUrl = data.AvatarUrl;
  86. app.globalData.userInfo.Language = data.Language;
  87. app.globalData.userInfo.Gender = data.Gender;
  88. app.globalData.userInfo.City = data.City;
  89. app.globalData.userInfo.Province = data.Province;
  90. app.globalData.userInfo.Country = data.Country;
  91. app.globalData.userInfo.IsMember=data.IsMember;
  92. that.buildInitData();
  93. });
  94. },
  95. buildInitData: function () {
  96. //app.globalData.userInfo.UserID=4;
  97. wx.showLoading({
  98. title: '数据初始化',
  99. });
  100. setTimeout(function () {
  101. wx.hideLoading();
  102. }, 5000);
  103. main.getData('BuildInitData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  104. wx.hideLoading();
  105. if (data) {
  106. wx.navigateBack({
  107. delta: 1
  108. });
  109. }
  110. });
  111. },
  112. onShareAppMessage: function () {
  113. return {
  114. title: app.globalData.ShareTitle,
  115. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  116. imageUrl: app.globalData.ShareImage,
  117. }
  118. },
  119. })