chengdu-blue-brothers/openapi-php-sdk-v2

蓝色兄弟 openapi sdk v2

v0.0.3 2025-03-24 02:00 UTC

This package is not auto-updated.

Last update: 2025-03-24 02:54:18 UTC


README

使用Composer安装

composer require chengdu-blue-brothers/openapi-php-sdk-v2

api 接口调用

use BlueBrothers\OpenapiV2\Api\Client;
use BlueBrothers\OpenapiV2\ResponseException;

const testMerchantId = "23329";
const testSecretKey  = "8db16e8cc8363ed4eb4c14f9520bcc32";
const isProd = false; // 是否是生产环境
try {
    $client = new Client(testMerchantId, testSecretKey, isProd, 10);
    $res = $client->ProductList();
} catch (\Exception $e) {
    if ($e instanceof ResponseException) {
        echo $e->getResponseCode();
        echo $e->getMessage();
    }
    echo $e->getMessage();
}

解密卡密

use BlueBrothers\OpenapiV2\Util;

$encCode = 'ezvbQdCehTDO7M7g22FjThOCypEhk/kswonAbdEEVsY=';
// 示例的密钥key
$secretKey = '8db16e8cc8363ed4eb4c14f9520bcc32';

// 第二步:aes-256-ecb 解密
try {
    $decryptedCode = Util::getDecodeCardMap($encCode, $secretKey)  ;
} catch (\Exception $e) {
    echo $e->getMessage();
}

验证签名

use BlueBrothers\OpenapiV2\Util;

$appSecret = '8db16e8cc8363ed4eb4c14f9520bcc32';
// "MD5 mchid=xxx,timestamp=xxx,signature=xxx"
// 解析header Authorization 获取到 mchid, timestamp, signature

Util::verifySign($sign, $appSecret, $path, $body, $timestamp, $mchId)

回调签名验证

use BlueBrothers\OpenapiV2\Util;
const testMerchantId = "23329";
$appSecret = '8db16e8cc8363ed4eb4c14f9520bcc32';
// 解析header Authorization 获取到 md5 加密字符串

Util::verifyCallbackSign($sign, $appSecret,$body, $mchId)