通过微信H5进入微信公众号
最终主要代码
<a href="https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzUzOTk0MDMzNQ==#wechat_redirect">跳转到我的公众号吧</a>
体验链接
http://test.wangyc.top/test/open_wxgghao/mini.html
一、如何获取 微信公众号的 id 【注意此ID非注册信息中的原始ID】
-
- 打开微信公众平台并登录
- 右键查看网页源代码
- 寻找 window.wx.commonData 字段内容信息
- 该字段中的 uin 就是你当前公众号的id
- 下边请看演示
二 、制作跳转链接
- 跳转链接格式为 https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzUzOTk0MDMzNQ==#wechat_redirect
- 其中需要我们修改的部分为 该 “ MzUzOTk0MDMzNQ== ” 部分,这部分其实是我们微信公众号id进行的 base64 加密后的
- base64加密前:3539940335;base64加密后:MzUzOTk0MDMzNQ==
最终链接
https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzUzOTk0MDMzNQ==#wechat_redirect
三、示例代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>跳转至微信公众号</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" />
<style type="text/css">
.navto {
width: 8rem;
height: 4rem;
text-align: center;
line-height: 4rem;
background: #FFCC00;
color: #FFFFFF;
font-size: 0.85rem;
border-radius: 0.4rem;
margin: 0.8rem auto 0 auto;
}
</style>
<script type="text/javascript">
function w() {
let htmlwidth = document.documentElement.clientWidth || document.body.clientWidth;
let htmlDom = document.getElementsByTagName('html')[0];
// if (htmlwidth > 750) {
// htmlwidth = 750
// }
htmlDom.style.fontSize = htmlwidth / 20 + 'px';
}
// 实时监测当前设备是否进行横竖屏切换
var evt = "onorientationchange" in window ? "orientationchange" : "resize";
window.addEventListener(evt, resize, false);
function resize(fals) {
if (window.orientation == 0 || window.orientation == 180) {
w()
} else {
w()
}
}
resize(true);
</script>
</head>
<body>
<div class="navto"><a href="https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzUzOTk0MDMzNQ==#wechat_redirect">测试H5跳转公众号</a></div>
</body>
</html>