1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace Api\Controller;
- use Think\Controller;
- class DownloadController extends Controller{
- public function index(){
- $checkos = $this->checkos();
- switch ($checkos) {
- case "weibo":
- $default_url="http://www.pengcieredu.com/";
- header("Location: ".$default_url);
- break;
- case "ios":
- if($this->is_weixin_ios()){//weixin
- $downurl="https://itunes.apple.com/cn/app/%E7%A2%B0%E8%AF%8D%E5%84%BF-%E5%85%A8%E8%83%BD%E7%9A%84%E5%8D%95%E8%AF%8D%E8%AE%B0%E5%BF%86%E5%8A%A9%E6%89%8B/id1353692603?mt=8";
- }
- break;
- case "android":
- if($this->is_weixin_ios()){//weixin
- // $downurl="https://mobile.baidu.com/item?docid=25707250";
- $downurl="https://sj.qq.com/myapp/detail.htm?apkName=com.hanlinyuan.vocabularygym";
- }else{
- //取最新版的软件
- $downurl='http://www.hanlinyuanonline.com/soft/pce_v1.8.6_19_186_jiagu_sign.apk';
- }
- break;
- default:
- $downurl="";
- break;
- }
-
- if($downurl){
- //echo $downurl;
- header("Location: ".$downurl);
- }else{
- //die("download error!");
- $default_url="http://www.pengcieredu.com/";
- header("Location: ".$default_url);
- }
- }
- private function checkos(){
- $os = "";
- $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
- if (preg_match("/weibo/i", $userAgent)) {
- $os = "weibo"; // android客户端
- } elseif (preg_match("/(ipod|ipad|iphone)/", $userAgent)) {
- $os = "ios"; // IOS客户端
- } elseif (preg_match("/wp/", $userAgent)) {
- $os = 'wp'; // WinPhone客户端
- } elseif (preg_match("/android/i", $userAgent)) {
- $os = "android"; // android客户端
- } else {
- $os = 'otheros';
- }
- return $os;
- }
-
- /*判断是否是微信浏览器 这个方法不太靠谱*/
- private function is_weixin_ios(){
- if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
- return true;
- }
- return false;
- }
- }
|