mirror of
https://github.com/easychen/pushdeer.git
synced 2024-11-01 08:09:19 +08:00
支持android推送(via MiPush)
This commit is contained in:
parent
9506384550
commit
18b16c8211
@ -56,3 +56,6 @@ GO_PUSH_IOS_PORT=8888
|
||||
GO_PUSH_IOS_TOPIC=com.pushdeer.app.ios
|
||||
GO_PUSH_IOS_CLIP_PORT=8889
|
||||
GO_PUSH_IOS_CLIP_TOPIC=com.pushdeer.app.ios.Clip
|
||||
|
||||
ANDROID_PACKAGE=com.pushdeer.app.quick.v2
|
||||
MIPUSH_SECRET=NONE
|
||||
|
@ -79,7 +79,10 @@ class PushDeerMessageController extends Controller
|
||||
|
||||
foreach ($devices as $device) {
|
||||
if ($device) {
|
||||
$result[] = ios_send($device->is_clip, $device->device_id, $validated['text'], '', env('APP_DEBUG'));
|
||||
$func_name = $device['type'].'_send';
|
||||
if (function_exists($func_name)) {
|
||||
$result[] = $func_name($device->is_clip, $device->device_id, $validated['text'], '', env('APP_DEBUG'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
use Rookiejin\Xmpush\Builder;
|
||||
use Rookiejin\Xmpush\HttpBase;
|
||||
use Rookiejin\Xmpush\Sender;
|
||||
use Rookiejin\Xmpush\Constants;
|
||||
use Rookiejin\Xmpush\Stats;
|
||||
use Rookiejin\Xmpush\Tracer;
|
||||
use Rookiejin\Xmpush\Feedback;
|
||||
use Rookiejin\Xmpush\DevTools;
|
||||
use Rookiejin\Xmpush\Subscription;
|
||||
use Rookiejin\Xmpush\TargetedMessage;
|
||||
|
||||
function getUserDataFromIdentityToken($idToken)
|
||||
{
|
||||
@ -46,6 +56,37 @@ function ErrorCode($code)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function android_sender()
|
||||
{
|
||||
if (!isset($GLOBALS['PD_ANDROID_SENDER'])) {
|
||||
Constants::setPackage(env('ANDROID_PACKAGE', 'com.pushdeer.app.quick.v2'));
|
||||
Constants::setSecret(env('MIPUSH_SECRET', 'NONE'));
|
||||
|
||||
$GLOBALS['PD_ANDROID_SENDER'] = new Sender();
|
||||
}
|
||||
return $GLOBALS['PD_ANDROID_SENDER'];
|
||||
}
|
||||
|
||||
function android_send($is_clip, $device_token, $text, $desp = '', $dev = true)
|
||||
{
|
||||
if (strlen($desp) < 1) {
|
||||
$desp = $text;
|
||||
$text = 'PushDeer';
|
||||
}
|
||||
|
||||
$message1 = new Builder();
|
||||
$message1->title($text); // 通知栏的title
|
||||
$message1->description($desp); // 通知栏的descption
|
||||
$message1->passThrough(0); // 这是一条通知栏消息,如果需要透传,把这个参数设置成1,同时去掉title和descption两个参数
|
||||
// $message1->payload($payload); // 携带的数据,点击后将会通过客户端的receiver中的onReceiveMessage方法传入。
|
||||
$message1->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0
|
||||
$message1->notifyId(2); // 通知类型。同样的类型的通知会互相覆盖,不同类型可以在通知栏并存
|
||||
$message1->build();
|
||||
|
||||
$sender = android_sender();
|
||||
return $sender->send($message1, $device_token)->getRaw();
|
||||
}
|
||||
|
||||
function ios_send($is_clip, $device_token, $text, $desp = '', $dev = true)
|
||||
{
|
||||
$notification = new stdClass();
|
||||
|
@ -11,7 +11,8 @@
|
||||
"guzzlehttp/guzzle": "^7.4",
|
||||
"laravel/framework": "^8.65",
|
||||
"laravel/sanctum": "^2.11",
|
||||
"laravel/tinker": "^2.5"
|
||||
"laravel/tinker": "^2.5",
|
||||
"rookiejin/mipush": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"facade/ignition": "^2.5",
|
||||
|
47
api/composer.lock
generated
47
api/composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "08199d4bca4a00de977a73bdcd9ea318",
|
||||
"content-hash": "0f637f60000aed6893b5527dc426032b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
@ -2897,6 +2897,49 @@
|
||||
],
|
||||
"time": "2021-09-25T23:10:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "rookiejin/mipush",
|
||||
"version": "1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/rookiejin/mipush.git",
|
||||
"reference": "90c7b856fbff73fca3e88040972a3f57ce7acc3d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/rookiejin/mipush/zipball/90c7b856fbff73fca3e88040972a3f57ce7acc3d",
|
||||
"reference": "90c7b856fbff73fca3e88040972a3f57ce7acc3d",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Rookiejin\\Xmpush\\": "src/xmpush"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mj",
|
||||
"email": "Mj@mj.com"
|
||||
}
|
||||
],
|
||||
"description": "小米推送官方包,https://dev.mi.com/console/doc/detail?pId=230,PHP 2.2.20版 于2017.06.13更新",
|
||||
"support": {
|
||||
"issues": "https://github.com/rookiejin/mipush/issues",
|
||||
"source": "https://github.com/rookiejin/mipush/tree/master"
|
||||
},
|
||||
"time": "2018-01-22T08:21:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "swiftmailer/swiftmailer",
|
||||
"version": "v6.3.0",
|
||||
@ -7952,5 +7995,5 @@
|
||||
"php": "^7.3|^8.0"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.1.0"
|
||||
"plugin-api-version": "2.0.0"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user