| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | 
							- <?php
 
- namespace app\api\controller;
 
- use ali\AliyunSMS;
 
- use app\api\ApiBaseController;
 
- 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', '');
 
-         $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();
 
-     }
 
- }
 
 
  |