微信调用手机浏览器打开链接

2024-01-24T20:14:00+08:00 | 2 分钟阅读 | 更新于 2024-01-24T20:14:00+08:00

hehe

不知道大家有没有这样的需求,当把app下载连接通过微信发送给他人时,在微信中点开这个链接,并不能直接下载,或者由于这样或那样的原因链接不想在微信打开,需要在手机浏览器打开。

那么针对需求,如何解决这个问题呢?

首先就是看看有没有现成的方案,搜索引擎搜索一番,搜来搜去并没有找到现成的开源代码,但是发现了网上有网站提供这种服务:
微信调用手机浏览器打开链接
不过测试版有时效,想长期使用还得付费,那就尝试只能尝试自己解决了。

在测试中发现访问.apk文件时无法下载也无法条状到默认浏览器,但是如果访问.doc或者.xlsx这类文件竟然可以直接跳转到默认浏览器中下载,那么问题迎刃而解:
先使用一个跳板网址,判断用户是否通过手机微信访问,如果是则模拟成成.doc文件,将跳转到默认浏览器,如果用户并未使用手机微信访问则直接跳转到apk下载地址。
如果是网页链接不想在微信打开,需要在手机浏览器打开的话也是同样的方法,只不过不用跳板网址,直接在页面上判断即可。

核心代码:

<?php
if(IsWeiXin()){
    Header("Content-type:application/vnd.ms-word");
    Header("Content-Disposition: attachment;filename=test.doc");
    exit();
}else{
    //根据需要选择是否要跳转
    $apkUrl = "";//APK下载链接
    header("Location: ".$apkUrl);
    exit(); 
}
function IsWeiXin(){
    $ua = $_SERVER['HTTP_USER_AGENT'];
    if (strpos($ua, 'MicroMessenger') == false && strpos($ua, 'Windows Phone') == false){
        return false;
    } else {
        return true;
    }
}
?>

功能完美实现,有时间的话我也搭建一个类似的服务,网上这个有点太丑了。

comments powered by Disqus

© 2024 和和日志

🌱 Powered by Hugo with theme Dream.

关于我

Hi…🐟 everyone! I’m Hehe. I’m passionate about computers and the internet, my hobby is playing pool, and I have a >special fondness for games. In the field of computers, I enjoy constantly learning new technologies. Pool is my >way of relieving stress, and gaming is a way for me to interact with friends. I like making new friends, so if you >share these interests, let’s connect and exchange experiences!

2024 年 07 月 19 日更新。

关于留言评论

本博客评论系统用的是 Disqus,如果您要留言 请登录👉 github后进行留言讨论~

赞助我(Sponsor Me)

If you like my works or find them helpful, please consider buying me a cup of coffee ☕️. It inspires me to create and maintain more projects in the future. 🦾

👉 Buy me a coffee

知识共享(Creative Commons)

此网站的所有内容都遵循 CC BY-NC-SA 4.0

社交链接