2016-11-18 101 views
1

我有點新的yii FrameWork,我需要幫助。yii2 Webhook發佈空

我需要實現一個條紋webhook控制器,用於由Stripe發送的訂閱事件。 對於這個控制器,沒有視圖,也沒有型號

我可以訪問控制器,但$ _POST內容是空的,我不明白爲什麼。

是否可以使用沒有視圖的帖子動詞?

這裏有一個例子:

class StripeWebhookController extends Controller 
{ 
    public function beforeAction($action) 
    { 
     if ($action->id == 'index') { 
      $this->enableCsrfValidation = false; 
     } 

     return parent::beforeAction($action); 
    } 

public function actionIndex() 
{ 
    header('Content-Type: text/html; charset=utf-8'); 

    StripeLoader::autoload(); 
    \Stripe\Stripe::setApiKey(Settings::get("stripe_secret_key")); 
     // retrieve the request's body and parse it as JSON 
     $input = file_get_contents('php://input'); // -> here $input is null 

     $event_json = json_decode($input, true); 

    //  Do the work... 
} 

我使用的

print_r(Yii::$app->request->post() /*$_POST*/); exit(); 

,我只得到了一個空數組。

後搜索的日子裏,我什麼也沒發現......

如果任何人有一個想法,我會很樂意把它

其它附加信息:我們是IIS Web服務器上運行,使用Yii2框架

感謝您閱讀我 CYA

回答

0

如果Yii::$app->request->post()爲空,那麼請求沒有POST數據。在beforeAction中抓取請求並轉儲整個事情。這將是您的機器正在接收。如果爲空,機器沒有收到與請求一起發送的數據。

+0

我試着你問了什麼,這是什麼出去: Array() 所以我控制器沒有收到任何東西。 我做的另一個測試: ($ _SERVER ['REQUEST_METHOD'] 給了我一個get ... soooooo我一個困惑 –

+0

這告訴我服務器正在接收一個空請求; _POST確實是空的,這讓我覺得 –

+0

你認爲IIS會拒絕那個控制器上的POST動作嗎? –