Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the message push of Friends in thinkphp

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "thinkphp how to achieve friendly League message push", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve friendly League message push" this article.

In the last article, the phpmailer of the thinkphp integration series talked about sending mail in bulk.

Email has the advantages of zero cost and rich content.

But a very hard wound; this guy's timeliness is too poor.

Especially with the rise of the post-90s and post-00s generation, the experience from the Internet is the instant messaging of QQ and Wechat.

The only mailbox is QQ Mail, which is opened automatically; however, it is still a series of unread.

So is there a zero-cost solution with better timeliness?

Yes; that's message push; of course; if the user has already installed app

First of all, let's explain the push of the friendly League; http://push.umeng.com/

Still take the example of an open source project: http://git.oschina.net/shuaibai123/thinkphp-bjyadmin

One: register the application

If you want to do good work, you must first pay attention to its key.

Find message push, add applications; get key and secret

There are two pits in here.

1: Android uses Appkey and App Master Secret;, not Umeng Message Sercet

2: be sure to add the ip address of the server. If you are testing locally, just fill in the checked ip under ip; directly under Baidu.

Add the Device Token; of the test equipment, which needs to be obtained by the mobile end.

Two: create tables

Download the sample project; there will be users table and oauth_ user table after installation

The users table is used to store users' accounts and passwords and so on.

The oauth_user table is used to store the Device Token sent by the mobile terminal.

Of course, it is possible to design your own table; the main thing is to associate the user id with Device Token.

Third: integrate the sdk of Friends

Sdk directory: / ThinkPHP/Library/Vendor/Umeng

Of course; this sdk has also been modified by me; specific changes have been made to those places; it is also a long time ago; there is no record.

Configuration item: / Application/Common/Conf/config.php

'UMENG_IOS_APP_KEY' = >', / / friendly ios AppKey 'UMENG_IOS_SECRET' = >'', / / friendly ios App Master Secret 'UMENG_ANDROID_APP_KEY' = >'', / / friendly android AppKey 'UMENG_ANDROID_SECRET' = >'', / / friendly android App Master Secret

Function: / Application/Common/Common/function.php

/ * send Youmai push message * @ param integer $uid user id * @ param string $title push title * @ param integer $type 1: official Secretary 2: whether my comment * @ return boolear is successful * / function umeng_push ($uid,$title) {/ / get token $device_tokens=D ('OauthUser')-> getToken ($uid,2); / / if there is no token indicating that the mobile is not logged in Do not send notification if (empty ($device_tokens)) {return false;} / / import YouMeng Vendor ('Umeng.Umeng'); / / Custom fields are assigned according to the actual environment If you do not need it, you can ignore the statistics of the total number of unread messages of $status=1; / / get the total number of unread messages according to the actual environment. This number will be displayed in the upper right corner of the app icon $count_number=1; $data=array ('key'= >' status', 'value'= > "$status",' count_number'= > $count_number) / / determine that device_token 64-bit 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:

The above is all the contents of the article "how to realize the message push of Friends by thinkphp" (umeng_push). Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report