摘要:公司客戶端選定的友盟消息推送文檔很少自己踩坑不少代碼引入核心文件推送廣播推送消息標題推送消息內容推送單播推送消息標題推送消息內容設備的值自定義
公司客戶端選定的友盟消息推送,PHP文檔很少,自己踩坑不少:
代碼andkey = "andriodkey"; $this->andMasterSecret = "andriodsecret"; //ios $this->ioskey = "ioskey"; $this->iosMasterSecret = "iossecret"; $this->timestamp = strval(time()); } /** * Android推送—廣播 * @param $title string 推送消息標題 * @param $content string 推送消息內容 * @return mixed */ function sendAndroidBroadcast($title, $content) { try { $brocast = new AndroidBroadcast(); $brocast->setAppMasterSecret($this->andMasterSecret); $brocast->setPredefinedKeyValue("appkey", $this->andkey); $brocast->setPredefinedKeyValue("timestamp", $this->timestamp); $brocast->setPredefinedKeyValue("ticker", "Android broadcast ticker"); $brocast->setPredefinedKeyValue("title", $title); $brocast->setPredefinedKeyValue("text", $content); $brocast->setPredefinedKeyValue("after_open", "go_app"); $brocast->setPredefinedKeyValue("production_mode", "true"); $brocast->setExtraField("test", "helloworld"); return $brocast->send(); } catch (Exception $e) { print("Caught exception: " . $e->getMessage()); } } /** * Android推送—單播 * @param $title string 推送消息標題 * @param $content string 推送消息內容 * @param $tokens array 設備的token值 * @return mixed */ function sendAndroidUnicast($title, $content, $tokens) { try { $unicast = new AndroidUnicast(); $unicast->setAppMasterSecret($this->andMasterSecret); $unicast->setPredefinedKeyValue("appkey", $this->andkey); $unicast->setPredefinedKeyValue("mipush", true); $unicast->setPredefinedKeyValue("mi_activity", "cn.weidijia.pccm.ui.activity.SplashActivity"); $unicast->setPredefinedKeyValue("timestamp", $this->timestamp); $unicast->setPredefinedKeyValue("device_tokens", $tokens); $unicast->setPredefinedKeyValue("ticker", "Android unicast ticker"); $unicast->setPredefinedKeyValue("title", $title); $unicast->setPredefinedKeyValue("text", $content); $unicast->setPredefinedKeyValue("after_open", "go_app"); $unicast->setPredefinedKeyValue("production_mode", "true"); $unicast->setExtraField("test", "helloworld"); return $unicast->send(); } catch (Exception $e) { print("Caught exception: " . $e->getMessage()); } } /* * android自定義 * */ function sendAndroidCustomizedcast($alias, $alias_type, $ticker, $title, $text) { try { $customizedcast = new AndroidCustomizedcast(); $customizedcast->setAppMasterSecret($this->andMasterSecret); $customizedcast->setPredefinedKeyValue("appkey", $this->andkey); $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp); $customizedcast->setPredefinedKeyValue("alias", $alias); $customizedcast->setPredefinedKeyValue("alias_type", $alias_type); $customizedcast->setPredefinedKeyValue("ticker", $ticker); $customizedcast->setPredefinedKeyValue("title", $title); $customizedcast->setPredefinedKeyValue("text", $text); $customizedcast->setPredefinedKeyValue("after_open", "go_app"); return $customizedcast->send(); } catch (Exception $e) { print("Caught exception: " . $e->getMessage()); } } /** * IOS推送—廣播 * @param $title string 推送消息標題 * @param $content string 推送消息內容 * @return mixed */ function sendIOSBroadcast($title, $content) { try { $brocast = new IOSBroadcast(); $brocast->setAppMasterSecret($this->iosMasterSecret); $brocast->setPredefinedKeyValue("appkey", $this->ioskey); $brocast->setPredefinedKeyValue("timestamp", $this->timestamp); $brocast->setPredefinedKeyValue("alert", $title); $brocast->setPredefinedKeyValue("badge", 0); $brocast->setPredefinedKeyValue("sound", "chime"); $brocast->setPredefinedKeyValue("production_mode", "false"); $brocast->setCustomizedField("test", $content); return $brocast->send(); } catch (Exception $e) { print("Caught exception: " . $e->getMessage()); } } /** * IOS推送—單播 * @param $title string 推送消息標題 * @param $content string 推送消息內容 * @param $tokens array 設備的token值 * @return mixed */ function sendIOSUnicast($title, $content, $tokens) { try { $unicast = new IOSUnicast(); $unicast->setAppMasterSecret($this->iosMasterSecret); $unicast->setPredefinedKeyValue("appkey", $this->ioskey); $unicast->setPredefinedKeyValue("timestamp", $this->timestamp); $unicast->setPredefinedKeyValue("device_tokens", $tokens); $unicast->setPredefinedKeyValue("alert", $title); $unicast->setPredefinedKeyValue("badge", 0); $unicast->setPredefinedKeyValue("sound", "chime"); $unicast->setPredefinedKeyValue("production_mode", "false"); $unicast->setCustomizedField("test", $content); return $unicast->send(); } catch (Exception $e) { print("Caught exception: " . $e->getMessage()); } } /* * IOS自定義 * */ function sendIOSCustomizedcast($alias, $alias_type, $ticker, $title, $text) { $alert = [ "title" => $title, "subtitle" => $ticker, "body" => $text ]; try { $customizedcast = new IOSCustomizedcast(); $customizedcast->setAppMasterSecret($this->iosMasterSecret); $customizedcast->setPredefinedKeyValue("appkey", $this->ioskey); $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp); $customizedcast->setPredefinedKeyValue("alias", $alias); $customizedcast->setPredefinedKeyValue("alias_type", $alias_type); $customizedcast->setPredefinedKeyValue("alert", $alert); $customizedcast->setPredefinedKeyValue("badge", 0); $customizedcast->setPredefinedKeyValue("sound", "chime"); $customizedcast->setPredefinedKeyValue("production_mode", "false"); return $customizedcast->send(); } catch (Exception $e) { print("Caught exception: " . $e->getMessage()); } } }
andriod和ios使用不同的key和secret,申請就好.下載的demo里面沒有列播,網上也沒有資料,客服就更別說了...
ios的自定義播送的alert要傳遞數組
離線推送這兩個字段需要在UmengNotification.php文件內添加這兩個字段,否則會報錯.
protected $DATA_KEYS = array("appkey", "timestamp", "type", "device_tokens", "alias", "alias_type", "file_id", "filter", "production_mode", "feedback", "description", "thirdparty_id", "mipush", "mi_activity");
友盟U-push參數解析
3.使用下載的官方demo一定要吧print都注釋掉.
第一篇寫的很亂,不好意思
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/29069.html
摘要:友盟推送后臺數據顯示,當在第一時間推送重大新聞時的打開率最高,最高甚至可以超過。友盟微推送結合友盟大數據優勢,統計出固定天數不活躍的用戶群。 雙十一剛過,相信不少開發者小伙伴還沉浸在剁手的余溫中,剛剛幫開發者在雙十一當天推送了 191,991,9272 條消息的友盟消息推送團隊,想借著雙十一的熱乎勁兒,為開發者小伙伴們帶來一些實用的推送技巧!一起來看一看以下三種類型的 App 在這個雙...
閱讀 2345·2021-11-11 16:54
閱讀 2596·2021-09-26 09:47
閱讀 3978·2021-09-08 09:36
閱讀 2727·2021-07-25 21:37
閱讀 927·2019-08-30 15:54
閱讀 2540·2019-08-30 14:22
閱讀 3245·2019-08-30 13:57
閱讀 2558·2019-08-29 17:17