当前位置:网站首页>H5页面打开微信小程序
H5页面打开微信小程序
2022-08-02 00:17:00 【m0_67401382】
一、介绍
背景:用于实现外部H5页面中实现打开微信小程序的功能(微信内打开请使用微信开放标签方式),用户在网页中一键唤起小程序,能够给用户提供更好的体验。采用的技术是URL Scheme,是微信小程序后台生成一种地址,适用于从短信、邮件、微信外网页等场景打开小程序任意页面。通过URL Scheme打开小程序的场景值为 1065
整体思路:前端调用后端接口,后端调用微信接口生成Url Scheme返回给前端,前端得到Url Scheme后,打开该链接即可实现跳转
生成的 URL Scheme 如下所示location.href = ‘weixin://dl/business/?t=SagndxolUds’
示例网页H5地址
https://postpay-2g5hm2oxbbb721a4-1258211818.tcloudbaseapp.com/jump-mp.html
二、操作步骤
2.1 开发前的准备工作
必须是企业的小程序
- 获取AppID,也就是小程序唯一凭证,可在微信公众平台 - 设置 - 开发设置」页中获得。(需要已经成为开发者,且帐号没有异常状态)
- 获取AppSecret,也就是小程序唯一凭证密钥
2.2 进入开发阶段
关于URL Scheme
微信官方文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/url-scheme.html
后端
- 代码逻辑:后端调用微信接口获取access_token,在用获取access_token去调用微信接口生成URL Scheme,在将URL Scheme返回给前端
1.获取access_token
微信官方文档https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
请求地址
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
参数列表:
参数
含义
grant_type
固定为client_credential
appid
小程序唯一凭证,即 AppID
secret
小程序唯一凭证密钥,即 AppSecret
得到以下数据说明成功:
{“access_token”: “56_iut0Umy6*********wERTaAHAVIK”, “expires_in”: 7200}
2.生成URL Scheme
微信官方文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
请求地址
POST https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN
参数列表:
参数
含义
access_token
接口凭证
得到以下数据说明成功:
{
“errcode”: 0,
“errmsg”: “ok”,
“openlink”: “weixin://dl/business/?t=SagndxolUds”
}
此时已经拿到了openlink ,也就是URL Scheme,将该信息返回前端即可
前端
请求后端接口拿到URL Scheme,然后已URL形式打开即可,该方式仅支持手机浏览器,如果是微信浏览器则需要使用(微信开放标签)方式
<a href="weixin://dl/business/?t=SagndxolUds">打开小程序</a>
href 绑定的是 URL Scheme 地址。
完
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- 构造方法,this关键字,方法的重载,局部变量与成员变量
- 渗透测试与攻防对抗——渗透测试基础
- uni-app project summary
- How does JSP use the page command to make the JSP file support Chinese encoding?
- ICML 2022 || 局部增强图神经网络GNN,在 GCN 和 GAT基础上 平均提高了 3.4% 和 1.6%
- 【HCIP】BGP小型实验(联邦,优化)
- 【软件工程之美 - 专栏笔记】34 | 账号密码泄露成灾,应该怎样预防?
- BGP综合实验 建立对等体、路由反射器、联邦、路由宣告及聚合
- 思维导图,UML在线画图工具
- Redis的集群模式
猜你喜欢

bgp 聚合 反射器 联邦实验

c语言字符和字符串函数总结(二)

nodeJs--mime模块

测试点等同于测试用例吗

Looking back at 5 recessionary times in history: How might this time be different?

Realize deletion - a specified letter in a string, such as: the string "abcd", delete the "a" letter in it, the remaining "bcd", you can also pass multiple characters to be deleted, and pass "ab" can

业务测试如何避免漏测 ?

管理基础知识21

期货开户调整交易所保证金标准

Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)
随机推荐
swing的Jlist列表滚动条以及增加元素的问题
冒泡排序函数封装
工业信息物理系统攻击检测增强模型
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
Unknown CMake command "add_action_files"
Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)
21.数据增强
管理基础知识18
06-SDRAM : SDRAM control module
Active Disturbance Rejection Control of Substation Inspection Robot Based on Data Drive
How does JSP use the page command to make the JSP file support Chinese encoding?
Multi-feature fusion face detection based on attention mechanism
After reshipment tencent greetings to monitor if the corresponding service does not exist by sc. Exe command to add services
期货开户调整交易所保证金标准
管理基础知识16
Identify memory functions memset, memcmp, memmove, and memcpy
An Enhanced Model for Attack Detection of Industrial Cyber-Physical Systems
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
如何期货开户和选择期货公司?
632. Minimum interval