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}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章