当前位置: 首页>>代码示例>>PHP>>正文


PHP ExtractNumber函数代码示例

本文整理汇总了PHP中ExtractNumber函数的典型用法代码示例。如果您正苦于以下问题:PHP ExtractNumber函数的具体用法?PHP ExtractNumber怎么用?PHP ExtractNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ExtractNumber函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendMessageNode

 /**
  * Send node to the servers.
  *
  * @param              $to
  * @param ProtocolNode $node
  * @param null         $id
  *
  * @return string            Message ID.
  */
 protected function sendMessageNode($to, $node, $id = null)
 {
     $msgId = $id == null ? $this->createMsgId() : $id;
     $to = $this->getJID($to);
     if ($node->getTag() == "body" || $node->getTag() == "enc") {
         $type = 'text';
     } else {
         $type = 'media';
     }
     $messageNode = new ProtocolNode("message", array('to' => $to, 'type' => $type, 'id' => $msgId, 't' => time(), 'notify' => $this->name), array($node), "");
     $this->sendNode($messageNode);
     $this->logFile('info', '{type} message with id {id} sent to {to}', array('type' => $type, 'id' => $msgId, 'to' => ExtractNumber($to)));
     $this->eventManager()->fire("onSendMessage", array($this->phoneNumber, $to, $msgId, $node));
     $this->waitForServer($msgId);
     return $msgId;
 }
开发者ID:Nanod10,项目名称:Chat-API,代码行数:25,代码来源:whatsprot.class.php

