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 に答える