sys_config('sms_account'), 'sms_token' => sys_config('sms_token'), 'site_url' => sys_config('site_url') ]); $res = $sms->send($phone, $template, $data); if ($res === false) { $errorSmg = $sms->getError(); Log::info($logMsg ?? $errorSmg); return $errorSmg; } else { SmsRecord::sendRecord($phone, $res['data']['content'], $res['data']['template'], $res['data']['id']); } return true; } else { return false; } } /** * 发送短信 * @param string $phone 手机号码 * @param array $data 模板替换内容 * @param string $template 模板编号 * @return bool|string * @throws DataNotFoundException * @throws ModelNotFoundException */ public static function AliSend(string $phone, array $data, string $template, $site_id = 0) { try { $sms = new AlismsService(sys_config('sms_account', '', true), sys_config('sms_token', '', true)); $res = $sms->setAction('SendSms')->setOptions([ 'PhoneNumbers' => $phone, 'SignName' => '六牛', 'TemplateCode' => Config::get('sms.stores.aliyun.template_id.' . $template, 'sms.stores.aliyun.template_id.DEFAULT'), 'TemplateParam' => json_encode($data), ])->execute(); // var_dump($res); // exit; if ($res['Code'] != 'OK') { return $res['Message']; } else { SmsRecord::sendRecord($phone, $data['code'], $template, '', $res['BizId'], $site_id); } return true; } catch (Exception $exception) { // Log::info($exception->getMessage()); return $exception->getMessage(); } } /** * 发送短信 * @param string $phone 手机号码 * @param array $data 模板替换内容 * @param string $template 模板编号 * @return bool|string * @throws DataNotFoundException * @throws ModelNotFoundException */ public static function NewSmsSend(string $phone, array $data, string $template, $site_id = 0) { try { $res = ZjSMSServerService::send($phone, $data); // var_dump($res); // exit; if ($res['status'] != '200') { return $res['msg']; } else { SmsRecord::sendRecord($phone, $data['code'], $template, '', '', $site_id); } return true; } catch (Exception $exception) { // Log::info($exception->getMessage()); return $exception->getMessage(); } } /** * 发送短信 * @param string $phone 手机号码 * @param array $data 模板替换内容 * @param string $template 模板编号 * @return bool|string * @throws DataNotFoundException * @throws ModelNotFoundException */ public static function EmailSend(string $phone, array $data, $site_id) { $mail = new PHPMailer(true); try { $mail->CharSet = $mail::CHARSET_UTF8; //Server settings // $mail->SMTPDebug = SMTP::DEBUG_SERVER; $mail->isSMTP(); $mail->Host = 'smtp.163.com'; $mail->SMTPAuth = true; $mail->Username = 'mybotao@163.com'; $mail->Password = 'CBVRANJUYSJLYQVT'; $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; $mail->Port = 465; //Recipients $mail->setFrom('mybotao@163.com', '星拼乐'); $mail->addAddress($phone); //Add a recipient //Content $mail->isHTML(true); //Set email format to HTML $mail->Subject = '【星拼乐】验证码'; $mail->Body = '您的验证码为:' . $data['code'] . ',若非本人操作,请勿泄露。验证码30分钟内有效。'; $res = $mail->send(); if ($res) { SmsRecord::sendRecord($phone, $data['code'], 'DEFAULT', '', '', $site_id); return true; } else return $mail->ErrorInfo; } catch (\PHPMailer\PHPMailer\Exception $exception) { // Log::info($exception->getMessage()); return $exception->getMessage(); } } }