示例2: processInboundDataNode

 /**
  * Will process the data from the server after it's been decrypted and parsed.
  *
  * This also provides a convenient method to use to unit test the event framework.
  * @param ProtocolNode $node
  * @param bool         $autoReceipt
  * @param              $type
  *
  * @throws Exception
  */
 protected function processInboundDataNode(ProtocolNode $node, $autoReceipt = true, $type = "read")
 {
     $this->debugPrint($node->nodeString("rx  ") . "\n");
     $this->serverReceivedId = $node->getAttribute('id');
     if ($node->getTag() == "challenge") {
         $this->processChallenge($node);
     } elseif ($node->getTag() == "failure") {
         $this->loginStatus = Constants::DISCONNECTED_STATUS;
         $this->eventManager()->fire("onLoginFailed", array($this->phoneNumber, $node->getChild(0)->getTag()));
     } elseif ($node->getTag() == "success") {
         if ($node->getAttribute("status") == "active") {
             $this->loginStatus = Constants::CONNECTED_STATUS;
             $challengeData = $node->getData();
             file_put_contents($this->challengeFilename, $challengeData);
             $this->writer->setKey($this->outputKey);
             $this->eventManager()->fire("onLoginSuccess", array($this->phoneNumber, $node->getAttribute("kind"), $node->getAttribute("status"), $node->getAttribute("creation"), $node->getAttribute("expiration")));
         } elseif ($node->getAttribute("status") == "expired") {
             $this->eventManager()->fire("onAccountExpired", array($this->phoneNumber, $node->getAttribute("kind"), $node->getAttribute("status"), $node->getAttribute("creation"), $node->getAttribute("expiration")));
         }
     } elseif ($node->getTag() == 'ack' && $node->getAttribute("class") == "message") {
         $this->eventManager()->fire("onMessageReceivedServer", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('class'), $node->getAttribute('t')));
     } elseif ($node->getTag() == 'receipt') {
         if ($node->hasChild("list")) {
             foreach ($node->getChild("list")->getChildren() as $child) {
                 $this->eventManager()->fire("onMessageReceivedClient", array($this->phoneNumber, $node->getAttribute('from'), $child->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('participant')));
             }
         }
         $this->eventManager()->fire("onMessageReceivedClient", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('participant')));
         $this->sendAck($node, 'receipt');
     }
     if ($node->getTag() == "message") {
         array_push($this->messageQueue, $node);
         if ($node->hasChild('x') && $this->lastId == $node->getAttribute('id')) {
             $this->sendNextMessage();
         }
         if ($this->newMsgBind && ($node->getChild('body') || $node->getChild('media'))) {
             $this->newMsgBind->process($node);
         }
         if ($node->getAttribute("type") == "text" && $node->getChild('body') != null) {
             $author = $node->getAttribute("participant");
             if ($autoReceipt) {
                 $this->sendReceipt($node, $type, $author);
             }
             if ($author == "") {
                 //private chat message
                 $this->eventManager()->fire("onGetMessage", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute("notify"), $node->getChild("body")->getData()));
                 if ($this->messageStore !== null) {
                     $this->messageStore->saveMessage(ExtractNumber($node->getAttribute('from')), $this->phoneNumber, $node->getChild("body")->getData(), $node->getAttribute('id'), $node->getAttribute('t'));
                 }
             } else {
                 //group chat message
                 $this->eventManager()->fire("onGetGroupMessage", array($this->phoneNumber, $node->getAttribute('from'), $author, $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute("notify"), $node->getChild("body")->getData()));
                 if ($this->messageStore !== null) {
                     $this->messageStore->saveMessage($author, $node->getAttribute('from'), $node->getChild("body")->getData(), $node->getAttribute('id'), $node->getAttribute('t'));
                 }
             }
         }
         if ($node->getAttribute("type") == "text" && $node->getChild(0)->getTag() == 'enc') {
             // TODO
             if ($autoReceipt) {
                 $this->sendReceipt($node, $type);
             }
         }
         if ($node->getAttribute("type") == "media" && $node->getChild('media') != null) {
             if ($node->getChild("media")->getAttribute('type') == 'image') {
                 if ($node->getAttribute("participant") == null) {
                     $this->eventManager()->fire("onGetImage", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild("media")->getAttribute('size'), $node->getChild("media")->getAttribute('url'), $node->getChild("media")->getAttribute('file'), $node->getChild("media")->getAttribute('mimetype'), $node->getChild("media")->getAttribute('filehash'), $node->getChild("media")->getAttribute('width'), $node->getChild("media")->getAttribute('height'), $node->getChild("media")->getData(), $node->getChild("media")->getAttribute('caption')));
                 } else {
                     $this->eventManager()->fire("onGetGroupImage", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('participant'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild("media")->getAttribute('size'), $node->getChild("media")->getAttribute('url'), $node->getChild("media")->getAttribute('file'), $node->getChild("media")->getAttribute('mimetype'), $node->getChild("media")->getAttribute('filehash'), $node->getChild("media")->getAttribute('width'), $node->getChild("media")->getAttribute('height'), $node->getChild("media")->getData(), $node->getChild("media")->getAttribute('caption')));
                 }
             } elseif ($node->getChild("media")->getAttribute('type') == 'video') {
                 if ($node->getAttribute("participant") == null) {
                     $this->eventManager()->fire("onGetVideo", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild("media")->getAttribute('url'), $node->getChild("media")->getAttribute('file'), $node->getChild("media")->getAttribute('size'), $node->getChild("media")->getAttribute('mimetype'), $node->getChild("media")->getAttribute('filehash'), $node->getChild("media")->getAttribute('duration'), $node->getChild("media")->getAttribute('vcodec'), $node->getChild("media")->getAttribute('acodec'), $node->getChild("media")->getData(), $node->getChild("media")->getAttribute('caption'), $node->getChild("media")->getAttribute('width'), $node->getChild("media")->getAttribute('height'), $node->getChild("media")->getAttribute('fps'), $node->getChild("media")->getAttribute('vbitrate'), $node->getChild("media")->getAttribute('asampfreq'), $node->getChild("media")->getAttribute('asampfmt'), $node->getChild("media")->getAttribute('abitrate')));
                 } else {
                     $this->eventManager()->fire("onGetGroupVideo", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('participant'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild("media")->getAttribute('url'), $node->getChild("media")->getAttribute('file'), $node->getChild("media")->getAttribute('size'), $node->getChild("media")->getAttribute('mimetype'), $node->getChild("media")->getAttribute('filehash'), $node->getChild("media")->getAttribute('duration'), $node->getChild("media")->getAttribute('vcodec'), $node->getChild("media")->getAttribute('acodec'), $node->getChild("media")->getData(), $node->getChild("media")->getAttribute('caption'), $node->getChild("media")->getAttribute('width'), $node->getChild("media")->getAttribute('height'), $node->getChild("media")->getAttribute('fps'), $node->getChild("media")->getAttribute('vbitrate'), $node->getChild("media")->getAttribute('asampfreq'), $node->getChild("media")->getAttribute('asampfmt'), $node->getChild("media")->getAttribute('abitrate')));
                 }
             } elseif ($node->getChild("media")->getAttribute('type') == 'audio') {
                 $author = $node->getAttribute("participant");
                 $this->eventManager()->fire("onGetAudio", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild("media")->getAttribute('size'), $node->getChild("media")->getAttribute('url'), $node->getChild("media")->getAttribute('file'), $node->getChild("media")->getAttribute('mimetype'), $node->getChild("media")->getAttribute('filehash'), $node->getChild("media")->getAttribute('seconds'), $node->getChild("media")->getAttribute('acodec'), $author));
             } elseif ($node->getChild("media")->getAttribute('type') == 'vcard') {
                 if ($node->getChild("media")->hasChild('vcard')) {
                     $name = $node->getChild("media")->getChild("vcard")->getAttribute('name');
                     $data = $node->getChild("media")->getChild("vcard")->getData();
                 } else {
                     $name = "NO_NAME";
                     $data = $node->getChild("media")->getData();
                 }
                 $author = $node->getAttribute("participant");
                 $this->eventManager()->fire("onGetvCard", array($this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $name, $data, $author));
             } elseif ($node->getChild("media")->getAttribute('type') == 'location') {
//.........这里部分代码省略.........
开发者ID:rezanadimi72,项目名称:Chat-API,代码行数:101,代码来源:whatsprot.class.php

示例3: unsetPendingNode

 public function unsetPendingNode($jid)
 {
     unset($this->pending_nodes[ExtractNumber($jid)]);
 }
开发者ID:Veivan,项目名称:WABuh,代码行数:4,代码来源:whatsprot.class.php

示例4: process

 public function process($node)
 {
     if ($node->getAttribute("type") == 'text') {
         $text = $node->getChild('body');
         $text = $text->getData();
         $number = ExtractNumber($node->getAttribute("from"));
         $nickname = $number;
         echo "\n- " . $nickname . ": " . $text . "    " . date('H:i') . "\n";
     }
 }
开发者ID:jeromez80,项目名称:dutyPhone,代码行数:10,代码来源:pollMessage.php

示例5: decryptMessage

 public function decryptMessage($from, $ciphertext, $type, $id, $t, $retry_from = null, $skip_unpad = false)
 {
     $version = '1';
     $this->parent->debugPrint("\n-> Decrypted Message: ");
     if ($type == 'pkmsg') {
         if (in_array(ExtractNumber($from), $this->parent->getv2Jids())) {
             $version = '2';
         }
         try {
             $preKeyWhisperMessage = new PreKeyWhisperMessage(null, null, null, null, null, null, null, $ciphertext);
             $sessionCipher = $this->parent->getSessionCipher(ExtractNumber($from));
             $plaintext = $sessionCipher->decryptPkmsg($preKeyWhisperMessage);
             if ($version == '2' && !$skip_unpad) {
                 $plaintext = unpadV2Plaintext($plaintext);
             }
             $this->parent->debugPrint(parseText($plaintext) . "\n\n");
             return $plaintext;
         } catch (Exception $e) {
             if ($e instanceof UntrustedIdentityException) {
                 $this->parent->getAxolotlStore()->clearRecipient(ExtractNumber($from));
             }
             $this->parent->debugPrint($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine());
             // if ($e->getMessage() != "Null values!"){
             $this->parent->debugPrint("Message {$id} could not be decrypted, sending retry.\n\n");
             $participant = null;
             if ($retry_from != null) {
                 if (strpos($retry_from, '-') !== false) {
                     $participant = $from;
                 }
                 $from = $retry_from;
             }
             //$this->sendRetry($from, $id, $t, $participant);
             return false;
             //}
         }
     } elseif ($type == 'msg') {
         if (in_array(ExtractNumber($from), $this->parent->getv2Jids())) {
             $version = '2';
         }
         try {
             $whisperMessage = new WhisperMessage(null, null, null, null, null, null, null, null, $ciphertext);
             $sessionCipher = $this->parent->getSessionCipher(ExtractNumber($from));
             $plaintext = $sessionCipher->decryptMsg($whisperMessage);
             if ($version == '2' && !$skip_unpad) {
                 $plaintext = unpadV2Plaintext($plaintext);
             }
             $this->parent->debugPrint(parseText($plaintext) . "\n\n");
             return $plaintext;
         } catch (Exception $e) {
             $this->parent->debugPrint($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine());
             $this->parent->debugPrint("Message {$id} could not be decrypted, sending retry.\n\n");
             if ($retry_from != null) {
                 $from = $retry_from;
             }
             //$this->sendRetry($from, $id, $t);
             return false;
         }
     } elseif ($type == 'skmsg') {
         if (in_array($from[1], $this->parent->v2Jids)) {
             $version = '2';
         }
         try {
             $groupCipher = $this->parent->getGroupCipher(ExtractNumber($from[0]) . ':' . $from[1]);
             $plaintext = $groupCipher->decrypt($ciphertext);
             if ($version == '2' && !$skip_unpad) {
                 $plaintext = unpadV2Plaintext($plaintext);
             }
             $this->parent->debugPrint("Message {$id} decrypted to " . parseText($plaintext) . "\n\n");
             return $plaintext;
         } catch (Exception $e) {
             $this->parent->debugPrint($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine());
             if ($retry_from != null) {
                 $from = $retry_from;
             }
             $this->parent->sendRetry($this->node, $this->parent->getJID($from[0]), $id, $t);
             return false;
         }
     }
 }
开发者ID:piersoft,项目名称:Chat-API,代码行数:79,代码来源:MessageHandler.php

示例6: Process


//.........这里部分代码省略.........
         }
         if (isset($this->parent->getNodeId()['leavegroup']) && $this->parent->getNodeId()['leavegroup'] == $this->node->getAttribute('id')) {
             $this->parent->setGroupId($this->node->getChild(0)->getChild(0)->getAttribute('id'));
             $this->parent->eventManager()->fire("onGroupsChatEnd", array($this->phoneNumber, $this->node->getChild(0)->getChild(0)->getAttribute('id')));
         }
         if (isset($this->parent->getNodeId()['getgroups']) && $this->parent->getNodeId()['getgroups'] == $this->node->getAttribute('id')) {
             $this->parent->eventManager()->fire("onGetGroups", array($this->phoneNumber, $groupList));
             //getGroups returns a array of nodes which are exactly the same as from getGroupV2Info
             //so lets call this event, we have all data at hand, no need to call getGroupV2Info for every
             //group we are interested
             foreach ($groupNodes as $groupNode) {
                 $this->handleGroupV2InfoResponse($groupNode, true);
             }
         }
         if (isset($this->parent->getNodeId()['get_groupv2_info']) && $this->parent->getNodeId()['get_groupv2_info'] == $this->node->getAttribute('id')) {
             $groupChild = $this->node->getChild(0);
             if ($groupChild != null) {
                 $this->handleGroupV2InfoResponse($groupChild);
             }
         }
     }
     if (isset($this->parent->getNodeId()['get_lists']) && $this->parent->getNodeId()['get_lists'] == $this->node->getAttribute('id')) {
         $broadcastLists = array();
         if ($this->node->getChild(0) != null) {
             $childArray = $this->node->getChildren();
             foreach ($childArray as $list) {
                 if ($list->getChildren() != null) {
                     foreach ($list->getChildren() as $sublist) {
                         $id = $sublist->getAttribute("id");
                         $name = $sublist->getAttribute("name");
                         $broadcastLists[$id]['name'] = $name;
                         $recipients = array();
                         foreach ($sublist->getChildren() as $recipient) {
                             array_push($recipients, $recipient->getAttribute('jid'));
                         }
                         $broadcastLists[$id]['recipients'] = $recipients;
                     }
                 }
             }
         }
         $this->parent->eventManager()->fire("onGetBroadcastLists", array($this->phoneNumber, $broadcastLists));
     }
     if ($this->node->getChild("pricing") != null) {
         $this->parent->eventManager()->fire("onGetServicePricing", array($this->phoneNumber, $this->node->getChild(0)->getAttribute("price"), $this->node->getChild(0)->getAttribute("cost"), $this->node->getChild(0)->getAttribute("currency"), $this->node->getChild(0)->getAttribute("expiration")));
     }
     if ($this->node->getChild("extend") != null) {
         $this->parent->eventManager()->fire("onGetExtendAccount", array($this->phoneNumber, $this->node->getChild("account")->getAttribute("kind"), $this->node->getChild("account")->getAttribute("status"), $this->node->getChild("account")->getAttribute("creation"), $this->node->getChild("account")->getAttribute("expiration")));
     }
     if ($this->node->getChild("normalize") != null) {
         $this->parent->eventManager()->fire("onGetNormalizedJid", array($this->phoneNumber, $this->node->getChild(0)->getAttribute("result")));
     }
     if ($this->node->getChild("status") != null) {
         $child = $this->node->getChild("status");
         $childs = $child->getChildren();
         if (isset($childs) && !is_null($childs)) {
             foreach ($childs as $status) {
                 $this->parent->eventManager()->fire("onGetStatus", array($this->phoneNumber, $status->getAttribute("jid"), "requested", $this->node->getAttribute("id"), $status->getAttribute("t"), $status->getData()));
             }
         }
     }
     if ($this->node->getAttribute('type') == "error" && $this->node->getChild("error") != null) {
         $errorType = null;
         $this->parent->logFile('error', 'Iq error with {id} id', array('id' => $this->node->getAttribute('id')));
         foreach ($this->parent->getNodeId() as $type => $nodeID) {
             if ($nodeID == $this->node->getAttribute('id')) {
                 $errorType = $type;
                 break;
             }
         }
         $nodeIds = $this->parent->getNodeId();
         if (isset($nodeIds['sendcipherKeys']) && isset($nodeIds['sendcipherKeys']) == $this->node->getAttribute('id') && $this->node->getChild("error")->getAttribute('code') == "406") {
             $this->parent->sendSetPreKeys();
         }
         $this->parent->eventManager()->fire("onGetError", array($this->phoneNumber, $this->node->getAttribute('from'), $this->node->getAttribute('id'), $this->node->getChild(0), $errorType));
     }
     if (isset($this->parent->getNodeId()['cipherKeys']) && $this->parent->getNodeId()['cipherKeys'] == $this->node->getAttribute('id')) {
         $users = $this->node->getChild(0)->getChildren();
         foreach ($users as $user) {
             $jid = $user->getAttribute("jid");
             $registrationId = deAdjustId($user->getChild('registration')->getData());
             $identityKey = new IdentityKey(new DjbECPublicKey($user->getChild('identity')->getData()));
             $signedPreKeyId = deAdjustId($user->getChild('skey')->getChild('id')->getData());
             $signedPreKeyPub = new DjbECPublicKey($user->getChild('skey')->getChild('value')->getData());
             $signedPreKeySig = $user->getChild('skey')->getChild('signature')->getData();
             $preKeyId = deAdjustId($user->getChild('key')->getChild('id')->getData());
             $preKeyPublic = new DjbECPublicKey($user->getChild('key')->getChild('value')->getData());
             $preKeyBundle = new PreKeyBundle($registrationId, 1, $preKeyId, $preKeyPublic, $signedPreKeyId, $signedPreKeyPub, $signedPreKeySig, $identityKey);
             $sessionBuilder = new SessionBuilder($this->parent->getAxolotlStore(), $this->parent->getAxolotlStore(), $this->parent->getAxolotlStore(), $this->parent->getAxolotlStore(), ExtractNumber($jid), 1);
             $sessionBuilder->processPreKeyBundle($preKeyBundle);
             if (isset($this->parent->getPendingNodes()[ExtractNumber($jid)])) {
                 foreach ($this->parent->getPendingNodes()[ExtractNumber($jid)] as $pendingNode) {
                     $msgHandler = new MessageHandler($this->parent, $pendingNode);
                     $msgHandler->Process();
                 }
                 unset($this->parent->getPendingNodes()[ExtractNumber($jid)]);
             }
             $this->parent->sendPendingMessages($jid);
         }
     }
 }
