开奖接口api制作-curl获取并制作接口json和xml格式

<?php 
//header('Content-Type:text/json;charset=utf8');
header("Content-type:text/xml");
$api = 'https://api.api.com/pks/getLotteryPksInfo.do?lotCode=10037';
$resource = file_get_contents_by_curl( $api );  
$data = json_decode( $resource , 1 );
//$rq="20" . $data['result']['data']['preDrawIssue'];
$rq=$data['result']['data']['preDrawIssue'];
$hm=$data['result']['data']['preDrawCode'];
$sj=$data['result']['data']['preDrawTime'];
//echo '{"sign":true,"message":"获取成功","data":[{"title":"极速赛车","name":"pl3","expect":"'.$rq.'","opencode":"'.$hm.'","opentime":"'.str_replace('/','-',$sj).'","source":"开彩采集","sourcecode":""}]}';
echo '<?xml version="1.0" encoding="UTF-8"?>
<xml>';
echo '<row expect="'.$rq.'" opencode="'.$hm.'"  opentime="'.str_replace('/','-',$sj).'"/>';
echo '</xml>';
function file_get_contents_by_curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//禁止调用时就输出获取到的数据
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
$result = curl_exec($ch);
curl_close($ch);return $result;
}
 ?>
 
************************************************
 时间获取api  php
 
<?php 
header('Content-Type:text/json;charset=utf8');
//header("Content-type:text/xml");
$api = 'http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json';
$resource = file_get_contents_by_curl( $api );  
$data = json_decode( $resource , 1 );
//$rq="20" . $data['result']['data']['preDrawIssue'];
$time1=$data['result']['datetime_1'];
$time2=$data['result']['timestamp'];
//$time3=$data['result']['datetime_2'];
//$sj=$data['result']['data']['preDrawTime'];
echo '{"sysTime2":"'.$time1.'","sysTime1":"'.$time2.'"}';
/*echo '<?xml version="1.0" encoding="UTF-8"?>
<xml>';
echo '<row expect="'.$rq.'" opencode="'.$hm.'"  opentime="'.str_replace('/','-',$sj).'"/>';
echo '</xml>';*/
function file_get_contents_by_curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//禁止调用时就输出获取到的数据
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
$result = curl_exec($ch);
curl_close($ch);return $result;
}
 ?>