Example #1
0
 public function actionSendcode()
 {
     if (!isset($_POST['CellPhone'])) {
         echo '请输入手机号。';
         exit;
     }
     $phone = $_POST['CellPhone'];
     //60秒发送一次验证码
     $time = time() - 60;
     $count = VerifyCode::find()->andWhere(['type' => 1, 'field' => $phone, 'status' => -1])->orderBy('b_time desc')->one();
     if ($time < $count['b_time']) {
         echo '请勿重复点击';
         exit;
     }
     try {
         $result = Port::ValidatePhone($phone);
         if ($result) {
             echo '验证码已发送,请注意查收。';
             exit;
         }
     } catch (ErrorException $ex) {
         echo $ex->getMessage();
         exit;
     }
 }
 public function actionDorecharge()
 {
     $uid = Yii::$app->user->id;
     if ($_POST) {
         //用户充值操作
         if (isset($_POST['code']) && isset($_POST['ticket']) && isset($_POST['out_trade_no'])) {
             $validate_code = $_POST['code'];
             $out_trade_no = $_POST['out_trade_no'];
             $ticket = $_POST['ticket'];
             try {
                 $info = sinapay::rechargeComfirm($out_trade_no, $ticket, $validate_code);
                 if ($info['errorNum'] == 0) {
                     echo "充值成功";
                     exit;
                 } elseif ($info['errorNum'] != 0) {
                     echo $info['errorMsg'];
                     exit;
                 }
             } catch (ErrorException $e) {
                 echo $e->getMessage();
                 exit;
             }
         } elseif (isset($_POST['money'])) {
             $phone = Info::find()->andWhere(['member_id' => $uid])->one()->bank_card_phone;
             //60秒发送一次验证码
             $time = time() - 60;
             $count = VerifyCode::find()->andWhere(['type' => 1, 'field' => $phone, 'status' => -1])->orderBy('b_time desc')->one();
             if ($time < $count['b_time']) {
                 $return = array('errorNum' => '1', 'errorMsg' => '请勿重复点击', 'data' => null);
                 echo json_encode($return);
                 exit;
             }
             $money = $_POST['money'];
             //充值金额
             try {
                 $info = sinapay::recharge($uid, $money);
                 echo json_encode($info);
                 exit;
             } catch (ErrorException $e) {
                 echo $e->getMessage();
                 exit;
             }
         } else {
             echo '您提交的信息不完整';
             exit;
         }
     }
 }
Example #3
0
 /**
  * 验证手机验证码
  * @param $phone 手机号
  * @param $code 验证码
  * @return mixed
  * @throws ErrorException
  */
 public static function checkPhnoe($phone, $code)
 {
     $VerifyCode = VerifyCode::find()->where(['field' => $phone, 'status' => Port::CONFIRM])->orderBy('b_time desc')->one();
     if ($VerifyCode) {
         $phoneCode = $VerifyCode->code;
         $endTime = $VerifyCode->e_time;
         $now = time();
         if ($now < $endTime) {
             if ($phoneCode == $code) {
                 $VerifyCode->status = Port::SUCCEED;
                 $VerifyCode->remark = "验证通过";
                 $res = $VerifyCode->save();
                 if ($res) {
                     return true;
                 } else {
                     self::phongLog($phone, $code, Port::CONFIRM, '发送成功,数据保存异常');
                     throw new ErrorException("数据保存异常");
                 }
             } else {
                 //                  self::phongLog($phone,$code,Port::CONFIRM,'发送成功,验证码错误');
                 throw new ErrorException("验证码错误");
             }
         } else {
             self::phongLog($phone, $code, Port::ERROR, '发送成功,验证码超时');
             throw new ErrorException('验证码超时');
         }
     } else {
         throw new ErrorException("请重新获取");
     }
 }
Example #4
0
 /**
  * 验证手机验证码
  * @param $phone 手机号
  * @param $code 验证码
  * @return array
  */
 public static function checkPhnoe($phone, $code)
 {
     //查找最后一条生效的验证码
     $VerifyCode = VerifyCode::find()->where(['field' => $phone, 'status' => Port::CONFIRM])->orderBy('b_time desc')->one();
     if ($VerifyCode) {
         $phoneCode = $VerifyCode->code;
         $endTime = $VerifyCode->e_time;
         $now = time();
         if ($now < $endTime) {
             if ($phoneCode == $code) {
                 $VerifyCode->status = Port::SUCCEED;
                 $VerifyCode->remark = "验证通过";
                 $res = $VerifyCode->save();
                 if ($res) {
                     $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
                     return $return;
                 } else {
                     self::phongLog($phone, $code, Port::CONFIRM, '发送成功,数据保存异常');
                     $return = array('errorNum' => '1', 'errorMsg' => '数据保存异常', 'data' => null);
                     return $return;
                 }
             } else {
                 //                    self::phongLog($phone,$code,Port::CONFIRM,'验证码错误');
                 $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;
     }
 }