开发者ID:prabhjotSL,项目名称:Chat-API,代码行数:101,代码来源:IqHandler.php

示例7: process

 public function process($node)
 {
     if ($node->getAttribute('type') == 'text') {
         $text = $node->getChild('body');
         $text = $text->getData();
         $number = ExtractNumber($node->getAttribute('from'));
         $nickname = findNicknameByPhone($number);
         echo "\n- " . $nickname . ': ' . $text . '    ' . date('H:i') . "\n";
     }
 }
开发者ID:MattPorto,项目名称:Chat-API,代码行数:10,代码来源:client.php

示例8: decryptMessage

 function decryptMessage($from, $ciphertext, $type, $id, $t, $retry_from = null, $skip_unpad = false)
 {
     $version = "1";
     $this->parent->debugPrint("\n-> Decrypted Message: ");
     if ($type == "pkmsg") {
         if (in_array(ExtractNumber($from), $this->parent->getv2Jids())) {
             $version = "2";
         }
         try {
             $preKeyWhisperMessage = new PreKeyWhisperMessage(null, null, null, null, null, null, null, $ciphertext);
             $sessionCipher = $this->parent->getSessionCipher(ExtractNumber($from));
             $plaintext = $sessionCipher->decryptPkmsg($preKeyWhisperMessage);
             if ($version == "2" && !$skip_unpad) {
                 $plaintext = unpadV2Plaintext($plaintext);
             }
             $this->parent->debugPrint(parseText($plaintext) . "\n\n");
             return $plaintext;
         } catch (Exception $e) {
             $this->parent->debugPrint($e->getMessage() . " - " . $e->getFile() . " - " . $e->getLine());
             if ($e->getMessage() != "Null values!") {
                 $this->parent->debugPrint("Message {$id} could not be decrypted, sending retry.\n\n");
                 $participant = null;
                 if ($retry_from != null) {
                     if (strpos($retry_from, "-") !== false) {
                         $participant = $from;
                     }
                     $from = $retry_from;
                 }
                 //$this->sendRetry($from, $id, $t, $participant);
                 return false;
             }
         }
     } else {
         if ($type == "msg") {
             if (in_array(ExtractNumber($from), $this->parent->getv2Jids())) {
                 $version = "2";
             }
             try {
                 $whisperMessage = new WhisperMessage(null, null, null, null, null, null, null, null, $ciphertext);
                 $sessionCipher = $this->parent->getSessionCipher(ExtractNumber($from));
                 $plaintext = $sessionCipher->decryptMsg($whisperMessage);
                 if ($version == "2" && !$skip_unpad) {
                     $plaintext = unpadV2Plaintext($plaintext);
                 }
                 $this->parent->debugPrint(parseText($plaintext) . "\n\n");
                 return $plaintext;
             } catch (Exception $e) {
                 $this->parent->debugPrint($e->getMessage() . " - " . $e->getFile() . " - " . $e->getLine());
                 $this->parent->debugPrint("Message {$id} could not be decrypted, sending retry.\n\n");
                 if ($retry_from != null) {
                     $from = $retry_from;
                 }
                 //$this->sendRetry($from, $id, $t);
                 return false;
             }
         } else {
             if ($type == "skmsg") {
                 if (in_array($from[1], $this->v2Jids)) {
                     $version = "2";
                 }
                 try {
                     $groupCipher = $this->parent->getGroupCipher(ExtractNumber($from[0]) . ":" . $from[1]);
                     $plaintext = $groupCipher->decrypt($ciphertext);
                     if ($version == "2" && !$skip_unpad) {
                         $plaintext = unpadV2Plaintext($plaintext);
                     }
                     $this->parent->debugPrint("Message {$id} decrypted to " . parseText($plaintext) . "\n\n");
                     return $plaintext;
                 } catch (Exception $e) {
                     $this->parent->debugPrint($e->getMessage() . " - " . $e->getFile() . " - " . $e->getLine());
                     if ($retry_from != null) {
                         $from = $retry_from;
                     }
                     $this->parent->sendRetry($this->parent->getJID($from[0]), $id, $t);
                     return false;
                 }
             }
         }
     }
 }
