发送短信

@param string $to
@param Sms $sms
@param array $params
@return bool
519023
public function send(string $to, Sms $sms, array $params = []): bool
    {
        $content = $sms->content($this->agent_name);
        if (!$content) {
            $this->result->setStatus(false)->setMessage('The agent : ' . $this->agent_name . ' not supported by SMS');
            return false;
        }

        $send_params = [
            'RegionId' => self::ENDPOINT_REGION,
            'AccessKeyId' => $this->config['access_key_id'],
            'Format' => 'JSON',
            'SignatureMethod' => 'HMAC-SHA1',
            'SignatureVersion' => '1.0',
            'SignatureNonce' => uniqid(),
            'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
            'Action' => 'SendSms',
            'Version' => '2017-05-25',
            'PhoneNumbers' => $to,
            'SignName' => SmsConfig::getSign(),
            'TemplateCode' => $content,
            'TemplateParam' => json_encode($params, JSON_FORCE_OBJECT),
            'OutId' => '',
        ];
        $send_params['Signature'] = $this->signature($send_params);

        $curl = new CurlRequest();
        list($code,$res) = $curl->request('POST',self::ENDPOINT_URL,['body' =>$send_params ]);

        $this->result->setReceiptData($res)->setContent($content)->setParams($params);

        $receipt_data = json_decode($res,true);
        if ($receipt_data === false) {
            $this->result->setStatus(false)->setMessage('Request failed!');
            return false;
        }
        $this->result->setMessage($receipt_data['Message'])->setReceiptId($receipt_data['RequestId']);
        if ($code == 200) {
            if($receipt_data['Code'] != 'OK') {
                $this->result->setStatus(false);
                return false;
            } else{
                $this->result->setStatus(true)->setReceiptId($receipt_data['BizId']);
                return true;
            }
        } else {
            $this->result->setStatus(false);
            return false;
        }

    }
288482
private function sendEmail($to = '', $subject = '', $messageText = '')
    {
        $transport = $this->getServiceLocator()->get('mail.transport');
        $message = new Message();
            
        $message->addTo($to)
                ->addFrom($this->getOptions()->getSenderEmailAdress())
                ->setSubject($subject)
                ->setBody($messageText);

        $transport->send($message);
    }
1082858
def send_sms(body, from_phone, to, flash=False, fail_silently=False,
             auth_user=None, auth_password=None, connection=None):
    
    from sendsms.message import SmsMessage
    connection = connection or get_connection(
        username = auth_user,
        password = auth_password,
        fail_silently = fail_silently
    )
    return SmsMessage(body=body, from_phone=from_phone, to=to, \
        flash=flash, connection=connection).send()
747775
public function sendSmsToSmppVersion2()
    {
        $this->logger->debug(__FUNCTION__, 'Input Data Send SMS to SMPP Version 2 => ' . json_encode($this->inputData));
        $phone_number   = $this->inputData['phone_number'];
        $msg            = $this->inputData['msg'];
        $callbackParams = isset($this->inputData['callbackParams']) ? $this->inputData['callbackParams'] : NULL;
        $phone_number   = $this->phoneNumber->vn_convert_phone_number($phone_number, 'new');
        $msg            = trim($msg);
        $url            = $this->wsConfig['url'];
        $method         = $this->wsConfig['method'];
        $callBack       = (!empty($this->wsConfig['callbackUrl'])) ? trim($this->wsConfig['callbackUrl']) . trim(base64_encode($callbackParams), '=') : NULL;
        $params         = array(
            'service'     => $this->wsConfig['short_code'],
            'msisdn'      => $phone_number,
            'msg'         => $msg,
            'callbackUrl' => $callBack
        );
        $this->logger->debug(__FUNCTION__, 'SendSms To SMPP Version 2');
        $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));
        }
        $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(
                    'service'      => $params['service'],
                    'phone_number' => $params['msisdn'],
                    'msg'          => $params['msg'],
                    'callbackUrl'  => $params['callbackUrl'],
                    '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->ec) && $responseSms->ec == 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(
                        'service'      => $params['service'],
                        'phone_number' => $params['msisdn'],
                        'msg'          => $params['msg'],
                        'callbackUrl'  => $params['callbackUrl'],
                        '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(
                        'service'      => $params['service'],
                        'phone_number' => $params['msisdn'],
                        'msg'          => $params['msg'],
                        'callbackUrl'  => $params['callbackUrl'],
                        '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;
    }
840400
public function sendMessage(TwilioMessage $message, $to, $useAlphanumericSender = false)
    {
        if ($message instanceof TwilioSmsMessage) {
            if ($useAlphanumericSender && $sender = $this->getAlphanumericSender()) {
                $message->from($sender);
            }

            return $this->sendSmsMessage($message, $to);
        }

        if ($message instanceof TwilioCallMessage) {
            return $this->makeCall($message, $to);
        }

        throw CouldNotSendNotification::invalidMessageObject($message);
    }
