zhuangdebiao 发布的文章

问题场景: SPA单页面应用, vuejs router, 微信WebView网页下给 JS SDK API 做 签名,报错

  1. 项目基于vue,在微信上的web应用
  2. 要使用原生系统某些功能(不同系统的兼容真的很多BUG,最后只能使用微信方案),支付功能,定位, 设置分享....
  3. 签名一直存在bug和问题,那么后面的功能都会唤不起(偶尔也可以)

具体表现:
项目使用 vue 开发微信手机网页端,获取从后端传来的 微信配置信息, android 端 能够配置正确并能 正常调用 微信提供的js api。 但是 在 ios 上 报 签名错误,重新刷新页面又能正确配置 微信的 config, 再次刷新页面又报 签名错误,

直接上解决代码

if (window.__wxjs_is_wkwebview) { // IOS, 签名地址,固定是入口地址,不是路由跳转地址
  window.entryUrl = window.location.href
}
router.afterEach((to, from) => {
  // window.__wxjs_is_wkwebview
  // true 时 为 IOS 设备
  // false时 为 安卓 设备
  if (window.__wxjs_is_wkwebview) {  // IOS
    // 什么也不做
  }else {       // 安卓, 签名地址,每次都变动
    window.entryUrl = `${window.location.origin}${to.fullPath}`
  }
})

后端做签名的时候, url encode 一下, 使用 window.entryUrl 而不是 window.location.href


问题的原因:

苹果微信App, 签名失败是因为: 苹果在微信中浏览器机制和安卓不同,有 IOS缓存问题,和IOS对单页面的优化问题,

安卓进行页面跳转分享时会刷新当前的history url,而苹果不会;

如果苹果下的微信App是通过vue router即H5的historyState历史记录进来的,不会刷新url所以会导致签名失败

问题来了: vue的history在IOS的微信不会刷新,但是我们又要做js签名。

有很多做法, 比如 beforerouteEnter的路由判断,或者写在Vue.prototype.Wxshare()的原型链中


微信下能检测内核的判断:window.__wxjs_is_wkwebview(是否为webview内核),如果是的情况下就变成true

