range

If there were you, the world would be just right

可生成泛域名ssl网站

https://freessl.cn/
1 选择多域名通配符
2 选择浏览器方式生成

证书过期时间检查demo

<?php
$g = stream_context_create ([
    "ssl" => ["capture_peer_cert" => true],
    'http' => [
          'method' => 'GET',
        'user_agent' => 'shouwang.io ssl detector',
        'timeout'=>10
    ]
]);
$r = fopen("https://range8.cn/", "rb", false, $g);
$cont = stream_context_get_params($r);
$cert = openssl_x509_parse($cont["options"]["ssl"]["peer_certificate"]);

if(empty($cert['validTo_time_t'])) {
    throw new \Exception("Can't get cert expire time");
}

$fortyEightHours = strtotime("+48 hours");
if($cert['validTo_time_t'] <= $fortyEightHours) {
    throw new \Exception("Cert will expire in 48 hours");
} else {
    echo "证书过期时间:", date("Y-m-d H:i:s", $cert['validTo_time_t']);
}

记录一个代码文件加密算法

function RandAbc($length = "")
{ // 返回随机字符串
    $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return str_shuffle($str);
}

$filename = 'getuser.php'; //要加密的文件
$T_k1 = RandAbc(); //随机密匙1
$T_k2 = RandAbc(); //随机密匙2
$vstr = file_get_contents($filename);
$v1 = base64_encode($vstr);
$c = strtr($v1, $T_k1, $T_k2); //根据密匙替换对应字符。
$c = $T_k1 . $T_k2 . $c;
$q1 = "O00O0O";
$q2 = "O0O000";
$q3 = "O0OO00";
$q4 = "OO0O00";
$q5 = "OO0000";
$q6 = "O00OO0";
$s = '$' . $q6 . '=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");$' . $q1 . '=$' . $q6 . '{3}.$' . $q6 . '{6}.$' . $q6 . '{33}.$' . $q6 . '{30};$' . $q3 . '=$' . $q6 . '{33}.$' . $q6 . '{10}.$' . $q6 . '{24}.$' . $q6 . '{10}.$' . $q6 . '{24};$' . $q4 . '=$' . $q3 . '{0}.$' . $q6 . '{18}.$' . $q6 . '{3}.$' . $q3 . '{0}.$' . $q3 . '{1}.$' . $q6 . '{24};$' . $q5 . '=$' . $q6 . '{7}.$' . $q6 . '{13};$' . $q1 . '.=$' . $q6 . '{22}.$' . $q6 . '{36}.$' . $q6 . '{29}.$' . $q6 . '{26}.$' . $q6 . '{30}.$' . $q6 . '{32}.$' . $q6 . '{35}.$' . $q6 . '{26}.$' . $q6 . '{30};eval($' . $q1 . '("' . base64_encode('$' . $q2 . '="' . $c . '";eval(\'?>\'.$' . $q1 . '($' . $q3 . '($' . $q4 . '($' . $q2 . ',$' . $q5 . '*2),$' . $q4 . '($' . $q2 . ',$' . $q5 . ',$' . $q5 . '),$' . $q4 . '($' . $q2 . ',0,$' . $q5 . '))));') . '"));';

$s = '<?php ' . "\n" . $s . "\n" . ' ?>';

// 生成 加密后的PHP文件
$fpp1 = fopen('temp_' . $filename, 'w');
fwrite($fpp1, $s) or die('写文件错误');

谷歌登陆demo

header('Content-Type:text/html; charset=utf-8');

class Google
{
    protected $setting = [
        'app_id' => 'xx',          //客户端ID
        'app_secret' => 'xx',     //客户端密钥
        'redirect_uri' => 'xx',  //回调地址
    ];

    public function __construct($pf_game_id)
    {
        $this->client_id = $this->setting['app_id'];
        $this->client_secret = $this->setting['app_secret'];
        $this->redirect_uri = $this->setting['redirect_uri']."?pf_game_id=".$pf_game_id;
    }

    public function index()
    {
        //第一步:请求CODE
        if (empty($_GET['code'])) {
            $this->getCode($this->client_id, $this->redirect_uri);
        } else {

            //用户允许授权后,将会重定向到redirect_uri的网址上,并且带上code参数
            $code = $_GET['code'];
            $postData = array(
                'code' => $code,
                'client_id' => $this->client_id,
                'client_secret' => $this->client_secret,
                'redirect_uri' => $this->redirect_uri,
                'grant_type' => 'authorization_code'
            );

            //第二步:通过code获取access_token
            $purl = 'https://accounts.google.com/o/oauth2/token';
            $token = $this->CurlSend($postData,$purl);
            if (empty($token)) {
                exit("获取token失败");
            }
            echo "<pre>";print_r($token);die;
        }
    }

    /**
     * 抓取CODE
     * @param $client_id
     * @param $redirect_uris
     */
    protected function getCode($client_id, $redirect_uris)
    {
        $redirect_uris = urlencode($redirect_uris);
        $scope = urlencode('https://www.googleapis.com/auth/androidpublisher');
        $url = "https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&client_id={$client_id}&redirect_uri={$redirect_uris}&state&scope={$scope}&approval_prompt=auto";
        header('Location:' . $url);
    }


