lnmp,tp6使用workman,自定义了worker,目的是要获取抖音直播间的弹幕,一直连不上,还有header要怎么设置,cookie怎么设置,请大佬指教。
<?php
namespace app\live\service;
use think\worker\Server;
use Workerman\Connection\AsyncTcpConnection;
/**
* 直播弹幕管理
* Class Worker
* @package app\live\service
*/
class Worker extends Server
{
protected $socket = "http://0.0.0.0:2346";
public function onMessage($connection, $data)
{
$connection->send("已经收到");
}
public function onWorkerStart($worker)
{
echo '%%%%%%%%%%%%%%%%%%%%%%监听开启%%%%%%%%%%%%%%%%%%%%';
$room_id = '765394307264';
$socket = "ws://webcast5-ws-web-lq.douyin.com:443/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.7&update_version_code=1.0.7&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1920&screen_height=1080&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/115.0.0.0%20Safari/537.36&browser_online=true&tz_name=Asia/Shanghai&cursor=t-1691576963542_r-1_d-1_u-1_h-1&internal_ext=internal_src:dim|wss_push_room_id:7264441938391141179|wss_push_did:7260770083504096805|dim_log_id:20230809182923D6E00D4F294D2D1CD718|first_req_ms:1691576963463|fetch_time:1691576963542|seq:1|wss_info:0-1691576963542-0-0|wrds_kvs:WebcastRoomRankMessage-1691576958792469411_WebcastInRoomBannerMessage-GrowthCommonBannerSubSyncKey-1691570976589853386_WebcastRoomStatsMessage-1691576958745688586&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=&im_path=/webcast/im/fetch/&room_id={$room_id}&identity=audience&heartbeatDuration=0&signature=RhSPTY+2JF2Tw8az";
$ttwid = "1%7CExyGCq8TOnM0s1DMVMPnXgJk7rH3y4xbgpakPEz1zzM%7C1691726776%7Cca98b17c8b54db95ae834f0dce319c12a9a5a16863587e7f09fa2d06f41af659";
$header = [];
$binance = new AsyncTcpConnection($socket);
$binance->transport = 'ssl';
$binance->onConnect =function (AsyncTcpConnection $con)
{
echo '###########################连接成功';
trace('###########################连接成功');
$con->send('连接成功');
};
$binance->onMessage = function (AsyncTcpConnection $con, $data) {
echo '###########################获取信息';
trace('###########################获取信息');
trace($data);
};
$binance->onError = function(AsyncTcpConnection $con, $code, $msg) {
echo '###########################连接失败';
trace('###########################连接失败');
trace($msg);
};
$binance->onClose = function() {
echo '###########################连接关闭';
trace('###########################连接关闭');
};
$binance->connect();
}
}
输入命令php think worker:server报下面的信息,网上相关帖子方法都试了,
抖音都没用wss?
抖音用的是wss,不过连接的时候不都是改成ws,然后配上transport='ssl'吗?直接用wss会报错
https://www.workerman.net/q/4902
感谢,不过这个sslv3我已经试过了,没效果,还是报这个错
顺便问一下,header和cookie要怎么配置
$connection->headers = ['Cookie'=> 'SID=25A15722E6DA4A7DE7A88BDEA7DBF946; PSTM=1691717247'];