PC Soft WinDEV Mobile通知属性接收异常问题排查
问题描述
我通过laravel-notification-channels/fcm发送FCM通知,发送流程无报错,但WinDEV Mobile端触发回调时,Notification对象的所有属性均为空。
发送端Laravel代码:
public function toFcm($notifiable): FcmMessage { $message = (new FcmMessage(notification: new FcmNotification))->data([ 'WX_PUSH_EXT_VERSION' => '1.0', 'WX_PROP_CONTENT' => 'Test', //'WX_PROP_MESSAGE' => 'Your account has been activated', 'WX_PROP_LOCAL' => false, 'WX_PROP_TITLE' => 'Account Activation', 'WX_PROP_ACTIVATEAPPLICATION' => true, 'WX_PROP_PRIORITY' => 1, 'WX_PROP_DELETABLE' => true, 'WX_PROP_VIBRATION' => true, ])->custom($this->customOptions()); config()->set('fcm.debug', $message->toArray()); return $message; }
WinDEV Mobile端回调代码:
PROCEDURE NotificationCallBack(MyNotif is Notification) <COMPILE IF ConfigurationType=Android> sContent is string sFContent is string sSecondary is string sTitle is string Info("Im In") sContent = MyNotif.Content // 期望此处为Test但为空 sTitle = MyNotif.Title Info(sContent) Info(sFContent) Info(sSecondary) Info(sTitle) <END>
实际发送的FCM Payload:
{ "data": { "WX_PUSH_EXT_VERSION": "1.0", "WX_PROP_CONTENT": "Test", "WX_PROP_LOCAL": false, "WX_PROP_TITLE": "Account Activation", "WX_PROP_ACTIVATEAPPLICATION": true, "WX_PROP_PRIORITY": 1, "WX_PROP_DELETABLE": true, "WX_PROP_VIBRATION": true }, "registration_ids": [ "<TRUNCATED>" ] }
根据WinDEV文档,WX_PROP_CONTENT应该映射到Notification.Content,但目前该属性为空,请问问题出在哪里?
问题原因与解决方案
1. FCM消息类型的核心差异
你当前发送的是纯FCM数据消息(仅包含data字段),而WinDEV Mobile的Notification对象基础属性(如Content、Title)仅会在接收FCM通知消息(包含notification字段)时自动填充。对于纯数据消息,WinDEV不会将data中的字段自动映射到Notification的属性上。
2. 纯数据消息的正确读取方式
当发送WX_PROP_LOCAL=false的静默数据消息时,所有自定义字段都需要通过Notification.AdditionalData集合获取,而非直接访问Notification.Content这类基础属性。修改WinDEV回调代码如下:
PROCEDURE NotificationCallBack(MyNotif is Notification) <COMPILE IF ConfigurationType=Android> sContent is string sTitle is string Info("Im In") // 从AdditionalData中提取自定义字段 IF MyNotif.AdditionalData.Exists("WX_PROP_CONTENT") THEN sContent = MyNotif.AdditionalData["WX_PROP_CONTENT"] END IF MyNotif.AdditionalData.Exists("WX_PROP_TITLE") THEN sTitle = MyNotif.AdditionalData["WX_PROP_TITLE"] END Info(sContent) // 此时会输出"Test" Info(sTitle) // 此时会输出"Account Activation" <END>
3. 验证WinDEV的静默消息逻辑
根据WinDEV文档,WX_PROP_LOCAL=false时消息属于静默同步消息,不会生成本地通知,直接触发回调。这种场景下Notification的基础属性(如Content、Title)本身就不会被填充,所有业务数据都需要从AdditionalData中提取。
4. 可选:混合消息格式(需显示通知时)
如果后续需要既显示本地通知又传递数据,可以同时发送notification和data字段:
public function toFcm($notifiable): FcmMessage { $message = (new FcmMessage( notification: new FcmNotification( title: 'Account Activation', body: 'Your account has been activated' ) ))->data([ 'WX_PUSH_EXT_VERSION' => '1.0', 'WX_PROP_CONTENT' => 'Test', 'WX_PROP_LOCAL' => true, 'WX_PROP_ACTIVATEAPPLICATION' => true, // 其他自定义字段... ])->custom($this->customOptions()); return $message; }
此时Notification.Content会自动填充notification.body的值,自定义数据仍需从AdditionalData中获取。
内容的提问来源于stack exchange,提问作者Jaquarh

