PHP code example of allesx / cgb-payment-sdk

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

    

allesx / cgb-payment-sdk example snippets


use Allesx\CgbPayment\Client\CgbClient;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$config = [
    'app_id' => '907kbk2aogw2',
    'ent_cst_no' => '60000007905',
    'ent_user_id' => '100001',
    'ent_password' => '1q2w3e4r',
    'gateway_url' => 'https://ebank-yd03.test.cgbchina.com.cn:49081/deib/E1DEIB/E101/',
    'version' => '2.0.0',
    'private_key' => __DIR__ . '/data/cert/merchant.pfx',         // 或 PEM 字符串
    'private_key_pass' => 'your_password',
    'public_key' => __DIR__ . '/data/cert/bank.cer',              // 银行公钥证书
    'bank_psw_enc_pub' => 'SM2_PUBLIC_KEY_HEX',                   // 可选:操作员密码加密公钥
    'sign_algo' => 'SHA1',                                        // 或 SHA256
    'timeout' => 30,
    'mac_address' => '',                                          // 可选:固定上送
];

$logger = new Logger('cgb');
$logger->pushHandler(new StreamHandler(__DIR__ . '/cgb.log'));

$client = new CgbClient($config, $logger);

// 示例:交易码 0021(行内/行外付款)
$body = [
    'tradeTypeNo' => 'AC0ZA001',
    'entBizDt' => '20240718',
    'entBizId' => '202407180021091902001',
    'entCstNo' => '60000007905',
    'payerAcctNo' => '100001',
    'payerAcctName' => '测试公司',
    'remark' => '备注',
    'payeeAcctNo' => '1111222233334444',
    'payeeAcctName' => '收款公司',
    'payeeBkFlag' => 'T',
    'payeeBkNo' => '307100003019',
    'payeeBkName' => '平安银行股份有限公司北京分行',
    'amount' => '1707.50',
    'postscript' => '附言',
    'addWord' => '11',
    'acBkShowFlag' => '',
];

$res = $client->request('0021', $body);
var_dump($res['parsed'] ?? $res);