成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

PHP支持友盟消息推送踩坑記錄

scq000 / 1775人閱讀

摘要:公司客戶端選定的友盟消息推送文檔很少自己踩坑不少代碼引入核心文件推送廣播推送消息標(biāo)題推送消息內(nèi)容推送單播推送消息標(biāo)題推送消息內(nèi)容設(shè)備的值自定義

公司客戶端選定的友盟消息推送,PHP文檔很少,自己踩坑不少:

代碼
andkey          = "andriodkey";
        $this->andMasterSecret = "andriodsecret";
        //ios
        $this->ioskey          = "ioskey";
        $this->iosMasterSecret = "iossecret";

        $this->timestamp = strval(time());
    }

    /**
     * Android推送—廣播
     * @param $title   string 推送消息標(biāo)題
     * @param $content string 推送消息內(nèi)容
     * @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 推送消息標(biāo)題
     * @param $content string 推送消息內(nèi)容
     * @param $tokens  array 設(shè)備的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 推送消息標(biāo)題
     * @param $content string 推送消息內(nèi)容
     * @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 推送消息標(biāo)題
     * @param $content string 推送消息內(nèi)容
     * @param $tokens  array 設(shè)備的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,申請(qǐng)就好.下載的demo里面沒(méi)有列播,網(wǎng)上也沒(méi)有資料,客服就更別說(shuō)了...

ios的自定義播送的alert要傳遞數(shù)組

離線推送這兩個(gè)字段需要在UmengNotification.php文件內(nèi)添加這兩個(gè)字段,否則會(huì)報(bào)錯(cuò).

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參數(shù)解析

3.使用下載的官方demo一定要吧print都注釋掉.

第一篇寫(xiě)的很亂,不好意思


文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/29069.html

相關(guān)文章

  • 運(yùn)營(yíng)必看!依托友盟大數(shù)據(jù)優(yōu)勢(shì),各類(lèi) App “雙十一”推送攻略

    摘要:友盟推送后臺(tái)數(shù)據(jù)顯示,當(dāng)在第一時(shí)間推送重大新聞時(shí)的打開(kāi)率最高,最高甚至可以超過(guò)。友盟微推送結(jié)合友盟大數(shù)據(jù)優(yōu)勢(shì),統(tǒng)計(jì)出固定天數(shù)不活躍的用戶群。 雙十一剛過(guò),相信不少開(kāi)發(fā)者小伙伴還沉浸在剁手的余溫中,剛剛幫開(kāi)發(fā)者在雙十一當(dāng)天推送了 191,991,9272 條消息的友盟消息推送團(tuán)隊(duì),想借著雙十一的熱乎勁兒,為開(kāi)發(fā)者小伙伴們帶來(lái)一些實(shí)用的推送技巧!一起來(lái)看一看以下三種類(lèi)型的 App 在這個(gè)雙...

    URLOS 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<