php做ios推送的服务器,后台运行的时候会推送两条信息?有代码
php
为什么php做ios推送的服务器的时候,后台运行的时候会推送两条信息?但是手机关掉屏幕推送的时候就正常了~ 就只有后台运行的时候是两条?? 怎么改呢?
下面是代码
<code> /**手机推送信息类@author:wtt*/class Push{ private $deviceToken; private $message; function __construct($deviceToken,$message){ $this->deviceToken = $deviceToken; $this->message = $message; } public function push(){ //ck.pem通关密码 $pass = '123456'; //消息内容 //badge我也不知是什么 $badge = 1; //sound我也不知是什么(或许是推送消息到手机时的提示音) $sound = 'Duck.wav'; //建设的通知有效载荷(即通知包含的一些信息) $body = array(); $body['aps'] = array('alert' => $this->message); if ($badge) $body['aps']['badge'] = $badge; if ($sound) $body['aps']['sound'] = $sound; //把数组数据转换为json数据 $payload = json_encode($body); //echo strlen($payload),"\r\n"; //下边的写法就是死写法了,一般不需要修改, //唯一要修改的就是:ssl://gateway.sandbox.push.apple.com:2195这个是沙盒测试地址,ssl://gateway.push.apple.com:2195正式发布地址 $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $pass); $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); if (!$fp) { print "Failed to connect {$err} {$errstr}\n"; return; } else { // print "Connection OK\n<br>"; } // send message $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $this->deviceToken)) . pack("n",strlen($payload)) . $payload; //print "Sending message :" . $payload . "\n"; fwrite($fp, $msg); fclose($fp); }} </code>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