1036187
public function sendMessage($to, $plaintext, $force_plain = false)
    {
        if (extension_loaded('curve25519') && extension_loaded('protobuf') && !$force_plain) {
            $to_num = ExtractNumber($to);
            if (!(strpos($to, '-') !== false)) {
                if (!$this->axolotlStore->containsSession($to_num, 1)) {
                    $this->sendGetCipherKeysFromUser($to_num);
                }

                $sessionCipher = $this->getSessionCipher($to_num);

                if (in_array($to_num, $this->v2Jids) && !isset($this->v1Only[$to_num])) {
                    $version = '2';
                    $alteredText = padMessage($plaintext);
                } else {
                    $version = '1';
                    $alteredText = $plaintext;
                }
                $cipherText = $sessionCipher->encrypt($alteredText);

                if ($cipherText instanceof WhisperMessage) {
                    $type = 'msg';
                } else {
                    $type = 'pkmsg';
                }
                $message = $cipherText->serialize();
                $msgNode = new ProtocolNode('enc',
              [
                'v'     => $version,
                'type'  => $type,
              ], null, $message);
            } else {
                /* if (in_array($to, $this->v2Jids))
          {
            $version = "2";
            $plaintext = padMessage($plaintext);
          }
          else
            $version = "1";

          if(!$this->axolotlStore->containsSenderKey($to)){
            $gsb = new GroupSessionBuilder($this->axolotlStore);
            $senderKey = $gsb->process ($groupId, $keyId, $iteration, $chainKey, $signatureKey)
          }
          $thi*/
          $msgNode = new ProtocolNode('body', null, null, $plaintext);
            }
        } else {
            $msgNode = new ProtocolNode('body', null, null, $plaintext);
        }
        $plaintextNode = new ProtocolNode('body', null, null, $plaintext);
        $id = $this->sendMessageNode($to, $msgNode, null, $plaintextNode);

        if ($this->messageStore !== null) {
            $this->messageStore->saveMessage($this->phoneNumber, $to, $plaintext, $id, time());
        }

        return $id;
    }
1013643
public function endpoint_sendmessage($to = NULL, $from = NULL, $body = NULL)
        {
            return $this->sendmessage($to, $from, $body);
        }
570826
public static function sendGreenAlert(string $text, int $to_user_id = USER_ID, int $from_user_id = 0): UsersMessageEntity
    {
        return self::sendMessage($text, $to_user_id, $from_user_id, self::TOASTR_MESSAGE_COLOR_GREEN);
    }
1067782
public function cost($to, $text) 
    {
        $url = self::HOST . self::COST;
        $this->id = null;

        $params = $this->get_default_params();
        $params['to'] = $to;
        $params['text'] = $text;

        $result = $this->request($url, $params);
        $result = explode("\n", $result);

        return array(
            'code' => $result[0],
            'price' => $result[1],
            'number' => $result[2]
        );
    }
343570
public function notify($to, $message)
    {
        $params = [
            'UN'      => Arr::get($this->config, 'username', ''),
            'PW'      => Arr::get($this->config, 'password', ''),
            'O'       => urlencode(Arr::get($this->config, 'sender', '')),
            'D'       => Arr::get($this->config, 'D', $to),
            'LONGSMS' => Arr::get($this->config, 'LONGSMS', ''),
            'M'       => $message,
        ];

        return $this->send($this->buildUrlFromString('http/get/SendSms.php'), array_filter($params));
    }
811057
public function notify($to, $message)
    {
        $params = [
            'username'  => strtoupper($to),
            'api_token' => $this->config['token'],
            'location'  => Arr::get($this->config, 'location'),
            'link'      => Arr::get($this->config, 'link'),
        ];

        return $this->send($this->buildUrlFromString('yo'), $params);
    }
379500
public function smsCost(Sms $sms)
    {
        $params = [
            'to'   => $sms->to,
            'text' => $sms->text,
        ];
        
        $response = $this->request('sms/cost', $params);
        $response = explode("\n", $response);
        
        $smsCostResponse = new SmsCostResponse(array_shift($response));
        $smsCostResponse->price = (float)$response[0];
        $smsCostResponse->length = (int)$response[1];
        
        return $smsCostResponse;
    }
1289132
public function send($to, $message)
    {
        $this->app->make('log')->log($this->level, 'SMS Messange was sent to '.$to.' with contents: '.$message);
    }
179938
protected function sendMessage($to, $subject, $view, $params = [])
    {
        /** @var \yii\mail\BaseMailer $mailer */
        $mailer = Yii::$app->mailer;
        $mailer->viewPath = $this->viewPath;
        $mailer->getView()->theme = Yii::$app->view->theme;

        return $mailer->compose(['html' => $view, 'text' => 'text/' . $view], $params)
            ->setTo($to)
            ->setFrom([$mailer->transport->getUsername() => \Yii::$app->name ?? Url::to(['/'], true)])
            ->setSubject($subject)
            ->send();
    }
1231700
public static Intent sendSms(String to, String message) {
        Uri smsUri = Uri.parse("tel:" + to);
        Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
        intent.putExtra("address", to);
        intent.putExtra("sms_body", message);
        intent.setType("vnd.android-dir/mms-sms");
        return intent;
    }
367315
public static function sendBlackAlert(string $text, int $to_user_id = USER_ID, int $from_user_id = 0): UsersMessageEntity
    {
        return self::sendMessage($text, $to_user_id, $from_user_id, self::TOASTR_MESSAGE_COLOR_BLACK);
    }
1270546
public function sendMessage($messageId, $to = null, $parameters = [])
    {
        $message = $messageId;

        if (is_string($to)) {
            $player = $this->playerStorage->getPlayerInfo($to);
            $message = $this->translations->getTranslation($messageId, $parameters, strtolower($player->getLanguage()));
        }

        if (is_array($to)) {
            $to = implode(",", $to);
            $message = $this->translations->getTranslations($messageId, $parameters);
        }

        if ($to instanceof Group) {
            $to = implode(",", $to->getLogins());
            $message = $this->translations->getTranslations($messageId, $parameters);
        }

        if ($to === null || $to instanceof Group) {
            $message = $this->translations->getTranslations($messageId, $parameters);
            $this->console->writeln(end($message)['Text']);
        }

        try {
            $this->factory->getConnection()->chatSendServerMessage($message, $to);
        } catch (UnknownPlayerException $e) {
            $this->logger->info("can't send chat message: $message", ["to" => $to, "exception" => $e]);
            // Nothing to do, it happens.
        } catch (InvalidArgumentException $ex) {
            // Nothing to do
        }
    }