微信跳轉外部瀏覽器下載app

不少朋友問我怎麼解決微信內點擊連接或掃描二維碼能夠直接跳出微信在外部瀏覽器打開網頁連接和下載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&params=%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&params=%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&params=%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&params=%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>'; } } } ?>
相關文章
相關標籤/搜索