Php implements the "push" function for "multiple" terminal devices. PHP terminal push
How can I use php code to implement the push information function of ios and other devices?
Many terminal devices may need to receive push information, and execute a script to push messages multiple times.
Helpful suggestions for passing by. thank you.
Reply to discussion (solution)
Let's talk about the specifics. do you want to send ipad or cash?
What triggers? What content is pushed?
Let's talk about the specifics. do you want to send ipad or cash?
What triggers? What content is pushed?
I read this on the Internet.
Http://www.iteye.com/topic/1130630
It is similar to the push sent by Apple to mobile phones.
Since you have read related articles, why are you still asking?
Here, we can only give you some ideas. the specific code should be written by yourself.
The principle is to establish a connection (similar to a socket). The slave server sends bytes to the device. how can this problem be solved after the device receives the packets ?? Direct display, pop-up window, notification, flashing reminder, etc.
There are two methods
1. the server acts as the server, and various devices act as the client to establish persistent connections. the server sends messages based on the trigger conditions, which is a bit like a chat room.
2. reverse thinking: a variety of devices act as servers (not wrong, it is the server), log on to the server and write down its listening ip/port (login is not necessarily sent, the purpose is to submit the online status ), based on the trigger condition, the server also runs the client program to submit connection requests to all the logged-on devices. after the connection is successful, the server sends a connection request.
Since you have read related articles, why are you still asking?
Here, we can only give you some ideas. the specific code should be written by yourself.
The principle is to establish a connection (similar to a socket). The slave server sends bytes to the device. how can this problem be solved after the device receives the packets ?? Direct display, pop-up window, notification, flashing reminder, etc.
There are two methods
1. the server acts as the server, and various devices act as the client to establish persistent connections. the server sends messages based on the trigger conditions, which is a bit like a chat room.
2. reverse thinking: a variety of devices act as servers (not wrong, it is the server), log on to the server and write down its listening ip/port (login is not necessarily sent, the purpose is to submit the online status ), based on the trigger condition, the server also runs the client program to submit connection requests to all the logged-on devices. after the connection is successful, the server sends a connection request.
It cannot be implemented!
But thanks for your guidance, although it is useless to me.
$ Fp = stream_socket_client ("ssl: // gateway.sandbox.push.apple.com: 2195", $ err, $ errstr, 60,
STREAM_CLIENT_CONNECT, $ ctx );
The key is this. The app needs to register with the apple server to receive notifications. After registration, PHP sends a message to the apple server, and the apple server completes the push.
Instead of pushing PHP directly to the app.
$ Fp = stream_socket_client ("ssl: // gateway.sandbox.push.apple.com: 2195", $ err, $ errstr, 60,
STREAM_CLIENT_CONNECT, $ ctx );
The key is this. The app needs to register with the apple server to receive notifications. After registration, PHP sends a message to the apple server, and the apple server completes the push.
Instead of pushing PHP directly to the app.
This is the problem,
$ DeviceToken = '5a25d318035c3be9c2ca00572b81463c73c433aea6c710940d46db6a64f70125 '; // $ deviceToken = $ _ REQUEST ["token"]; // Push method, included content and sound $ body = array ("aps" => array ("alert" => 'push test', "badge" => 11, "sound" => 'default'); // creates a data stream Context Object $ ctx = stream_context_create (); // Set the pem format FILE // $ pem = dirname (_ FILE __). '/'. 'server _ certificates_bundle_sandbox.pem '; $ pem = "server_certificates_bundle_sandbox.pem"; // echo $ pem; // Set the local authentication certificate for the data stream context stream_context_set_option ($ ctx, "ssl", "local_cert", $ pem); $ pass = ""; // Set the data stream context password stream_context_set_option ($ ctx, 'SSL ', 'passphrase', $ pass); // APNS server for product release, region = stream_socket_client ("ssl: // gateway.push.apple.com: 2195 ", $ err, $ errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ ctx); if (! $ Fp) {echo "failed to connect to the Apple server. "; return;} print" connect to the Apple server OK \ n "; // load information, JSON encoded $ payload = json_encode ($ body ); // Construct the binary information sent $ msg = chr (0 ). pack ("n", 32 ). pack ("H *", str_replace (''," ", $ deviceToken )). pack ("n", strlen ($ payload )). $ payload; echo "send message :". $ payload. "\ n"; fwrite ($ fp, $ msg); fclose ($ fp );
When the browser is opened, it is displayed that the server cannot be connected to the Apple server...
That is to say, socket communication fails. I don't know what the situation is.
The browser accesses this: https://gateway.push.apple.com: 2195/
The ssl protocol is used in the program.
Do you have the devicetoken and certificate account and password?
Both the token and account password are available. this is sent to me on ios.
Have you implemented this push function? One item is pushed to multiple devices at the same time!
How did you do it?