月度归档:2021年04月

PHP替换Emoji表情

在检测文本语言的时候,emoji表情会影响检测的准确性,从stackoverflow上找了一个函数,作一下记录:

function removeEmoji($text) {
    return trim(preg_replace('/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{1F000}-\x{1FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F9FF}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F9FF}][\x{1F000}-\x{1FEFF}]?/u', '', $text));
}

 

CentOS安装多PHP环境

yum install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xmll
systemctl enable php73-php-fpm
systemctl start php73-php-fpm

安装的配置文件路径:
/etc/opt/remi/php73/

安装路径:
/opt/remi/php83/root/usr/

启动fpm服务
systemctl restart php80-php-fpm

设置为自动运行
chkconfig php80-php-fpm on

CentOS升级curl
rpm -ivh http://www.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/city-fan.org-release-2-1.rhel7.noarch.rpm

yum update curl –enablerepo=city-fan.org -y

 

PHP里用SoapClient出现”Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL”处理

在一台很老的服务器上,调用bing的接口时,出现如下错误,以前都是好好的:

PHP Fatal error:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adinsight.api.bingads.microsoft.com/Api/Advertiser/AdInsight/v13/AdInsightService.svc?singleWsdl' : failed to load external entity "https://adinsight.api.bingads.microsoft.com/Api/Advertiser/AdInsight/v13/AdInsightService.svc?singleWsdl"

后面发现Curl也不行,报:Peer certificate cannot be authenticated with known CA certificates 错误。

wget也不行,也报:ERROR: cannot verify certificate。

现在看来是由于系统的根证书无效了(系统太老应该是很多年前的机器了),所以无法判断microsoft的证书的有效性,按如下操作就可以了:

cd /etc/pki/tls/certs
wget https://curl.haxx.se/ca/cacert.pem
cat cacert.pem >> ca-bundle.crt

思路是去下载一个新的可信证书串(上面是curl的,也可以找一个其它的),把这个串放到系统的可信证书后面去。

如果是在php程序里用curl的话,不用设置操作系统的,可以试试把 https://curl.haxx.se/ca/cacert.pem 下载下来后,再设置php.ini的curl设置

[curl]
curl.cainfo=/path/to/downloaded/cacert.pem

 

通过smtp向google gmail发送邮件报错问题处理

在Laravel里用smtp方式通过gmail发送邮件出现下面的错误:

Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials a25sm9780898pfo.27 - gsmtp
". Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials a25sm9780898pfo.27 - gsmtp
". Authenticator XOAUTH2 returned Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials a25sm9780898pfo.27 - gsmtp
".

需要按下面的步骤去解决:

1、开启2步验证方式,通过这里:https://www.google.com/landing/2step/

2、为GMAIL设置一个单独的密码,通过这里:https://security.google.com/settings/security/apppasswords

3、把第二步里的密码设置到Laravel的.env文件里。

对于.env邮件的设置也要注意加密方式,下面的我的配置:

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=独立密码
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"

 

Laravel操作Redis笔记

Laravel操作Redis好麻烦的,也不封闭完。。。

操作Sortd Set

// 判断是否存在
if (Redis::command("exists", [self::REDIS_KEY_MERCHANT_TITLE])) {
    return;
}
// 增加
Redis::zadd(self::REDIS_KEY_MERCHANT_TITLE, 1, "sdfsdf");
// 加分
Redis::command('zIncrBy', [self::REDIS_KEY_MERCHANT_TITLE, 1, "sdfsdf"]);
// 弹出最小的
Redis::command('zPopMin', [self::REDIS_KEY_PROMOTION_DESC, 1]);
// 弹出最大的
Redis::command('zPopMax', [self::REDIS_KEY_PROMOTION_DESC, 1]);

 

Git记录

删除本地分支
git branch -D test –没合并也删除
git branch -d test — 没合并删除不了

删除远程分支
git push origin :feature/ttkh

查看本地分支:git branch
查看远程分支:git branch -r
查看所有分支:git branch -a

切换远程分支:git checkout -b myRelease origin/Release

git remote add origin https://github.com/wu347771769/learngit.git

把某历史版本打出分支
git checkout -b xxx/xxx 5f4648474fb38c75b69dce0db9c4d4ec1b1e6b74

合并到master分支:
git checkout master
git merge issue1234

把本地分支推送到远程分支
新建远程分支前端 CSS.md
git push origin hotfix/liyan-190905:hotfix/liyan-190905

远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch
git push -u origin/remote_branch

远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch
git push

处理更新不下来,分支冲突的情况
[www@xxx]$ git pull
error: ‘refs/remotes/origin/hotfix’ exists; cannot create ‘refs/remotes/origin/hotfix/business-button’
From gitlab.xxxx.com:Project/backend/gocashback-api
! [new branch] hotfix/business-button -> origin/hotfix/business-button (unable to update local ref)
error: some local refs could not be updated; try running
‘git remote prune origin’ to remove any old, conflicting branches
[www@xxxt]$ git remote prune origin
Pruning origin

指定本地分支和远程某个分支的关系
git branch –set-upstream-to=origin/branch_remote branch_local
查看本地的分支是和哪个远程分支关联的
git branch -vv

提交错误后,回滚
https://blog.csdn.net/BigData_Mining/article/details/88179370