122 lines
3.6 KiB
Dart
122 lines
3.6 KiB
Dart
|
|
import 'package:device_info/device_info.dart';
|
|
import 'package:tencent_chat_push_for_china/model/appInfo.dart';
|
|
import 'package:tencent_chat_push_for_china/tencent_chat_push_for_china.dart';
|
|
|
|
class PushConfig{
|
|
|
|
//These `Business ID` can be found in the offline push section for each manufacturers,
|
|
// on the main page of console from Tencent Cloud IM.
|
|
|
|
// Business ID for HUAWEI
|
|
static const HWPushBuzID = 30671;
|
|
|
|
// Business ID for XiaoMi
|
|
static const XMPushBuzID = 30672;
|
|
static const String XMChannelID = "111363";
|
|
|
|
// APP Info of XiaoMi
|
|
static const String XMPushAPPID = "2882303761520264048";
|
|
static const String XMPushAPPKEY = "Yagmr/c0hntFMGWKweXqgg==";
|
|
|
|
// Business ID for Meizu
|
|
static const MZPushBuzID = 0;
|
|
|
|
// APP Info of Meizu
|
|
static const String MZPushAPPID = "";
|
|
static const String MZPushAPPKEY = "";
|
|
|
|
// Business ID for Vivo
|
|
static const VIVOPushBuzID = 30673;
|
|
|
|
// Business ID for OPPO
|
|
static const OPPOPushBuzID = 30674;
|
|
|
|
// APP Info of OPPO
|
|
static const String OPPOPushAPPKEY = "09e35257df174f9db390b4b3257f241c";
|
|
static const String OPPOPushAPPSECRET = "7d17a5b2b2fc43eda61005807002f654";
|
|
static const String OPPOPushAPPID = "31286141";
|
|
static const String OPPOChannelID = "new_message";
|
|
//appsecret:7d17a5b2b2fc43eda61005807002f654
|
|
//appserversecret:07a4d3b9f3f249d2954866706af000d9
|
|
//07a4d3b9f3f249d2954866706af000d9
|
|
|
|
// Business ID for Apple APNS 正式环境39381 测试环境39382
|
|
static const ApplePushBuzID = 39381;
|
|
|
|
|
|
static final PushAppInfo appInfo = PushAppInfo(
|
|
hw_buz_id: PushConfig.HWPushBuzID,
|
|
mi_app_id: PushConfig.XMPushAPPID,
|
|
mi_app_key: PushConfig.XMPushAPPKEY,
|
|
mi_buz_id: PushConfig.XMPushBuzID,
|
|
mz_app_id: PushConfig.MZPushAPPID,
|
|
mz_app_key: PushConfig.MZPushAPPKEY,
|
|
mz_buz_id: PushConfig.MZPushBuzID,
|
|
vivo_buz_id: PushConfig.VIVOPushBuzID,
|
|
oppo_app_key: PushConfig.OPPOPushAPPKEY,
|
|
oppo_app_secret: PushConfig.OPPOPushAPPSECRET,
|
|
oppo_buz_id: PushConfig.OPPOPushBuzID,
|
|
oppo_app_id: PushConfig.OPPOPushAPPID,
|
|
apple_buz_id: PushConfig.ApplePushBuzID
|
|
);
|
|
}
|
|
|
|
|
|
class ChannelPush{
|
|
static final TimUiKitPushPlugin cPush = TimUiKitPushPlugin();
|
|
|
|
static init(PushClickAction pushClickAction) async {
|
|
// initialize the push plugin
|
|
print("ChannelPush init");
|
|
bool isInit = await cPush.init(
|
|
pushClickAction: pushClickAction,
|
|
appInfo: PushConfig.appInfo,
|
|
);
|
|
print("token=初始化"+isInit.toString());
|
|
AndroidDeviceInfo androidInfo;
|
|
try {
|
|
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
androidInfo = await deviceInfo.androidInfo;
|
|
} catch (e) {
|
|
// 处理异常
|
|
return true;
|
|
}
|
|
if (androidInfo.brand == 'Xiaomi'||androidInfo.brand == 'Redmi') {
|
|
cPush.createNotificationChannel(
|
|
channelId: PushConfig.XMChannelID,
|
|
channelName: "消息推送",
|
|
channelDescription:
|
|
"The notification for chat message from Tencent Cloud IM"
|
|
);
|
|
}else{
|
|
cPush.createNotificationChannel(
|
|
channelId: PushConfig.OPPOChannelID,
|
|
channelName: "消息推送",
|
|
channelDescription:
|
|
"The notification for chat message from Tencent Cloud IM"
|
|
);
|
|
}
|
|
// create new notification channel
|
|
|
|
|
|
|
|
// require the permission for notification
|
|
cPush.requireNotificationPermission();
|
|
|
|
|
|
}
|
|
|
|
static Future<String> getDeviceToken() async {
|
|
return cPush.getDevicePushToken();
|
|
}
|
|
static Future<bool> uploadToken() async {
|
|
return await cPush.uploadToken(PushConfig.appInfo);
|
|
}
|
|
|
|
static setBadgeNum(int unreadCount){
|
|
cPush.setBadgeNum(unreadCount);
|
|
}
|
|
|
|
}
|