因为SPA应用下,会有一定的问题,路由采用的是history模式(不带#号)。因为在页面每次进入到路由之后才去获取签名授权,所以将方法公用写在路由的模块下

window.entryUrl这个是什么鬼?这个是自己定义的全局属性,就是为了获取IOS第一次进入页面的时候存储起来的,如果IOS的签名的路径不是第一次进入的页面,那么就一定会失败,所以这个路由第一次进入就要储存起来

为什么要写在router.afterEach,因为页面进入了再去做申请和签名,如果在beforeEach,会导致页面申请签名的时候还是上一个页面,但是到了新页面却没有注册签名,或者因为签名的路径不同,导致invalid signature

安卓会存在一些情况,就是即便签名成功,但是还是会唤不起功能, 增加一个延时器或者页面mounted之后再签名一次比较稳妥


题外话

分享的跳转地址会携带一下参数

对于IOS系统会自动增加如下参数:
朋友圈 from=timeline&isappinstalled=0
微信群 from=groupmessage&isappinstalled=0
好友分享 from=singlemessage&isappinstalled=0

对于安卓系统会自动添加如下参数:
朋友圈 from=timeline
微信群 from=groupmessage
好友分享 from=singlemessage

任务: 更新

yum -y update
reboot

任务: ssh连接终端

查看IP地址
ifconfig
检查服务端口情况
netstat -natp |grep 22

任务: 删除 CentOS7 更新后产生的多余的内核

1.首先列出系统中正在使用的内核:

# uname -a 或者 uname -r

2.查询系统中全部的内核:

# rpm -qa | grep kernel

3.将你想删除的内核删除掉:(需要把所有含有kernel且相同版本号的全部删掉)

# yum remove -y kernel-modules-4.18.0-193.el8.x86_64
# yum remove -y kernel-4.18.0-193.el8.x86_64
# yum remove -y kernel-core-4.18.0-193.el8.x86_64

4.重启后就可以看到,内核被删掉了,同时多余的启动项也自动被删掉了。
reboot

任务: 补充安装常用命令

yum install -y wget

任务: 安装基础编译器,默认依赖Perl5

yum install -y gcc gcc-c++ make automake

任务: 安装CMake3

yum remove cmake
wget https://github.com/Kitware/CMake/releases/download/v3.17.5/cmake-3.17.5-Linux-x86_64.tar.gz
tar zxvf cmake-3.17.5-Linux-x86_64.tar.gz
vi /etc/profile.d/cmake.sh
export CMAKE_HOME=/root/cmake-3.17.5-Linux-x86_64
export PATH=$PATH:$CMAKE_HOME/bin
chmod +x /etc/profile.d/cmake.sh
source /etc/profile

(跳过)任务: 安装Perl5,官网教程 https://www.cpan.org/src/

wget https://www.cpan.org/src/5.0/perl-5.32.0.tar.gz
tar -xzf perl-5.32.0.tar.gz
cd perl-5.32.0
此时依赖make或gmake,还有gcc
./Configure -des -Dprefix=/usr/local/perl
make
make test
make install

软链接,替换掉旧的perl命令
mv /usr/bin/perl /usr/bin/perl.old
ln -s /usr/local/perl/bin/perl /usr/bin/perl

验证安装完成
perl -v

任务: 安装最新版openssl至/usr/local/openssl-1.1.1g

wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz
tar zxvf OpenSSL_1_1_1g.tar.gz
cd openssl-OpenSSL_1_1_1g
此时需要Perl5
./config enable-weak-ssl-ciphers -fPIC --prefix=/usr/local/openssl-1.1.1g --openssldir=/usr/local/openssl-1.1.1g
make depend
make
make install

任务: 创建禁止登录终端的www用户组和用户

groupadd www
useradd -s /sbin/nologin -g www www

任务: 安装nginx
依赖 pcre openssl zlib

wget https://nginx.org/download/nginx-1.19.2.tar.gz
tar -xzf nginx-1.19.2.tar.gz
cd nginx-1.19.2
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module  --with-http_realip_module --with-pcre=/ --with-stream --with-stream_ssl_module --with-openssl=/usr/local/openssl-1.1.1g --with-openssl-opt='enable-weak-ssl-ciphers' --with-http_addition_module --with-http_image_filter_module --with-http_flv_module --with-http_mp4_module --with-http_secure_link_module
make
make install

下载安装编译工具

yum groupinstall 'Development Tools'

安装依赖包

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel

安装CMake3

yum remove cmake
wget https://github.com/Kitware/CMake/releases/download/v3.17.5/cmake-3.17.5-Linux-x86_64.tar.gz
tar zxvf cmake-3.17.5-Linux-x86_64.tar.gz
vi /etc/profile.d/cmake.sh
export CMAKE_HOME=/root/cmake-3.17.5-Linux-x86_64
export PATH=$PATH:$CMAKE_HOME/bin
chmod +x /etc/profile.d/cmake.sh
source /etc/profile

简单介绍: CMake的好处是方便跨平台,在Linux环境下,请先创建build目录,并到目录build下,执行cmake:

mkdir build && cd build
cmake ../

安装libzip库(要求CMake版本至少3.0.0,而2.8.12.2太低), 1.3.1和1.7.0(1.7.3)都被禁止了,我换1.3.2

yum remove -y libzip
wget https://libzip.org/download/libzip-1.7.3.tar.gz
tar -zxvf libzip-1.7.3.tar.gz
cd libzip-1.7.3
mkdir build && cd build/
选项一 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip ..
[选这个]选项二 cmake ..
[1.3.2低版本] ./configure
make
make install
选项一 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
[选这个]选项二 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:/usr/lib/pkgconfig/
ldconfig

错误libxml

No package 'libxml-2.0' found
rpm -qa |grep  libxml2
libxml2-2.9.1-6.el7.4.x86_64

安装libxml2和libxml2-devel包
yum install -y libxml2
yum install -y libxml2-devel

错误sqlite3

No package 'sqlite3' found
error: Package requirements (sqlite3 > 3.7.4) were not met

yum install libsqlite3x-devel -y

错误libcurl

configure: error: Package requirements (libcurl >= 7.15.5) were not met:
No package 'libcurl' found

安装
yum install -y libcurl libcurl-devel

错误libjpeg

configure: error: Package requirements (libjpeg) were not met:
No package 'libjpeg' found

error: Package requirements (oniguruma) were not met

由于PHP 7.4.x中mbstring的正则功能需要oniguruma的支持,编译PHP的时候使用了 --enable-mbstring 参数,系统中却没有oniguruma库,

规避方式一: 不使用mbstring的正则功能,即在“--enable-mbstring”后再添加“--disable-mbregex”参数

规避方式二: 安装oniguruma库

yum install -y epel-release
yum install oniguruma-devel -y

编译PHP7.4 默认查找64位的动态链接库,
centos系统默认的动态链接库配置文件/etc/ld.so.conf里并没有将64位库文件加入搜索路径,
需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。

添加搜索路径到配置文件

echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf

更新配置
ldconfig -v

其他安装源

yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-6.7.0-1.el7.x86_64.rpm
yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-devel-6.7.0-1.el7.x86_64.rpm

编译安装oniguruma

wget https://github.com/kkos/oniguruma/releases/download/v6.9.5_rev1/onig-6.9.5-rev1.tar.gz
tar zxvf onig-6.9.5-rev1.tar.gz
cd onig-6.9.5
./configure --prefix=/usr --libdir=/lib64
make
make install

编译安装freetype, centos8开始要安装freetype2.10.x, 旧版系统可以是2.8.1

wget https://download.savannah.gnu.org/releases/freetype/freetype-2.10.2.tar.gz
tar zxvf freetype-2.10.2.tar.gz
cd freetype-2.10.2
./configure --prefix=/usr/local/freetype
make
make install
mkdir /usr/lib/pkgconfig
cp /usr/local/freetype/lib/pkgconfig/freetype2.pc /usr/lib/pkgconfig/
cat > /etc/ld.so.conf.d/freetype.conf<<EOF
/usr/local/freetype/lib
EOF
ldconfig
ln -sf /usr/local/freetype/include/freetype2/* /usr/include/


export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig/
ldconfig

心累,依然报错缺少libjpeg和libpng
yum install -y libjpeg libjpeg-devel libpng libpng-devel
ldconfig

编译安装openssl

wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1f.tar.gz
./config enable-weak-ssl-ciphers -fPIC --prefix=/usr/local/openssl1.1.1 --openssldir=/usr/local/ope        nssl1.1.1
make depend
make
make install

wget https://github.com/openssl/openssl/archive/OpenSSL_1_0_2u.tar.gz
tar zxvf OpenSSL_1_0_2u.tar.gz
cd openssl-OpenSSL_1_0_2u/
./config -fPIC --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make depend
make
make install
ldconfig

编译安装curl

wget https://github.com/curl/curl/releases/download/curl-7_72_0/curl-7.72.0.tar.gz
tar zxvf curl-7.72.0.tar.gz
cd curl-7.72.0
./configure --prefix=/usr/local/curl --enable-ares --without-nss --with-zlib --with-ssl=/usr/local/openssl
make
make install
ldconfig

安装libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar zxvf libiconv-1.16.tar.gz
cd libiconv-1.16
./configure --prefix=/usr/local/libiconv --enable-static
make
make install

报错缺少icu

configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found

yum install -y libicu-devel

安装PHP7.4


wget https://www.php.net/distributions/php-7.4.10.tar.gz
tar zxvf php-7.4.10.tar.gz
cd php-7.4.10
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv=/usr/local/libiconv --with-freetype=/usr/local/freetype --with-jpeg --with-png --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --enable-gd --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-zip --without-libzip --enable-soap --with-gettext --enable-opcache --with-xsl --with-pear

make
make install

依然报错: configure: WARNING: unrecognized options: --with-png, --without-libzip

安装Zip库

http://pecl.php.net/get/zip-1.19.0.tgz
tar xvf zip-1.19.0.tgz
./configure  --with-php-config=/usr/bin/php-config

ln -sf /usr/local/php/bin/php /usr/bin/php
ln -sf /usr/local/php/bin/phpize /usr/bin/phpize
ln -sf /usr/local/php/bin/pear /usr/bin/pear
ln -sf /usr/local/php/bin/pecl /usr/bin/pecl
ln -sf /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
rm -f /usr/local/php/conf.d/*

mkdir -p /usr/local/php/{etc,conf.d}
cp php.ini-production /usr/local/php/etc/php.ini

cd /root/php-7.4.10

sed -i 's/post_max_size =.*/post_max_size = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize =.*/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =.*/date.timezone = PRC/g' /usr/local/php/etc/php.ini
sed -i 's/short_open_tag =.*/short_open_tag = On/g' /usr/local/php/etc/php.ini
sed -i 's/;cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time =.*/max_execution_time = 300/g' /usr/local/php/etc/php.ini
sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/php/etc/php.ini

pear config-set php_ini /usr/local/php/etc/php.ini
pecl config-set php_ini /usr/local/php/etc/php.ini

wget --prefer-family=IPv4 --no-check-certificate -T 120 -t3 ${Download_Mirror}/web/php/composer/composer.phar -O /usr/local/bin/composer
if [ $? -eq 0 ]; then
    echo "Composer install successfully."
    chmod +x /usr/local/bin/composer
else
    echo "Composer install failed, try to from composer official website..."
    curl -sS --connect-timeout 30 -m 60 https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
    if [ $? -eq 0 ]; then
        echo "Composer install successfully."
    fi
fi
if [ "${country}" = "CN" ]; then
    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
fi

cat >/usr/local/php/etc/php-fpm.conf<<EOF
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
pm.max_requests = 1024
pm.process_idle_timeout = 10s
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
EOF

cp ${cur_dir}/src/${Php_Ver}/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp ${cur_dir}/init.d/php-fpm.service /etc/systemd/system/php-fpm.service
chmod +x /etc/init.d/php-fpm

groupadd www
useradd -s /sbin/nologin -g www www

yum -y install libxml2
yum -y install libxml2-devel
yum install sqlite-devel
yum install bzip2 bzip2-devel
yum install libxslt-devel
yum install libpng-devel

六间房直播间 聊天室, 刷屏脚本


let str = '1.绿色要正,我们都知道翡翠是以绿为贵,所以对于一块好翡翠来说,绿色的色调越纯正越好,尽可能不偏黄、不偏蓝、不偏灰,绿色越纯正,翡翠价值越高。2.绿色分布要均匀,一般来说一件翡翠作品,它的绿色分布的越均匀,价值高,比如满绿的翡翠那是翡翠中价值最高的翡翠。3.水头要足,俗话说内行看种,外行看色,一件翡翠种水好的话,就算翡翠不是绿色,它的价值也会很低,而且是水头越好,翡翠的价值越高,如果翡翠的水头达到了半透明以上,那么这块翡翠就是特级翡翠了。4.瑕疵要少,不管是任何的宝石,瑕疵越少,价值越高,翡翠越是一样的,不过由于翡翠是天然的玉石,多少都会有一定瑕疵,因此在瑕疵不影响翡翠价值的情况下,我们要学会接受翡翠的瑕疵。5.裂纹要少,裂纹那是翡翠价值的杀手,因为裂纹不仅仅影响翡翠的美观,还影响翡翠的强度。翡翠裂纹对翡翠影响是致命的,所以我们在挑选翡翠的千万要看清楚,因为裂纹轻者有断裂的隐患,严重的情况就是翡翠饰品在佩戴的时候有可能会从裂纹处断裂。';
let i = 0;
window.setInterval(function(){
let end = Math.floor(Math.random()*10+1)
Room.chatList.sendPubMsg({tuid: "",con: str.substr(i, end)});
i += end;
},3100);

对于sendPubMsg 方法, 进一步跟踪, 得到以下代码

function echo(str){
var b = {
 r: page.rid,
 ak: page.authKey,
 t: "",
            m: str,
            ttt: new Date().getTime()
        };
        jQuery.extend(b, zhangZhiParam(Room.chatList._tracing));
b = '{"t":"msg_room", "content":' + jQuery.toJSON(b) + "}";
Room.Socket.proxy.convey(["command=sendmessage", "content=" + Room.Socket.proxy.encode(b)])
}