nigel/utils

1.0.1 2024-03-29 21:21 UTC

This package is auto-updated.

Last update: 2024-09-29 22:21:40 UTC


README

PHP 工具脚本

安装

 composer require nigel/utils

1. SSL 证书生成器

此脚本是一个 PHP 工具,用于生成 SSL 证书,包括私钥、证书签名请求(CSR)和证书本身。

示例

<?php

use Nigel\Utils\Core\SSL\SSLGenerator;

require_once './app/bootstrap.php';

header('Content-type: application/json');

$domain = 'example.com';

$rootFolder = rtrim(__DIR__, '/') . '/files/';
$sslGenerator = new SSLGenerator($rootFolder);

$csrDetails = array(
    "countryName" => "ZW",
    "stateOrProvinceName" => "Harare",
    "localityName" => "Harare",
    "organizationName" => "Example Inc",
    "organizationalUnitName" => "IT Department",
    "commonName" => $domain,
    "emailAddress" => "admin@$domain",
);

try {
    $ssStrings = $sslGenerator->generateSSLStrings($domain, $csrDetails);
    echo "Private Key:\n\n" . $ssStrings['privateKey'] . "\n\n" .
        "CSR:\n\n" . $ssStrings['csr'] . "\n\n" .
        "Cert:\n\n" . $ssStrings['cert'];
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

// OR

try {
    $sslFiles = $sslGenerator->generateSSLFiles($domain, $csrDetails);
    echo $sslFiles;
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

?>

2. Contipay 校验和生成器

此 PHP 脚本使用 Contipay 的校验和算法生成校验和,用于交易验证。生成的校验和对于确保交易数据的完整性和真实性至关重要。

示例

<?php
use Nigel\Utils\Core\Checksums\ContipayChecksum;

require_once './app/bootstrap.php';

$privKey = <<<EOD
-----BEGIN PRIVATE KEY-----
    SSL KEY HERE
-----END PRIVATE KEY-----
EOD;

$authKey = "NmZKTkdJdnVDJMWnJMQT";
$reference = "PAYOUT-83bbbe26-1cfa-435d";
$merchantId = $MERCHANT_ID;
$accountNumber = "0782000340";
$amount = "5.0";

$checksum = (new ContipayChecksum())->generateChecksum($authKey . $reference . $merchantId . $accountNumber . $amount, true, openssl_get_privatekey($privKey, ""));

echo $checksum;
?>

3. 电话助手

此脚本利用围绕 'giggsey/libphonenumber-for-php' 库的自定义包装来格式化和验证电话号码。

示例

<?php

use Nigel\Utils\Core\Phone\Phone;

require_once './app/bootstrap.php';

header('Content-type: application/json');

$phone = "0782000340"; // Zimbabwe Econet Number

$test = (new Phone($phone, 'ZW'))->internationalFormat();


echo $test;

响应


263782000340

可用方法

  1. isValid()
  • 检查号码是否有效
  1. internationalFormat()
  • 从解析的号码获取国际格式
  1. nationalFormat()
  • 从解析的号码获取国家格式
  1. getCountry()
  • 从解析的号码获取国家名称
  1. providerInfo()
  • 从解析的号码获取提供者信息
  1. timeZoneInfo()
  • 从解析的号码获取时区信息