标签:[1] ike date echo 请求 redirect mat 理想 llb
将打包好的apk/ios文件部署到服务器,把下载页面的URL通过二维码编辑器或根据URL代码生成一个二维码,然后通过二维码进行微信推广已经成为很多用户惯用的方式。但微信会对含apk/ios文件的链接进行了屏蔽,所以导致微信扫码打不开下载链接。理想的状态是安卓自动下载,苹果点击左上角按钮前往Safari下载。那么究竟该如何处理才能达到理想的结果呢?
我们知道 js 可以通过 window.navigator.userAgent 来获取浏览器的相关信息,比如:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36,那么我们也可以通过该方法来获取微信内置浏览器的相关信息:Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11d201 MicroMessenger/5.3。根据关键字 MicroMessenger 来判断是否是微信内置的浏览器。从而实现安卓自动下载或跳转到浏览器打开下载链接,苹果会提示点击右上角的按钮前往Safari下载。
HTML代码
<?php // 统一调用微信白名单接口:https://wq.jd.com/mjgj/link/GetOpenLink?callback=getOpenLink&rurl=https://dc2.jd.com/auto.php?service=transfer&type=pms&to=(这里是拼接自己的内容地址比如http://mjbbs.jd.com/data/attachment/forum/201806/08/173526pb2zpjzzooo2ofze.jpg) if($_GET[‘t‘]){ // include("admin/config.php"); // include("admin/function.php"); $code = $_GET[‘t‘]; $info = query ( "jump_logs", "where code=‘" . $code . "‘" ); if($info[‘code‘] == ‘‘){ echo ‘跳转失败‘; exit(0); } if($info[‘state‘] == ‘1‘){ if($info[‘count‘] >= $info[‘num‘]){ echo ‘跳转失败‘; exit(0); } $time = strtotime($info[‘time‘]); if(time() > $time){ echo ‘跳转失败‘; exit; } }else{ echo ‘跳转失败‘; exit; } if($info[‘www_url‘] == ‘‘){ echo ‘请先配置落地页‘; exit; }else{ $w_url_code = $info[‘rl‘]; } ?>
CSS代码
1 #weixin-tip{display:none;position:fixed;left:0;top:0;background:rgba(0,0,0,0.8);filter:alpha(opacity=80);width:100%;height:100%;z-index:100;} 2 #weixin-tip p{text-align:center;margin-top:10%;padding:0 5%;position:relative;} 3 #weixin-tip .close{color:#fff;padding:5px;font:bold 20px/24px simsun;text-shadow:0 1px 0 #ddd;position:absolute;top:0;left:5%;}
JS封装代码
<?php function get_ticket($code){ //初始化 $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts $headers = array(); $headers[] = ‘User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_1_2 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/15B202 UCBrowser/11.7.7.1031 Mobile AliApp(TUnionSDK/0.1.20)‘; $headers[] = ‘Referer: https://m.mall.qq.com/release/?busid=mxd2&ADTAG=jcp.h5.index.dis‘; $headers[] = ‘Content-Type:application/x-www-form-urlencoded; charset=UTF-8‘; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $content = curl_exec($ch); curl_close($ch); //$arr = json_decode($content,1); //if($arr[‘success‘] == ‘1‘){ // $shotCode = $arr[‘shotCode‘]; //}else{ // $shotCode = ‘‘; //} //preg_match(‘/openlink\":\"(.*?)\"}/‘,$content,$result); //$url = $result[1]; preg_match(‘/href=\"(.*?)#wechat/‘,$content,$result); $url = $result[1]; return $url; } $time = time()-$info[‘ticket_time‘]; $minute=floor($time/60); query_update ( "jump_logs", "count=count+1". " where code=‘" . $code . "‘" ); if($minute >= 59){ //如果超过1小时,更新ticket $url = get_ticket($w_url_code); if($url){ query_update ( "jump_logs", "ticket_time=‘".time()."‘, ticket=‘" . $url . "‘ where code=‘" . $code . "‘" ); $ticket_url = $url.‘#‘; if(strpos($_SERVER[‘HTTP_USER_AGENT‘], ‘baiduboxapp‘)||strpos($_SERVER[‘HTTP_USER_AGENT‘], ‘baiduboxapp‘)){//安卓百度手机APP echo ‘<script>window.location.href = "bdbox://utils?action=sendIntent&minver=7.4¶ms=%7b%22intent%22%3a%22‘.$url.‘%23wechat_redirect%23wechat_redirect%23Intent%3bend%22%7d";</script>‘; }else{ echo ‘<script>window.location.href = "‘.$ticket_url.‘";</script>‘; } } }else{ $ticket_url = $info[‘ticket‘].‘#‘; if(strpos($_SERVER[‘HTTP_USER_AGENT‘], ‘baiduboxapp‘)||strpos($_SERVER[‘HTTP_USER_AGENT‘], ‘baiduboxapp‘)){//安卓百度手机APP echo ‘<script>window.location.href = "bdbox://utils?action=sendIntent&minver=7.4¶ms=%7b%22intent%22%3a%22‘.$info[‘ticket‘].‘%23wechat_redirect%23wechat_redirect%23Intent%3bend%22%7d";</script>‘; }else{ echo ‘<script>window.location.href = "‘.$ticket_url.‘";</script>‘; } } } ?> <!--有不懂的地方联系我的Q:3358246772-->
至此,我们就可以直接用微信扫描二维码在微信中分享和宣传引流了。这样我们能够极大的提高自己的APP在微信中的推广转化率。解决掉了微信中下载链接被屏蔽等问题。充分利用微信的用户群体来宣传引流。
标签:[1] ike date echo 请求 redirect mat 理想 llb
原文地址:https://www.cnblogs.com/yhmaq/p/10295824.html