php版本的短視頻去水印流量小程序,提供前后端源碼核心解析也包含在本倉(cāng)庫(kù),同時(shí)項(xiàng)目也對(duì)接了第三方平臺(tái),保證解析的穩(wěn)定性。
shortVideoParse
composer install -vvv
# v1.0.0版本需要執(zhí)行
php webman app-plugin:install admin
php webman app-plugin:install shortVideoParse
## 第三方去水印解析接口配置
目前平臺(tái)對(duì)接了一家 [keke](https://api.ake999.com/)。這樣的配置保證了小程序的穩(wěn)定性。需要說(shuō)明的是,本項(xiàng)目采用多引擎解析,保證了解析的穩(wěn)定性。因此如果你想更穩(wěn)定,還可以自行實(shí)現(xiàn)解析驅(qū)動(dòng)(這部分代碼看:`plugin/shortVideoParse/app/core/videoParse/Gateway.php`)。當(dāng)然,每次解析第一個(gè)解析引擎是自己開發(fā)的php版本,這個(gè)版本也是2024年最新的php視頻解析包,還是很穩(wěn)定。
配置keke(具體大家注冊(cè)平臺(tái)賬號(hào)獲取配置信息),修改`plugin/shortVideoParse/config/keke.php`文件:
```php
<?php
return [
'api' => 'https://api.ake999.com/',
'clientId' => '',
'clientSecretKey' => '',
];
解壓docs\micro-v.1.0.0
(版本號(hào)跟隨版本更新調(diào)整),里面就是源碼了
修改.env
, 配置源碼在plugin/shortVideoParse/config/easywechat.php
文件:
WECHAT_MINI_APP_ID=自己的
WECHAT_MINI_APP_SECRET=自己的
默認(rèn)使用騰訊云對(duì)象存儲(chǔ)存儲(chǔ)解析的視頻和圖片,如果不配置OSS_COS_BUKET則不會(huì)保存解析的視頻和圖片。
修改plugin/shortVideoParse/config/oss.php
配置文件:
<?php
use plugin\shortVideoParse\app\core\oss\AliOss;
use plugin\shortVideoParse\app\core\oss\CosOss;
return [
'default' => env('OSS_DEFAULT', 'CosOss'),
'CosOss' => [
'class' => CosOss::class,
'bucket' => env('OSS_COS_BUKET'),
'appId' => env('OSS_COS_APPID'),
'secretId' => env('OSS_COS_SECRET_ID'),
'secretKey' => env('OSS_COS_SECRET_KEY'),
'region' => env('OSS_COS_REGION', 'cd'),
'domain' => env('OSS_COS_DOMAIN'),
'host' => env('OSS_COS_HOST'),
],
'AliOss' => [
'class' => AliOss::class,
'bucket' => env('OSS_ALI_BUKET'),
'accessKey' => env('OSS_ALI_ACCESS_KEY'),
'accessSecret' => env('OSS_ALI_ACCESS_SECRET'),
'endPoint' => env('OSS_ALI_ENDPOINT', 'oss-cn-chengdu.aliyuncs.com'),
'region' => env('OSS_ALI_REGION', 'cn-chengdu'),
'host' => env('OSS_ALI_HOST')
]
];
或者(推薦)修改.env
文件:
OSS_DEFAULT=CosOss
OSS_COS_APPID=自己的
OSS_COS_SECRET_ID=自己的
OSS_COS_SECRET_KEY=自己的
OSS_COS_BUKET=自己的
OSS_COS_WATERMARK_BUKET=自己的
OSS_COS_WATERMARK_REGION=自己的
OSS_COS_WATERMARK_DOMAIN=自己的
OSS_COS_WATERMARK_HOST=自己的
OSS_COS_REGION=自己的
OSS_COS_DOMAIN=自己的
OSS_COS_HOST=自己的
OSS_ALI_BUKET=自己的
OSS_ALI_ACCESS_KEY=自己的
OSS_ALI_ACCESS_SECRET=自己的
OSS_ALI_ENDPOINT=自己的
OSS_ALI_REGION=自己的
OSS_ALI_HOST=自己的
request
請(qǐng)求域名配置參考https://api.example.com
request
請(qǐng)求域名配置中,這樣會(huì)減少不合法的域名請(qǐng)求
https://ali2.a.kwimgs.com
https://aweme.snssdk.com
https://cn-hncs-cu-01-07.bilivideo.com
https://cn-hncs-cu-01-09.bilivideo.com
https://cn-lnsy-cu-01-01.bilivideo.com
https://cn-nmghhht-cu-01-07.bilivideo.com
https://cn-sccd-ct-01-05.bilivideo.com
https://cn-sccd-ct-01-07.bilivideo.com
https://cn-sccd-ct-01-08.bilivideo.com
https://cn-sccd-ct-01-22.bilivideo.com
https://cn-sccd-ct-01-30.bilivideo.com
https://cn-sccd-ct-01-31.bilivideo.com
https://cn-sdqd-cu-01-33.bilivideo.com
https://cn-tj-cu-01-01.bilivideo.com
https://cn-tj-cu-01-07.bilivideo.com
https://cn-tj-cu-01-08.bilivideo.com
https://cn-zjhz-cu-01-06.bilivideo.com
https://cn-zjjh-ct-04-35.bilivideo.com
https://f.video.weibocdn.com
https://i0.hdslb.com
https://i1.hdslb.com
https://i2.hdslb.com
https://image1.pearvideo.com
https://img.momocdn.com
https://mvimg10.meitudata.com
https://mvvideo10.meitudata.com
https://p11-sign.douyinpic.com
https://p3-pc-sign.douyinpic.com
https://p6-ppx-sign.byteimg.com
https://p9-pc-sign.douyinpic.com
https://pic640.weishi.qq.com
https://sf5-hl-cdn-tos.douyinstatic.com
https://sns-video-hw.xhscdn.com
https://sns-webpic-qc.xhscdn.com
https://txmov2.a.yximgs.com
https://upos-sz-mirrorali.bilivideo.com
https://upos-sz-mirrorcos.bilivideo.com
https://v.weishi.qq.com
https://v26-default.365yg.com
https://v3-cha.toutiaovod.com
https://v3-default.365yg.com
https://video.momocdn.com
https://video.pearvideo.com
https://watermark-1255543940.cos.ap-chengdu.myqcloud.com
https://web-f01.izuiyou.com
https://web-v01.izuiyou.com
https://wx2.sinaimg.cn
https://api.example.com
downloadFile
合法域名配置中,這樣會(huì)減少不合法的域名請(qǐng)求
https://ali2.a.kwimgs.com
https://aweme.snssdk.com
https://cn-ahwh-ct-01-05.bilivideo.com
https://cn-ahwh-ct-01-06.bilivideo.com
https://cn-ahwh-ct-01-09.bilivideo.com
https://cn-ahwh-ct-01-10.bilivideo.com
https://cn-cq-ct-01-01.bilivideo.com
https://cn-fjqz-cm-01-06.bilivideo.com
https://cn-gddg-cm-01-02.bilivideo.com
https://cn-gddg-ct-01-13.bilivideo.com
https://cn-gddg-ct-01-22.bilivideo.com
https://cn-gddg-cu-01-06.bilivideo.com
https://cn-gdfs-ct-01-07.bilivideo.com
https://cn-gdfs-ct-01-09.bilivideo.com
https://cn-gdfs-ct-01-10.bilivideo.com
https://cn-gdfs-ct-01-12.bilivideo.com
https://cn-gdfs-ct-01-18.bilivideo.com
https://cn-gdfs-ct-01-19.bilivideo.com
https://cn-gdgz-cm-01-01.bilivideo.com
https://cn-gdgz-cm-01-02.bilivideo.com
https://cn-gdgz-cm-01-03.bilivideo.com
https://cn-gdgz-cm-01-04.bilivideo.com
https://cn-gdgz-cm-01-05.bilivideo.com
https://cn-gdgz-cm-01-08.bilivideo.com
https://cn-gdgz-cm-01-09.bilivideo.com
https://cn-gdgz-cm-01-10.bilivideo.com
https://cn-gdgz-cm-01-11.bilivideo.com
https://cn-gdgz-cm-01-14.bilivideo.com
https://cn-hbsjz-cm-02-02.bilivideo.com
https://cn-hbsjz-cm-02-03.bilivideo.com
https://cn-hbsjz-cm-02-05.bilivideo.com
https://cn-hbsjz-cm-02-08.bilivideo.com
https://cn-hbsjz-cm-02-09.bilivideo.com
https://cn-hbsjz-cm-02-10.bilivideo.com
https://cn-hbsjz-cm-02-11.bilivideo.com
https://cn-hbsjz-cm-02-13.bilivideo.com
https://cn-hbwh-cm-01-03.bilivideo.com
https://cn-hbwh-cm-01-04.bilivideo.com
https://cn-hbwh-cm-01-05.bilivideo.com
https://cn-hbwh-cm-01-06.bilivideo.com
https://cn-hbwh-cm-01-07.bilivideo.com
https://cn-hbwh-cm-01-09.bilivideo.com
https://cn-hbwh-cm-01-10.bilivideo.com
https://cn-hbwh-cm-01-13.bilivideo.com
https://cn-hbwh-cm-01-17.bilivideo.com
https://cn-hbwh-cm-01-19.bilivideo.com
https://cn-hbyc-ct-02-05.bilivideo.com
https://cn-hbyc-ct-02-12.bilivideo.com
https://cn-hbyc-ct-02-23.bilivideo.com
https://cn-hbyc-ct-02-24.bilivideo.com
https://cn-hbyc-ct-02-25.bilivideo.com
https://cn-hljheb-ct-01-03.bilivideo.com
https://cn-hncs-cu-01-02.bilivideo.com
https://cn-hncs-cu-01-03.bilivideo.com
https://cn-hncs-cu-01-05.bilivideo.com
https://cn-hncs-cu-01-10.bilivideo.com
https://cn-hnld-ct-01-22.bilivideo.com
https://cn-hnld-ct-01-24.bilivideo.com
https://cn-hnld-ct-01-39.bilivideo.com
https://cn-hnld-ct-01-47.bilivideo.com
https://cn-hnld-ct-01-51.bilivideo.com
https://cn-hnzz-cm-01-01.bilivideo.com
https://cn-jsnt-ct-01-10.bilivideo.com
https://cn-jsnt-ct-01-21.bilivideo.com
https://cn-jsnt-ct-01-25.bilivideo.com
https://cn-jsnt-ct-01-32.bilivideo.com
https://cn-jsnt-ct-01-38.bilivideo.com
https://cn-jsnt-ct-01-52.bilivideo.com
https://cn-jxnc-cm-01-13.bilivideo.com
https://cn-sdjn-cm-02-11.bilivideo.com
https://cn-sh-ct-01-10.bilivideo.com
https://cn-sxty-cu-03-05.bilivideo.com
https://cn-zjjh-ct-04-06.bilivideo.com
https://f.video.weibocdn.com
https://i0.hdslb.com
https://i1.hdslb.com
https://i2.hdslb.com
https://image1.pearvideo.com
https://img.momocdn.com
https://mvimg10.meitudata.com
https://mvvideo10.meitudata.com
https://n98-v-ncdnon.toutiaovod.com
https://p11-sign.douyinpic.com
https://p26-sign.douyinpic.com
https://p26.douyinpic.com
https://p29.douyinpic.com
https://p3-b-sign.douyinpic.com
https://p3-ch-a-sign.douyinpic.com
https://p3-d.douyinpic.com
https://p3-pc-sign.douyinpic.com
https://p3-sign.toutiaoimg.com
https://p6-ch-b.douyinpic.com
https://p6-ppx-sign.byteimg.com
https://p9-pc-sign.douyinpic.com
https://p9-sign.douyinpic.com
https://p9-tt-video-play-sign.byteimg.com
https://p9.douyinpic.com
https://p95-sign.douyinpic.com
https://pic640.weishi.qq.com
https://sf5-hl-cdn-tos.douyinstatic.com
https://sns-img-hw.xhscdn.com
https://sns-video-al.xhscdn.com
https://sns-video-bd.xhscdn.com
https://sns-video-hw.xhscdn.com
https://sns-webpic-qc.xhscdn.com
https://txmov2.a.yximgs.com
https://upos-sz-mirrorali.bilivideo.com
https://upos-sz-mirrorcos.bilivideo.com
https://v.weishi.qq.com
https://v11-x.toutiaovod.com
https://v26-default.365yg.com
https://v3-cha.toutiaovod.com
https://v3-default.365yg.com
https://v5-x.toutiaovod.com
https://v6-default.365yg.com
https://v9-default.365yg.com
https://v9-x.toutiaovod.com
https://v95-zj-colda.douyinvod.com
https://video.momocdn.com
https://video.pearvideo.com
https://watermark-1255543940.cos.ap-chengdu.myqcloud.com
https://web-f01.izuiyou.com
https://web-v01.izuiyou.com
https://wx2.sinaimg.cn
https://api.example.com
。此項(xiàng)目目前沒有使用oss,所以不需要配置,然后是個(gè)人頭像使用了上傳https://oss.example.com
項(xiàng)目已經(jīng)開發(fā)好。開發(fā)者只需要更新隱私協(xié)議即可。具體流程參考:小程序隱私協(xié)議開發(fā)指南
-接入流程
由于短視頻平臺(tái)都是oss+cdn地址太多,不可能在小程序downloadFile合法域名里面全部配置,那現(xiàn)在需要保證下載成果,就需要代理。
同時(shí)目前的代理機(jī)制是:
其他平臺(tái)是小程序首先請(qǐng)求原始的視頻下載地址下載,如果下載失敗,就請(qǐng)求代理地址下載,如果代理地址下載失敗,就返回下載失敗。
以下是代理的詳細(xì)處理方案(暫時(shí)只對(duì)WanzijVideoParser
解析驅(qū)動(dòng)做了代理處理,后續(xù)根據(jù)情況調(diào)整):
在.env
里面設(shè)置:
TOUTIAO_MP4_DOWNLOAD_PROXY=自己的域名/proxy_video.php
TOUTIAO_IMG_DOWNLOAD_PROXY=自己的域名/proxy_img.php
這部分代碼處理使用了php fpm,因此也需要配置nginx,以下提供寶塔配置:
寶塔的根目錄是項(xiàng)目下的public
location /proxy_video {
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi-74.sock;
fastcgi_index proxy_video.php;
include fastcgi.conf;
include pathinfo.conf;
}
location /proxy_img {
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi-74.sock;
fastcgi_index proxy_img.php;
include fastcgi.conf;
include pathinfo.conf;
}
通過(guò)在nginx下配置代理,以下是寶塔配置參考:
resolver 8.8.8.8 114.114.114.114 valid=300s;
location /download {
# 提取 url 參數(shù)并存儲(chǔ)到變量
if ($query_string ~* "^url=(.*)$") {
set $target_url $1; # 設(shè)置變量 $target_url 存儲(chǔ)解析出的 URL
}
if ($target_url = "") {
return 400 "Missing URL parameter.";
}
# 代理請(qǐng)求到目標(biāo) URL
proxy_pass $target_url;
# 設(shè)置請(qǐng)求頭
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
#proxy_set_header Referer "https://m.toutiao.com/";
proxy_set_header Accept-Encoding "";
# 支持?jǐn)帱c(diǎn)續(xù)傳
proxy_set_header Range $http_range;
proxy_cache_bypass $http_range;
# 啟用錯(cuò)誤攔截
proxy_intercept_errors on;
}
.env
里配置:VIDEO_DOWNLOAD_PROXY=自己的/proxy_video.php
有用戶反饋redis密碼配置問題,這里提供解決方案:
config/redis.php
文件:
return [
'default' => [
'host' => '127.0.0.1',
'password' => '填寫自己的密碼',
'port' => 6379,
'database' => 0,
],
];
config/plugin/webman/redis-queue/redis.php
文件:
<?php
return [
'default' => [
'host' => 'redis://127.0.0.1:6379',
'options' => [
'auth' => '填寫自己的密碼', // 密碼,字符串類型,可選參數(shù)
'db' => 0, // 數(shù)據(jù)庫(kù)
'prefix' => '', // key 前綴
'max_attempts' => 5, // 消費(fèi)失敗后,重試次數(shù)
'retry_seconds' => 5, // 重試間隔,單位秒
]
],
];
## 下載缺少.env.example文件`.env.example`
```php
OSS_DEFAULT=CosOss
OSS_COS_APPID=自己的
OSS_COS_SECRET_ID=自己的
OSS_COS_SECRET_KEY=自己的
OSS_COS_BUKET=自己的
OSS_COS_WATERMARK_BUKET=自己的
OSS_COS_WATERMARK_REGION=自己的
OSS_COS_WATERMARK_DOMAIN=自己的
OSS_COS_WATERMARK_HOST=自己的
OSS_COS_REGION=自己的
OSS_COS_DOMAIN=自己的
OSS_COS_HOST=自己的
OSS_ALI_BUKET=自己的
OSS_ALI_ACCESS_KEY=自己的
OSS_ALI_ACCESS_SECRET=自己的
OSS_ALI_ENDPOINT=自己的
OSS_ALI_REGION=自己的
OSS_ALI_HOST=自己的
VIDEO_PARSE_SECRET=自己的
WEIBO_MP4_PROXY=自己的域名/proxy/weibo
VIDEO_DOWNLOAD_PROXY=自己的域名/proxy_video.php
IMG_DOWNLOAD_PROXY=自己的域名/proxy_img.php
WECHAT_MINI_APP_ID=自己的
WECHAT_MINI_APP_SECRET=自己的
下面是一些小問題,需要安裝者手動(dòng)修改,后續(xù)有大版本更新在一起調(diào)整到新版本。
電腦端微信下載視頻提示:“下載鏈接獲取失敗”
進(jìn)入:plugin/shortVideoParse/app/controller/VideoController.php
找到shortVideoParse
方法,做如何修改:
if (!$request->isWechat() && !$request->isWechatDevTools() || !$request->isWechatPc()) {
return json(['code' => 1, 'msg' => '非微信端', 'data' => null]);
}
接著,在support/Request.php
增加isWechatPc
public function isWechatPc(): bool
{
$userAgent = $this->header('user-agent', '');
return false !== strpos($userAgent, 'MicroMessenger') || false !== strpos($userAgent, 'MiniProgram' || false !== strpos($userAgent, 'Wechat'));
}