Skip to content

Instantly share code, notes, and snippets.

@Illvili
Last active October 29, 2015 09:55
Show Gist options
  • Save Illvili/cbf694383801556280ac to your computer and use it in GitHub Desktop.
Save Illvili/cbf694383801556280ac to your computer and use it in GitHub Desktop.
APP QR Download Detect
<?php
// 地址配置
$iOSAPPStoreLink = '[iOS APP Store Link here]';
$AndroidLink = '[APK Link here]';
function redirect($url) {
header('Location: ' . $url);
exit();
}
// 获取UA
$userAgent = $_SERVER['HTTP_USER_AGENT'];
// 检测
$is_iOS = !!preg_match('/(iPad|iPhone|iPod)/i', $userAgent);
$is_Android = false !== strpos($userAgent, 'Android');
$is_MicroMessenger = false !== strpos($userAgent, 'MicroMessenger');
$is_FromWXMenu = isset($_GET['f']) && 'wxm' == $_GET['f'];
if ($is_iOS) {
if (!$is_FromWXMenu && !$is_MicroMessenger) {
redirect($iOSAPPStoreLink);
}
} else if ($is_Android) {
if (!$is_MicroMessenger) {
redirect($AndroidLink);
}
} else {
redirect('[APP Description Page Link here]');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta charset="UTF-8">
<title>移动客户端下载</title>
<style>
body {
background: #f0f0f0;
color: #333;
text-shadow: 1px 1px 0 #fff;
-webkit-text-shadow: 1px 1px 0 #fff;
font-size: 16px;
text-align: center;
line-height: 2;
padding-top: 40px;
}
</style>
</head>
<body>
您当前正在使用微信<?php if (!$is_FromWXMenu) : ?>扫一扫<?php endif ?><br>请点击右上角菜单选择“在浏览器中打开”
</body>
</html>
@Illvili
Copy link
Author

Illvili commented Feb 28, 2015

据说Android QQ/Android Weibo扫一扫也是需要特殊处理 未测试

@Illvili
Copy link
Author

Illvili commented Mar 25, 2015

微信公众菜单打开页面测试情况

方法 结果
HTTP Header跳转
Javascript跳转
HTML A链接
提示右上角打开 😔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment