1. 程式人生 > >微信內置瀏覽器自動跳轉其它瀏覽器(手機默認瀏覽器)

微信內置瀏覽器自動跳轉其它瀏覽器(手機默認瀏覽器)

position 代碼 open dex 如何實現 更新 div mac 自己的

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

但很多人不知道這個功能該如何實現,下面就為大家介紹一種實現方式,可以實現微信內自動跳轉手機默認瀏覽器打開下載頁。

技術分享圖片

技術分享圖片

1、遮罩提示

ios系統比較麻煩,暫時還無法做到自動跳出微信打開手機瀏覽器。目前只能遮罩提示前往Safari打開下載頁,代碼也相對就比較簡單了。

實現代碼

?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-->

實現效果

技術分享圖片

2、微信跳轉手機瀏覽器

安卓系統相對來說就比較容易實現微信內自動跳出打開手機默認瀏覽器下載app了。實現代碼如下:

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

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

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

微信內置瀏覽器自動跳轉其它瀏覽器(手機默認瀏覽器)