doubangzhang6992 2016-03-16 11:26
浏览 42

使用php从itunes获取销售报告

This code is use to get sales report from itunes.

when i run this code through browser refresh it works but when i put this code in cron jobs it not create any files so it can not store data

$logText = '';
$ch1 = curl_init();
$startTime = strtotime('10 days ago');

$today = time();
while ($startTime < $today)
{
    process($startTime);
    $startTime = strtotime('+1 day', $startTime);
}
curl_close ($ch1);

// start process function

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); }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据