【Flutter】极光推送配置流程(小米厂商通道) 章二

news/2024/10/19 2:23:28/

前言

继【Flutter】极光推送配置流程(极光通道/华为厂商/IOS) 章一
并且,我大概率不会去修改第一篇文章的内容。
随着我自己在配置公司的项目的同时,我希望一直更新这个推送系列文章。
在章一配置完后,也是出现了一些问题,所以本章主要围绕

  • 华为厂商通道配置出现的问题
  • 如何配置小米厂商通道

极光插件

首先是极光插件,可以去更新,但要看更新了什么内容
在这里插入图片描述
看这个更新内容,JPush 5.2.4
记得在之前那篇blog,我写了5.2.3
所以在.gradle文件中,把版本提到5.2.4(这里我直接截)
在这里插入图片描述

配置小米厂商通道

小米是需要上架应用的,需要企业开发者。
以下截图和代码是公司的项目,部分地方就马赛克了

上架

需要公司提供资料(软著/APP备案等),上架可能会快一些(1天以上)
在这里插入图片描述

推送申请估计要点时间(3天以上)

在这里插入图片描述
在这里插入图片描述
通道要申请下来,这里的类别,记得按自己需要。
在这里插入图片描述
类别选择参考这篇
在这里插入图片描述
填完类别等信息后
这里的channel_ID记一下
在这里插入图片描述
这里的appKey AppSecret AppID对应极光那三个要填写的
在这里插入图片描述
名字都一样的,把内容填写进去,再开启
在这里插入图片描述

build.gradle

回到项目
看这篇文章
在这里插入图片描述

配置依赖

在这里插入图片描述

    // 小米implementation 'cn.jiguang.sdk.plugin:xiaomi:5.2.4.a'

小米参数
在这里插入图片描述

填写小米参数

在这里插入图片描述

用一台小米手机来运行项目

在这里插入图片描述
若出现

xiao mi push register success

就代表配置好了
在这里插入图片描述

调用API发送推送

在这里插入图片描述
这里的channel id是之前创建的通道的id
代码之前篇章一有贴过
在这里插入图片描述

import 'dart:convert';
import 'dart:io';import 'package:dio/dio.dart';
import 'package:flutter/material.dart';void main() {runApp(const MyApp());
}class MyApp extends StatelessWidget {const MyApp({super.key});Widget build(BuildContext context) {return MaterialApp(title: '推送',theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),useMaterial3: true,),home: const MyHomePage(title: '信息推送'),);}
}class MyHomePage extends StatefulWidget {const MyHomePage({super.key, required this.title});final String title;State<MyHomePage> createState() => _MyHomePageState();
}class _MyHomePageState extends State<MyHomePage> {final String appKey = "XXXX";final String masterSecret = "XXXXXXX";late String base64AuthString;final Dio dio = Dio();late String notificationAlert;late String notificationTitle;late String notificationAudienceAlias;void initState() {final content = utf8.encode("$appKey:$masterSecret");base64AuthString = "Basic ${base64Encode(content)}";super.initState();}Widget build(BuildContext context) {return Scaffold(appBar: AppBar(backgroundColor: Theme.of(context).colorScheme.inversePrimary,title: Text(widget.title),),body: Center(child: Padding(padding: const EdgeInsets.all(8.0),child: ListView(children: [TextField(decoration: const InputDecoration(labelText: "主标题",hintText: "请输入...",),onChanged: (s) {notificationAlert = s;},),TextField(decoration: const InputDecoration(labelText: "副标题",hintText: "请输入...",),onChanged: (s) {notificationTitle = s;},),TextField(decoration: const InputDecoration(labelText: "别名",hintText: "请输入...",),onChanged: (s) {notificationAudienceAlias = s;},),Padding(padding: const EdgeInsets.all(8.0),child: ElevatedButton(onPressed: () {showDialog(context: context,builder: (context) {return SimpleDialog(title: const Text("确定发送?"),children: [SimpleDialogOption(child: const Text("确定"),onPressed: () {pushMessage(notificationAlert: notificationAlert,notificationTitle: notificationTitle,notificationAudienceAlias: [notificationAudienceAlias],);Navigator.of(context).pop();},),SimpleDialogOption(child: const Text("取消"),onPressed: () {Navigator.of(context).pop();},)],);});},child: const Text("推送消息"),),),],),),),);}/// 推送pushMessage({required String notificationAlert,required String notificationTitle,required List<String> notificationAudienceAlias,}) async {const String url = "https://api.jpush.cn/v3/push";var data = json.encode({"platform": ["android", "ios"],"inapp_message": {"inapp_message": false},"options": {"classification": 0,"time_to_live": 86400,"apns_production": false,"third_party_channel": {"huawei": {"skip_quota": false,"distribution": "secondary_push","channel_id": "","category": "DEVICE_REMINDER","receipt_id": ""},"xiaomi": {"channel_id": "XXXXXX","distribution": "secondary_push","skip_quota": false}}},"notification": {"alert": notificationAlert,"android": {"alert": notificationAlert,"title": notificationTitle,"intent": {"url": "intent:#Intent;action=android.intent.action.MAIN;end"},"sound": "","priority": 0,"category": "","alert_type": 7,"style": 0,"builder_id": 0,"large_icon": "","badge_add_num": 1,"extras": {"param": "123"}},"ios": {"alert": {"title": notificationAlert,"body": notificationTitle,},"content-available": 0,"mutable-content": 1,"sound": "default","badge": "+1","thread-id": "","interruption-level": "active","filter-criteria": "","extras": {"参数": "A"}}},"audience": {"alias": notificationAudienceAlias,}});final response = await dio.request(url,data: data,options: Options(headers: {HttpHeaders.authorizationHeader: base64AuthString,},method: "POST",),);print(response.data.toString());}
}

