碧桂园
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
2.9 KiB

  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. ischecked: true,
  7. bindInfo: false,
  8. userid:'',
  9. token: ''
  10. },
  11. onLoad() {
  12. this.loginGettoken()
  13. },
  14. backGame(){
  15. wx.navigateTo({
  16. url: ''
  17. })
  18. },
  19. checkFun(){
  20. this.setData({
  21. ischecked: !this.data.ischecked
  22. })
  23. },
  24. // 协议
  25. toxieyi(){
  26. },
  27. //登录-获取token
  28. loginGettoken(){
  29. let that = this
  30. wx.login({
  31. success (res) {
  32. if (res.code) {
  33. //发起网络请求
  34. wx.request({
  35. url:'https://cktest.2weisou.com/meta/auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@'+res.code+'@'+'',
  36. method: "POST",
  37. data: {
  38. },
  39. header: {
  40. Authorization: "Basic YXBwbGV0OmFwcGxldA==",
  41. },
  42. success(res1) {
  43. if (res1.statusCode == 200) {
  44. that.setData({
  45. token: res1.data.access_token,
  46. userid: res1.data.user_info.id
  47. })
  48. }
  49. }
  50. })
  51. } else {
  52. console.log('登录失败!' + res.errMsg)
  53. }
  54. }
  55. })
  56. },
  57. // 绑定用户头像信息
  58. bindNickname(obj) {
  59. let that = this
  60. let params = {
  61. id: that.data.userid,
  62. userWxHeadImgUrl: obj.avatarUrl,
  63. userWxName: obj.nickName,
  64. userVxGender: obj.gender
  65. }
  66. wx.request({
  67. url: 'https://cktest.2weisou.com/meta/ar/user/bindNickname',
  68. method: "POST",
  69. data: params,
  70. header: {
  71. Authorization: 'bearer '+ that.data.token
  72. },
  73. success(res) {
  74. if (res.statusCode == 200) {
  75. that.setData({
  76. bindInfo: true
  77. })
  78. console.log('绑定用户头像信息成功')
  79. }
  80. }
  81. })
  82. },
  83. getUserInfo(){
  84. if(!this.data.ischecked){
  85. wx.showToast({
  86. title: '请勾选协议',
  87. icon: 'none',
  88. duration: 2000
  89. })
  90. return;
  91. }
  92. let that = this
  93. wx.getUserProfile({
  94. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  95. success: (res) => {
  96. console.log(res)
  97. that.bindNickname(res.userInfo)
  98. }
  99. })
  100. },
  101. // 授权手机号
  102. getPhoneNumber(e) {
  103. console.log(e);
  104. let that = this
  105. if (e.detail.errMsg == "getPhoneNumber:ok") {
  106. const {
  107. iv,
  108. encryptedData
  109. } = e.detail;
  110. wx.request({
  111. url: 'https://cktest.2weisou.com/meta/ar/user/bindMini',
  112. method: "POST",
  113. data: {
  114. encrypted: encryptedData,
  115. iv
  116. },
  117. header: {
  118. Authorization: 'bearer '+ that.data.token
  119. },
  120. success(res) {
  121. console.log(res)
  122. if (res.statusCode == 200) {
  123. // console.log(res)
  124. }
  125. }
  126. })
  127. } else {
  128. wx.showToast({
  129. icon: "none",
  130. title: "请授权手机号"
  131. })
  132. }
  133. }
  134. })