开发者ID:RhuanGonzaga,项目名称:WhatsBot,代码行数:80,代码来源:MessageHandler.php

示例9: onGetAudio

 public function onGetAudio($mynumber, $from, $id, $type, $time, $name, $size, $url, $file, $mimeType, $fileHash, $duration, $acodec, $fromJID_ifGroup = null)
 {
     $number = ExtractNumber($from);
     $nickname = $number;
     $path = "data/media/{$nickname}/";
     if (!file_exists($path)) {
         mkdir($path);
     }
     $filename = __DIR__ . DIRECTORY_SEPARATOR . $path . time() . ".jpg";
     $data = file_get_contents($url);
     $fp = @fopen($filename, "w");
     if ($fp) {
         fwrite($fp, $data);
         fclose($fp);
     }
     echo " < Received audio from {$nickname} >\n";
 }
开发者ID:jeromez80,项目名称:dutyPhone,代码行数:17,代码来源:MyEvents.php

示例10: handleMessageReceived

 static function handleMessageReceived($mynumber, $from, $id, $type, $time, $name, $body)
 {
     $number = ExtractNumber($from);
     $contact = getUserInfo($number);
     if (!$contact) {
         addContact($number, $name);
         $contact = getUserInfo($number);
         $main_menu = GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, GenieConstants::$REGISTRATION_MENU_CONTEXT, 'subMenu');
         setMessageContext($main_menu, NULL, $contact['phone']);
     }
     //Handle ShortCut in request
     $requestArray = $data = preg_split('/\\s+/', $body);
     if ($requestArray[0][0] == '#') {
         self::handleShortCuts($contact, $requestArray);
         return;
     }
     $context = getMessageContext($number);
     $callBackFunction = 'initializeService';
     if ($context['main_menu'] == -1) {
         self::handleGeneralConversation($body, $context, $contact);
         return;
     }
     if ($context['main_menu'] == 0) {
         if (GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT, $body, 'id') != NULL) {
             updateMessageContext($body, NULL, $contact['phone']);
             PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$body]->menuItem, $callBackFunction, $contact);
         } else {
             MessaggingController::sendMessage($contact, GenieConstants::$INVALID_SERVICE);
             MessaggingController::sendMessage($contact, GenieConstants::$MAIN_MENU_STRING);
         }
         return;
     }
     if ($context['main_menu'] != 0 && $context['main_menu'] != 8 && $context['sub_menu'] == NULL) {
         $subMenuKey = GenieConstants::searchElement(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu, $body, 'id');
         $SubMenuDict = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu;
         if ($subMenuKey != NULL) {
             updateMessageContext($context['main_menu'], $body, $contact['phone']);
             $callBackFunction = $SubMenuDict[$subMenuKey]->callBackMethod;
             PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->menuItem, $callBackFunction, $contact);
         } else {
             MessaggingController::sendMessage($contact, GenieConstants::$INVALID_SERVICE);
             PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->menuItem, $callBackFunction, $contact);
         }
         return;
     } else {
         if ($context['main_menu'] != 0 && $context['main_menu'] != 8 && $context['sub_menu'] != NULL) {
             $SubMenuDict = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu;
             $callBackFunction = $SubMenuDict[$context['sub_menu']]->requestServer;
             PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->menuItem, $callBackFunction, $contact, $body);
             return;
         } else {
             if ($context['sub_menu'] != NULL) {
                 $callBackFunction = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->subMenu[$context['sub_menu']]->callBackMethod;
             } else {
                 if (GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->callBackMethod != NULL) {
                     $callBackFunction = GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->callBackMethod;
                 }
             }
         }
     }
     PubSub::publish(GenieConstants::$MAIN_MENU_CONTEXT[$context['main_menu']]->menuItem, $callBackFunction, $contact, $body);
 }
