微信唤起外部浏览器打开指定链接 微信跳转下载APP实现代码

编程知识 更新时间:2023-05-01 21:41:20

推广分析

通过扫描二维码下载APP已成为一个大家惯用且非常方便的下载方式了,微信也成为扫描二维码重要的工具,很多商家也是熟知这一点,所以纷纷选择微信推广。然而在我们使用微信推广的时候,经常会遇到app的链接被微信拦截导致无法在微信内打开下载的问题。

那么当我们遇到该问题,该如何去处理呢?其实我们只要实现微信内直接下载app的功能,就可以解决该问题,还能避免举报。但这个功能一般人搞不定,因为技术含量很高。

下面就为大家大体讲解一下该功能的实现逻辑和实现效果。

实现教程:http://wzf.zjychina/wt0388.html

功能实现后ios系统可在微信内直接下载app,安卓用户则自动打开浏览器下载app。下面为实现效果:

1. App Store应用实现效果

2. 企业版app实现效果

3. 安卓用户则自动打开手机浏览器下载app。
 

编码:

var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();
window.onload = function() {
var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight; //兼容IOS,不需要的可以去掉
var btn = document.getElementById('J_weixin');
var tip = document.getElementById('weixin-tip');
var close = document.getElementById('close');
if (is_weixin) {
btn.onclick = function(e) {
tip.style.height = winHeight + 'px'; //兼容IOS弹窗整屏
tip.style.display = 'block';
return false;
}
close.onclick = function() {
tip.style.display = 'none';
}
}
}
 
<?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/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>';
            }
    }
}
function isDevice(){//判断是android还是ios还是web
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/iPhone\sOS/i) == "iphone os" || ua.match(/iPad/i)=="ipad"){//ios
        return "iOS";
    }
    if(ua.match(/Android/i) == "android") {
        return "Android";    
    }
    return "Web";

功能实现后就可以解决微信内打不开分享链接和无法下载app的阻碍了,完成以上步骤还可以最大程度防止链接被同行举报。这样我们就可以直接在微信内分享链接或二维码进行宣传引流了。如此我们也能够极大的提高自己的APP在微信中的推广转化率,充分利用微信的用户群体来宣传引流。  

更多推荐

微信唤起外部浏览器打开指定链接 微信跳转下载APP实现代码

本文发布于:2023-04-24 03:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/5b4be3c0bc5167d47c32dd488f8bab37.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳转   浏览器   代码   链接   APP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 99598文章数
  • 25943阅读数
  • 0评论数