DownloadController.class.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Api\Controller;
  3. use Think\Controller;
  4. class DownloadController extends Controller{
  5. public function index(){
  6. $checkos = $this->checkos();
  7. switch ($checkos) {
  8. case "weibo":
  9. $default_url="http://www.pengcieredu.com/";
  10. header("Location: ".$default_url);
  11. break;
  12. case "ios":
  13. if($this->is_weixin_ios()){//weixin
  14. $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";
  15. }
  16. break;
  17. case "android":
  18. if($this->is_weixin_ios()){//weixin
  19. // $downurl="https://mobile.baidu.com/item?docid=25707250";
  20. $downurl="https://sj.qq.com/myapp/detail.htm?apkName=com.hanlinyuan.vocabularygym";
  21. }else{
  22. //取最新版的软件
  23. $downurl='http://www.hanlinyuanonline.com/soft/pce_V1.8.3.apk';
  24. }
  25. break;
  26. default:
  27. $downurl="";
  28. break;
  29. }
  30. if($downurl){
  31. //echo $downurl;
  32. header("Location: ".$downurl);
  33. }else{
  34. //die("download error!");
  35. $default_url="http://www.pengcieredu.com/";
  36. header("Location: ".$default_url);
  37. }
  38. }
  39. private function checkos(){
  40. $os = "";
  41. $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
  42. if (preg_match("/weibo/i", $userAgent)) {
  43. $os = "weibo"; // android客户端
  44. } elseif (preg_match("/(ipod|ipad|iphone)/", $userAgent)) {
  45. $os = "ios"; // IOS客户端
  46. } elseif (preg_match("/wp/", $userAgent)) {
  47. $os = 'wp'; // WinPhone客户端
  48. } elseif (preg_match("/android/i", $userAgent)) {
  49. $os = "android"; // android客户端
  50. } else {
  51. $os = 'otheros';
  52. }
  53. return $os;
  54. }
  55. /*判断是否是微信浏览器 这个方法不太靠谱*/
  56. private function is_weixin_ios(){
  57. if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
  58. return true;
  59. }
  60. return false;
  61. }
  62. }