将数据从Python POST请求传递到PHP

时间:2015-04-07 17:28:21

标签: php python request laravel-5

使用PHP Laravel 5.似乎无法了解如何执行此特定操作。我在python脚本中有数据。运行python命令将成功发布到我的PHP方法,并在我硬编码api密钥和密码时执行以下命令。

    $api_key = 1;
    $api_secret = 'sesame';

    //if api id and secret match, get oldest job with available timestamp before current time with status of 0

    if ($api_key == 1 and $api_secret == 'sesame') {

        $current_dt = '';
        $current_dt = date('Y.m.d H:i:s');

        $first_job_that_qualifies = \App\Job::orderBy('created_at', 'desc')
            ->where('status', 0)
            ->where('available_ts', '<', $current_dt)
            ->first();

        if ($first_job_that_qualifies != null){

            $first_job_that_qualifies->status = 1;
            $first_job_that_qualifies->save();
        }


    }


    }

现在我想取出硬编码的值并用我从python传递的数据检查它们。

    data = {
        'api_key': api_key,
        'api_secret': api_secret,
        }

    print data

    r = requests.post(quasar_url, data=data)
    print r.text

我如何称呼该词典&#34;数据&#34;从PHP函数中的python中我可以在我的初始if语句中使用它吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

您的意思是阅读$_POST参数吗?

if ($api_key == $_POST['api_key'] and $api_secret == $_POST['api_secret']) {

相关问题