PHP code example of vtoday / shucang

1. Go to this page and download the library: Download vtoday/shucang library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vtoday / shucang example snippets




$appId = "1002";
$privateKey = "MIIEvAIBADANBgkq......jkl9aD/5k8I/Hag==";
$publicKey = "MIIBIjANBgkq......IDAQAB";


try {
    $client = new \Vtoday\Shucang\Client($appId, $privateKey, $publicKey, false);

} catch (\Vtoday\Shucang\Exceptions\ConfigurationException $e) {
    //do something ...

}


try {
    $client->doRequest("collection.info.sync", [
        "product_id"   => "123",
        "product_name" => "cccccccccccc",
        //other fields......
        //注意字段值类型,需要严格匹配类型值
    ]);
} catch (\Vtoday\Shucang\Exceptions\InvalidParamException $e) {
    // do something ...

}

try {
    $method = "";
    [$method, $data] = $client->parseRequestData();

    $bizData = [];

    if ($method == "user.info") {
        $bizData = [
            "user_id" => "123", // 字符串类型
            "wallet_address" => "xxxxxx",
            "verify_sign" => "eeeeee",
        ];
    }
    // do something ......

    $response = $client->genSignResponse(\Vtoday\Shucang\Client::SUCCESS_CODE, "成功", $method, $bizData);
    
} catch (\Vtoday\Shucang\Exceptions\ApiException $exception) {
    $response = $client->genSignResponse($exception->getErrCode(), $exception->getErrMessage(), $method);
    // do something ......
}catch(\Exception $exception){
    $response = $client->genSignResponse("5500", $exception->getMessage(), $method);
    // do something ......
}

//return $response