add mqtt server ( in docker )

This commit is contained in:
Easy 2022-02-16 17:47:54 +08:00
parent ab15e50950
commit 630d479826
4 changed files with 45 additions and 2 deletions

View File

@ -141,7 +141,7 @@ function pushdeer_send($text, $desp = '', $type='text', $key = '[PUSHKEY]')
```
git clone https://gitee.com/easychen/pushdeer.git
cd pushdeer
docker-compose -f docker-compose.self-hosted.yml up --build -d
docker-compose -f docker-compose.self-hosted.yml up --build -d
```
(海外服务器使用)

View File

@ -79,6 +79,19 @@ class PushDeerMessageController extends Controller
$the_message['pushkey_name'] = $key->name;
$pd_message = Message::create($the_message);
$sent = false;
// 如果配置MQTT服务
// if (strtolower(env('MQTT_ON')) == 'true') {
if (env('MQTT_ON') > 0) {
// 给 mqtt/send 转发消息
$result[] = make_post('http://mqtt/send', [
'key' => env('MQTT_API_KEY'),
'content' => $validated['text'],
'type' => $validated['type'] == 'image' ? 'bg_url' : 'text',
'topic' => $validated['pushkey'],
], 3);
}
if ($devices = PushDeerDevice::where('uid', $key->uid)->get()) {
foreach ($devices as $device) {
if ($device) {
@ -89,7 +102,9 @@ class PushDeerMessageController extends Controller
}
}
} else {
return send_error('没有可用的设备,请先注册', ErrorCode('ARGS'));
if (!$sent) {
return send_error('没有可用的设备,请先注册', ErrorCode('ARGS'));
}
}
}

View File

@ -151,3 +151,19 @@ function android_send($is_clip, $device_token, $text, $desp = '', $dev = true)
error_log('push error'. $ret);
return $ret;
}
function make_post($url, $data, $timeout = 3, $form=false)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if ($form) {
$data = http_build_query($data);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
return json_encode(["counts"=>1,"logs"=>[$response]]);
}

View File

@ -32,5 +32,17 @@ services:
- GO_PUSH_IOS_TOPIC=com.pushdeer.self.ios
- GO_PUSH_IOS_CLIP_TOPIC=com.pushdeer.self.ios.Clip
- APP_DEBUG=false
- MQTT_API_KEY=9LKo3
- MQTT_ON=false
# mqtt:
# image: 'ccr.ccs.tencentyun.com/ftqq/pushdeeresp'
# ports:
# - '1883:1883'
# environment:
# - API_KEY=9LKo3
# - MQTT_PORT=1883
# - MQTT_USER=easy
# - MQTT_PASSWORD=y0urp@ss
# - MQTT_BASE_TOPIC=default
volumes:
mariadb_data: