网页跳转微信小程序并传参数,使用明文Scheme

console.log('测试跳转小程序');
  let query ={
    Code: "测试跳转小程序",
    Url: "",
    brandId: "",
    userId: "",
    userName: ""
  }
  // 把对象转换成 a=1&b=2&c=3&d=4 的字符串格式
  let queryString = Object.keys(query).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`).join('&')
  // 对其进行转码
  let res = encodeURIComponent(queryString)  
  console.log('queryString',queryString);
  window.location.href = "weixin://dl/business/?appid=xxxxxxxx&path=pages/index/Index&env_version=trial&query="+res; 

小程序使用onload函数,获取被调用时收到的参数即可

补充

关于微信平台使用明文Scheme的规则描述:

https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/url-scheme.html

小程序scheme是一种用于在移动设备上打开小程序的链接格式。通过使用小程序scheme,可以在其他应用或网页直接跳转小程序。引用\[1\]提到了一种实现方式,即通过准备一个H5页面,然后从H5页面跳转小程序URL Scheme来打开小程序。具体实现方式是使用JavaScript代码,例如使用location.href来跳转到指定的小程序URL Scheme。引用\[2\]给出了一个示例,展示了如何通过scheme连接跳转到支付宝小程序。在示例使用window.location.href来跳转到指定的支付宝小程序scheme链接。根据具体的小程序使用的平台,scheme的格式可能会有所不同,需要根据实际情况进行相应的调整。 #### 引用[.reference_title] - *1* [微信小程序新能力:URL Scheme,可从短信跳转小程序](https://blog.csdn.net/liubangbo/article/details/117803878)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [支付宝小程序 scheme跳转](https://blog.csdn.net/weixin_38639882/article/details/118059763)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值