コード例 #1
0
ファイル: NodeReader.php プロジェクト: CarsonF/WhatsApi
 /**
  * @param  string|null                                        $input
  * @return \Tmv\WhatsApi\Message\Node\NodeInterface|null
  * @throws \Tmv\WhatsApi\Exception\IncompleteMessageException
  * @throws \Tmv\WhatsApi\Exception\RuntimeException
  */
 public function nextTree($input = null)
 {
     if ($input != null) {
         $this->input = $input;
     }
     $stanzaFlag = ($this->peekInt8() & 0xf0) >> 4;
     $stanzaSize = $this->peekInt16(1);
     if ($stanzaSize > strlen($this->input)) {
         $exception = new IncompleteMessageException("Incomplete message");
         $exception->setInput($this->input);
         throw $exception;
     }
     $this->readInt24();
     if ($stanzaFlag & 8) {
         if (!isset($this->key)) {
             throw new RuntimeException("Encountered encrypted message, missing key");
         }
         $realSize = $stanzaSize - 4;
         $this->input = $this->key->decodeMessage($this->input, $realSize, 0, $realSize);
     }
     if ($stanzaSize > 0) {
         return $this->nextTreeInternal();
     }
     return null;
 }
コード例 #2
0
 /**
  * Authenticate with the Whatsapp Server.
  *
  * @param  Connection $connection
  * @param  Identity   $identity
  * @param  string     $challengeData
  * @return string     Returns binary string
  */
 protected function getAuthData(Connection $connection, Identity $identity, $challengeData)
 {
     $keys = KeyStream::generateKeys(base64_decode($identity->getPassword()), $challengeData);
     $connection->setInputKey($this->createKeyStream($keys[2], $keys[3]));
     $connection->setOutputKey($this->createKeyStream($keys[0], $keys[1]));
     $array = "" . $identity->getPhone()->getPhoneNumber() . $challengeData;
     $response = $connection->getOutputKey()->encodeMessage($array, 0, 4, strlen($array) - 4);
     return $response;
 }
コード例 #3
0
ファイル: NodeWriter.php プロジェクト: CarsonF/WhatsApi
 protected function flushBuffer($encrypt = true)
 {
     $size = strlen($this->output);
     $data = $this->output;
     if ($this->key != null && $encrypt) {
         $bsize = $this->getInt24($size);
         //encrypt
         $data = $this->key->encodeMessage($data, $size, 0, $size);
         $len = strlen($data);
         $bsize[0] = chr(8 << 4 | ($len & 16711680) >> 16);
         $bsize[1] = chr(($len & 65280) >> 8);
         $bsize[2] = chr($len & 255);
         $size = $this->parseInt24($bsize);
     }
     $ret = $this->writeInt24($size) . $data;
     $this->output = '';
     return $ret;
 }