Comments (13)
Hi,
Can you provide code how do you use Client ?
from pushok.
Here's my whole code :
<?php
require ROOTPATH . 'vendor/autoload.php';
use Pushok\AuthProvider;
use Pushok\Client;
use Pushok\Notification;
use Pushok\Payload;
use Pushok\Payload\Alert;
class PushiOS {
private $key_id;
private $team_id;
private $app_bundle_id;
private $private_key_path;
private $private_key_secret;
private $authProvider;
public function __construct() {
// Load iOS options
$this->loadOptions();
// Init auth provider
$this->initAuthProvider();
}
private function loadOptions() {
$key_id = get_option('freenews_ios_key_id', array('text_string' => null));
$this->key_id = $key_id['text_string'];
$team_id = get_option('freenews_ios_team_id', array('text_string' => null));
$this->team_id = $team_id['text_string'];
$app_bundle_id = get_option('freenews_ios_app_bundle_id', array('text_string' => null));
$this->app_bundle_id = $app_bundle_id['text_string'];
$private_key_path = get_option('freenews_ios_private_key_path', array('text_string' => null));
$this->private_key_path = $private_key_path['text_string'];
$private_key_secret = get_option('freenews_ios_private_key_secret', array('text_string' => null));
$this->private_key_secret = $private_key_secret['text_string'];
}
private function initAuthProvider() {
$options = [
'key_id' => $this->key_id,
'team_id' => $this->team_id,
'app_bundle_id' => $this->app_bundle_id,
'private_key_path' => $this->private_key_path,
'private_key_secret' => $this->private_key_secret
];
$this->authProvider = AuthProvider\Token::create($options);
}
private function generatePayload($title, $body, $sound = 'default', $customValues = array()): Payload {
$alert = Alert::create()->setTitle($title);
$alert = $alert->setBody($body);
$payload = Payload::create()->setAlert($alert);
$payload = $payload->setSound($sound);
foreach ($customValues as $key => $value) {
$payload = $payload->setCustomValue($key, $value);
}
return $payload;
}
public function notify($devices, $data) {
$payload = $this->generatePayload($data['mtitle'], $data['mdesc']);
$notifications = [];
foreach ($devices as $device) {
$notifications[] = new Notification($payload, $device['token']);
}
$client = new Client($this->authProvider, $production = !WP_LOCAL_DEV);
$client->addNotifications($notifications);
$responses = $client->push();
foreach ($responses as $response) {
var_dump($response->getApnsId());
var_dump($response->getStatusCode());
var_dump($response->getReasonPhrase());
var_dump($response->getErrorReason());
var_dump($response->getErrorDescription());
}
}
}
?>
And I'm doing this when publishing a post :
$pushiOS = new PushiOS();
$pushiOS->notify($ios_devices, $data);
It's more or less your exemple in the readme.
from pushok.
I think it is the same bug as here #7.
Please read my answer
from pushok.
Indeed, it looks like my version of curl wasn't compatible with HTTP/2, now it seems good for that part, but it seems like I still need to find how to update openssl to v1.0.2 on Jessie.
from pushok.
All right, I managed to correctly install everything needed (I think).
Here's a curl request showing that it's working :
# curl --http2 -I https://nghttp2.org/
HTTP/2.0 200
date:Wed, 15 Feb 2017 21:15:53 GMT
content-type:text/html
last-modified:Wed, 25 Jan 2017 12:22:17 GMT
etag:"58889879-19e1"
accept-ranges:bytes
content-length:6625
x-backend-header-rtt:0.001475
strict-transport-security:max-age=31536000
server:nghttpx nghttp2/1.20.0-DEV
via:2 nghttpx
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
x-content-type-options:nosniff
I have OpenSSL 1.0.2k:
OpenSSL Header Version => OpenSSL 1.0.2j 26 Sep 2016```
But I still have the same error, but now with two more notices :
Notice: Use of undefined constant CURLPIPE_MULTIPLEX - assumed 'CURLPIPE_MULTIPLEX' in .../vendor/edamov/pushok/src/Client.php on line 62
Notice: Use of undefined constant CURL_HTTP_VERSION_2 - assumed 'CURL_HTTP_VERSION_2' in .../vendor/edamov/pushok/src/Request.php on line 67
Notice: Undefined offset: 1 in .../vendor/edamov/pushok/src/Client.php on line 95
Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given, called in .../vendor/edamov/pushok/src/Client.php on line 97 and defined in .../vendor/edamov/pushok/src/Response.php:136
from pushok.
@ThibaultVlacich What version of PHP do you have?
from pushok.
I've just find CURL_HTTP_VERSION_2
constant is available only from PHP 7.0.7
from pushok.
I have PHP 7.0.15
# php -v
PHP 7.0.15-1+0~20170120094752.20+jessie~1.gbpe03972 (cli) (built: Jan 20 2017 11:15:00) ( NTS )
from pushok.
It's the version of php-cli
. It can be different with php-fpm
version. Can you look in phpinfo();
?
from pushok.
Yep, I looked in phpinfo();
and it's the exact same version PHP Version 7.0.15-1+0~20170120094752.20+jessie~1.gbpe03972
.
Here's other interesting info I have in the phpinfo :
curl
cURL support enabled
cURL Information 7.46.0
HTTP2 Yes
SSL Version OpenSSL/1.0.2k
from pushok.
Hmm. I just have no idea. When I have time I'll try to investigate this issue.
CURL_HTTP_VERSION_2
is available since PHP 7.0.7 and cURL 7.43.0
CURLPIPE_MULTIPLEX
is available since PHP 7.0.0 and cURL 7.43.0
http://php.net/manual/en/curl.constants.php
from pushok.
It seems like PHP doesn't just need Curl 7.43+ to be available at runtime, but it needs to be compiled against Curl 7.43+ to be working.
https://bugs.php.net/bug.php?id=74050
from pushok.
I added this constants in library if they don't exist in php dist
from pushok.
Related Issues (20)
- Support PHP 8
- Uncaught Exception HOT 3
- Package spomky-labs/jose is abandoned, you should avoid using it. Use web-token/jwt-framework instead. HOT 1
- Deprecation notices with PHP 8.1 HOT 4
- Question: Push Notifications for PkPass Updates HOT 8
- send a notification on a chosen date HOT 1
- Updating a badge HOT 1
- Support for creating WeatherKit JWT tokens
- The `Alert` option is set in the code but there is no Alert on the phone
- Package fgrosse/phpasn1 is abandoned HOT 2
- Started getting InvalidArgumentException "Unable to load the key." HOT 4
- Live Activities Supported? HOT 3
- Laravel Vapor - HTTP/2 stream 15 was not closed cleanly before end of the underlying stream HOT 3
- 0.15.x is no longer compatible with PHP 8.0 HOT 4
- HTTP/2 stream was not closed cleanly: REFUSED STREAM HOT 9
- Sending `Alert` as `Background` due to `content-available` set HOT 1
- php 8.0 via command package not installed
- Random "Send failure: Broken pipe" error
- Need to add custome key/value to aps HOT 2
- curl error when pusing to apns HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pushok.