文档中心>即时通信 IM

离线推送 V2TIMOfflinePushInfo.vendorParams 说明

最近更新时间:2025-09-11 10:22:12

我的收藏
支持设置 V2TIMOfflinePushInfo 推送消息的扩展特性,详细支持字段如下:

字段说明如下

字段
类型
属性
使用说明
备注
fcmPriority
String
选填
FCM 推送消息优先级设置:
"normal":普通优先级,应用在前台运行时,普通优先级消息会被立即传递。当应用在后台运行时,消息传递可能会延迟。如果是对时间不太敏感的消息(例如新电子邮件通知、使界面保持同步或在后台同步应用数据),建议您选择普通传递优先级;
"high":高优先级,即使设备处于低电耗模式,FCM 也会立即尝试传递高优先级消息。 高优先级消息适用于对时间敏感的用户可见内容。
vivoNotifyType
Integer
选填
vivo 通知类型:
1:无。
2:响铃。
3:振动。
4:响铃和振动。
默认值:4。
oppoTemplateId
String
选填
OPPO 私信申请的模板 ID,申请方式详见 OPPO 私信通道
下发对应私信模板时必须携带,不支持自拟。
说明:
控制台也支持单独设置模板 ID, 主要用来支持 IM 场景下 (category = "IM") 推送消息生效模板 ID:
控制台设置模板 ID 后,会默认填充 V2TIMOfflinePushInfo 的 title 和 desc 字段内容给模板标题和内容,格式如下:
{
"oppoTitleParam": {
"title":"titleInfo"
},
"oppoContentParam":{
"desc":"descInfo"
}
}
对应的申请模板示例:

以上,可以支持存量 IM 场景的离线消息适配私信模板功能,达到存量用户 IM 消息依然可走私信通道的目标。IM 类型消息也建议使用该方式使用私信模板。
oppoTitleParam
JSON
选填
OPPO 标题模板填充参数:
例:私信模板 ID 标题模板为:欢迎来到$ {city} $ ,$ {city} $ 欢迎您。
此参数内容为:{“city”:“北京”}
oppoContentParam
JSON
选填
OPPO 内容模板填充参数:
例:私信模板 ID 对应的内容模板为:欢迎$ {userName} $ 来到$ {city} $
参数内容为:{“userName”:“汤姆”,“city”:“深圳市”}

用法示例

Android
iOS
C++
Java
Kotlin
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
Map<String, Object> map = new HashMap<>();
map.put("fcmPriority", "high");
map.put("vivoNotifyType", 4);
map.put("oppoTemplateId", "oppoid");

Map<String, Object> oppoTitleMap = new HashMap<>();
oppoTitleMap.put("title", "title");
map.put("oppoTitleParam", new Gson().toJson(oppoTitleMap));

Map<String, Object> oppoContentMap = new HashMap<>();
oppoContentMap.put("desc", "desc");
map.put("oppoContentParam", new Gson().toJson(oppoContentMap));

String param = new Gson().toJson(map);
v2TIMOfflinePushInfo.setVendorParams(param);
val map = mutableMapOf<String, Any>(
"fcmPriority" to "high",
"vivoNotifyType" to 4,
"oppoTemplateId" to "oppoid"
)

val oppoTitleMap = mapOf("title" to "title")
map["oppoTitleParam"] = Gson().toJson(oppoTitleMap)

val oppoContentMap = mapOf("desc" to "desc")
map["oppoContentParam"] = Gson().toJson(oppoContentMap)

val param = Gson().toJson(map)
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
v2TIMOfflinePushInfo.setVendorParams(param)
OC
Swift
NSMutableDictionary *map = [@{
@"fcmPriority": @"high",
@"vivoNotifyType": @4,
@"oppoTemplateId": @"oppoid"
} mutableCopy];

NSDictionary *oppoTitleMap = @{@"title": @"title"};
NSData *titleData = [NSJSONSerialization dataWithJSONObject:oppoTitleMap options:0 error:nil];
NSString *oppoTitleJson = [[NSString alloc] initWithData:titleData encoding:NSUTF8StringEncoding];
[map setObject:oppoTitleJson forKey:@"oppoTitleParam"];

NSDictionary *oppoContentMap = @{@"desc": @"desc"};
NSData *contentData = [NSJSONSerialization dataWithJSONObject:oppoContentMap options:0 error:nil];
NSString *oppoContentJson = [[NSString alloc] initWithData:contentData encoding:NSUTF8StringEncoding];
[map setObject:oppoContentJson forKey:@"oppoContentParam"];

NSData *paramsData = [NSJSONSerialization dataWithJSONObject:map options:0 error:nil];
NSString *params = [[NSString alloc] initWithData:paramsData encoding:NSUTF8StringEncoding];

V2TIMOfflinePushInfo *v2TIMOfflinePushInfo = [[V2TIMOfflinePushInfo alloc] init];
v2TIMOfflinePushInfo.vendorParams = params;
var map: [String: Any] = [
"fcmPriority": "high",
"vivoNotifyType": 4,
"oppoTemplateId": "oppoid"
]

let oppoTitleMap: [String: String] = ["title": "title"]
if let titleData = try? JSONSerialization.data(withJSONObject: oppoTitleMap),
let oppoTitleJson = String(data: titleData, encoding: .utf8) {
map["oppoTitleParam"] = oppoTitleJson
}

let oppoContentMap: [String: String] = ["desc": "desc"]
if let contentData = try? JSONSerialization.data(withJSONObject: oppoContentMap),
let oppoContentJson = String(data: contentData, encoding: .utf8) {
map["oppoContentParam"] = oppoContentJson
}

let paramsData = try! JSONSerialization.data(withJSONObject: map)
let params = String(data: paramsData, encoding: .utf8)!

let v2TIMOfflinePushInfo = V2TIMOfflinePushInfo()
v2TIMOfflinePushInfo.vendorParams = params;
#include <sstream>
#include <string>

V2TIMOfflinePushInfo offline_push_info;
//std::string param = R"({"fcmPriority":"high","vivoNotifyType":4})";

std::ostringstream param;
// 拼主结构体
param << "{";
param << "\\"fcmPriority\\":\\"high\\",";
param << "\\"vivoNotifyType\\":4,";
param << "\\"oppoTemplateId\\":\\"oppoid\\",";

// 拼oppoTitleParam的json字符串
std::string oppo_title_json = "{\\"title\\":\\"title\\"}";
param << "\\"oppoTitleParam\\":\\"";
for (const char c : oppo_title_json) {
// 转义嵌套json里的双引号
if (c == '"') oss << '\\\\';
oss << c;
}
param << "\\",";

// 拼oppoContentParam的json字符串
std::string oppo_content_json = "{\\"desc\\":\\"desc\\"}";
param << "\\"oppoContentParam\\":\\"";
for (const char c : oppo_content_json) {
if (c == '"') oss << '\\\\';
oss << c;
}
param << "\\"}";
offline_push_info.vendorParams = param.str();
注意:
IMSDK 8.7 及以上版本支持。