-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle exception of decrypting unencrypted message
- Loading branch information
Showing
6 changed files
with
202 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
set_time_limit(0); | ||
|
||
require('../../vendor/autoload.php'); | ||
|
||
use PubNub\PubNub; | ||
use PubNub\PNConfiguration; | ||
use PubNub\CryptoModule; | ||
|
||
$pnUuid = 'pn-610da4553bb079.92567429'; //uniqid('pn-', true); | ||
|
||
$pnConfig = new PNConfiguration(); | ||
$pnConfig->setPublishKey(getenv('PN_KEY_PUBLISH')); | ||
$pnConfig->setSubscribeKey(getenv('PN_KEY_SUBSCRIBE')); | ||
// $pnConfig->setSecretKey('sec-c-YjZiZWQzZWItMmZlNS00NjBlLTkyNTUtOGFhZjZiY2E1ZDc1'); | ||
$pnConfig->setUuid($pnUuid); | ||
if (array_key_exists(2, $argv)) { | ||
$pnConfig->setCrypto(CryptoModule::aesCbcCryptor($argv[2], true)); | ||
} | ||
|
||
$pubnub = new PubNub($pnConfig); | ||
|
||
$ts = $pubnub->time()->sync(); | ||
|
||
$channelName = $argv[1]; | ||
$history = $pubnub->history() | ||
->channel($channelName) | ||
->reverse(false) | ||
->end((int)($ts->getTimetoken() - 3000000000)) | ||
->count(50) | ||
->sync(); | ||
|
||
foreach ($history->getMessages() as $key => $message) { | ||
print($message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
set_time_limit(0); | ||
|
||
require('../../vendor/autoload.php'); | ||
|
||
|
||
use PubNub\PubNub; | ||
use PubNub\PNConfiguration; | ||
use PubNub\CryptoModule; | ||
|
||
$pnUuid = $argv[1] . '-pn-610da4553bb079.92567429'; | ||
|
||
$pnConfig = new PNConfiguration(); | ||
$pnConfig->setPublishKey(getenv('PN_KEY_PUBLISH')); | ||
$pnConfig->setSubscribeKey(getenv('PN_KEY_SUBSCRIBE')); | ||
$pnConfig->setUuid($pnUuid); | ||
if (array_key_exists(4, $argv)) { | ||
$pnConfig->setCrypto(CryptoModule::aesCbcCryptor($argv[4], true)); | ||
} | ||
|
||
$pubnub = new PubNub($pnConfig); | ||
|
||
$pubResult = $pubnub->publish()->channel($argv[2])->message($argv[3])->sync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED); | ||
|
||
set_time_limit(0); | ||
|
||
require('../../vendor/autoload.php'); | ||
|
||
use PubNub\Callbacks\SubscribeCallback; | ||
use PubNub\Exceptions\PubNubException; | ||
use PubNub\Models\Consumer\PubSub\PNMessageResult; | ||
use PubNub\Models\Consumer\PubSub\PNPresenceEventResult; | ||
use PubNub\Models\ResponseHelpers\PNStatus; | ||
use PubNub\PubNub; | ||
use PubNub\PNConfiguration; | ||
use PubNub\CryptoModule; | ||
|
||
|
||
$pnUuid = 'pn-610da4553bb079.92567429'; | ||
|
||
$pnConfig = new PNConfiguration(); | ||
$pnConfig->setPublishKey(getenv('PN_KEY_PUBLISH')); | ||
$pnConfig->setSubscribeKey(getenv('PN_KEY_SUBSCRIBE')); | ||
if (array_key_exists(2, $argv)) { | ||
$pnConfig->setCrypto(CryptoModule::aesCbcCryptor($argv[2], true)); | ||
} | ||
$pnConfig->setUuid($pnUuid); | ||
|
||
$pubnub = new PubNub($pnConfig); | ||
|
||
$channelName = $argv[1]; | ||
|
||
// phpcs:ignore | ||
class MySubscribeCallback extends SubscribeCallback | ||
{ | ||
/** | ||
* @param PubNub $pubnub | ||
* @param PNStatus $status | ||
* @return void | ||
* @throws PubNubException | ||
*/ | ||
public function status($pubnub, $status) | ||
{ | ||
printf( | ||
"Category: %s\nPublisher user_id: %s", | ||
$status->getCategory(), | ||
$status->getUuid() | ||
); | ||
} | ||
|
||
/** | ||
* @param PubNub $pubnub | ||
* @param PNMessageResult $messageResult | ||
* @return void | ||
*/ | ||
public function message($pubnub, $messageResult) | ||
{ | ||
printf( | ||
"\nMessage %s\n Channel: %s\n Timetoken: %s\n Publisher: %s\n", | ||
$messageResult->getMessage(), | ||
$messageResult->getChannel(), | ||
$messageResult->getTimetoken(), | ||
$messageResult->getPublisher(), | ||
); | ||
if ($messageResult->isError()) { | ||
printf('\nError occured during parsing the message: %s', $messageResult->getError()->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* @param PubNub $pubnub | ||
* @param PNPresenceEventResult $presence | ||
* @return void | ||
*/ | ||
public function presence($pubnub, $presence) | ||
{ | ||
print("{$presence->getEvent()}: {$presence->getUuid()}"); | ||
} | ||
|
||
/** | ||
* @param PubNub $pubnub | ||
* @param PNSignalMessageResult $signal | ||
* @return void | ||
*/ | ||
public function signal($pubnub, $signal) | ||
{ | ||
} | ||
} | ||
|
||
$subscribeCallback = new MySubscribeCallback(); | ||
|
||
$pubnub->addListener($subscribeCallback); | ||
|
||
echo "subscribing to: $channelName\n"; | ||
|
||
$subResult = $pubnub->subscribe() | ||
->channels($channelName) | ||
->withTimetoken(true) | ||
->withPresence(true) | ||
->execute(); | ||
|
||
echo "done.\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters