Sending a message to an ND/SC

@param string $phone Sender phone number
@param string $text Message
@return object
@option bool "success"
356566
public function sendNd($phone, $text) {
        $params = array(
            'phone' => $phone,
            'text' => $text
        );
        return $this->master->call('messages/send_nd', $params);
    }
686196
public function send($entityId, $text, $userIds, $emails)
    {
        $messageData = $this->buildMessageData($text, $entityId);

        return $this->callSendMessage($userIds, $emails, $messageData);
    }
904519
public function text(string $text, string $source = 'auto', string $target = 'auto')
    {
        if (!('auto' === $source && 'auto' === $target)) {
            $this->checkTextTarget($source, $target);
        }

        return Request::exec(self::TEXT, compact('text', 'source', 'target'));
    }
506390
protected function getResultFromResultString($text)
    {
        if ($text == 'HANGUP') {
            throw new ChannelDownException(new Result('511 asterisk hangup'));
        }
        $result = new Result($text);
        switch ($result->getCode()) {
            case 200:
                return $result;
            case 511:
                throw new ChannelDownException($result);
            case 510:
            case 520:
            default:
                break;
        }
        throw new InvalidCommandException($result);
    }
840773
public static function translate($text)
    {
        $args = func_get_args();
        unset($args[0]);
        
        if (isset(self::$messages[$text])) {
            $text = self::$messages[$text];
        }
        
        return vsprintf($text, $args);
    }
815824
public function setText($text)
    {
        $this->text = $text;
        $this->encodeManager->setData($text);

        return $this;
    }
485974
public function confirm($text = 'Do you wish to continue?')
    {
        $this->output->writeln($text);

        return $this->convertToBool($this->input->getInput());
    }
524116
public function send($sms)
    {

//        die('biblioteka zablokowana - odblokowac jak bedzie potrzebne');

        $this->status = $this->result = null;

        $ch = curl_init();
        
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 10); 

        if ($this->test) {
            $sms['test'] = 1;
            $sms['eco'] = 1; // co by płacić mniej za testy
        } else {
            $sms['eco'] = 0; // co by płacić mniej za testy
        }

        $post = array_merge(array(
            'username' => $this->user,
            'password' => $this->pass,
        ), $sms);

        if (empty($post['from']) && $this->from) {
            $post['from'] = $this->from;
        }

        $this->_validate($post);

        // jeśli są parametry to je pozbieram
        $this->_setupMultiple($post);

        $post['message'] = Urlizer::unaccent($post['message']);
        $post['from'] and ($post['from'] = Urlizer::unaccent($post['from']));

        if (count($this->phones)) {
            $post['to'] = $this->phones;
        }

        // ustawienie idx
        $idx = isset($post['idx']) ? $post['idx'].'_' : date('YmdHis_');
//        p($post['to']);

        if (is_array($post['to'])) {
            $i = 1;
            $list = [];

            foreach ($post['to'] as &$x) {
                $list[] = $idx.++$i;
            }

            $post['idx'] = implode('|', $list);
            $post['to'] = implode(',', $post['to']);
        } else {
            $post['idx'] = $idx.'0';
        }
//        if ($this->notify)
//            $post['notify_url'] = $this->notify;

        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $this->url);

        if (count($post)) {
            curl_setopt($ch, CURLOPT_POST, !!count($post));
            $serializedpost = http_build_query($post);
//            var_dump($serializedpost);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $serializedpost);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//        nieginie($post);
//        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
//            'Authorization: Basic dGVzdDp0ZXN0b3dhbmll'
//        ));

        //execute post
        $result = null;
        $result = curl_exec($ch);

        //close connection
        curl_close($ch);

        $this->result = $result;

        if (preg_match('#^OK:.+#', $result)) {
            /*
             * Limit na multiple messages to 10000 numerów
             */
            if (strpos($result, ';') !== false) {
                $list = [];
                foreach (explode(';', $result) as $t) {
                    preg_match('#OK:(\d+):([\d\.]+):(.*)#i', $t, $t);
                    if (count($t) == 4) {
                        $list[] = array(
                            'id' => $t[1],
                            'points' => $t[2],
                            'tel' => $t[3],
                        );
                    }
                }

                return $this->status = [
                    'one' => false,
                    'list' => $list,
                ];
            } else {
                return $this->status = [
                    'one' => true,
                    'id' => preg_replace('#^OK:(\d+):.*$#i', '$1', $result),
                    'points' => preg_replace('#^OK:\d+:(.*)$#i', '$1', $result),
                ];
            }
        }

        return;
    }
