✏️ 正在编辑: Sms.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/library/Core/Service/Sms.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_Service_Sms { private $_url = "https://sistemayuppie.com.br/sms2you/operacional/service/acesso-externo"; private $_token; private $_tipoMensagem = "MARKETING"; public function __construct() { $config = new Zend_Config_Ini(CLIENT_PATH . "/configs/application.ini"); if( empty($config->production->sms2you->token) || empty($config->production->sms2you->token) ){ throw new Core_Exception("Dados de integração com o SMS2You não estão configurados." ); } $this->_token = $config->production->sms2you->token; } /** * * @param string $number * @param boolean $onlyPhone informe se é para tratar sem o ddd * @return type * @throws Core_Exception */ public static function isValidPhone($number, $onlyPhone = false) { $dddList = [11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 24, 27, 28, 31, 32, 33, 34, 35, 37, 38, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 53, 54, 55, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 73, 74, 75, 77, 79, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99]; $phone = ltrim(String_Refatorar::soNumeros($number), 0); $ddd = (strlen($phone) == 13 || strlen($phone) == 12) ? substr($phone, 2, 2) : substr($phone, 0, 2); /* Teste numeros que contenham 55 (código do país) Ex: 5583998038776 */ if( strlen($phone) == 13 || strlen($phone) == 12 ){ if( substr($phone, 0, 2) == "55" && in_array(substr($phone, 2, 2), $dddList) ){ $phone = substr($phone, 2); } else { return false; } } /* Teste numeros que contenham ou não, o dígito 9 para celular Ex: 83998038776 ou 8335070700 */ if( (strlen($phone) == 10 || strlen($phone) == 11) && in_array($ddd, $dddList) ){ if( $onlyPhone ){ $numeroDddOff = substr($phone, 2); if( substr($numeroDddOff, 0, 1) >= 6 ){ return $phone; } else { return false; } } else { return $phone; } } else { return false; } } /** * * @param string $phoneNumber * @param string $text * @param int $externalId * @return string */ public function sendMessage($phoneNumber, $text, $externalId = 1) { $data = [ 'token' => $this->_token, 'tipo_mensagem' => $this->_tipoMensagem, 'mensagem' => $text, 'id_message_externo' => $externalId, 'celular' => $phoneNumber ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $this->_url, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, CURLOPT_ENCODING => "UTF-8", CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false )); $response = json_decode(curl_exec($curl)); curl_close($curl); if( !empty($response->success) ){ return $response->success; } return !empty($response->error) ? false : true; } }
💾 保存文件
← 返回文件管理器