Aurora push code

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to learn ThinkPHP + Cordova + Aurora push SDK + CoreThink to implement a message push mechanism for non-native apps, iOS requires Apple's APNS service. Therefore, the developer account is required. Android is a TCP persistent connection.
ThinkPHP + Cordova + Aurora push SDK + CoreThink implement a message push mechanism for non-native apps. iOS needs to use Apple's APNS service, so it needs a developer account. Android is a TCP persistent connection. // + ----------------------------------------------------------------------
// | OpenCMF [Simple Efficient Excellent]
// + ----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.opencmf.cn All rights reserved.
// + ----------------------------------------------------------------------
// | Author: jry <598821125@qq.com>
// + ----------------------------------------------------------------------
Namespace Addons \ Jpush \ Model;
Use Think \ Model;
Use Home \ Controller \ AddonController;
Require_once dirname (_ FILE _). '/JPush. php ';
/**
* Push Model
* @ Author jry <598821125@qq.com>
*/
Class JpushModel {
/**
* Message sending function pushed by a single user
* @ Param string $ push_data push message structure
* @ Return boolean
* @ Author jry <598821125@qq.com>
*/
Function send ($ push_data ){
$ Addon_config = \ Common \ Controller \ Addon: getConfig ('jpush ');
If ($ addon_config ['status']) {
// Obtain the user's device identification
$ Push_token_list = D ('user/MessagePush ')-> where (array ('uid' => $ push_data ['to _ uid']) -> getField ('Token', true );
If ($ addon_config ['production ']) {
$ Production = true;
} Else {
$ Production = false;
}
If ($ push_token_list ){
// Initialization
$ Client = new \ JPush ($ addon_config ['app _ key'], $ addon_config ['master _ secret']);
$ Result = null;
Foreach ($ push_token_list as $ key => $ push_token ){
If ($ push_token ){
// Simple push
$ Tmp = $ client-> push ()
-> SetPlatform ('all ')
-> AddRegistrationId ($ push_token)
-> SetNotificationAlert ($ push_data ['title'])
-> AddAndroidNotification ($ push_data ['title'], $ push_data ['title'], 1, array ("url" => $ push_data ['url'])
-> AddIosNotification ($ push_data ['title'], 'default', '+ 1', true, 'ios category ', array ("url" => $ push_data ['url'])
-> SetOptions ($ sendno = null, $ time_to_live = null, $ override_msg_id = null, $ apns_production = $ production, $ big_push_duration = null)
-> Send ();

If ($ tmp ){
$ Result [$ key] = $ tmp;
}
}
}
If ($ result ){
Return $ result;
} Else {
$ This-> error = 'push failed ';
Return false;
}
} Else {
$ This-> error = 'this user cannot push the device ';
Return false;
}
} Else {
$ This-> error = 'plug-In closures ';
Return false;
}
}
}

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.