需求分析
在我们做营销活动或推广宣传的时候,容易遇到链接被微信拦截,导致在微信内打开提示“已停止访问该网页”,故无法下载app等情况。这时就需要微信内直接下载app的功能,很多用户并不知道这样的实现,所以针对这个问题,特写此篇文章分享我们公司之前的处理方案。首先如果我们没有专业的技术团队,我们可以去找一家提供个该技术的团队合作,我们之前一直用的是366API平台的接口,效果还不错,很稳定。然后如果大家有自己的技术团队,是可以自行编写跳转程序的,参考案例见下文。
一、首先我们说说366API平台的使用方法:
1、使用浏览器打开我们需要用到的 366API平台
2、复制链接粘贴进api工具框中,点击生成跳转短链接和二维码
3、复制短连接和二维码前往微信中打开链接或扫码即可。
二、其次我们说说如何构建微信跳转浏览器的源码:
1、ios端微信加遮罩提示前往浏览器打开的代码
<style type="text/css"> .mask { position: absolute; top: 0px; filter: alpha(opacity=60); background-color: #777; z-index: 1002; left: 0px; opacity:0.5; -moz-opacity:0.5; } </style>
<pre class="html" name="code"><script type="text/javascript"> //兼容火狐、IE8 //显示遮罩层 function showMask(){ $("#mask").css("height",$(document).height()); $("#mask").css("width",$(document).width()); $("#mask").show(); } //隐藏遮罩层 function hideMask(){ $("#mask").hide(); } </script>
<div id="mask" class="mask"></div> <a href="javascript:;" onclick="showMask()" >点我显示遮罩层</a><br />
2、Android端微信自动唤醒默认浏览器打开网页链接的代码
<?php // 统一调用微信白名单接口:https://api.366api.cn/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‘]; } ?>
<?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¶ms=%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¶ms=%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>‘; } } } ?> <!详情可参考:http://www.366api.cn-->
原文地址:https://www.cnblogs.com/jinlous/p/10945689.html
时间: 2024-10-07 19:31:23