Exemple #1
0
 /**
  * 短信验证码
  * @param array $params
  * @return array
  */
 public static function smsVerification($params)
 {
     $cur_time = time();
     //验证数据
     $validation = static::validateData($params);
     if (!$validation) {
         return Common::result(500, '请求数据不规范!', []);
     }
     //一天内次数设置
     $day_time = static::getCache($params['userid'], 'day_time');
     if (!$day_time || date('Ymd', $day_time) != date('Ymd', $cur_time)) {
         static::setCache($params['userid'], 'day_time', $cur_time);
         static::setCache($params['userid'], 'day_num', 0);
     }
     $day_num = static::getCache($params['userid'], 'day_num') ?: 0;
     if ($day_num >= 5) {
         return Common::result(500, '当天请求次数超过5次!', []);
     }
     //60秒内禁止提交
     $sms_time = static::getCache($params['userid'], 'sms_time');
     if ($sms_time && $cur_time - $sms_time < 60) {
         return Common::result(500, '60秒内不要重复请求!', array());
     }
     //生成验证码、发送给用户、后台存储验证码(跨域session不可用)
     $code = rand(100000, 999999);
     $content = '您正在绑定手机号,校验码' . $code . ',请于30分钟内输入,工作人员不会索取,请勿泄漏';
     $mobile = Sms::send($params['mobile'], $content);
     static::setCache($params['userid'], 'sms_verification_code', $code);
     static::setCache($params['userid'], 'sms_time', $cur_time);
     static::setCache($params['userid'], 'day_num', $day_num++);
     return Common::result(200, '发送成功!', ['sms_time' => $cur_time]);
 }
Exemple #2
0
 public static function upload($params)
 {
     if (isset($params['userid']) && isset($params['src'])) {
         $res = self::save($params);
         if ($res) {
             return Common::result(200, '图片上传成功!', ['image_url' => $res]);
         }
     }
     return Common::result(500, '图片上传失败!', []);
 }
 public static function add($params)
 {
     $userid = intval($params['userid']);
     $username = $params['username'];
     $data = ['surgets' => 4, 'content' => $params['content'], 'contact' => $params['contact'], 'userid' => $params['userid'], 'username' => $params['username'], 'createtime' => time()];
     $feebback = new d_feedback();
     $res = $feebback->feedbackAdd($data);
     $code = $res ? 200 : 500;
     $message = $res ? '意见反馈成功!' : '意见反馈失败,请再次提交!';
     return Common::result($code, $message, array());
 }