1. 程式人生 > >APP在微信中的下載鏈接掃一掃無法打開解決方案

APP在微信中的下載鏈接掃一掃無法打開解決方案

images char adt api mob orm config 步驟 baidu

通過掃描二維碼下載APP已成為一個大家慣用且非常方便的下載方式了,微信也成為掃描二維碼重要的工具,因為目前微信的用戶占據了市場的半壁江山。然而在我們做營銷活動或推廣宣傳的時候,容易遇到域名被封,無法跳轉app下載等情況。這時需要微信跳轉外部瀏覽器打開頁面的功能,對於ios系統的用戶默認可以通過點擊右上角的更多符號從而選擇“在瀏覽器中打開”的方法很多用戶並不知道這樣的實現,因此需要在代碼中進行相關處理。

技術分享圖片

目前ios只能通過遮罩層來提示用戶前往Safari打開分享域名,對於安卓可以直接跳出手機默認瀏覽器,下面就分別介紹下這2種方式的實現方式。

技術分享圖片

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、微信內跳打開瀏覽器

安卓系統相對來說就簡單的多了,直接可以實現微信內自動跳轉手機瀏覽器打開下載頁。實現代碼如下

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在微信中的推廣轉化率。也解決掉了微信中下載鏈接被屏蔽等問題。充分利用微信的用戶群體來宣傳引流~~

APP在微信中的下載鏈接掃一掃無法打開解決方案