不少朋友问我怎么解决微信内点击连接或扫描二维码能够直接跳出微信在外部浏览器打开网页连接和下载APP,其实这并不难,只要咱们实现微信跳转功能便可。下面给你们介绍这个功能php
方案实现教程:http://sk.go51w.cn/nt0025.htmlhtml
功能目的
生成微信跳转连接,实现微信内置浏览器跳转外部浏览器打开网页。
功能效果
功能实现后, 苹果用户便可在微信内直接下载app也能够跳转浏览器下载,安卓用户则自动打开手机浏览器下载app, 若是不含下载文件,则直接从微信内跳转到外部浏览器访问指定页面 。下面是含app下载文件的实现效果:json
1. 苹果跳转浏览器效果浏览器
2. App Store应用实现效果微信
3. 企业版app实现效果app
4. 安卓用户则自动打开手机默认浏览器访问指定h5页面或者下载app。curl
用以上方式就能够实现用户在微信内打开分享连接直接跳转到外部浏览器打开了。url
如此一来咱们就解决了网页分享连接被微信拦截而没法打开的问题了,那么接下来就能够在微信内大量的分享连接或二维码来进行宣传引流。不只提升了用户体验,也可以极大地提升本身的APP在微信中的推广转化率,充分利用微信的用户群体来达到咱们的指望! spa
代码分享code
1. 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']; } ?>-有不懂的加我q:511979480-->
<?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>'; } } } ?>
2. 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%;}
3. 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>'; } } } ?>