<?php
 namespace Module\Vendor\Sms; use Module\Vendor\Sms\Service\AliyunSmsService; use Module\Vendor\SoftApi\SoftApi; use ModStart\Core\Input\Response; class SmsUtil { public static function calcNumber($content) { return ceil(mb_strlen($content) / 67); } public static function parseContent($template, $values = array()) { $param1 = []; $param2 = []; foreach ($values as $k => $v) { $param1[] = '{' . $k . '}'; $param2[] = $v; } return str_replace($param1, $param2, $template); } public static function send($phone, $type, $templateData = []) { if (!modstart_config('systemSmsEnable')) { return Response::generate(-1, '短信发送未开启'); } $senderFunc = modstart_config('systemSmsSender') . 'Execute'; return self::$senderFunc($phone, $type, $templateData); } private static function softApiExecute($phone, $type, $templateData = []) { $api = SoftApi::instance(modstart_config('systemSmsSender_softApi_appId'), modstart_config('systemSmsSender_softApi_appSecret')); switch ($type) { case SmsTemplate::VERIFY: return $api->smsSend($phone, modstart_config('systemSmsSender_softApi_verify_templateId'), [ 'code' => $templateData['code'] ]); } return Response::generate(-1, '错误'); } private static function aliyunExecute($phone, $type, $templateData = []) { $driver = new AliyunSmsService( modstart_config('systemSmsSender_aliyun_accessKeyId'), modstart_config('systemSmsSender_aliyun_accessKeySecret'), modstart_config('systemSmsSender_aliyun_signName') ); switch ($type) { case SmsTemplate::VERIFY: return $driver->send($phone, modstart_config('systemSmsSender_aliyun_verify_templateId'), [ 'code' => $templateData['code'] ]); } } } 