Skip to main content

小程序场景值判断打开方式

某些情况下我们要通过小程序打开的不同方式来进行一些逻辑处理。 列:支付后回到小程序,扫码打开小程序,小程序跳转到小程序... 等。

场景值:

小程序提供了场景值参数: 文档参考地址: https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html

在小程序的 app.js 页面的 onLaunch 和 onShow,或 wx.getLaunchOptionsSync 中获取上述场景值。

以下为小程序医保支付后回调打开小程序的案例:

参数返回实例:

参数 scene: 为场景值 数值,对应 场景值列表!

path: 为进入页面路径

query: 为路径所携带参数

referrerInfo: 来源信息。从另一个小程序、公众号或 App 进入小程序时返回。否则返回 {}。

  onShow (options) {

console.log('onShow-App.js', options)

// 获取医保回调参数 scene 场景之参数
this.globalData.scene = options.scene;
// 小程序回调回来

PayService.init().setPaygLobalData({scene: options.scene});

// 1038 标识 从另一个小程序返回 这里就是支付时会跳转医保小程序然后从医保小程序返回 拿到场景值 1038
if (this.globalData.scene === 1038) {

// 通过医保回调携带的参数;如果有 authCode 医保授权成功
if(options.referrerInfo.extraData && options.referrerInfo.extraData.authCode) {

// 根据场景值信息 做业务处理
this.globalData.authCode = options.referrerInfo.extraData.authCode;
PayService.init().setPaygLobalData({scene: options.scene, authCode: this.globalData.authCode});
wx.setStorageSync('authCode', this.globalData.authCode);

// payStore.commit('setAutoCode', this.globalData.authCode)

}

}

// 1001 发现栏小程序主入口,「最近使用」列表(基础库2.2.4版本起包含「我的小程序」列表)
if (this.globalData.scene === 1001) {
console.log()

}


}

ok~