The previous article thinkphp integrated series of Phpmailer in bulk sent the message said;
Mail has 0 cost, rich content of the advantages;
But a very hard mishap; this guy's timeliness is too bad;
Especially with the rise after 90, 00, from the Internet began to experience QQ, the instant communication;
The only mailbox is also automatically opened QQ mailbox, but still a series of unread;
Then there is a kind of wood has a zero cost, but the timeliness of a better solution?
Yes, that's the message push; Of course, the premise is that the user has installed the app;
This is the first to the friends of the push to explain the next; http://push.umeng.com/
Still an open source project example: Http://git.oschina.net/shuaibai123/thinkphp-bjyadmin
One: Register app
工欲善其事 must first note its key;
Find messages to push, add apps, get key and secret;
650) this.width=650; "alt=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160529/1464493389337978.jpg " title= "Bai Jun Haruka Blog"/>
There are 2 pits in it;
1: Android to use Appkey and app Master Secret; not Umeng Message Sercet;
2: Be sure to add the server IP address, if it is in the local test; that direct Baidu under the IP, the isolated IP can be filled;
650) this.width=650; "alt=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160529/1464493687187040.jpg " title= "Bai Jun Haruka Blog"/>
Add device Token for test equipment; This is to be acquired by the mobile side;
650) this.width=650; "alt=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160529/1464494930793143.jpg " title= "Bai Jun Haruka Blog"/>
Two: Create a table
Download the sample project; the Users and Oauth_user tables will be available after installation;
The users table is used to store the user's account password and the like;
The Oauth_user table is used to store device tokens sent over the mobile side;
Of course, the design of the table is also possible, mainly to let the user ID and device token associated;
Three: Integration of the Friends League SDK
SDK Directory:/thinkphp/library/vendor/umeng
Of course, this SDK has been modified by me, the specific modification of those places, the same age, no record;
Configuration item:/application/common/conf/config.php
' Umeng_ios_app_key ' + ', '//Friends ' iOS AppKey ' umeng_ios_secret ' + ',//Friends ' iOS APP Master SECRET ' umen G_android_app_key ' + ',//Friends League Android AppKey ' Umeng_android_secret ' + ',//Friends league Android APP Master SECRET
Function:/application/common/common/function.php
/** * send friends push message * @param integer $uid user id * @param string $title push title * @param integer $ Type 1: The official Little Secretary 2: My comments * @return boolear Success */function umeng_push ($uid, $title) { // get token $device _tokens=d (' Oauthuser ')->gettoken ($uid, 2); // Do not send notification if (empty ($device _tokens) { If no token indicates that the mobile side is not logged in; return false; } // Import Friends League vendor (' Umeng.umeng '); // custom fields assigned according to actual environment If you do not have to ignore $status =1; // message Unread Total statistics get the total number of unread messages based on the actual environment This number will be displayed in the top right corner of the app icon $count _number=1; $data =array ( ' key ' = ' status ', ' value ' = ' $status ', ' count_number ' = $count _number ); // judgment device_token 64 is represented as Apple otherwise Android if (strlen ($device _tokens) ==64) { $key =c (' Umeng_ios_app_key '); $timestamp =c (' Umeng_ios_secret '); $umeng =new \umeng ($key, $timestamp); $umeng->sendiosunicast ($data, $title, $device _tokens); }else{ $key =c (' Umeng_android_app_key '); $timestamp =c (' UmenG_android_secret '); $umeng =new \umeng ($key, $ Timestamp); $umeng->sendandroidunicast ($data, $title, $device _ tokens); } return true;}
Call:
Umeng_push (' 1 ', ' Test ')
This article for Bai Jun Remote original article, reprinted without contact with me, but please specify from Bai Jun Remote blog http://baijunyao.com
Thinkphp Integration series of Friends Alliance message push