<?php
header("Access-Control-Allow-Origin: https:// ");
$version = PAPI_GetSafeParam(‘version‘);
//设置缓存
$arr = [];
$down_path = ‘‘;
$mem_key = "get_app_version";
$down_path = $mem->get($mem_key);
//对象转化为数组函数
function xmlToArrayElement($getData) {
$data = array();
foreach ((array) $getData as $key => $value) {
$data[$key] = !is_string($value) ? xmlToArrayElement($value) : $value;
}
return $data;
}
if(!$down_path){
//读取xml文件中的版本号
$file_path="version.xml";
$file_arr = file_get_contents($file_path);
$file_arr = simplexml_load_string($file_arr, ‘SimpleXMLElement‘, LIBXML_NOCDATA);
$xml = xmlToArrayElement($file_arr);
$down_path = $xml[‘path‘];
$mem->set($mem_key,$down_path,0,MEMCACHE_MEDIA);
}
$arr[‘down_path‘] = $down_path;
if($version) exit(json_encode($arr));
//判断是否是微信
function is_Weixin()
{
if (strpos($_SERVER[‘HTTP_USER_AGENT‘], ‘MicroMessenger‘) !== false)
{
return true;
}
return false;
}
//判断是否是安卓
function is_Android()
{
if (strpos($_SERVER[‘HTTP_USER_AGENT‘], ‘Android‘) !== false)
{
return true;
}
return false;
}
//判断是否是ios
function is_Ios()
{
if (strpos($_SERVER[‘HTTP_USER_AGENT‘], ‘iPhone‘) !== false || strpos($_SERVER[‘HTTP_USER_AGENT‘], ‘iPad‘) != false)
{
return true;
}
return false;
}
//是微信打开情况下直接跳转下载页面
if(is_weixin())
{
header("Location:https://a.app.qq.com/o/simple.jsp?pkgname=com.deskmate100");
}
if(!is_weixin())
{
if(is_Android())
{
header("Location:{$down_path}");
}
else if(is_Ios())
{
header("Location:https://itunes.apple.com/cn/app/id980606650");
}
else
{
header("Location:{$down_path}");
}
}
扫二维码 下载app