|
- // index.js
- // 获取应用实例
- const app = getApp()
- Page({
- data: {
- token: '',
- userInfo: null,
- shareid: ''// 邀请人ID
- },
- onLoad(option) {
- console.log(option.id)
- this.setData({
- shareid: option.id
- })
- this.loginGettoken()
- },
- // 判断是跳转游戏还是静态页
- panduanFun(){
- let that = this
- wx.request({
- url: getApp().globalData.httpurl + 'ar/game/getOne',
- method: "get",
- data: {},
- header: {
- Authorization: 'bearer '+ that.data.token
- },
- success(res) {
- console.log(res)
- if (res.data.code == 0) {
- let data = res.data.data
- // gameVersion为指定发版,和后台是否保持一致,方便提审通过,后续只需更改1为2,3,4,5...
- if(data.miniType==0&&data.gameVersion==3){
- getApp().globalData.gameurl = data.linkUrl
- that.tabindex(data.linkUrl)
- }else{
- wx.navigateTo({
- url: '/pages/guodu/index'
- })
- }
- }else{
- wx.navigateTo({
- url: '/pages/guodu/index'
- })
- wx.showToast({
- icon: 'none',
- title: res.data.msg
- })
- return ;
- }
- }
- })
- },
- //分享接口调用
- inviteFun(id){
- let that = this
- wx.request({
- url: getApp().globalData.httpurl + 'ar/user/bindNShareUserId?shareUserId='+ id,
- method: "get",
- data: {},
- header: {
- Authorization: 'bearer '+ that.data.token
- },
- success(res) {
- console.log(res)
- if (res.data.code == 0) {
- }else{
- wx.showToast({
- icon: 'none',
- title: res.data.msg
- })
- return ;
- }
- }
- })
- },
- tabindex(url) {
- let openid = 0
- if(this.data.userInfo.phone){
- openid = this.data.userInfo.openid
- }
- wx.navigateTo({
- url: '/pages/out/index?index=1&userid=' + openid+ '&gameid=1&type=1&url='+url
- })
- },
- saoma() {
- wx.navigateTo({
- url: '/pages/AR/index'
- })
- },
- //登录-获取token
- loginGettoken(){
- let that = this
- wx.login({
- success (res) {
- if (res.code) {
- //发起网络请求
- wx.request({
- url: getApp().globalData.httpurl+ 'auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@'+res.code+'@'+'',
- method: "POST",
- data: {
- },
- header: {
- Authorization: "Basic YXBwbGV0OmFwcGxldA==",
- },
- success(res1) {
- if (res1.statusCode == 200) {
- that.setData({
- token: res1.data.access_token,
- userInfo: res1.data.user_info
- })
- if(that.data.shareid){ // 有ID则是通过分享链接进来的
- that.inviteFun(that.data.shareid)
- }
- getApp().globalData.token = res1.data.access_token
- getApp().globalData.userInfo = res1.data.user_info
- }
- }
- })
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- }
- })
- }
- })
|