php 加密解密调用

function encrypted($data)
{
    $key = "liumanaiqiaoqiaonicaibudao";
    $key = strtoupper(md5($key));
    $x = 0;
    $len = strlen($data);
    $l = strlen($key);
    $char = "";
    $str = "";
    for ($i = 0; $i < $len; $i++)
    {
        if ($x == $l)
        {
            $x = 0;
        }
        $char .= substr($key, $x, 1);
        $x++;
    }
    for ($i = 0; $i < $len; $i++)
    {
        $str .= substr("00" . (ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1))) % 256), -3);
    }
    return $str;
}

function decrypt($data)
{
	$key = "liumanaiqiaoqiaonicaibudao";
	$key = strtoupper(md5($key));
    $x = 0;
    $len = strlen($data)/3;
    $l = strlen($key);
    $char = "";
    $str = "";
    for ($i = 0; $i < $len; $i++)
    {
        if ($x == $l) 
        {
         $x = 0;
        }
        $char .= substr($key, $x, 1);
        $x++;
    }
    
    for ($i = 0; $i < $len; $i++)
    {
        if (substr($data, $i*3, 3) < ord(substr($char, $i, 1)))
        {
            $str .= chr((substr($data, $i*3, 3) + 256) - ord(substr($char, $i, 1)));
        }
        else
        {
            $str .= chr(substr($data, $i*3, 3) - ord(substr($char, $i, 1)));
        }
    }
    return $str;
}
Function 解密字符串(字符串)
    解密字符串 = ""
    临时字符串 = ""
    秘钥 = "liumanaiqiaoqiaonicaibudao"
    秘钥 = Plugin.Encrypt.Md5String(秘钥)
    秘钥位置 = 1
    字符串长度 = Len(字符串)/3
    秘钥长度 = Len(秘钥)
    For i = 1 To 字符串长度
        If 秘钥位置 > 秘钥长度 Then 
            秘钥位置 = 1
        End If
        临时字符串 = 临时字符串 & Mid(秘钥,秘钥位置,1)
        秘钥位置 = 秘钥位置 + 1
    Next
    For i = 0 To 字符串长度 - 1
        If Mid(字符串, i*3 + 1, 3) < Asc(Mid(临时字符串, i + 1, 1)) Then 
            解密字符串 = 解密字符串 & Chr((Mid(字符串, i*3 + 1, 3) + 256) - Asc(Mid(临时字符串, i + 1, 1)))
        Else 
            解密字符串 = 解密字符串 & Chr((Mid(字符串, i*3 + 1, 3)) - Asc(Mid(临时字符串, i + 1, 1)))
        End If
    Next
End Function

Function 加密字符串(字符串)
    加密字符串 = ""
    临时字符串 = ""
    秘钥 = "liumanaiqiaoqiaonicaibudao"
    秘钥 = Plugin.Encrypt.Md5String(秘钥)
    秘钥位置 = 1
    字符串长度 = Len(字符串)
    秘钥长度 = Len(秘钥)
    For i = 1 To 字符串长度
        If 秘钥位置 > 秘钥长度 Then 
            秘钥位置 = 1
        End If
        临时字符串 = 临时字符串 & Mid(秘钥,秘钥位置,1)
        秘钥位置 = 秘钥位置 + 1
    Next
    For i = 1 To 字符串长度
        加密字符串 = 加密字符串 & Right("00" & (Asc(Mid(字符串,i,1)) + Asc(Mid(临时字符串,i,1)) Mod 256), 3)
    Next
End Function

thinkphp sqlserver could not find driver

windows 宝塔php安装sqlsrv

https://www.microsoft.com/en-us/download/details.aspx?id=20098

下载SQLSRV40.EXE,右键解压,复制对应ts或者nts64位到宝塔目录php的扩展文件夹ext里。

修改php.ini里扩展

extension=php_pdo_sqlsrv_7_nts_x64.dll
extension=php_sqlsrv_7_nts_x64.dll

宝塔php服务,重载配置。

下载 ODBC Driver:

Microsoft® ODBC Driver 11 for SQL Server® – Windows (支持Sql Server® 2005)

https://www.microsoft.com/zh-CN/download/details.aspx?id=36434

Microsoft® ODBC Driver 13 for SQL Server® – Windows + Linux (支持最新的SQL Server® 2016)

https://www.microsoft.com/zh-CN/download/details.aspx?id=50420

这里下一步下一步安装…

建议 安装ODBC Driver,根据自己的需要选择上面的地址下载并安装。

如果上面的ODBC版本太高,那么用这个低一点的 ODBC Driver 下载 https://files.cnblogs.com/files/wtcl/sqlserverodbc.zip

现在可以使用phpinfo() 来查看是否成功加载了 pdo_sqlsrv 模块。

laravel openssl_cipher_iv_length()

laravel 错误

Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()

phpinfo()

OpenSSL support disabled (install ext/openssl)

下载https://windows.php.net/downloads/php-sdk/deps/vc15/x64/openssl-1.1.1a-vc15-x64.zip

解压后bin目录能看到libcrypto-1_1-x64.dll和libssl-1_1-x64.dll,两个文件都拷到php目录和apache的bin下

开启extension=openssl

重启Apache就好了

laravel获取微信Post xml

由于HTTP_RAW_POST_DATA这个特性在PHP5.6之后已经废弃,所以要或许xml数据可以考虑以下方案
1.由于PHP是兼容的,你可以在php.ini中修改配置,以获得此选项的支持
2.通过PHP的标准输入,php://input来获得数据,如file_get_content(“php://input”),fopen(“php://input”)
3.在laravel中,框架已经封装了一个方法在Request类中,使用$request->getContent()即可,在laravel的源码中可以看到,
getContent的实现就是通过fopen打开标准输入来进行数据的读取的

mysqli代替mysql

<?PHP 
$dbhost="127.0.0.1";
$dbport="3306";
$dbuser="root";
$dbpass="1234";
$dbname="menghaozi";
if(!function_exists('mysql_pconnect')){
    $mysqli = mysqli_connect("$dbhost:$dbport", $dbuser, $dbpass, $dbname);
    function mysql_pconnect($dbhost, $dbuser, $dbpass){
        global $dbport;
        global $dbname;
        global $mysqli;
        $mysqli = mysqli_connect("$dbhost:$dbport", $dbuser, $dbpass, $dbname);
        return $mysqli;
        }
    function mysql_select_db($dbname){
        global $mysqli;
        return mysqli_select_db($mysqli,$dbname);
        }
    function mysql_fetch_array($result){
        return mysqli_fetch_array($result);
        }
    function mysql_fetch_assoc($result){
        return mysqli_fetch_assoc($result);
        }
    function mysql_fetch_row($result){
        return mysqli_fetch_row($result);
        }
    function mysql_query($query){
        global $mysqli;
        $data=mysqli_query($mysqli,$query);
        if (!$data) {
         printf("Error: %s\n", mysqli_error($mysqli));
         exit();
        }
        return $data;
        }
    function mysql_escape_string($data){
        global $mysqli;
        return mysqli_real_escape_string($mysqli, $data);
        //return addslashes(trim($data));
        }
    function mysql_real_escape_string($data){
        return mysql_real_escape_string($data);
        }
    function mysql_close(){
        global $mysqli;
        return mysqli_close($mysqli);
        }
}
?>