accredit.js 3.5 KB

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