Exemplo n.º 1
0
 /**
  *发送手机验证码
  * @param $phone  手机号
  * @param $templateid 短信模板编码
  * @param $money 钱数 ---提现时发送提醒--模板2
  * @return array
  */
 public static function ValidatePhone2($phone, $templateid, $money = '')
 {
     //有效时间
     $exptime = 2;
     //20秒发送一次验证码
     $time = time() - 20;
     $count = VerifyCode::find()->andWhere(['type' => 1, 'field' => $phone, 'status' => self::CONFIRM])->orderBy('b_time desc')->one();
     if ($time > $count['b_time']) {
         //生成验证码
         $code = self::verification(6);
         if ($money != "" && $templateid == '2') {
             $code = $money;
         }
         $b_time = time();
         $sms = new VerifyCode();
         $sms->code = $code;
         $sms->field = $phone;
         $sms->type = '1';
         $sms->b_time = $b_time;
         $sms->e_time = $b_time + $exptime * 60;
         $sms->status = Port::CONFIRM;
         $flag = $sms->save();
         if ($flag) {
             $res = \frontend\actions\Port::sendSms2($phone, $code, $exptime, $templateid);
             //发送成功
             if (!$res['errorNum']) {
                 $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
                 return $return;
             } elseif ($res['errorNum'] == '2') {
                 $errmsg = $res['errorMsg'];
                 self::phongLog($phone, $code, Port::ERROR, $errmsg);
                 $return = array('errorNum' => '1', 'errorMsg' => $errmsg, 'data' => null);
                 return $return;
             } else {
                 $errmsg = $res['errorMsg'];
                 self::phongLog($phone, $code, Port::ERROR, $errmsg);
                 $return = array('errorNum' => '1', 'errorMsg' => '短信发送失败', 'data' => null);
                 return $return;
             }
         } else {
             self::phongLog($phone, $code, Port::ERROR, '数据写入失败');
             $return = array('errorNum' => '1', 'errorMsg' => '数据写入失败', 'data' => null);
             return $return;
         }
     } else {
         $return = array('errorNum' => '1', 'errorMsg' => '发送验证码频率过快', 'data' => null);
         return $return;
     }
 }