コード例 #1
0
ファイル: VerifyTrigger.php プロジェクト: kukujiabo/linpai
 private function verifyRegister()
 {
     $mobile = $this->info['mobile'];
     $code = $this->info['code'];
     $verify = RegisterVerify::where('mobile', '=', $mobile)->where('verify_code', '=', $code)->where('active', '=', 1)->first();
     if (empty($verify->id)) {
         return ['code' => 0, 'type' => 'not_found'];
     }
     $now = strtotime(date('Y-m-d H:i:s'));
     $sentTime = strtotime($verify->deliver_at);
     $duration = ceil(($now - $sentTime) / 60);
     /*
      * 过期
      */
     if ($duration > 30) {
         $verify->success = 0;
         $verify->active = 0;
         $verify->save();
         return ['code' => 0, 'type' => 'delay'];
     } else {
         $verify->success = 1;
         $verify->active = 0;
         $verify->save();
         return ['code' => 1];
     }
 }
コード例 #2
0
ファイル: TriggerSms.php プロジェクト: kukujiabo/linpai
 private function registerSms($mobile)
 {
     /*
      * 获取之前的验证条目
      */
     $verify = RegisterVerify::where('mobile', '=', $mobile)->where('active', '=', 1)->first();
     /*
      * 如果之前存在验证条目,则将其置为无效
      */
     if (!empty($verify->active)) {
         $verify->active = 0;
         $verify->save();
     }
     /*
      * 生成验证码
      */
     $vcode = rand(100000, 999999);
     $post_data = array('appid' => $this->appid, 'signature' => $this->signature, 'project' => $this->pro_register, 'vars' => "{ \"verify_code\": \"{$vcode}\"}", 'to' => $mobile);
     /*
      * 纪录验证码
      */
     $rv = RegisterVerify::create(['mobile' => $mobile, 'verify_code' => $vcode, 'success' => 0, 'deliver_at' => date('Y-m-d H:i:s'), 'active' => 1]);
     /*
      * todo: 如果纪录失败
      */
     if (empty($rv)) {
     }
     /*
      * 短信发送
      */
     return $this->send('post', $mobile, $post_data);
 }