PHP code example of corporate / paysdk

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

    

corporate / paysdk example snippets




orporate\PaySDK\Base\CorporateClient;
use Corporate\PaySDK\Base\Config;


//加载配置文件
$corporateClient = new CorporateClient(getOptions());


 //付款請求接口
$params = [
    "out_trade_no" => "20200326235526001",
    "public_chain" => "TRON",
    "digital_coin" => "USDT",
    "amount" => 1,
    "protocol" => "TRC-20",
    "receipt_address" => "TWK3vomsDgKNSwdvezcGGs24jztNjmKK99",
    "timestamp" => 1666245173,
    "note" => "test"
];

$result = $corporateClient->execute("/api/wallet/goPay",$params);
if($result->isSuccess()){

    if($result->verify()){

        print_r($result->dataMap());
    }else{
        throw new \Exception("驗簽失敗,請檢查Corporate應用公鑰或應用私鑰是否配置正確。");
    }

}else{
    throw new \Exception($result->ret() .":".$result->msg());
}


//异步回调通知處理示例
$json_string = '{"ret":1000,"msg":"\u8bf7\u6c42\u6210\u529f","data":"WDlwdnBoSkFDeS96bVdIYjg4WUNaaXVuV3NTQ......."}';
$result = $corporateClient->getApiResponse($json_string);
if($result->isSuccess()){

    if($result->verify()){

        print_r($result->dataMap());
    }else{
        throw new \Exception("驗簽失敗,請檢查Corporate應用公鑰或應用私鑰是否配置正確。");
    }
}


function getOptions()
{
    $options = new Config();

    $options->apiUrl = "<-- 請填寫應用分配的接口域名,例如:https://xxx.corporate.com/ -->";
    $options->appToken = "<-- 請填寫您的appToken,例如:377b26eb8c25bd... -->";

    //語系(參考文檔中最下方語系表,如:TC)
    $options->lang = "TC";

    $options->corporatePrivateCertPath = "<-- 請填寫您的應用私鑰路徑,例如:/foo/MyPrivateKey.pem -->";
    $options->corporatePublicCertPath = "<-- 請填寫Corporate應用公鑰證書文件路徑,例如:/foo/CorporatePublicKey.pem -->";

    return $options;
}