Php 如何在bigcommerce中使用Webhook?

Php 如何在bigcommerce中使用Webhook?,php,oauth,webhooks,bigcommerce,Php,Oauth,Webhooks,Bigcommerce,我试了很多, 我能够使用基本身份验证成功创建连接 Bigcommerce::configure(array( 'store_url' => 'https://store.mybigcommerce.com', 'username' => 'admin', 'api_key' => 'd81aada4xc34xx3e18f0xxxx7f36ca' )); 但是当我尝试使用“OAuth”时 它显示了这个错误: 注意:未定义变量:第25行/var/ww

我试了很多, 我能够使用基本身份验证成功创建连接

Bigcommerce::configure(array(
    'store_url' => 'https://store.mybigcommerce.com',
    'username'  => 'admin',
    'api_key'   => 'd81aada4xc34xx3e18f0xxxx7f36ca'
));
但是当我尝试使用“OAuth”时

它显示了这个错误:

注意:未定义变量:第25行/var/www/html/tests/bigcommerce/test/index.php中的请求
致命错误:对第25行/var/www/html/tests/bigcommerce/test/index.php中的非对象调用成员函数get()


谁能帮帮我吗?如何在php中使用bigcommerce的Webhook?

下面是在Laravel上使用的示例函数。一旦应用程序获得授权,就会触发此操作。
$request->get('code')
可以替换为
$\u request['code']
,因为它们纯粹是请求参数

一旦
Bigcommerce::configure
步骤完成,Webhook注册就会在try-catch块中开始

 public function onAppAuth(Request $request)
 {
    $object = new \stdClass();
    $object->client_id = env('BC_CLIENT_ID');
    $object->client_secret = env('BC_CLIENT_SECRET');
    $object->redirect_uri = env('BC_CALLBACK_URL');
    $object->code = $request->get('code');
    $object->context = $request->get('context');
    $object->scope = $request->get('scope');
    Bigcommerce::useJson();

    $authTokenResponse = Bigcommerce::getAuthToken($object);

    // configure BC App
    Bigcommerce::configure([
        'client_id' => env('BC_CLIENT_ID'),
        'auth_token' => $authTokenResponse->access_token,
        'store_hash' => explode('/', $request->get('context'))[1]
    ]);

    Bigcommerce::verifyPeer(false);

    try {
        $store_hash =  explode('/', $request->get('context'))[1];

        // register webhook
        Bigcommerce::createWebhook([
                "scope" => "store/order/created",
                "destination" => env('APP_URL')."api/order/process",
                "is_active" => true
            ]);

        return view('thankyou');

    } catch(Error $error) {
        echo $error->getCode();
        echo $error->getMessage();
    }

}

看来你自己也有错误的解释<代码>$request不在范围内。根据您使用的框架,它将更改访问$\u请求参数的用户。这与webhook注册无关。
 public function onAppAuth(Request $request)
 {
    $object = new \stdClass();
    $object->client_id = env('BC_CLIENT_ID');
    $object->client_secret = env('BC_CLIENT_SECRET');
    $object->redirect_uri = env('BC_CALLBACK_URL');
    $object->code = $request->get('code');
    $object->context = $request->get('context');
    $object->scope = $request->get('scope');
    Bigcommerce::useJson();

    $authTokenResponse = Bigcommerce::getAuthToken($object);

    // configure BC App
    Bigcommerce::configure([
        'client_id' => env('BC_CLIENT_ID'),
        'auth_token' => $authTokenResponse->access_token,
        'store_hash' => explode('/', $request->get('context'))[1]
    ]);

    Bigcommerce::verifyPeer(false);

    try {
        $store_hash =  explode('/', $request->get('context'))[1];

        // register webhook
        Bigcommerce::createWebhook([
                "scope" => "store/order/created",
                "destination" => env('APP_URL')."api/order/process",
                "is_active" => true
            ]);

        return view('thankyou');

    } catch(Error $error) {
        echo $error->getCode();
        echo $error->getMessage();
    }

}