range

If there were you, the world would be just right

在 RabbitMQ 中,获取队列内的消息有多种方式,下面列举几种:

1、basic_get 方法:可以使用 basic_get 方法从队列中获取一条消息。可以在循环中多次调用该方法来批量获取消息。

while ($message = $channel->basic_get($queueName)) {
    // 处理消息
}

2、basic_consume 方法:可以使用 basic_consume 方法订阅队列,并在回调函数中处理获取到的消息。可以设置 prefetch_count 参数控制每次获取的消息数量。

$channel->basic_qos(null, 10, null); // 每次最多获取 10 条消息
$channel->basic_consume($queueName, '', false, false, false, false, function ($message) {
    // 处理消息
    $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
});
while ($channel->is_consuming()) {
    $channel->wait();
}

3、basic_get 和 basic_consume 结合使用:可以使用 basic_get 方法获取一定数量的消息,然后使用 basic_ack 方法确认已经处理完消息。

$channel->basic_qos(null, 10, null); // 每次最多获取 10 条消息
while ($message = $channel->basic_get($queueName)) {
    // 处理消息
    $channel->basic_ack($message->delivery_info['delivery_tag']);
}

需要注意的是,在批量获取消息时,需要设置适当的 prefetch_count 参数来控制每次获取的消息数量,避免一次性获取过多的消息导致处理能力不足或者消息堵塞的问题。同时,也需要在处理完每一条消息后及时调用 basic_ack 方法确认消息已经被处理完成,以避免消息重复消费的问题。


可生成泛域名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);
    }
}