Tovanix(原 NexCore)平台全能 PHP 客户端,覆盖 Payment / Exchange / Energy / SMTP / Withdraw / Account / VCard 7 大命名空间全部 44 个 v1 公开 endpoint.
- PHP 7.4+(支持 PHP 8.x)
- ext-curl, ext-json
composer require nexcore/sdk(SDK 包发布到 Packagist 后)
cp -r sdk/php/src your-project/lib/nexcore/
# 然后在代码里 require src/Client.php(及其他依赖文件)src/
├── Client.php 主客户端入口
├── Http.php 底层 HTTP 传输
├── NexCoreError.php 统一异常
└── Namespaces/
├── Payment.php 多链收款(7 endpoints)
├── Exchange.php 汇率(5 endpoints)
├── Energy.php TRON 能量租赁(8 endpoints)
├── Smtp.php SMTP 聚合 API(6 endpoints)
├── Withdraw.php 提币(4 endpoints,RSA 签名)
├── Account.php 账户(2 endpoints)
└── VCard.php 虚拟信用卡(12 endpoints)
<?php
require_once __DIR__ . '/vendor/autoload.php';
use NexCore\Client;
use NexCore\NexCoreError;
$client = new Client([
'base_url' => 'https://your-domain.com',
'payment_app_id' => 'APP20260412XXXX',
'payment_app_key' => 'your_app_key_here',
'energy_api_key' => 'energy_api_key_here',
'energy_secret_key' => 'energy_secret_key_here',
'smtp_api_key' => 'smk_xxx',
'timeout' => 30,
]);
try {
// 创建支付订单
$order = $client->payment->createOrder([
'out_order_id' => 'ORDER_' . time(),
'amount' => '100.00',
'currency' => 'CNY',
'trade_type' => 'usdt.trc20',
'call_type' => 'rotation',
'timeout' => 1800,
]);
echo "支付地址: {$order['pay_address']}\n";
// 查询汇率
$rate = $client->exchange->getRate('USDT', 'CNY');
echo "USDT/CNY: {$rate['rate']}\n";
// 估算 TRC20 能量
$est = $client->energy->estimateEnergy('TXxxxxxxxxxxxxxxxxxxxxx');
echo "建议能量: {$est['suggested_energy']}\n";
// 发送邮件
$mail = $client->smtp->send([
'to' => 'user@example.com',
'subject' => '验证码',
'body' => '<h1>123456</h1>',
'is_html' => true,
]);
echo "消息 ID: {$mail['message_id']}\n";
} catch (NexCoreError $e) {
echo "Error #{$e->code}: {$e->getMessage()} (trace: {$e->requestId})\n";
}| 方法 | HTTP | endpoint |
|---|---|---|
createOrder($params) |
POST | /api/v1/pay/create |
queryOrder($outOrderId) |
GET | /api/v1/pay/query |
closeOrder($outOrderId) |
POST | /api/v1/pay/close |
getAppConfig() |
GET | /api/v1/pay/app-config |
bindAddress($userId, $tradeType) |
POST | /api/v1/pay/bind-address |
getUserAddress($userId) |
POST | /api/v1/pay/get-address |
unbindAddress($userId) |
POST | /api/v1/pay/unbind-address |
sign($params) |
(工具) | HMAC-SHA256 签名 |
verifyNotifySign($payload) |
(工具) | webhook 校验(常量时间比较) |
| 方法 | HTTP | endpoint |
|---|---|---|
getRate($from, $to) |
GET | /api/v1/rate |
convert($from, $to, $amount) |
POST | /api/v1/convert |
getRates($symbols, $base = '') |
GET | /api/v1/rates |
getFiatRates($base) |
GET | /api/v1/rates/fiat |
getAllRates($base) |
GET | /api/v1/rates/all |
注:getRates 的 $base 不传时由后端取默认(USDT).
| 方法 | HTTP | endpoint |
|---|---|---|
getInfo() |
GET | /api/v1/energy/info |
getPrice($energyAmount, $period = '1D') |
GET | /api/v1/energy/price?energy_amount=&period= |
estimateEnergy($toAddress) |
GET | /api/v1/energy/estimate-energy?to_address= |
createOrder($params) |
POST | /api/v1/energy/order |
createOnetimeOrder($params) |
POST | /api/v1/energy/order/onetime |
queryOrder($serial) |
GET | /api/v1/energy/order/:serial |
listOrders($filter) |
GET | /api/v1/energy/orders |
reclaimOrder($params) |
POST | /api/v1/energy/order/reclaim |
注:租期 $period 枚举 1H / 1D / 3D / 7D / 30D;createOrder 必填 receive_address / energy_amount / period,可选 out_trade_no / remark.
| 方法 | HTTP | endpoint |
|---|---|---|
send($params, $idempotencyKey = null) |
POST | /api/v1/smtp/send |
sendBatch($params, $idempotencyKey = null) |
POST | /api/v1/smtp/send/batch |
sendTemplate($params) |
POST | /api/v1/smtp/send/template |
getQuota() |
GET | /api/v1/smtp/quota |
getStatus($messageId) |
GET | /api/v1/smtp/status/:message_id |
reportInbound($params) |
POST | /api/v1/smtp/inbound |
send可选字段:from_name/reply_to/text_body/headers/cc/bcc/attachments/account_id/send_at(定时,RFC3339);$idempotencyKey写入Idempotency-Key幂等头sendBatch必填recipients数组(元素{to, variables?, from_name?}),静态subject+body或template_code二选一;同样支持$idempotencyKeysendTemplate必填to+template_code,可选variables/from_namegetQuota返回daily_limit/daily_used/daily_remaining/monthly_*/expire_atreportInbound上报退信/投诉(email与message_id至少其一,type=bounce|complaint)
| 方法 | HTTP | endpoint |
|---|---|---|
createWithdraw($params) |
POST | /api/v1/withdraw |
getWithdraw($orderId) |
GET | /api/v1/withdraw/:id |
getWithdrawableBalance() |
GET | /api/v1/balance/withdrawable |
quoteFee($chain, $symbol, $amount) |
GET | /api/v1/fee/quote($amount 必填) |
sign(...) / verifyCallback(...) |
(工具) | RSA 签名 / 平台回调验签 |
| 方法 | HTTP | endpoint |
|---|---|---|
getBalance() |
GET | /api/v1/account/balance |
getDepositAddress() |
GET | /api/v1/account/deposit-address |
| 方法 | HTTP | endpoint |
|---|---|---|
getInfo() / listBins() / listCards() |
GET | /api/v1/vcard/*(读,X-API-Key) |
getCardTransactions($cardId) / listOrders($query) / getOrder($orderId) |
GET | 同上 |
updateCardRemark($cardId, $remark) |
POST | 同上 |
getCardDetails($cardId) / getCardCode($cardId) |
GET | 敏感读(HMAC 头签名) |
openCard($params) / rechargeCard($cardId, $params) / cancelCard($cardId) |
POST | 资金操作(HMAC 头签名) |
$payload = json_decode(file_get_contents('php://input'), true);
if (!$client->payment->verifyNotifySign($payload)) {
http_response_code(400);
echo 'invalid sign';
exit;
}
// 处理回调... 同一订单可能重试,务必幂等
http_response_code(200);verifyNotifySign 内部用 hash_equals 常量时间比较,防时序攻击.
NexCore\NexCoreError:
$code— 平台错误码(0=成功,-1=客户端层)getMessage()— 错误描述$requestId— 服务端追踪 ID(响应头X-Trace-Id)$httpStatus— HTTP 状态码
见 examples/:
create_order.php— 完整下单流程webhook.php— 接收回调