How can I use php code to implement the push information function of multiple devices such as ios? How can I use the & nbsp; php code to implement the push information functions of devices such as & nbsp; ios & nbsp? A maximum of terminal devices may need to receive the push information and execute the push information once, so that multiple devices can receive the information. Some useful suggestions for passing by. thank you !!! How can I use php code to implement the push information function of multiple devices such as ios?
How can I use php code to implement the push information function of ios and other devices?
A maximum of terminal devices may need to receive the push information and execute the push information once, so that multiple devices can receive the information.
Some useful suggestions for passing by. thank you !!!
Php ios terminal
Share:
------ Solution --------------------
This cannot be implemented using php.
We certainly do not recommend that you use persistent connections until a message is returned to the user. in this case, the server is under great pressure.
We recommend that you use the client browser to obtain the latest message from the server.
In addition, if you are not using php, such as python, nodejs, and c ++, you can use long polling.
------ Solution --------------------
This is not what php can do!
Php is a server-side script, not a server, not a network operating system.
You just need to apply the mobile communication operating system to achieve your goal.
------ Solution --------------------
You need the source code to go to the mobile version-> iphone, just a friend of the altar posted a post you need
I can also tell you how to do it. In fact, it is very simple. it is mainly to use the Apple development account to generate a certificate.
Step 1
-------
First, you have to use php to open an interface on the server and provide it to the iphone to register device_token. that is, the mobile phone with your application will make an http request to this interface, submit the device_token and some parameters of each machine. then, you can use php to receive the device_token and save it to the database.
Step 2
-----------
Read data using php, read the registered device_token from the database, splice it into a string in the specified format, carry the generated Apple certificate, and make a socket request to the push service api provided by Apple
Key code 1:
Stream_context_set_option ($ ctx, 'SSL ', 'local _ cert', $ pemFile); // $ pemFile is the certificate file. you can search for the generation process on your own, you must have an apple development account
$ Ctx = stream_context_create ();
Stream_context_set_option ($ ctx, 'SSL ', 'passphrase', $ passphrase );
// Open a connection to the APNS server, push service api, the following is the sandbox environment
$ Fp = stream_socket_client ('SSL: // gateway.sandbox.push.apple.com: 8080', $ err, $ errstr, 60, STREAM_CLIENT_CONNECT
------ Solution --------------------
STREAM_CLIENT_PERSISTENT, $ ctx );
Guan Jian code 2:
// Create the payload body
$body['aps'] = array(
'alert' => array(
'body' => $message,
//'action-loc-key' => 'Bango App',
),
'badge' => $badge,
'sound' => 'oven.caf',
);
$deviceTokens = array();
$payload = FMFactory::GetJson()->encode($body);