/** * Bootstrap any application services. * * @return void */ public function boot() { Validator::extend('sms', function ($attribute, $value, $parameters) { try { $sms = Sms::where('to', $value)->orderBy('id', 'desc')->firstOrFail(); $dt = Carbon::now(); $sentTime = Carbon::createFromTimestamp($sms->sent_time); $second = $dt->diffInSeconds($sentTime); if ($second < 40) { return false; } return true; } catch (ModelNotFoundException $e) { return true; } }); Validator::extend('mobile', function ($attribute, $value, $parameters) { return preg_match('/^1[3|4|5|7|8|][0-9]{9}$/', $value); }); Validator::extend('verify_code_mock', function ($attribute, $value, $parameters) { $smsData = \SmsManager::getSmsDataFromSession(); if ($smsData && $smsData['deadline_time'] >= time() && $smsData['code'] == $value || $value == '8888') { return true; } return false; }); }
/** * create instance */ public function __construct() { $this->agent = \SmsManager::agent(); //init attributes $this->data = json_encode([]); $this->content = ''; }
public function sendNotifications() { $pdf = Yii::app()->pdfGenerator; $pdfFileNames = array(); $orderBooking = $this->getOrderBooking(); foreach ($this->itemsOnePerGroup as $item) { if ($item instanceof HotelTripElement) { if ($item->hotelBookerId) { if ($pdfFileInfo = $pdf->forHotelItem($item)) { $pdfFileNames[] = array('type' => 'hotel', 'filename' => $pdfFileInfo['realName'], 'visibleName' => $pdfFileInfo['visibleName']); } else { return false; } } } elseif ($item instanceof FlightTripElement) { if ($item->flightBookerId) { if ($pdfFileInfo = $pdf->forFlightItem($item)) { $pdfFileNames[] = array('type' => 'avia', 'filename' => $pdfFileInfo['realName'], 'visibleName' => $pdfFileInfo['visibleName']); } } } } EmailManager::sendEmailOrderInfo(array('orderBookingId' => $orderBooking->readableId, 'email' => $orderBooking->email), $pdfFileNames); SmsManager::sendSmsOrderInfo($orderBooking->phone, array('email' => $orderBooking->email, 'orderBookingId' => $orderBooking->readableId)); }
<?php Validator::extend('mobile', function ($attribute, $value, $parameters) { return preg_match('/^1[3|5|7|8|][0-9]{9}$/', $value); }); Validator::extend('mobile_changed', function ($attribute, $value, $parameters) { $smsData = SmsManager::getSmsDataFromSession(); if ($smsData && $smsData['mobile'] == $value) { return true; } return false; }); Validator::extend('verify_code', function ($attribute, $value, $parameters) { $smsData = SmsManager::getSmsDataFromSession(); if ($smsData && $smsData['deadline_time'] >= time() && $smsData['code'] == $value) { return true; } return false; }); Validator::extend('verify_rule', function ($attribute, $value, $parameters) { $smsData = SmsManager::getSmsDataFromSession(); if ($smsData && $smsData['verify']['mobile']['choose_rule'] == $parameters[0]) { return true; } return false; });
use Toplan\Sms\LaravelSmsException; Validator::extend('zh_mobile', function ($attribute, $value, $parameters) { return preg_match('/^(\\+?0?86\\-?)?((13\\d|14[57]|15[^4,\\D]|17[678]|18\\d)\\d{8}|170[059]\\d{7})$/', $value); }); Validator::extend('confirm_mobile_not_change', function ($attribute, $value, $parameters) { $token = isset($parameters[0]) ? $parameters[0] : null; $smsData = SmsManager::retrieveSentInfo($token); if ($smsData && $smsData['mobile'] === $value) { return true; } return false; }); Validator::extend('verify_code', function ($attribute, $value, $parameters) { $token = isset($parameters[0]) ? $parameters[0] : null; $smsData = SmsManager::retrieveSentInfo($token); if ($smsData && $smsData['deadline_time'] >= time() && $smsData['code'] === $value) { return true; } return false; }); Validator::extend('confirm_mobile_rule', function ($attribute, $value, $parameters) { if (!isset($parameters[0])) { throw new LaravelSmsException('Please give validator rule [confirm_mobile_rule] a parameter'); } $token = isset($parameters[1]) ? $parameters[1] : null; $smsData = SmsManager::retrieveSentInfo($token); if ($smsData && $smsData['verify']['mobile']['use'] === $parameters[0]) { return true; } return false; });
/** * set template id for template sms * @param $agentName * @param $tempId * * @return $this */ public function template($agentName, $tempId = null) { $tempIdArray = $this->getTemplate(true); if (!is_null($tempId)) { $tempIdArray["{$agentName}"] = $tempId; } else { if (is_array($agentName)) { $tempIdArray = $agentName; } else { $defaultAgentName = SM::getDefaultAgent(); $tempIdArray["{$defaultAgentName}"] = $agentName; } } $this->temp_id = json_encode($tempIdArray); return $this; }
use Toplan\Sms\LaravelSmsException; Validator::extend('zh_mobile', function ($attribute, $value, $parameters) { return preg_match('/^(\\+86)*1[3|4|5|7|8][0-9]{9}$/', $value); }); Validator::extend('confirm_mobile_not_change', function ($attribute, $value, $parameters) { $uuid = isset($parameters[0]) ? $parameters[0] : null; $smsData = SmsManager::retrieveSentInfo($uuid); if ($smsData && $smsData['mobile'] == $value) { return true; } return false; }); Validator::extend('verify_code', function ($attribute, $value, $parameters) { $uuid = isset($parameters[0]) ? $parameters[0] : null; $smsData = SmsManager::retrieveSentInfo($uuid); if ($smsData && $smsData['deadline_time'] >= time() && $smsData['code'] == $value) { return true; } return false; }); Validator::extend('confirm_mobile_rule', function ($attribute, $value, $parameters) { if (!isset($parameters[0])) { throw new LaravelSmsException('Please give validator rule [confirm_mobile_rule] a parameter'); } $uuid = isset($parameters[1]) ? $parameters[1] : null; $smsData = SmsManager::retrieveSentInfo($uuid); if ($smsData && $smsData['verify']['mobile']['use'] == $parameters[0]) { return true; } return false; });
function send_newsletter($send_id) { checkPerm('view'); require_once _base_ . '/lib/lib.json.php'; $json = new Services_JSON(); $path = '/appCore/newsletter/'; //access control $nl_sendpercycle = $GLOBALS["framework"]["nl_sendpercycle"]; //-TP// funAdminAccess('OP'); //@set_time_limit(60*15); // 15 minutes! $out =& $GLOBALS['page']; $out->setWorkingZone("content"); $lang =& DoceboLanguage::createInstance('admin_newsletter', 'framework'); $out->add(getTitleArea($lang->def("_NEWSLETTER"), "newsletter")); $out->add("<div class=\"std_block\">\n"); $info = get_send_info($send_id); $sel_groups = $info["sel_groups"]; $sel_lang = $info["sel_lang"]; $tot = $info["tot"]; $sub = $info["sub"]; $msg = $info["msg"]; $msg = str_replace("{site_base_url}", getSiteBaseUrl(), $msg); $fromemail = $info["fromemail"]; $file_array = $json->decode($info['file']); $attach = array(); foreach ($file_array as $file) { $attach[] = '../files' . $path . $file; } $cycle = (int) $_GET["cycle"]; // Items per cycle $ipc = $nl_sendpercycle; if (($cycle + 1) * $ipc < $tot) { $sendcomplete = 0; } else { $sendcomplete = 1; } $limit = $cycle * $ipc . ", " . $ipc; $arr_st = getSendToIdst($send_id, $limit); $acl_manager = Docebo::user()->getAclManager(); if (!empty($sel_lang) && $sel_lang != _ANY_LANG_CODE) { $user_info = $acl_manager->getUsersByLanguage($sel_lang, $arr_st); } else { // Send to all languages $user_info = $acl_manager->getUsers($arr_st); } $send_type = $info["send_type"]; switch ($send_type) { case "email": $tempemail = array(); foreach ($user_info as $info) { // collect recipients email addresses: ------------------------------ $email = $info[ACL_INFO_EMAIL]; if ($email != "") { $tempemail[] = $email; } // ---------------------------------------------- } //send all mails require_once _base_ . '/lib/lib.mailer.php'; $mailer = DoceboMailer::getInstance(); if (count($attach)) { $mailer->SendMail($fromemail, $tempemail, $sub, $msg, $attach, array(MAIL_REPLYTO => $fromemail, MAIL_SENDER_ACLNAME => false)); } else { $mailer->SendMail($fromemail, $tempemail, $sub, $msg, false, array(MAIL_REPLYTO => $fromemail, MAIL_SENDER_ACLNAME => false)); } break; case "sms": // Collect users sms numbers require_once $GLOBALS["where_framework"] . "/lib/lib.field.php"; $acl_man =& Docebo::user()->getACLManager(); $field_man = new FieldList(); $arr_sms_recipients = array(); $send_to_field = Get::sett('sms_cell_num_field'); $users_sms = $field_man->showFieldForUserArr($arr_st, array($send_to_field)); $users_info = $acl_man->getUsers($arr_st); while (list(, $user_dett) = each($users_info)) { // recover media setting $idst_user = $user_dett[ACL_INFO_IDST]; if ($users_sms[$idst_user][$send_to_field] != '') { $arr_sms_recipients[$idst_user] = $users_sms[$idst_user][$send_to_field]; } } require_once $GLOBALS["where_framework"] . "/lib/lib.sms.php"; $sms_manager = new SmsManager(); $sms_manager->sendSms($msg, $arr_sms_recipients); break; } if ($sendcomplete) { require_once _base_ . '/lib/lib.upload.php'; if (count($attach)) { foreach ($attach as $file) { sl_open_fileoperations(); sl_unlink(str_replace('../files', '', $file)); sl_close_fileoperations(); } } $url = "index.php?modname=public_newsletter_admin&op=complete"; Util::jump_to($url); } else { $url = "index.php?modname=public_newsletter_admin&op=pause&ipc=" . $ipc . "&cycle=" . ($cycle + 1) . "&id_send=" . $send_id; Util::jump_to($url); } $out->add("</div><br />\n"); $out->add("<form action=\"index.php?modname=public_newsletter_admin&op=newsletter\" method=\"post\">\n"); $out->add("<div class=\"std_block\">\n" . '<input type="hidden" id="authentic_request_pubr" name="authentic_request" value="' . Util::getSignature() . '" />'); $out->add("<input class=\"button\" type=\"submit\" value=\"" . $lang->def("_BACK") . "\" />\n"); $out->add("</div>\n"); $out->add("</form>\n"); }
<?php Validator::extend('zh_mobile', function ($attribute, $value) { return preg_match('/^(\\+?0?86\\-?)?((13\\d|14[57]|15[^4,\\D]|17[678]|18\\d)\\d{8}|170[059]\\d{7})$/', $value); }); Validator::extend('confirm_mobile_not_change', function ($attribute, $value) { $state = SmsManager::retrieveState(); return $state && $state['to'] === $value; }); Validator::extend('verify_code', function ($attribute, $value) { $state = SmsManager::retrieveState(); $maxAttempts = config('laravel-sms.verifyCode.maxAttempts', 0); $attempts = $state['attempts'] + 1; SmsManager::updateState('attempts', $attempts); if ($maxAttempts > 0 && $attempts > $maxAttempts) { return false; } return $state && $state['deadline'] >= time() && $state['code'] === $value; }); Validator::extend('confirm_rule', function ($attribute, $value, $parameters) { $state = SmsManager::retrieveState(); $name = null; if (array_key_exists(0, $parameters)) { $name = $parameters[0]; } elseif ($path = SmsManager::pathOfUrl(URL::previous())) { $name = $path; } return $state && array_key_exists($attribute, $state['usedRule']) && $state['usedRule'][$attribute] === $name; });
/** * //发送短信验证码 * @param $phone * @param $temId 短信模板id * @param array $data 短信参数 */ private function sendTokenMessage($mobile, $smsToken = null, $temId, $deadline_time = 60, $data = array()) { $code = $data[0]; $result = PhpSms::make()->to($mobile)->template($this->smsTemplate, $temId)->data($data)->send(); //$result = 'true'; //设置过期时间 $deadline_time += time(); \SmsManager::storeSentInfo($smsToken, compact('mobile', 'code', 'deadline_time')); // $code = '1314'; return compact('smsToken', 'code'); }
function _sendSms($body, &$sms_recipients, &$users_info = false) { // in the future, if we'll have more than one gateway, smsmarket // will became a class that will include all the smsmarket's methods // and we will just load the class and call $obj->sendsms(..) /* switch(Get::sett('sms_gateway')) { case "smsmarket": { $this->_smsmarket_Send(strip_tags($body), $sms_recipients); } break; } */ require_once _adm_ . '/lib/lib.sms.php'; $sms_manager = new SmsManager(); $sms_manager->sendSms(strip_tags($body), $sms_recipients); }