PHP code example of youzanyun / open-sdk

1. Go to this page and download the library: Download youzanyun/open-sdk 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/ */

    

youzanyun / open-sdk example snippets




$clientId = "YOUR_CLIENT_ID";
$clientSecret = "YOUR_CLIENT_SECRET";
$resp = (new \Youzan\Open\Token($clientId, $clientSecret))->refreshToken('YOUR_REFRESH_TOKEN');
var_dump($resp);


$secretClient = SecretClient::getInstance("clientId","clientSecret");

$kdtId = xxxx;
// 单项加密
$encryptRel = $secretClient->singleEncrypt($kdtId, "加密内容");
// 单项解密
$decryptRel = $secretClient->singleDecrypt($kdtId,"解密内容");
// 批量加密
$batchEncryptArray = array("xxx1","xxx2","xxx3");
$batchEncryptArrayRel = $secretClient->batchEncrypt($kdtId,$batchEncryptArray);
// 批量解密
$batchDecryptArrayRel = $secretClient->batchDecrypt($kdtId,array_values($batchEncryptArrayRel));
// 单项密文判断
$encryptIsEncrypt = $secretClient->singleIsEncrypt($encryptRel);
// 批量密文判断
$batchEncryptIsEncrypt = $secretClient->batchIsEncrypt($batchEncryptArray);
// 单项解密并脱敏 如果是密文则解密脱敏,明文直接脱敏
// 脱敏类型: MaskHandler::$const_address 地址,MaskHandler::$const_bank_card 银行卡,MaskHandler::$const_name 中文名,MaskHandler::$const_email 邮箱,MaskHandler::$const_company_name 企业名称,MaskHandler::$const_id_card 身份证,MaskHandler::$const_mobile 手机号
$markAddress = $secretClient->singleDecryptMask($kdtId,"华泰创业园5号楼2楼217室",MaskHandler::$const_address);
// 批量解密并脱敏 如果是密文则解密脱敏,明文直接脱敏
// 脱敏类型: MaskHandler::$const_address 地址,MaskHandler::$const_bank_card 银行卡,MaskHandler::$const_name 中文名,MaskHandler::$const_email 邮箱,MaskHandler::$const_company_name 企业名称,MaskHandler::$const_id_card 身份证,MaskHandler::$const_mobile 手机号
$batchDncryptMarkArray = array("18736955554","18736955555","18736955556");
$batchMarkMobileRel = $secretClient->batchDecryptMask($kdtId,$batchDncryptMarkArray,MaskHandler::$const_mobile);
// 密文检索摘要生成
$addressDigest = $secretClient->generateEncryptSearchDigest($kdtId,"华泰创业园5号楼2楼217室");

 php
 php
lientId = "YOUR_CLIENT_ID";
$clientSecret = "YOUR_CLIENT_SECRET";
$resp = (new \Youzan\Open\Token($clientId, $clientSecret))->getToolAppToken('YOUR_CODE');
var_dump($resp);
 php
lientId = "YOUR_CLIENT_ID";
$clientSecret = "YOUR_CLIENT_SECRET";

// 1. 不获取refresh_token
$resp = (new \Youzan\Open\Token($clientId, $clientSecret))->getSelfAppToken('YOUR_KDT_ID');
var_dump($resp);

// 2. 获取refresh_token
$config['refresh'] = true;  //是否获取refresh_token(可通过refresh_token刷新token)
$resp = (new \Youzan\Open\Token($clientId, $clientSecret))->getSelfAppToken('YOUR_KDT_ID', $config);
var_dump($resp);
 php
ccessToken = 'YOUR_TOKEN';
$client = new \Youzan\Open\Client($accessToken);

$method = 'youzan.item.get';
$apiVersion = '3.0.0';

$params = [
    'alias' => 'fa8989ad342k',
];

$response = $client->post($method, $apiVersion, $params);
var_dump($response);
 php
lient = new \Youzan\Open\Client();

$method = 'youzan.item.get';
$apiVersion = '3.0.0';

$params = [
    'alias' => 'fa8989ad342k',
];

$response = $client->post($method, $apiVersion, $params);
var_dump($response);