此代码用于从iTunes发送销售报告。
当我通过浏览器刷新运行此代码时,它可以工作,但是当我将此代码放入cron作业时,它不会创建任何文件,因此它无法存储数据
$logText = '';
$ch1 = curl_init();
$startTime = strtotime('10 days ago');
$today = time();
while ($startTime < $today)
{
process($startTime);
$startTime = strtotime('+1 day', $startTime);
}
curl_close ($ch1);
//启动流程功能
function process($time) {
global $logText;
$date = date('Ymd', $time);
global $ch1, $accounts;
$accounts = array(array('username' => 'xxx',
'password' => 'xxx',
'vndnumber' => 'xxx',
),);
foreach($accounts as $account)
{
$fields_string = "USERNAME=" . urlencode($account['username']);
$fields_string .= "&PASSWORD=" . urlencode($account['password']);
$fields_string .= "&VNDNUMBER=" . $account['vndnumber'];
$fields_string .= "&TYPEOFREPORT=Sales";
$fields_string .= "&DATETYPE=Daily";
$fields_string .= "&REPORTTYPE=Summary";
$fields_string .= "&REPORTDATE=$date";
$filename = "{$date}-{$account['vndnumber']}";
**$fp = fopen("$filename.gz", 'w');
//set the url, number of POST vars, POST data
curl_setopt($ch1, CURLOPT_URL, 'https://reportingitc.apple.com/autoingestion.tft');
curl_setopt($ch1, CURLOPT_POST, 7);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_FILE, $fp);
//execute post
$contents = curl_exec ($ch1);
//$logText .= $contents;
if ($contents === false)
{
echo 'Curl error: ' . curl_error($ch1);
}
$logText .= curl_error($ch1);
fclose($fp);**
if (filesize("$filename.gz"))
{
if (function_exists('gzdecode')) {
file_put_contents($filename, gzdecode(file_get_contents("$filename.gz")) );
} else {
exec("gunzip $filename.gz");
}
}
}
file_put_contents(__DIR__."/log_backup.txt",file_get_contents(__DIR__."/log_backup.txt").$logText); }