request->header('token'); $ip = $this->request->ip(); if (empty($token)) { ajax_success(); } $auth = SmsAuthModel::where('token', $token)->find(); if (empty($auth)) { Log::error("无权限token访问,token:{$token},ip:{$ip}"); ajax_success(); } if ($auth['ip'] != $ip) { Log::error("无权限ip访问,token:{$token},ip:{$ip}"); ajax_success(); } //发送短信 $type = input('post.type', ''); $mobile = input('post.mobile', ''); $content = input('post.content', ''); $template_code = input('post.template_code', ''); $template_param = input('post.template_param', ''); if ($type == 'ali') { if (empty($mobile) || empty($template_code) || empty($template_param)) { ajax_error('手机号或模板号或模板参数不能为空!'); } } else { if (empty($mobile) || empty($content)) { ajax_error('手机号或内容不能为空!'); } } $res = SmsService::apiSend($mobile, $content, $type, $template_code, $template_param); //记录日志 $log = [ 'ip' => $ip, 'token' => $token, 'mobile' => $mobile, 'content' => $content, 'template_code' => $template_code, 'template_param' => json_encode($template_param), 'status' => $res['code'] ? 2 : 1, 'error' => $res['code'] ? $res['msg'] : '', ]; SmsLogModel::create($log); //返回结果 if ($res['code']) { ajax_error($res['msg']); } ajax_success(); } }