Beispiel #1
0
 public function testSettersAndGettersMethods()
 {
     $data = array('nickname' => 'my-nickname', 'password' => 'my-password', 'token' => 'my-token');
     $phoneMock = m::mock(__NAMESPACE__ . '\\Phone');
     $this->object->setNickname($data['nickname']);
     $this->object->setPassword($data['password']);
     $this->object->setToken($data['token']);
     $this->object->setPhone($phoneMock);
     $this->assertEquals($data['nickname'], $this->object->getNickname());
     $this->assertEquals($data['password'], $this->object->getPassword());
     $this->assertEquals($data['token'], $this->object->getToken());
     $this->assertEquals($phoneMock, $this->object->getPhone());
 }
Beispiel #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;
 }
Beispiel #3
0
 /**
  * @param  NodeInterface $node
  * @return bool
  */
 protected function isNodeFromMyNumber(Identity $identity, NodeInterface $node)
 {
     $currentPhoneNumber = $identity->getPhone()->getPhoneNumber();
     return 0 === strncmp($node->getAttribute('from'), $currentPhoneNumber, strlen($currentPhoneNumber));
 }
Beispiel #4
0
 public function uploadMediaFile(MediaFile $mediaFile, Identity $identity, $uploadUrl, $to)
 {
     return $this->sendMediaFile($mediaFile, $uploadUrl, Identity::createJID($to), $identity->getPhone()->getPhoneNumber());
 }
Beispiel #5
0
 /**
  * Check if account credentials are valid.
  *
  * WARNING: WhatsApp now changes your password everytime you use this.
  * Make sure you update your config file if the output informs about
  * a password change.
  *
  * @param  Identity $identity
  * @return array
  *                           An object with server response.
  *                           - status: Account status.
  *                           - login: Phone number with country code.
  *                           - pw: Account password.
  *                           - type: Type of account.
  *                           - expiration: Expiration date in UNIX TimeStamp.
  *                           - kind: Kind of account.
  *                           - price: Formatted price of account.
  *                           - cost: Decimal amount of account.
  *                           - currency: Currency price of account.
  *                           - price_expiration: Price expiration in UNIX TimeStamp.
  *
  * @throws \RuntimeException
  */
 public function checkCredentials(Identity $identity)
 {
     $host = 'https://' . Client::WHATSAPP_CHECK_HOST;
     $query = ['cc' => $identity->getPhone()->getCc(), 'in' => $identity->getPhone()->getPhoneNumber(), 'id' => $identity->getIdentityString(), 'lg' => $identity->getPhone()->getIso639() ?: 'en', 'lc' => $identity->getPhone()->getIso3166() ?: 'US', 'network_radio_type' => "1"];
     $response = $this->getResponse($host, $query);
     if ($response['status'] != 'ok') {
         $message = 'There was a problem trying to request the code. ' . $response['reason'];
         throw new \RuntimeException($message);
     }
     return $response;
 }