碧桂园
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

125 rindas
3.1 KiB

  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. token: '',
  7. userInfo: null,
  8. shareid: ''// 邀请人ID
  9. },
  10. onLoad(option) {
  11. console.log(option.id)
  12. this.setData({
  13. shareid: option.id
  14. })
  15. this.loginGettoken()
  16. },
  17. // 判断是跳转游戏还是静态页
  18. panduanFun(){
  19. let that = this
  20. wx.request({
  21. url: getApp().globalData.httpurl + 'ar/game/getOne',
  22. method: "get",
  23. data: {},
  24. header: {
  25. Authorization: 'bearer '+ that.data.token
  26. },
  27. success(res) {
  28. console.log(res)
  29. if (res.data.code == 0) {
  30. let data = res.data.data
  31. // gameVersion为指定发版,和后台是否保持一致,方便提审通过,后续只需更改1为2,3,4,5...
  32. if(data.miniType==0&&data.gameVersion==3){
  33. getApp().globalData.gameurl = data.linkUrl
  34. that.tabindex(data.linkUrl)
  35. }else{
  36. wx.navigateTo({
  37. url: '/pages/guodu/index'
  38. })
  39. }
  40. }else{
  41. wx.navigateTo({
  42. url: '/pages/guodu/index'
  43. })
  44. wx.showToast({
  45. icon: 'none',
  46. title: res.data.msg
  47. })
  48. return ;
  49. }
  50. }
  51. })
  52. },
  53. //分享接口调用
  54. inviteFun(id){
  55. let that = this
  56. wx.request({
  57. url: getApp().globalData.httpurl + 'ar/user/bindNShareUserId?shareUserId='+ id,
  58. method: "get",
  59. data: {},
  60. header: {
  61. Authorization: 'bearer '+ that.data.token
  62. },
  63. success(res) {
  64. console.log(res)
  65. if (res.data.code == 0) {
  66. }else{
  67. wx.showToast({
  68. icon: 'none',
  69. title: res.data.msg
  70. })
  71. return ;
  72. }
  73. }
  74. })
  75. },
  76. tabindex(url) {
  77. let openid = 0
  78. if(this.data.userInfo.phone){
  79. openid = this.data.userInfo.openid
  80. }
  81. wx.navigateTo({
  82. url: '/pages/out/index?index=1&userid=' + openid+ '&gameid=1&type=1&url='+url
  83. })
  84. },
  85. saoma() {
  86. wx.navigateTo({
  87. url: '/pages/AR/index'
  88. })
  89. },
  90. //登录-获取token
  91. loginGettoken(){
  92. let that = this
  93. wx.login({
  94. success (res) {
  95. if (res.code) {
  96. //发起网络请求
  97. wx.request({
  98. url: getApp().globalData.httpurl+ 'auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@'+res.code+'@'+'',
  99. method: "POST",
  100. data: {
  101. },
  102. header: {
  103. Authorization: "Basic YXBwbGV0OmFwcGxldA==",
  104. },
  105. success(res1) {
  106. if (res1.statusCode == 200) {
  107. that.setData({
  108. token: res1.data.access_token,
  109. userInfo: res1.data.user_info
  110. })
  111. if(that.data.shareid){ // 有ID则是通过分享链接进来的
  112. that.inviteFun(that.data.shareid)
  113. }
  114. getApp().globalData.token = res1.data.access_token
  115. getApp().globalData.userInfo = res1.data.user_info
  116. }
  117. }
  118. })
  119. } else {
  120. console.log('登录失败!' + res.errMsg)
  121. }
  122. }
  123. })
  124. }
  125. })