mPaas 厂商push不通排查指南

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"一 背景"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"金融级移动开发平台 "},{"type":"link","attrs":{"href":"https://www.aliyun.com/product/mpaas","title":null},"content":[{"type":"text","text":"mPaaS"}]},{"type":"text","text":"(Mobile PaaS)为 App 开发、测试、运营及运维提供云到端的一站式解决方案,能有效降低技术门槛、减少研发成本、提升开发效率,协助企业快速搭建稳定高质量的移动应用。其中消息推送服务(Message Push Service,简称 MPS)为开发者提供了专业的移动消息推送方案,针对不同的场景推出多种推送类型,满足个性化推送需求。为了提升推送的到达率,mPaaS 集成了华为、小米等厂商的推送功能,从而有效地提高用户留存率,提升用户体验。在我们日常运维过程中,发现少部分设备在厂商push下无法push,在此分享下相关案例的排查过程,方便后续同类问题借鉴。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"二 push相关背景"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1. push整体架构"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以接触最多的国内Android设备为例,整体结构如下,官网已经给出详细介绍("},{"type":"link","attrs":{"href":"https://help.aliyun.com/document_detail/97485.html?spm=a2c4g.11186623.6.745.6a06530dwB0Zp0","title":null},"content":[{"type":"text","text":"链接"}]},{"type":"text","text":"),这里不在赘述。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/44/44135beb47b2036adc058ffbbc518e9d.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2. 厂商push和自建push"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"厂商push通道:优点是通过各个OS厂商维护的长链接进行推送,在App被系统杀掉后也可以进行推送,推送到达率高于自建push。支持华为,小米,oppo,vivo等厂商。缺点是,目前厂商的push基本都只支持通知栏消息的推送,"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"user"}}],"text":"在用户点击通知前,不启动应用"},{"type":"text","text":",对红点, 图片等消息格式支持有限。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"自建push通道:通过App启动后和自建服务端的长连接通道实现推送,缺点也很明显,App被杀掉后,就无法收到信息。主要用于不支持厂商渠道场景下的push。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"三 问题排查举例"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通过上面的介绍,可以看出三方厂商push是否成功,主要取决于三个链路,分别为:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1.三方token正确生成上报"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2.服务端正常转发到厂商服务器  "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"3.下发到客户端消息可以正常显示"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1. 测试准备"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"为了快速验证问题,我们需要准备一个推送程序,可以快速推送信息到App上。MPS提供了推送的Http接口供外部调用,我们可以通过初始化一个简单的java程序实现推送信息的发送,方便联调。使用链接:"},{"type":"link","attrs":{"href":"https://help.aliyun.com/document_detail/158619.html","title":null},"content":[{"type":"text","text":"链接"}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2. 三方token生成阶段"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前mPaas对三方厂商push的token生成分为以下步骤。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.1 设备在三方push的厂商列表里"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以华为设备为例,判断是否是华为设备的标准是,检测当前手机是否是emui, 如果是才走华为PUSH SDK。在我们日常运维的case中,发现过部分设备由于刷机或者其他操作,在华为手机上安装的不是emui,类似这种设备是走不了华为push的,只能走自建push。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以vivo设备为例,低版本手机只有在vivo公布的白名单设备内才支持推送。白名单见:"},{"type":"link","attrs":{"href":"https://dev.vivo.com.cn/documentCenter/doc/156","title":null},"content":[{"type":"text","text":"链接"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"  "}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/9f/9fd78599a6cc3884b735f61433d8c0e3.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.2 生成三方token"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在调用push sdk生成token的过程中,由于push sdk的生成也依赖当前手机的room版本,以华为为例,就强依赖华为手机内置的HMS Core版本。针对这种场景下的问题,在获取三方token失败的时候,会在回调里返回对应错误码。如下图所示,搜索push的关键字mPush14, 然后过滤,可以获取token返回错误码2。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/87/87a48dc031e1786e080777afbed56ed6.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我们查看华为定义的错误码("},{"type":"link","attrs":{"href":"https://developer.huawei.com/consumer/en/doc/development/HMS-2-References/hmssdk_jointOper_api_reference_errorcode","title":null},"content":[{"type":"text","text":"链接"}]},{"type":"text","text":"),发现2表示SERVICE_VERSION_UPDATE_REQUIRED,需要升级当前的HMS版本。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/5e/5e6914700ab764beb00c323b0f0c0ca9.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"升级HMS版本的方案有两个"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"方案1: 主动升级,调用更新服务接口,升级更新效果如下所示:"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"在启动阶段调用如下服务,安装更新华为推送服务\nif (HuaweiApiAvailability.getInstance().isHuaweiMobileNoticeAvailable(context) == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED) {\n // 需要升级\n HuaweiApiAvailability.getInstance().resolveError(activity, ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED, 1);\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b5/b5270c50ad23c5258e747392ed613845.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"方案2: 引导用户去华为设置里去升级"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://consumer.huawei.com/cn/support/content/zh-cn04461342/","title":null},"content":[{"type":"text","text":"https://consumer.huawei.com/cn/support/content/zh-cn04461342/"}]}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.3 三方token正常上报"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 生成token后会通过RPC接口上报到MPS服务端,需要检查RPC接口是否有异常,上报接口是:alipay.client.yunpushcore.device.report"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/00/007f5eff71d0c81ea63e716980ab3421.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.4 token过期"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以oppo为例,是在应用第一次启动时注册生效,后在刷机、还原手机(设置-其他设置-还原手机)、卸载应用时会失效,需要重新注册才能推送。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/04/043b653afd84feb1ae727a4f8b4c7336.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"3. 服务端投送阶段"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"3.1 消息包含了红点,静默,群发"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前如果消息设置了红点或者静默,因为厂商push不支持,MPS会自动走自建push。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"3.2 三方服务端报错"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这种主要用作mPaas服务端推送到三方服务端后,三方返回异常。这种需要去MPS拉取服务端报错日志,然后核对厂商文档解决,比如华为服务端报错文档链接如下:"},{"type":"link","attrs":{"href":"https://developer.huawei.com/consumer/cn/doc/development/HMS-2-References/hmssdk_huaweipush_api_reference_agent_s2","title":null},"content":[{"type":"text","text":"链接"}]},{"type":"text","text":"。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"3.3 三方服务端限流"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以vivo为例,默认推送走的是运营消息,每天只能对同一个用户推送5次。只有改成系统push类型才能没有这个限制,参考:"},{"type":"link","attrs":{"href":"https://dev.vivo.com.cn/documentCenter/doc/359","title":null},"content":[{"type":"text","text":"链接"}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"4. 设备显示阶段"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"4.1 设备必须打开通知权限才能显示"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"比如oppo的通知权限默认是关闭的,需要打开通知权限,或者引导用户打开后才能显示。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"4.2 应用包名和注册oppo配置保持一致"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"应用的包名要和注册oppo平台填写的包名要一致,不然不会显示"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"四 其他常见问题"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1. 常用日志举例"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"1.1 tag:mPush14"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"主要是mPaas上层应用层日志打印,打印push注册token相以及自建通道push相关信息"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/87/87a48dc031e1786e080777afbed56ed6.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"1.2 tag: mcssdk"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"mcssdk 是oppo push sdk的日志tag, 可以查看厂商的一些日志信息,比如查看三方token"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/99/990b79677b0e4994a3279b5c64251bdc.png","alt":"image.png","title":"image.png","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2. 其他思路"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果以上都解决不了,最后建议去看各个厂商的官方介绍,可能会找到一些思路,"}]},{"type":"numberedlist","attrs":{"start":"1","normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"oppo的faq: "},{"type":"link","attrs":{"href":"https://open.oppomobile.com/wiki/doc#id=10200","title":null},"content":[{"type":"text","text":"链接"}]}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"vivo的faq: "},{"type":"link","attrs":{"href":"https://dev.vivo.com.cn/documentCenter/doc/156","title":null},"content":[{"type":"text","text":"链接"}]}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章