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', ''); if (empty($mobile) || empty($content)) { ajax_error('手机号或内容不能为空!'); } $res = SmsService::apiSend($mobile, $content, $type); //记录日志 $log = [ 'ip' => $ip, 'token' => $token, 'mobile' => $mobile, 'content' => $content, 'status' => $res['code'] ? 2 : 1, 'error' => $res['code'] ? $res['msg'] : '', ]; SmsLogModel::create($log); //返回结果 if ($res['code']) { ajax_error($res['msg']); } ajax_success(); } }