后台关闭APP,杀掉APP,再发送一下
在这里插入图片描述
手机收到就代表配置完成
在这里插入图片描述

遇到的问题

设置别名

这个是在公司项目里面遇到的
需求是这样的:注册好极光的插件之后,若用户登录之后,我需要给当前设备设置别名为手机号。
当调用

final value = await jPush.setAlias("17777777777");

在这里插入图片描述
在这里插入图片描述
这个问题目前解决的办法是在手机号前加了一些数字比如000001777777777,就可以了。不清楚原因,所以就先记录一下。


http://www.ppmy.cn/news/1448971.html

相关文章

Acwing 818. 数组排序

给定一个长度为 n n n的数组 a a a以及两个整数 l l l和 r r r&#xff0c;请你编写一个函数&#xff0c;void sort(int a[], int l, int r)&#xff0c;将 a [ l ] ∼ a [ r ] a[l]∼a[r] a[l]∼a[r]从小到大排序。 输出排好序的数组 a。 输入格式 第一行包含三个整数 n &…

全网最强JavaWeb笔记 | 万字长文爆肝JavaWeb开发——day09Mybatis

万字长文爆肝黑马程序员2023最新版JavaWeb教程。这套教程打破常规&#xff0c;不再局限于过时的老套JavaWeb技术&#xff0c;而是与时俱进&#xff0c;运用的都是企业中流行的前沿技术。笔者认真跟着这个教程&#xff0c;再一次认真学习一遍JavaWeb教程&#xff0c;温故而知新&…

XML:简介

一、何为XML XML 指可扩展标记语言&#xff08;EXtensible Markup Language&#xff09;&#xff0c;设计宗旨是传输数据&#xff0c;而非显示数据&#xff0c;其是W3C&#xff08;指万维网联盟&#xff08;World Wide Web Consortium&#xff09;&#xff09;的推荐标准。 实例…

MATLAB初学者入门(21)—— 霍夫曼树

霍夫曼编码是一种广泛用于数据压缩的有效技术。它基于字符频率或概率来构造最优的前缀码&#xff0c;使得常用字符的编码长度较短&#xff0c;不常用的字符编码长度较长&#xff0c;从而达到压缩数据的目的。MATLAB中可以通过一系列步骤来实现霍夫曼树的构建和相应的编码过程。…

容器安全-镜像扫描

前言 容器镜像安全是云原生应用交付安全的重要一环&#xff0c;对上传的容器镜像进行及时安全扫描&#xff0c;并基于扫描结果选择阻断应用部署&#xff0c;可有效降低生产环境漏洞风险。容器安全面临的风险有&#xff1a;镜像风险、镜像仓库风险、编排工具风险&#xff0c;小…

使用Python及R语言绘制简易数据分析报告

Pytohn实现 在python中有很多包可以实现绘制数据分析报告的功能&#xff0c;推荐两个较为方便的包&#xff1a;pandas-profiling 和 sweetviz 。 使用 pandas-profiling 包&#xff08;功能全面&#xff09; 这个包的个别依赖包与机器学习的 sklearn 包的依赖包存在版本冲突&a…

AI大模型探索之路-训练篇7:大语言模型Transformer库之HuggingFace介绍

系列篇章&#x1f4a5; AI大模型探索之路-训练篇1&#xff1a;大语言模型微调基础认知 AI大模型探索之路-训练篇2&#xff1a;大语言模型预训练基础认知 AI大模型探索之路-训练篇3&#xff1a;大语言模型全景解读 AI大模型探索之路-训练篇4&#xff1a;大语言模型训练数据集概…

pytorch对音频数据的读取和保存

torchaudio是PyTorch深度学习框架的一部分&#xff0c;主要用于处理和分析音频数据。它提供了丰富的音频信号处理工具、特征提取功能以及与深度学习模型结合的接口&#xff0c;使得在PyTorch中进行音频相关的机器学习和深度学习任务变得更加便捷。   通过使用torchaudio&…