mirror of
https://github.com/easychen/pushdeer.git
synced 2025-04-30 16:29:51 +08:00
add mqtt server ( in docker )
This commit is contained in:
parent
ab15e50950
commit
630d479826
@ -141,7 +141,7 @@ function pushdeer_send($text, $desp = '', $type='text', $key = '[PUSHKEY]')
|
|||||||
```
|
```
|
||||||
git clone https://gitee.com/easychen/pushdeer.git
|
git clone https://gitee.com/easychen/pushdeer.git
|
||||||
cd pushdeer
|
cd pushdeer
|
||||||
docker-compose -f docker-compose.self-hosted.yml up --build -d
|
docker-compose -f docker-compose.self-hosted.yml up --build -d
|
||||||
```
|
```
|
||||||
|
|
||||||
(海外服务器使用)
|
(海外服务器使用)
|
||||||
|
@ -79,6 +79,19 @@ class PushDeerMessageController extends Controller
|
|||||||
$the_message['pushkey_name'] = $key->name;
|
$the_message['pushkey_name'] = $key->name;
|
||||||
$pd_message = Message::create($the_message);
|
$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()) {
|
if ($devices = PushDeerDevice::where('uid', $key->uid)->get()) {
|
||||||
foreach ($devices as $device) {
|
foreach ($devices as $device) {
|
||||||
if ($device) {
|
if ($device) {
|
||||||
@ -89,7 +102,9 @@ class PushDeerMessageController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return send_error('没有可用的设备,请先注册', ErrorCode('ARGS'));
|
if (!$sent) {
|
||||||
|
return send_error('没有可用的设备,请先注册', ErrorCode('ARGS'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,3 +151,19 @@ function android_send($is_clip, $device_token, $text, $desp = '', $dev = true)
|
|||||||
error_log('push error'. $ret);
|
error_log('push error'. $ret);
|
||||||
return $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]]);
|
||||||
|
}
|
||||||
|
@ -32,5 +32,17 @@ services:
|
|||||||
- GO_PUSH_IOS_TOPIC=com.pushdeer.self.ios
|
- GO_PUSH_IOS_TOPIC=com.pushdeer.self.ios
|
||||||
- GO_PUSH_IOS_CLIP_TOPIC=com.pushdeer.self.ios.Clip
|
- GO_PUSH_IOS_CLIP_TOPIC=com.pushdeer.self.ios.Clip
|
||||||
- APP_DEBUG=false
|
- 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:
|
volumes:
|
||||||
mariadb_data:
|
mariadb_data:
|
Loading…
x
Reference in New Issue
Block a user