碧桂园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 rivejä
3.3 KiB

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