1. 程式人生 > >微信中點擊鏈接直接跳到默認瀏覽器是怎麽實現的?(不是在微信內置瀏覽器打開)

微信中點擊鏈接直接跳到默認瀏覽器是怎麽實現的?(不是在微信內置瀏覽器打開)

peer 如何實現 宣傳 padding 介紹 ray tag ani UNC

在我們使用微信營銷的時候,很容易碰到推廣連接在微信內無法打開或不提示前往瀏覽器打開。首先說一下推廣域名在微信內無法打開的問題,這是因為微信風控系統封殺了第三方下載鏈接,所以在微信內無法打開。其次再說一下為什麽微信內置瀏覽器不提示前往Safari打開,這是因為缺少了一個微信跳轉外部瀏覽器的接口,如果我們在代碼中加入該接口,那麽就可以實現ios系統提示前往Safari打開下載頁,安卓系統則可以直接跳出到手機默認瀏覽器。

但很多人不知道這個功能該如何實現,下面就為大家介紹一種實現方式,可直接實現微信外跳手機瀏覽器下載app的功能。

技術分享圖片

一、遮罩提示

此方法適用於ios系統,可實現微信內置瀏覽器中提示用戶前往Safari下載app。實現代碼如下:

function isWx(){//判斷是否為微信
    var ua = window.navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i) == micromessenger){
        return true;
    }
    return false;
};
if(isWx()){//判斷瀏覽器是否微信
    var html=<div class="box"><img src="images/head.png"></box>
    layer.open({
//這裏使用了layer的彈窗組件,你也可以自己寫 type: 1,content: html,anim: up, style: position:fixed; bottom:0; left:0; width: 100%; height: 100%; padding:0; border:none; }); return; }<--有不懂的咨詢我的q:3358246772-->

實現效果:

技術分享圖片

二、微信自動跳轉手機瀏覽器

該方法適用於安卓系統,可實現微信內置瀏覽器自動打開手機瀏覽器下載app。實現代碼如下:

?<?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>‘; } } } ?>

如此,我們就解決了微信內置瀏覽器無法跳轉手機瀏覽器下載app的難題,完成以上步驟還可以最大程度防止下載鏈接被微信屏蔽。這樣我們就可以直接用微信掃描二維碼在微信中分享和宣傳引流了。如此我們即能夠極大的提高自己的APP在微信中的推廣轉化率。也解決掉了微信中下載鏈接被屏蔽等問題。充分利用微信的用戶群體來宣傳引流

微信中點擊鏈接直接跳到默認瀏覽器是怎麽實現的?(不是在微信內置瀏覽器打開)