微信分享域名打開自動喚醒默認瀏覽器
阿新 • • 發佈:2019-01-27
tro amp 選擇 blank dir release upd end 喚醒
1. 遮罩提示(多用於ios系統)
問題概述
通過掃描二維碼下載APP已成為一個大家管用且非常方便的下載方式了,微信也成為掃描二維碼重要的工具,因為目前微信的用戶占據了市場的半壁江山。
然而在我們做營銷活動或推廣宣傳的時候,容易遇到域名被封,無法跳轉app下載等情況。這時需要微信跳轉外部瀏覽器打開頁面的功能,對於ios系統的用戶默認可以通過點擊右上角的更多符號從而選擇“在瀏覽器中打開”的方法很多用戶並不知道這樣的實現,因此需要在代碼中進行相關處理。 目前ios只能通過遮罩層來提示用戶前往Safari打開分享域名,對於安卓可以直接跳出手機默認瀏覽器,下面就分別介紹下這2種方式的實現方式。
實現方式
1. 遮罩提示(多用於ios系統)
遮罩引導法,這種是最簡單的方法,一般會用在ios系統上。屏蔽圖如下
1.1 實現代碼
? 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.2 實現效果
2. 鏈接跳轉(多用於安卓系統)
對於安卓系統而言,微信中打開分享域名可以自動跳轉手機默認瀏覽器前往下載頁。實現代碼如下:
? <?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‘]; } ?>-有不懂的請咨詢我的q:3358246772->
? <?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>‘; } } }
至此,我們在微信中分享下載鏈接或二維碼就不會出現無法自動跳轉的問題了,本代碼另外還附帶了防封接口,可最大程度防止微信封域名的情況。這樣我們就可以直接用微信掃描二維碼在微信中分享和宣傳引流了。如此我們即能夠極大的提高自己的APP在微信中的推廣轉化率。也解決掉了微信中下載鏈接被屏蔽等問題。充分利用微信的用戶群體來宣傳引流。
微信分享域名打開自動喚醒默認瀏覽器