wx.getLaunchOptionsSync API的 BUG(有没有微信官方的大佬帮我看看)
发布于 5 年前 作者 gang10 4491 次浏览 来自 问答

BUG一:我们小程序有个需求,就是通过微信公众号消息查看到小程序中的详情页面,公众号消息点击时会传一个task_id参数到授权页面,授权页面登陆成功后,通过wx.getLaunchOptionsSync方法获取到scene场景值,判断scene为1043后就跳转到详情页面,(每个消息模版所带的task_id不同),但是我发现,点击模板消息后,只有第一次带的task_id,后面不管点哪个消息模板,传到小程序的task_id始终是第一个消息的task_id。(下面截图)

BUG二:如果第一次通过下拉打开小程序(冷启动),再从微信消息模版打开小程序,获取到的场景值居然是1089(微信聊天主界面下拉,「最近使用」栏(基础库2.2.4版本起包含「我的小程序」栏)),而只有在第一次通过微信公众号消息模版冷启动时,得到的场景值是1043。


这里是我授权页面,使用的判断方法,通过参数和场景值,来判断要不要跳转,我想知道这是微信官方的BUG还是我写的代码逻辑不好?各位有遇到过这种问题么?怎么解决的呢

// 判断登录时是否要通过场景值来跳转页面

launchOptionLogin() {

const that = this;

const dataInfo = wx.getLaunchOptionsSync();

console.log("场景值:", dataInfo);

const {

scene,

query

} = dataInfo;

const {

taskid

} = query;

if ((scene == "1043" || scene == "1014") && query && taskid) {

wx.navigateTo({

url: `/pages/tranManage/tranDetail/index?taskid=${taskid}`//事务的详情页

})

} else {

wx.switchTab({

url: "/pages/index/index" //首页

})

}

},

1 回复
// 这是授权页面的全部代码

import Dialog from '../../miniprogram_npm/[@vant](/user/vant)/weapp/dialog/dialog';
import Notify from '../../miniprogram_npm/[@vant](/user/vant)/weapp/notify/notify';

const app = getApp();
const {interfaceUrl} = app.globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    authBtnShow:false,//显示授权
    code:"",
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options{
    const that = this;
    wx.login({
      success(res){
        const {code} = res;
        that.setData({
          code,
        },()=>{
          that.getAuthSetting();
        })
      }
    })
    
  },
  getAuthSetting(){
    const that = this;
    wx.getSetting({
      success (res){
        if (res.authSetting['scope.userInfo']) {
          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
          that.setData({
            authBtnShow:false,
          })
          wx.getUserInfo({
            success: function(res{
              const {encryptedData,iv} = res;
              that.loginHandle({encryptedData,iv});
            }
          })
        }else{
          that.setData({
            authBtnShow:true,
          })
        }
      }
    })
  },
  loginHandle(authData){
    wx.showLoading({
      title: '校验信息...',
    })
    const that = this;
    const {code} = this.data;
    const ob = {
      code,
      ...authData,
    }
    wx.request({
      url: `${interfaceUrl}/api/common/miniLogin`,
      method:"POST",
      data:ob,
      success(res){
        wx.hideLoading()
        const {data} = res;
        if(data.code!=200){
          wx.hideLoading()
          Dialog.alert({
            title: '提示',
            showConfirmButton:false,
            showCancelButton:false,
            message: data.msg,
          })
          return false;
        }
        wx.setStorage({
          data: data.token,
          key: 'token',
          success(res){
            wx.hideLoading()
            that.launchOptionLogin();
          },
          fail(err){
            console.log(err);
          }
        })
      },
      fail(err){
        wx.hideLoading()
        Dialog.alert({
          title: '错误',
          message: err.response.data.msg,
        })
      }
    })
  },
  // 判断登录时是否要通过场景值来跳转页面
  launchOptionLogin(){
    const that = this;
    const dataInfo = wx.getLaunchOptionsSync();
    console.log("场景值:",dataInfo);
    const {scene,query} = dataInfo;
    const {taskid} = query;
    if((scene=="1043" || scene=="1014") && query && taskid){
      wx.navigateTo({
        url:`/pages/tranManage/tranDetail/index?taskid=${taskid}`
      })
    }else{
      wx.switchTab({
        url:"/pages/index/index"
      })
    }
    
    
  },
  // 获取授权
  bindGetUserInfo (e) {
    const {encryptedData,iv} = e.detail;
    if(encryptedData && iv){
      this.loginHandle({encryptedData,iv});
    }else{
      Notify({ type'warning', message: '请先授权登录', duration: 1000, });
    }

  }
})
回到顶部