accredit.js 2.8 KB

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