开发者ID:neerav-mehta,项目名称:yboocs,代码行数:62,代码来源:ServiceController.php

示例11: processInboundDataNode

 /**
  * Will process the data from the server after it's been decrypted and parsed.
  *
  * This also provides a convenient method to use to unit test the event framework.
  * @param ProtocolNode $node
  * @param bool $autoReceipt
  * @param $type
  *
  * @throws \Exception
  */
 protected function processInboundDataNode(ProtocolNode $node, $autoReceipt = true, $type = 'read')
 {
     $this->debugPrint($node->nodeString('rx  ') . "\n");
     $this->serverReceivedId = $node->getAttribute('id');
     if ($node->getTag() == 'challenge') {
         $this->processChallenge($node);
     } elseif ($node->getTag() == 'failure') {
         $this->loginStatus = DISCONNECTED_STATUS;
         $this->eventsManager()->fire('onLoginFailed', [$this->phoneNumber, $node->getChild(0)->getTag()]);
     } elseif ($node->getTag() == 'success') {
         if ($node->getAttribute('status') == 'active') {
             $this->loginStatus = CONNECTED_STATUS;
             $challengeData = $node->getData();
             file_put_contents($this->challengeFilename, $challengeData);
             $this->writer->setKey($this->outputKey);
             $this->eventsManager()->fire('onLoginSuccess', [$this->phoneNumber, $node->getAttribute('kind'), $node->getAttribute('status'), $node->getAttribute('creation'), $node->getAttribute('expiration')]);
         } elseif ($node->getAttribute('status') == 'expired') {
             $this->eventsManager()->fire('onAccountExpired', [$this->phoneNumber, $node->getAttribute('kind'), $node->getAttribute('status'), $node->getAttribute('creation'), $node->getAttribute('expiration')]);
         }
     } elseif ($node->getTag() == 'ack' && $node->getAttribute('class') == 'message') {
         $this->eventsManager()->fire('onMessageReceivedServer', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('class'), $node->getAttribute('t')]);
     } elseif ($node->getTag() == 'receipt') {
         if ($node->hasChild('list')) {
             foreach ($node->getChild('list')->getChildren() as $child) {
                 $this->eventsManager()->fire('onMessageReceivedClient', [$this->phoneNumber, $node->getAttribute('from'), $child->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('participant')]);
             }
         }
         $this->eventsManager()->fire('onMessageReceivedClient', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('participant')]);
         $this->sendAck($node, 'receipt');
     }
     if ($node->getTag() == 'message') {
         array_push($this->messageQueue, $node);
         if ($node->hasChild('x') && $this->lastId == $node->getAttribute('id')) {
             $this->sendNextMessage();
         }
         if ($this->newMsgBind && ($node->getChild('body') || $node->getChild('media'))) {
             $this->newMsgBind->process($node);
         }
         if ($node->getAttribute('type') == 'text' && $node->getChild('body') != null) {
             $author = $node->getAttribute('participant');
             if ($autoReceipt) {
                 $this->sendReceipt($node, $type, $author);
             }
             if ($author == '') {
                 //private chat message
                 $this->eventsManager()->fire('onGetMessage', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild('body')->getData()]);
                 if ($this->messageStore !== null) {
                     $this->messageStore->saveMessage(ExtractNumber($node->getAttribute('from')), $this->phoneNumber, $node->getChild('body')->getData(), $node->getAttribute('id'), $node->getAttribute('t'));
                 }
             } else {
                 //group chat message
                 $this->eventsManager()->fire('onGetGroupMessage', [$this->phoneNumber, $node->getAttribute('from'), $author, $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild('body')->getData()]);
                 if ($this->messageStore !== null) {
                     $this->messageStore->saveMessage($author, $node->getAttribute('from'), $node->getChild('body')->getData(), $node->getAttribute('id'), $node->getAttribute('t'));
                 }
             }
         }
         if ($node->getAttribute('type') == 'text' && $node->getChild(0)->getTag() == 'enc') {
             // TODO
             if ($autoReceipt) {
                 $this->sendReceipt($node, $type);
             }
         }
         if ($node->getAttribute('type') == 'media' && $node->getChild('media') != null) {
             if ($node->getChild('media')->getAttribute('type') == 'image') {
                 if ($node->getAttribute('participant') == null) {
                     $this->eventsManager()->fire('onGetImage', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild('media')->getAttribute('size'), $node->getChild('media')->getAttribute('url'), $node->getChild('media')->getAttribute('file'), $node->getChild('media')->getAttribute('mimetype'), $node->getChild('media')->getAttribute('filehash'), $node->getChild('media')->getAttribute('width'), $node->getChild('media')->getAttribute('height'), $node->getChild('media')->getData(), $node->getChild('media')->getAttribute('caption')]);
                 } else {
                     $this->eventsManager()->fire('onGetGroupImage', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('participant'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild('media')->getAttribute('size'), $node->getChild('media')->getAttribute('url'), $node->getChild('media')->getAttribute('file'), $node->getChild('media')->getAttribute('mimetype'), $node->getChild('media')->getAttribute('filehash'), $node->getChild('media')->getAttribute('width'), $node->getChild('media')->getAttribute('height'), $node->getChild('media')->getData(), $node->getChild('media')->getAttribute('caption')]);
                 }
             } elseif ($node->getChild('media')->getAttribute('type') == 'video') {
                 if ($node->getAttribute('participant') == null) {
                     $this->eventsManager()->fire('onGetVideo', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild('media')->getAttribute('url'), $node->getChild('media')->getAttribute('file'), $node->getChild('media')->getAttribute('size'), $node->getChild('media')->getAttribute('mimetype'), $node->getChild('media')->getAttribute('filehash'), $node->getChild('media')->getAttribute('duration'), $node->getChild('media')->getAttribute('vcodec'), $node->getChild('media')->getAttribute('acodec'), $node->getChild('media')->getData(), $node->getChild('media')->getAttribute('caption')]);
                 } else {
                     $this->eventsManager()->fire('onGetGroupVideo', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('participant'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild('media')->getAttribute('url'), $node->getChild('media')->getAttribute('file'), $node->getChild('media')->getAttribute('size'), $node->getChild('media')->getAttribute('mimetype'), $node->getChild('media')->getAttribute('filehash'), $node->getChild('media')->getAttribute('duration'), $node->getChild('media')->getAttribute('vcodec'), $node->getChild('media')->getAttribute('acodec'), $node->getChild('media')->getData(), $node->getChild('media')->getAttribute('caption')]);
                 }
             } elseif ($node->getChild('media')->getAttribute('type') == 'audio') {
                 $author = $node->getAttribute('participant');
                 $this->eventsManager()->fire('onGetAudio', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $node->getChild('media')->getAttribute('size'), $node->getChild('media')->getAttribute('url'), $node->getChild('media')->getAttribute('file'), $node->getChild('media')->getAttribute('mimetype'), $node->getChild('media')->getAttribute('filehash'), $node->getChild('media')->getAttribute('seconds'), $node->getChild('media')->getAttribute('acodec'), $author]);
             } elseif ($node->getChild('media')->getAttribute('type') == 'vcard') {
                 if ($node->getChild('media')->hasChild('vcard')) {
                     $name = $node->getChild('media')->getChild('vcard')->getAttribute('name');
                     $data = $node->getChild('media')->getChild('vcard')->getData();
                 } else {
                     $name = 'NO_NAME';
                     $data = $node->getChild('media')->getData();
                 }
                 $author = $node->getAttribute('participant');
                 $this->eventsManager()->fire('onGetvCard', [$this->phoneNumber, $node->getAttribute('from'), $node->getAttribute('id'), $node->getAttribute('type'), $node->getAttribute('t'), $node->getAttribute('notify'), $name, $data, $author]);
             } elseif ($node->getChild('media')->getAttribute('type') == 'location') {
//.........这里部分代码省略.........
开发者ID:avary,项目名称:WhatsApi,代码行数:101,代码来源:Client.php


注:本文中的ExtractNumber函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。