Пример #1
0
 /**
  * @param  MediaFile  $mediafile
  * @param  string     $uploadUrl
  * @param  string     $to
  * @param  string     $from
  * @return bool|array
  */
 protected function sendMediaFile(MediaFile $mediafile, $uploadUrl, $to, $from)
 {
     $host = parse_url($uploadUrl, PHP_URL_HOST);
     //filename to md5 digest
     $cryptoname = md5($mediafile->getFilepath()) . "." . $mediafile->getExtension();
     $boundary = "zzXXzzYYzzXXzzQQ";
     $contentlength = 0;
     if (is_array($to)) {
         $to = implode(',', $to);
     }
     $hBAOS = "--" . $boundary . "\r\n";
     $hBAOS .= "Content-Disposition: form-data; name=\"to\"\r\n\r\n";
     $hBAOS .= $to . "\r\n";
     $hBAOS .= "--" . $boundary . "\r\n";
     $hBAOS .= "Content-Disposition: form-data; name=\"from\"\r\n\r\n";
     $hBAOS .= $from . "\r\n";
     $hBAOS .= "--" . $boundary . "\r\n";
     $hBAOS .= "Content-Disposition: form-data; name=\"file\"; filename=\"" . $cryptoname . "\"\r\n";
     $hBAOS .= "Content-Type: " . $mediafile->getMimeType() . "\r\n\r\n";
     $fBAOS = "\r\n--" . $boundary . "--\r\n";
     $contentlength += strlen($hBAOS);
     $contentlength += strlen($fBAOS);
     $contentlength += $mediafile->getSize();
     $post = "POST " . $uploadUrl . "\r\n";
     $post .= "Content-Type: multipart/form-data; boundary=" . $boundary . "\r\n";
     $post .= "Host: " . $host . "\r\n";
     $post .= "User-Agent: " . Client::WHATSAPP_USER_AGENT . "\r\n";
     $post .= "Content-Length: " . $contentlength . "\r\n\r\n";
     return $this->sendData($mediafile, $host, $post, $hBAOS, $fBAOS);
 }
Пример #2
0
 /**
  * @param  MediaFile   $mediaFile
  * @return null|string
  */
 protected function checkMediaFileType(MediaFile $mediaFile)
 {
     $mimeType = $mediaFile->getMimeType();
     if (0 === strpos($mimeType, 'image')) {
         return MediaFileInterface::TYPE_IMAGE;
     } elseif (0 === strpos($mimeType, 'video')) {
         return MediaFileInterface::TYPE_VIDEO;
     } elseif (0 === strpos($mimeType, 'audio')) {
         return MediaFileInterface::TYPE_VIDEO;
     }
     $map = $this->getExtensionTypeMap();
     if (isset($map[$mediaFile->getExtension()])) {
         return $map[$mediaFile->getExtension()];
     }
     return null;
 }