shoplo/bonapiti-bonanza-php-sdk

Bonanza 市场及其 "Bonapitit" REST API 的 PHP SDK。

v0.2.3 2018-07-10 13:00 UTC

This package is not auto-updated.

Last update: 2024-09-11 16:02:36 UTC


README

Bonanza 市场及其 "Bonapitit" REST API 的 PHP SDK。

该软件包目前支持调用 Bonanza 的方法

请参考以下 Bonanza API 文档: https://api.bonanza.com/docs

基本用法

对于每个调用,您需要在此处获取的 devID 和 certID: https://api.bonanza.com/accounts/new

非安全调用

<?php

use Shoplo\BonanzaApi\Client\BonanzaClient;
use Shoplo\BonanzaApi\Credentials\Credentials;
use Shoplo\BonanzaApi\Request\GetBoothItemsRequest;

//Create credentials object using obtained data
$credentials = new Credentials('devID', 'certID');

//Create bonanza client
$client = new BonanzaClient($credentials);

//Create request
$request = new GetBoothItemsRequest();
$request->page = 1;
$request->itemsPerPage = 3;
$request->boothId = 'boothName';

//Make a call and receive GetBoothItemsResponse object
$response = $client->getBoothItems($request);

安全调用

要执行安全调用,您首先需要获取用户认证令牌。要获取它,您需要执行 fetchToken 调用

<?php

use Shoplo\BonanzaApi\Request\FetchTokenRequest;

//Create request, and provide the callback url
$request = new FetchTokenRequest();
$request->validationCompleteURL = 'http://return.to/url';

//Make a call and get the authorization URL
$response = $client->fetchToken($request);

//You have the auth token here, but it is inactive, so you can save it for example in the session
$authToken = $response->fetchTokenResponse->authToken;

//Then you redirect user to the page, where he need to log in and confirm the token.
// After confirmation the user is taken back to the validationCompleteURL.
header('Location: '.$response->fetchTokenResponse->authenticationURL);

当访问令牌签名后,您可以执行安全调用。

<?php

use Shoplo\BonanzaApi\Client\BonanzaClient;
use Shoplo\BonanzaApi\Credentials\Credentials;
use Shoplo\BonanzaApi\Request\GetBoothItemsRequest;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

//Create credentials object using obtained data
$credentials = new Credentials('devID', 'certID');

//Create bonanza client
$client = new BonanzaClient($credentials);

//Create requester credentials containing the received token
$requesterCredentials = new RequesterCredentialsType();
$requesterCredentials->bonanzleAuthToken = 'authToken';

//Create request and pass the requesterCredentials to authorize the request
$request = new GetBoothItemsRequest();
$request->requesterCredentials = $requesterCredentials;
$request->page = 1;
$request->itemsPerPage = 3;
$request->boothId = 'boothName';

//Make a call and receive GetBoothItemsResponse object
$response = $client->getBoothItems($request);