mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2026-09-04 23:12:09 +08:00
- 将 InteractsProtocol 移动到 src/Contract/Trait,并更名为 WechatInteractsProtocol。 - 更新公众平台、小程序、第三方平台客户端的 Trait 引用和通用调用入口。 - 保留 access_token 缓存、raw/download/upload、消息加解密伪路径等协议层能力。 - 补充客户端工厂与 token 缓存相关测试夹具,确保迁移后调用路径保持兼容。
69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/**
|
|
* This file is part of HyperfAdmin.
|
|
*
|
|
* @Link https://thinkadmin.top
|
|
* @Author Anyon<zoujingli@qq.com>
|
|
*/
|
|
|
|
namespace We\Tests;
|
|
|
|
/**
|
|
* 测试密钥夹具。
|
|
*/
|
|
final class TestKeys
|
|
{
|
|
/** @var null|array{0:string,1:string} */
|
|
private static ?array $keyPair = null;
|
|
|
|
/**
|
|
* 返回测试用 EncodingAESKey。
|
|
*/
|
|
public static function encodingAesKey(): string
|
|
{
|
|
return 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG';
|
|
}
|
|
|
|
/**
|
|
* 返回测试用 RSA 私钥。
|
|
*/
|
|
public static function privateKey(): string
|
|
{
|
|
return self::keyPair()[0];
|
|
}
|
|
|
|
/**
|
|
* 返回测试用 RSA 公钥。
|
|
*/
|
|
public static function publicKey(): string
|
|
{
|
|
return self::keyPair()[1];
|
|
}
|
|
|
|
/**
|
|
* 生成并缓存测试使用的 RSA 密钥对。
|
|
*
|
|
* @return array{0:string,1:string}
|
|
*/
|
|
public static function keyPair(): array
|
|
{
|
|
if (self::$keyPair !== null) {
|
|
return self::$keyPair;
|
|
}
|
|
|
|
$resource = openssl_pkey_new(['private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA]);
|
|
if ($resource === false) {
|
|
throw new \RuntimeException('Unable to create test RSA key pair.');
|
|
}
|
|
openssl_pkey_export($resource, $privateKey);
|
|
$details = openssl_pkey_get_details($resource);
|
|
if (!is_array($details)) {
|
|
throw new \RuntimeException('Unable to read test RSA public key.');
|
|
}
|
|
|
|
return self::$keyPair = [$privateKey, (string)$details['key']];
|
|
}
|
|
}
|