PHP code example of takecloud / tpay-sdk

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

    

takecloud / tpay-sdk example snippets



use \TPay\TPayManager;

$client = TPayManager::newClient('your merchantNo', 'your secretKey');


use \TPay\TPayManager;

$client = TPayManager::newClient('your merchantNo', 'your secretKey');
$response = TPayManager::barcodePay($client, 1, 'FZY2019112204', 0.03, 'xxxxxxxxxxxxxxx', '测试订单', '测试订单');


use \TPay\TPayManager;

$client = TPayManager::newClient('your merchantNo', 'your secretKey');
// 构造请求参数
$params = new \TPay\BarcodePay\BarcodePayParams();
$params->setOutTradeNo('FZY2019112101');
$params->setPayType(1);
$params->setTotalAmount(0.01);
$params->setBody('测试订单');
$params->setSubject('测试订单');
$params->setAuthCode('xxxxxxxxxxxxxxxxxxxxxxxx');
// 发起请求
$response = $client->barcodePay($params);


use \TPay\TPayManager;

// 回调的请求参数
$params = $_POST;
// 回调的签名
$sign = $params['sign'];
unset($params['sign']);

$client = TPayManager::newClient('your merchantNo', 'your secretKey');

// 比对服务端和客户端签名
if ($sign === $client->generateSign($params)) {
    // 有效签名
}