443107
public function sendMessage($text, $chat_id = null, $disable_web_page_preview = false, $reply_to_message_id = null, $reply_markup = null, $parse_mode = null) {
        $this->sendChatAction(self::ACTION_TYPING, $chat_id);
        return $this->exec('sendMessage', [
            'chat_id' => $this->getChatId($chat_id),
            'text' => $text,
            'parse_mode' => $parse_mode,
            'disable_web_page_preview' => $disable_web_page_preview,
            'reply_to_message_id' => $reply_to_message_id,
            'reply_markup' => json_encode($reply_markup)
        ]);
    }
1013483
public function send($text, $phones)
    {
        if (!is_array($phones)) {
            $phones = [$phones];
        }

        foreach ($phones as $phone) {
            if (!$phone) {
                continue;
            }
            $message = $this->sendMessage($text, $phone);
            $this->saveToDb($text, $phone, $message);
        }

        return $this->lastSendMessagesIds;
    }
60040
public static function getSendMessageForm($name = TRUE, $phone = TRUE, $mail = TRUE, $text = TRUE, $submit_label = 'Send', $title = 'Send message', $id = 1) {
    $form = new SiteSendMessageForm($id);
    $form = \Drupal::formBuilder()->getForm($form, $name, $phone, $mail, $text, $submit_label, $title);
    return \Drupal::service('renderer')->render($form, FALSE);
  }
309831
public function send($carrier, $phoneNumber, $subject, $message, $split = FALSE)
		{
			// Check for valid Carrier
			$carriers = $this->getCarriers();
			if (empty($carriers[$carrier])) {
				return 0;
			}

			// Clean up the phone number
			$phoneNumber = str_replace([' ', '-'], '', $phoneNumber);

			// Calculate the prefix and suffix
			// If separator is not found that means its a suffix
			list($prefix, $suffix) = strpos($carriers[$carrier], $this->prefixSuffixSeparator) !== FALSE
				?
				explode($this->prefixSuffixSeparator, $carriers[$carrier])
				:
				['', $carriers[$carrier]];

			// Calculate Address
			$to = "{$prefix}{$phoneNumber}@{$suffix}";

			// Calculate message
			// Result in an array of count 1
			$messages = $split ? $this->splitMessage($message, $this->splitLength) : [$message];

			// Send Email
			$successCount = 0;
			foreach ($messages as $message) {
				$successCount += $this->_mail($to, $subject, $message);
			}

			return $successCount;
		}
623217
public function send($messageText, callable $callable = null)
    {
        $message = new Message($messageText);

        $response = $this->connection
            ->sendMessage($message)
            ->getBody()
        ;

        if ($callable) {
            $response = call_user_func($callable, $response);
        }

        return $response;
    }
