对于 PHP
我在 RestMethods.php 中创建了 2 个额外的方法,它们使用 Walletobjects.php 中定义的方法
public function updateLoyaltyClass($classId, $objectPayload){
$response = NULL;
$service = new Google_Service_Walletobjects($this->client);
try {
$response = $service->loyaltyclass->update($classId, $objectPayload);
$response["code"] = 200;
} catch (Google_Service_Exception $gException) {
$response = $gException->getErrors();
$response["code"] = $gException->getCode();
echo("\n>>>> [START] Google Server Error response:");
var_dump($response);
echo("\n>>>> [END] Google Server Error response\n");
} catch (Exception $e){
var_dump($e->getMessage());
}
return $response;
}
public function updateLoyaltyObject($objectId, $objectPayload){
$response = NULL;
$service = new Google_Service_Walletobjects($this->client);
try {
$response = $service->loyaltyobject->update($objectId, $objectPayload);
$response["code"] = 200;
} catch (Google_Service_Exception $gException) {
$response = $gException->getErrors();
$response["code"] = $gException->getCode();
echo("\n>>>> [START] Google Server Error response:");
var_dump($response);
echo("\n>>>> [END] Google Server Error response\n");
} catch (Exception $e){
var_dump($e->getMessage());
}
return $response;
}
然后创建了我自己的 update.php,它重用了 ResourceDefinitions.php 类和对象,您可以在文档中进行内联编辑
<?php
require_once "Config.php"; // define constants
require_once 'RestMethods.php';
require_once "Services.php";
require_once 'Walletobjects.php';
require_once 'ResourceDefinitions.php';
$restMethods = RestMethods::getInstance();
$issuerUID = "Your Issuer ID";
$classUid = "Your Class ID";
$classId = sprintf("%s.%s" , $issuerUID, $classUid);
$objectUid= "Your Object ID";
$objectId = sprintf("%s.%s", $issuerUID, $objectUid);
//fetch object and class from resource
$objectResourcePayload = ResourceDefinitions::makeLoyaltyObjectResource($classId, $objectId);
$classResourcePayload = ResourceDefinitions::makeLoyaltyClassResource($classId);
//print_r($objectResourcePayload);
//print_r($classResourcePayload);
$classUpdateResponse = $restMethods->updateLoyaltyClass($classId,$classResourcePayload);
$objectUpdateResponse = $restMethods->updateLoyaltyObject($objectId,$objectResourcePayload);
print_r($classUpdateResponse);
print_r($objectUpdateResponse);
?>