From 8624607a2b66509cefa675f3b6588966e6ae09b0 Mon Sep 17 00:00:00 2001 From: chengkun <chengkun@ishangstudy.com> Date: Fri, 30 May 2025 14:40:01 +0800 Subject: [PATCH] 提交 --- app/model/notice.model.php | 58 ++++++++++++++++++++++++++++++---------------------------- 1 files changed, 30 insertions(+), 28 deletions(-) diff --git a/app/model/notice.model.php b/app/model/notice.model.php index d9a1015..b77286c 100644 --- a/app/model/notice.model.php +++ b/app/model/notice.model.php @@ -307,9 +307,10 @@ return array('status' => -1, 'msg' => '该手机号已被禁止使用'); } } - if (!$this->_isKey('content', $data) || $data['content'] == '') { - return array('status' => -1, 'msg' => '短信内容为空'); - } + +// if (!$this->_isKey('content', $data) || $data['content'] == '') { +// return array('status' => -1, 'msg' => '短信内容为空'); +// } //发送短信 $row = array( @@ -319,7 +320,7 @@ 'sy_sms_sign_name' => $this->config['sy_sms_sign_name'], 'template_id' => $data['template_id'], 'phone' => $data['mobile'], - 'code' => $data['code'], + 'template_param' => $data['template_param'], ); $location = ''; @@ -425,11 +426,11 @@ if (isset($tpl['status'])) { return $tpl; } - $content = $tpl['content']; +// $content = $tpl['content']; $template_id = $tpl['template_id']; } - - $data['content'] = $content; + +// $data['content'] = $content; $data['template_id'] = $template_id; return $this->sendSMS($data); } @@ -503,19 +504,19 @@ /** * @desc 短信验证码时效性 - * @param array $data + * @param string $data * @return boolean */ - public function checkTime($data) { + public function checkTime($data = 0) { $cert_validity = $this->config['moblie_codetime'] * 60; // 验证码有效时间 + if (!$data) { + return false; + } $time = time(); - $ctime = bcsub($time, $data); - + $ctime = round($time - intval($data)); if ($ctime <= $cert_validity) { - return true; } else { - return false; } } @@ -535,7 +536,7 @@ $time = time(); $overtime = $time - $validity; $today = strtotime('today'); - $code = gt_Generate_code($length); //验证码 + $code = strval(gt_Generate_code($length)); //验证码 $lastSend = []; $result = []; if ($kind == 'msg') { @@ -604,7 +605,7 @@ if ($ipSendNum >= $this->config['ip_msgnum']) { return array('error' => 104, 'msg' => '同一IP一天最多发送' . $this->config['ip_msgnum'] . '条'); } - $result = $this->sendType($sended, $type, $code, 'msg', $user, $port); + $result = $this->sendType($sended, $type, [$code], 'msg', $user, $port); } elseif ($kind == 'email') { if (!CheckRegEmail($sended)) { @@ -700,12 +701,12 @@ private function sendType($sended, $type, $code, $kind = 'msg', $user = array(), $port = null) { $finfo = $this->forsend($user); //用户信息 $data = array( - 'uid' => $finfo['uid'], - 'username' => $finfo['name'], - 'cuid' => $finfo['cuid'], - 'cname' => $finfo['cname'], - 'type' => $type, - 'code' => $code + 'uid' => $finfo['uid'], + 'username' => $finfo['name'], + 'cuid' => $finfo['cuid'], + 'cname' => $finfo['cname'], + 'type' => $type, + 'template_param' => $code ); $result = []; if ($kind == 'msg') { @@ -826,16 +827,17 @@ $version = "2021-01-11"; $action = "SendSms"; - //////数字转字符串 ////// $params = [ - 'PhoneNumberSet' => ['+86' . $data['phone']], - 'SmsSdkAppId' => $data['sy_sms_sdk_app_id'], - 'TemplateId' => $data['template_id'], - 'SignName' => $data['sy_sms_sign_name'], - 'TemplateParamSet' => [strval($data['code'])] + 'PhoneNumberSet' => ['+86' . $data['phone']], + 'SmsSdkAppId' => $data['sy_sms_sdk_app_id'], + 'TemplateId' => $data['template_id'], + 'SignName' => $data['sy_sms_sign_name'], ]; + if ($data['template_param'] && is_array($data['template_param'])) { + $params['TemplateParamSet'] = $data['template_param'];// 短信模板中的变量 + } + $payload = json_encode($params, JSON_UNESCAPED_UNICODE); - var_dump($payload); $endpoint = "https://sms.tencentcloudapi.com"; $algorithm = "TC3-HMAC-SHA256"; $timestamp = time(); -- Gitblit v1.9.0