    protected function CurlSend($postData, $purl)
    {
        $fields = (is_array($postData)) ? http_build_query($postData) : $postData;
        $curlHeaders = [
            'content-type: application/x-www-form-urlencoded;CHARSET=utf-8',
            'Content-Length: ' . strlen($fields),
        ];

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $purl);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($curl);
        $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);

        if ($response && $responseCode == 200) {
            $json_data = json_decode($response, true);
            return $json_data;
        } else {
            return false;
        }
    }

    public function getATokenToRefToken($refresh_token){
        $url = 'https://accounts.google.com/o/oauth2/token';
        $postData = array(
            'client_id' => $this->client_id,
            'client_secret' => $this->client_secret,
            'grant_type' => 'refresh_token',
            'refresh_token' => $refresh_token
        );
        $token_data = $this->CurlSend($postData,$url);
        echo $token_data["access_token"];
    }
}

if(empty($_GET["pf_game_id"])){
    exit("pf_game_id is empty");
}
$google = new Google($_GET["pf_game_id"]);
$google->index();

记录AES加密算法

<?php

namespace Aes;
 
class Aes
{
    /**
     * var string $method 加解密方法,可通过openssl_get_cipher_methods()获得
     */
    protected $method;
 
    /**
     * var string $secret_key 加解密的密钥
     */
    protected $secret_key;
 
    /**
     * var string $iv 加解密的向量,有些方法需要设置比如CBC
     */
    protected $iv;
 
    /**
     * var string $options (不知道怎么解释,目前设置为0没什么问题)
     */
    protected $options;
 
    /**
     * 构造函数
     *
     * @param string $key 密钥
     * @param string $method 加密方式
     * @param string $iv iv向量
     * @param mixed $options 还不是很清楚
     *
     */
    public function __construct($key, $method = 'AES-128-ECB', $iv = '', $options = 0)
    {
        // key是必须要设置的
        $this->secret_key = isset($key) ? $key : 'morefun';
 
        $this->method = $method;
 
        $this->iv = $iv;
 
        $this->options = $options;
    }
 
    /**
     * 加密方法,对数据进行加密,返回加密后的数据
     *
     * @param string $data 要加密的数据
     *
     * @return string
     *
     */
    public function encrypt($data)
    {
        return openssl_encrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
    }
 
    /**
     * 解密方法,对数据进行解密,返回解密后的数据
     *
     * @param string $data 要解密的数据
     *
     * @return string
     *
     */
    public function decrypt($data)
    {
        return openssl_decrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
    }
}

demo:

class Rsa
{
    private $_config = [
        'public_key' => '',
        'private_key' => '',
    ];

    public function __construct($private_key_filepath, $public_key_filepath) {
        $this->_config['private_key'] = $this->_getContents($private_key_filepath);
        $this->_config['public_key'] = $this->_getContents($public_key_filepath);
    }

    /**
     * @uses 获取文件内容
     * @param $file_path string
     * @return bool|string
     */
    private function _getContents($file_path) {
        file_exists($file_path) or die ('密钥或公钥的文件路径错误');
        return file_get_contents($file_path);
    }

    /**     
     * @uses 获取私钥
     * @return bool|resource     
     */ 
    private function _getPrivateKey() {
       $priv_key = $this->_config['private_key'];
       return openssl_pkey_get_private($priv_key);
    }

    /**     
     * @uses 获取公钥
     * @return bool|resource     
     */    
    private function _getPublicKey() {        
        $public_key = $this->_config['public_key'];
        return openssl_pkey_get_public($public_key);
    }

    /**     
     * @uses 私钥加密
     * @param string $data     
     * @return null|string     
     */    
    public function privEncrypt($data = '') {        
        if (!is_string($data)) {
            return null;       
        }
        return openssl_private_encrypt($data, $encrypted, $this->_getPrivateKey()) ? base64_encode($encrypted) : null;
    }

    /**     
     * @uses 公钥加密     
     * @param string $data     
     * @return null|string     
     */    
    public function publicEncrypt($data = '') {        
        if (!is_string($data)) {
            return null;        
        }        
        return openssl_public_encrypt($data, $encrypted, $this->_getPublicKey()) ? base64_encode($encrypted) : null;
    }

    /**     
     * @uses 私钥解密     
     * @param string $encrypted     
     * @return null     
     */    
    public function privDecrypt($encrypted = '') {        
        if (!is_string($encrypted)) {
            return null;        
        }
        return (openssl_private_decrypt(base64_decode($encrypted), $decrypted, $this->_getPrivateKey())) ? $decrypted : null;
    }    

    /**     
     * @uses 公钥解密     
     * @param string $encrypted     
     * @return null     
     */    
    public function publicDecrypt($encrypted = '') {        
        if (!is_string($encrypted)) {
            return null;        
        }        
           return (openssl_public_decrypt(base64_decode($encrypted), $decrypted, $this->_getPublicKey())) ? $decrypted : null;
    }
}

测试:

$private_key = 'private_key.pem'; // 私钥路径
$public_key = 'rsa_public_key.pem'; // 公钥路径
$rsa = new Rsa($private_key, $public_key);

$origin_data = '这是一条测试数据';

$ecryption_data = $rsa->privEncrypt($origin_data);

$decryption_data = $rsa->publicDecrypt($ecryption_data);

echo '私钥加密后的数据为:' . $ecryption_data;
echo PHP_EOL;
echo '公钥解密后的数据为: ' . $decryption_data;
echo PHP_EOL;

最后要说明的是,公钥、私钥都可以加密,也都可以解密。其中:用公钥加密需要私钥解密,称为“加密”。由于私钥是不公开的,确保了内容的保密,没有私钥无法获得内容;用私钥加密需要公钥解密,称为“签名”。由于公钥是公开的,任何人都可以解密内容,但只能用发布者的公钥解密,验证了内容是该发布者发出的。