1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\api\controller;
- use app\api\ApiBaseController;
- use app\common\model\SettingModel;
- use app\common\model\SmsAuthModel;
- use app\common\model\SmsLogModel;
- use app\common\service\SmsService;
- use think\facade\Log;
- class Sms extends ApiBaseController
- {
- public function send()
- {
- //权限校验
- $token = $this->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();
- }
- }
|