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