uni push推送 tp6
https://ask.dcloud.net.cn/question/108521 里有大佬说只能透传消息来执行播报,那就很好办了

前台监听
// #ifdef APP-PLUS
const _self = this;
const _handlePush = function(message) {
console.log('监听消息推送');
console.log(message);
// TODO
let order_video = plus.audio.createPlayer( 'XXXXXXXXXXXXXX/new_order.mp3' );
order_video.play( function () {
console.log('播放完成');
}, function ( e ) {
console.log('播放失败'+e);
} );
};
plus.push.addEventListener('click', _handlePush);
plus.push.addEventListener('receive', _handlePush);
// #endif
后台发送
后台直接用官方给出的demo就能用,默认是通知消息,改一下就行了,这里只考虑应用打开的状态,就不考虑厂商推送什么的了
public function do_order_message()
{
$param = $this->request->param();
$cid = 'XXXXXXXXXXXXXXXXXXXXXXX';//这里填指定用户的cid就行
$res = $this->message_notice_ct($cid);
}
//透传消息
public function message_notice_ct($cid)
{
$push = new GTPushRequest();
//创建API,APPID等配置参考 环境要求 进行获取
$api = new GTClient("https://restapi.getui.com","APPKEY", "APPID","MASTERSECRET");
//设置推送参数
$push = new GTPushRequest();
$push->setRequestId($this->micro_time());
$message = new GTPushMessage();
$notify = new GTNotification();
$notify->setTitle("您有新的订单");
$notify->setBody("新订单来了");
//点击通知后续动作,目前支持以下后续动作:
//1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
$notify->setClickType("payload");
// $message->setNotification($notify);
//透传 ,与通知、撤回三选一
$message->setTransmission("试试透传");
$push->setPushMessage($message);
$push->setCid($cid);
//处理返回结果
$result = $api->pushApi()->pushToSingleByCid($push);
dump($result);
}
function micro_time()
{
list($usec, $sec) = explode(" ", microtime());
$time = ($sec . substr($usec, 2, 3));
return $time;
}

浙公网安备 33010602011771号