Example #1
0
 /**
  * 绑定用户手机,发送验证码
  * PUT /user/1/phone {phone:"13888888888"}
  * @method GET_infoAction
  * @param  integer        $id [description]
  * @author NewFuture
  */
 public function POST_phoneAction($id = 0)
 {
     $id = $this->auth($id);
     $response['status'] = 0;
     if (!Input::post('phone', $phone, 'phone')) {
         $response['info'] = '手机号码无效';
     } elseif (UserModel::getByPhone($phone)) {
         $response['info'] = '已经绑定过用户';
     } elseif (!Safe::checkTry('bind_phone_' . $id)) {
         $response['info'] = '发送次数过多,稍后重试';
     } else {
         /*手机有效,发送验证码*/
         $code = Random::number(6);
         Session::set('code_phone', [$code => $phone]);
         if (Sms::bind($phone, $code)) {
             $response['status'] = 1;
             $response['info'] = '发送成功[最多可重发5次]';
         } else {
             $response['info'] = '短信发送出错[最多可重发5次]';
         }
     }
     $this->response = $response;
 }