PHP code example of suifuda / suifuda-open-sdk
1. Go to this page and download the library: Download suifuda/suifuda-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/ */
suifuda / suifuda-open-sdk example snippets
use Suifuda\Sdk\SfdClient;
use Suifuda\Sdk\Config\SignType;
use Suifuda\Sdk\Config\SfdConfig;
$sfdConfig = SfdConfig::builder()
->useProdEnv() // ->useTestEnv()测试环境 ->useProdEnv()生产环境
->appKey('YOUR_APP_KEY')
->privateKey('YOUR_PRIVATE_KEY') // Base64,可不含 PEM 头尾
->signType(SignType::RSA()) // 或 SignType::SM() / 'SM'
->platformPublicKey('PLATFORM_PUBLIC_KEY')
->enableLog(true)
->enableResponseVerify(true) // HTTP 2xx 强制验签;非 2xx 无签名头则跳过
->sslVerify(true) // 测试证书异常时可临时 false
->build();
$client = SfdClient::create($sfdConfig);
$params = array(
'merchantOrgCode' => '100001568',
'orderTradeNo' => 'P2026091821008565894443704327',
);
$httpResponse = $client->execute('/open/trade/v1/pay/query', $params);
echo $httpResponse->getStatusCode();
echo $httpResponse->getBody();
// getResponse() 仅允许 HTTP 2xx;开启验签时 2xx 必须验签通过
$response = $httpResponse->getResponse();
if ($response->isSuccess()) {
$response->getData();
}
$ok = $client->verifyNotify($requestHeaders, $rawBody);
// 或
$ok2 = $client->verifyNotifyFields($appKey,$nonce, $sign, $timestamp, $signType, $rawBody);