PHP code example of wop-platform / wop-php-sdk

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

    

wop-platform / wop-php-sdk example snippets


use Wop\Sdk\WopClient;
use Wop\Sdk\WopConfig;
use Wop\Sdk\Transport\CurlTransport;

$client = new WopClient(new WopConfig(
    appKey:         'app_10012481831',
    securityReq:    'WOP-RSA3072-SHA256',
    privateKey:     $merchantPrivateKeyPemOrBase64,   // 己方私钥(出向加签 / 入向 DEK 解包)
    peerPublicKey:  $platformPublicKeyPemOrBase64,    // 平台公钥(响应/回调验签 / DEK 包装)
));

// 1. 构造请求(L0 明文 / L2 数字信封),得到可直接发送的 RequestDraft
$draft = $client->buildRequest('POST', '/gateway/logistics.order.query', $jsonBody, 'L2');

// 2. 任选 Transport 发送(curl 扩展适配器 / Guzzle peer 适配器,或自带 HTTP 栈)
$transport = new CurlTransport();
$response  = $transport->send($draft->method, 'https://gateway.example.com' . $draft->path,
                              $this->toHeaderLines($draft->headers), $draft->wireBody);

// 3. 验证平台响应(验签 → digest 复核 → DEK 解包 → alg 族比对 → 解密,顺序固定)
$result = $client->verifyResponse(
    $this->toArray($response->headers), $response->body, '/gateway/logistics.order.query');
if ($result->ok) {
    $plaintext = $result->plaintext;
}

// 商户回调接收端(POST)
$result = $client->verifyCallback($headers, $body, 'https://merchant.example.com/callback/notify');