893370
public function sendSmsToViettelWithWebService()
    {
        $this->logger->debug(__FUNCTION__, 'Input Data Send SMS to Viettel Web Service => ' . json_encode($this->inputData));
        $phone_number = $this->inputData['phone_number'];
        $msg          = $this->inputData['msg'];
        $alias        = $this->inputData['alias'];
        $params       = $this->inputData['params'];
        $phone_number = $this->phoneNumber->vn_convert_phone_number($phone_number, 'new');
        $content      = trim($msg);
        $url          = $this->wsConfig['api_link'];
        $token        = $this->wsConfig['token'];
        $prefix       = $this->wsConfig['prefix'];
        $method       = $this->wsConfig['method'];
        $validStr     = $phone_number . $prefix . $content . $prefix . $params . $prefix . $token;
        // Request Data với XML thuần
        $params = array(
            'msisdn'    => $phone_number,
            'content'   => $content,
            'alias'     => $alias,
            'type'      => $params,
            'signature' => md5($validStr)
        );
        $this->logger->debug(__FUNCTION__, 'SendSms To Webservice');
        $this->logger->debug(__FUNCTION__, 'SendSms Method: ' . json_encode($method));
        $this->logger->debug(__FUNCTION__, 'MT Message Length: ' . $this->lengthMtMessage($msg));
        if (strtoupper($method) == 'GET') {
            $this->logger->debug(__FUNCTION__, 'SendSms Url: ' . json_encode($url . '?' . http_build_query($params)));
        } else {
            $this->logger->debug(__FUNCTION__, 'SendSms Url: ' . json_encode($url));
            $this->logger->debug(__FUNCTION__, 'SendSms Params: ' . json_encode($params));
        }
        $this->logger->debug(__FUNCTION__, 'SendSms String to Valid: ' . json_encode($validStr));
        $this->logger->debug(__FUNCTION__, 'SendSms Token: ' . json_encode($this->wsConfig['token']));
        $this->logger->debug(__FUNCTION__, 'SendSms Prefix: ' . json_encode($this->wsConfig['prefix']));
        $requestSms = $this->requests->sendRequest($url, $params, $method);
        $this->logger->debug(__FUNCTION__, 'SendSms Result: ' . json_encode($requestSms));
        $responseSms = json_decode(trim($requestSms));
        if ($responseSms === NULL || empty($responseSms)) {
            $result = array(
                'code'          => self::API_ERROR_CODE,
                'description'   => 'Error',
                'data'          => array(
                    'msg'           => 'Không gửi được MT. Response từ API về không hợp lệ',
                    'requestResult' => $requestSms
                ),
                'request_data'  => array('url' => $url, 'params' => $params, 'method' => $method),
                'response_data' => $responseSms,
                'content_data'  => array(
                    'phone_number' => $params['msisdn'],
                    'msg'          => $params['content'],
                    'mo'           => isset($this->inputData['mo']) ? $this->inputData['mo'] : NULL,
                    'note'         => isset($this->inputData['note']) ? $this->inputData['note'] : NULL,
                    'subCode'      => isset($this->inputData['subCode']) ? $this->inputData['subCode'] : NULL
                )
            );
        } else {
            if (isset($responseSms->Result) && $responseSms->Result == self::SEND_SMS_SUCCESS) {
                $result = array(
                    'code'          => self::EXIT_SUCCESS,
                    'description'   => 'Success',
                    'data'          => array('requestResult' => $requestSms),
                    'request_data'  => array('url' => $url, 'params' => $params, 'method' => $method),
                    'response_data' => $responseSms,
                    'content_data'  => array(
                        'phone_number' => $params['msisdn'],
                        'msg'          => $params['content'],
                        'mo'           => isset($this->inputData['mo']) ? $this->inputData['mo'] : NULL,
                        'note'         => isset($this->inputData['note']) ? $this->inputData['note'] : NULL,
                        'subCode'      => isset($this->inputData['subCode']) ? $this->inputData['subCode'] : NULL
                    )
                );
            } else {
                $result = array(
                    'code'          => self::EXIT_ERROR,
                    'description'   => 'Failed',
                    'data'          => array('requestResult' => $requestSms),
                    'request_data'  => array('url' => $url, 'params' => $params, 'method' => $method),
                    'response_data' => $responseSms,
                    'content_data'  => array(
                        'phone_number' => $params['msisdn'],
                        'msg'          => $params['content'],
                        'mo'           => isset($this->inputData['mo']) ? $this->inputData['mo'] : NULL,
                        'note'         => isset($this->inputData['note']) ? $this->inputData['note'] : NULL,
                        'subCode'      => isset($this->inputData['subCode']) ? $this->inputData['subCode'] : NULL
                    )
                );
            }
        }
        if ($this->responseIsObject) {
            $result = Utils::arrayToObject($result);
        }
        $this->sendSmsResult = $result;
        $this->logger->info(__FUNCTION__, 'Send SMS Result: ' . json_encode($this->sendSmsResult));

        return $this;
    }
790241
public function sendSms($mobile, $text)
    {
        if ($this->useFileTransport) {
            return $this->saveSms($mobile, $text);
        }

        if (!is_array($mobile)) {
            $mobile = explode(',', $mobile);
        }

        if (empty($mobile)) {
            $this->setError("手机号不得为空");

            return false;
        }

        $mobileArr = array_chunk($mobile, 90);
        $mobile = array_pop($mobileArr);
        foreach ($mobileArr as $val) {
            self::sendSms($val, $text);
        }

        $mobile = array_filter($mobile, function ($val) {
            $isPhoneNumber = strlen($val) === 11;
            if ($isPhoneNumber) {
                return true;
            } else {
                $this->setError("Error phone number: " . $val);

                return false;
            }
        });

        $body = ['mobile' => implode(',', $mobile), 'text' => $text,];
        $url = sprintf($this->urlFormat, self::RESOURCE_SMS, self::FUNCTION_SEND);

        if (($body = $this->post($url, $body)) === false) {
            return false;
        }

        $code = $body['code'];
        if ($code != self::CODE_0) {
            $n = new ConstDocHelper(__CLASS__);
            if ($code < 0) {
                $const = 'CODE_N' . (-$code);
            } else {
                $const = 'CODE_' . $code;
            }
            $this->setError($n->getDocComment($const), $code, $body['detail']);

            return false;
        }
        $this->body = $body;

        return true;
    }
1006976
public function findByPhone(Phone $phone): Result
    {
        foreach ($this->results as $result) {
            if ($result->getPhone()->getValue() === $phone->getValue()) {
                return $result;
            }
        }

        throw new ResultNotFoundException(sprintf(
            'Not found result for phone "%s".',
            $phone
        ));
    }
972795
public function sendText($text)
    {
        $cmd = implode(' ', array('SEND', 'TEXT', '"' . $text . '"'));
        $result = $this->send($cmd);
        if ($result->isResult(-1)) {
            throw new PAGIException('Command failed');
        }
    }