| Server IP : 119.36.225.67 / Your IP : 43.159.78.200 Web Server : nginx/1.28.0 System : Linux 1763701629066 6.8.0-53-generic #55-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan 17 15:37:52 UTC 2025 x86_64 User : www ( 1001) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/www.lengcat.cn/wp-content/themes/onenav/vendor/yurunsoft/pay-sdk/src/Lib/ |
Upload File : |
<?php
namespace Yurun\PaySDK\Lib;
/**
* 证书工具类.
*
* @source https://github.com/alipay/alipay-easysdk/blob/master/php/src/Kernel/Util/AntCertificationUtil.php 算法代码来自支付宝官方sdk
*/
class CertUtil
{
/**
* 从证书中提取序列号.
*
* @param $certPath
*
* @return string
*/
public static function getCertSN($certPath)
{
$cert = file_get_contents($certPath);
$ssl = openssl_x509_parse($cert);
$SN = md5(static::array2string(array_reverse($ssl['issuer'])) . $ssl['serialNumber']);
return $SN;
}
/**
* 提取根证书序列号.
*
* @param $certPath string 根证书
*
* @return string|null
*/
public static function getRootCertSN($certPath)
{
$cert = file_get_contents($certPath);
$array = explode('-----END CERTIFICATE-----', $cert);
$SN = null;
for ($i = 0; $i < \count($array) - 1; ++$i)
{
$ssl[$i] = openssl_x509_parse($array[$i] . '-----END CERTIFICATE-----');
if (0 === strpos($ssl[$i]['serialNumber'], '0x'))
{
$ssl[$i]['serialNumber'] = static::hex2dec($ssl[$i]['serialNumber']);
}
if ('sha1WithRSAEncryption' == $ssl[$i]['signatureTypeLN'] || 'sha256WithRSAEncryption' == $ssl[$i]['signatureTypeLN'])
{
if (null == $SN)
{
$SN = md5(static::array2string(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']);
}
else
{
$SN = $SN . '_' . md5(static::array2string(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']);
}
}
}
return $SN;
}
/**
* 数组转字符串.
*
* @param array $array
*
* @return string
*/
public static function array2string($array)
{
$string = [];
if ($array && \is_array($array))
{
foreach ($array as $key => $value)
{
$string[] = $key . '=' . $value;
}
}
return implode(',', $string);
}
/**
* 0x转高精度数字.
*
* @param $hex
*
* @return int|string
*/
public static function hex2dec($hex)
{
$dec = 0;
$len = \strlen($hex);
for ($i = 3; $i <= $len; ++$i)
{
$dec = bcadd($dec, bcmul((string) (hexdec($hex[$i - 1])), bcpow('16', (string) ($len - $i))));
}
return $dec;
}
}