博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
apicloud拉起小程序并传递参数
阅读量:7120 次
发布时间:2019-06-28

本文共 1161 字,大约阅读时间需要 3 分钟。

最近工作中遇到一个需求:App拉起微信小程序。App是用APICloud开发的。查阅APICloud文档发现 端API->开放SDK->wx模块下有launchMiniProgram方法可以实现

于是在项目中添加wx模块。

官方示例代码:

var wx = api.require('wx');wx.launchMiniProgram({    apiKey: '', // 字符串,微信开放平台获取的appid, 不传则从当前widget的config.xml中读取    miniProgramType: 'test', // 字符串,['test', 'preview', 'release'](开发版,体验版,正式版)默认test    userName: '', // 字符串,小程序的原始ID    path: '', // 字符串,拉起小程序页面的可带参数路径,不填默认拉起小程序首页}, function(ret, err) {    if (ret.status) {        alert('成功');    } else {        alert(err.code);    }});

按照官方文档配置发现只能跳转到微信,不能拉起小程序。

apicloud App端代码:
config.xml文件小程序有关配置如下:

拉起小程序相关代码:

function launchMini () {    var wx = api.require('wx')    wx.launchMiniProgram({        // apiKey: '', // 不知道是因为配置文件中已经配置过了还是什么原因,带上该项参数仅能打开微信,无法拉起小程序,注释后成功拉起小程序        miniProgramType: 'preview',        userName: 'gh_******',        path: 'pages/index/index?from=app666' // 传递参数from 值为 app666    }, function(ret, err) {        if (ret.status) {            alert('成功')        } else {            alert(err.code)        }    }}

小程序端代码:

index.js

onLoad: function (options) {    console.log(options)    console.log(options.from) // 'app666'}

转载地址:http://yubel.baihongyu.com/

你可能感兴趣的文章