0

我正在尝试为 Coinbase 比特币支付创建回调脚本。这是我的支付控制器的以下功能:

function callback($secret = NULL) {
    if ($secret == 'testSECRETkey') {

    //If order is "completed", please proceed.

    $data = json_decode(file_get_contents('php://input'), TRUE);

    $status = $data['order']['status'];
    $userid = '507';

    if (($status === 'completed')) {
        $this->db->query( 'update users set user_money=user_money+15, user_credits=user_credits+5 WHERE users_id=' . $userid );
    }
}

如何包含special parameter,所以当我请求 url:www.example.com/payments/callback 添加特殊密钥时,如果拒绝访问脚本无效。例子:

www.example.com/payments/callback?secret=testSECRETkey

不幸的是,它没有按我的意愿工作。它没有生效。它有什么问题?

4

1 回答 1

0

要访问key参数,您将使用 Input 类的get方法https://ellislab.com/codeigniter/user-guide/libraries/input.html

$this->input->get('key');

function callback()
{
    $key = $this->input->get('key');
    if( ! $this->is_valid_key($key)) {
       // do something here and return
       return;
    }

    //If order is "completed", please proceed.

    $data = json_decode(file_get_contents('php://input'), TRUE);

    $status = $data['order']['status'];
    $userid = '507';

    if (($status === 'completed')) {
        $this->db->query( 'update users set user_money=user_money+15, user_credits=user_credits+5 WHERE users_id=' . $userid );
    }
}

创建一个新方法来验证密钥

function is_valid_key($key) {
    // logic to check key
    $valid = true;
    if($valid) {
        return true;
    }
    else {
       return false;
    }
}
于 2014-09-15T18:45:41.200 回答