Exemple #1
0
 function action_update()
 {
     $id = Utils::I("id");
     $row = self::getSaveRow();
     self::_db()->update("small", $row, array("id" => $id));
     return array("id" => $id);
 }
Exemple #2
0
 function action_upload()
 {
     if (empty($_FILES)) {
         _throw("请选择上传文件");
     }
     $file_path = $_FILES['file']['tmp_name'];
     $file_name = "upload/img/" . date("YmdHis") . "/" . rand(10000, 99999) . "/" . $_FILES['file']['name'];
     $res = Model_Tools_Qiniu::upload_file($file_path, $file_name);
     $url = Model_Tools_Qiniu::get_res_url($res);
     self::_debug($url);
     if (Utils::I("simditor")) {
         echo json_encode(array("success" => true, "msg" => "ok", "file_path" => $url));
         exit;
     } else {
         return array("url" => $url);
     }
     //self::_debug($_FILES);
     //self::_debug($_REQUEST);
 }
Exemple #3
0
<?php

use PtPHP\Utils;
use PtPHP\Logger;
include_once __DIR__ . "/init.php";
$result = null;
$error_code = 0;
try {
    $controller = Utils::I("controller");
    if (!$controller) {
        _throw("controller is null", 9001);
    }
    if (!preg_match("/^[a-zA-Z]+[a-zA-Z0-9\\/]+?\$/", $controller)) {
        _throw("controller: {$controller} is invalid", 9001);
    }
    $action = Utils::I("action");
    if (!$action) {
        _throw("action is null", 9002);
    }
    if (!preg_match("/^[a-zA-Z]+[A-Za-z0-9_]+?\$/", $action)) {
        _throw("action:" . $action . " is invalid", 9001);
    }
    $c_t = explode("/", $controller);
    $controller = "Controller";
    foreach ($c_t as $i) {
        if ($i) {
            $controller .= "\\" . ucfirst(strtolower($i));
        }
    }
    if (!class_exists($controller)) {
        _throw($controller . " is no exsits", 9003);
Exemple #4
0
 /**
  * 微信绑定手机号
  * @return string
  */
 function action_wechat_bind_mobile()
 {
     Model_Session::session_start(true);
     $mobile = Utils::I("mobile");
     $nick_name = Utils::I("nick_name");
     $captcha = Utils::I("captcha");
     $oauth_id = Utils::I("oauth_id");
     self::_debug(array($oauth_id));
     $safe_token = Utils::I(Model_Auth::ENCRYPT_FIELD_NAME);
     if (!$safe_token) {
         _throw("safe_token is null");
     }
     //Model_Auth::login_safe($username,$password,$safe_token);
     $encrypt_data = self::_redis()->get(Model_Auth::ENCRYPT_CACEH_KEY . $safe_token);
     if (empty($encrypt_data)) {
         _throw("加密信息已过期");
     }
     $encrypt_data = json_decode($encrypt_data);
     $private_key = $encrypt_data->private_key;
     $reqData = array('mobile' => $mobile, 'captcha' => $captcha, 'nick_name' => $nick_name);
     $reqData = Safe::decrypt($reqData, $private_key);
     self::_debug($reqData);
     if (!$reqData) {
         _throw("解密失败");
     }
     $mobile = $reqData['mobile'];
     $nick_name = $reqData['nick_name'];
     $captcha = $reqData['captcha'];
     if (!Utils::is_mobile($mobile)) {
         _throw("手机号不合法");
     }
     $key = Controller_Captcha::get_captcha_session_key($mobile, "wechat_bind_mobile");
     self::_debug($key);
     if (empty($_SESSION[$key])) {
         _throw("验证码已过期");
     }
     $_captcha_session = $_SESSION[$key];
     self::_debug($_captcha_session);
     list($_captcha, $time) = explode("|", $_captcha_session);
     if (time() - $time > 60 * 60 * 5) {
         unset($_SESSION[$key]);
         _throw("验证码已过期");
     }
     self::_debug($_captcha_session);
     if ($captcha != $_captcha) {
         _throw("验证码不正确");
     }
     if (!($user_id = Model_User::check_user_exsits($mobile))) {
         $user = array("password" => null, "mobile" => $mobile, "nick_name" => $nick_name, "add_time" => Utils::date_time_now(), "email" => null);
         self::_debug("create user");
         self::_debug($user);
         $user_id = self::_db()->insert(Model_User::TABLE, $user);
     }
     self::_debug(array("update", Model_Wechat_User::TABLE, $user_id, $oauth_id));
     self::_db()->update(Model_Wechat_User::TABLE, array("uid" => $user_id), array("id" => $oauth_id));
     $wx_auth_info = $_SESSION['wx_auth_info'];
     $wx_auth_info['uid'] = $user_id;
     $_SESSION['wx_auth_info'] = $wx_auth_info;
     self::_debug($user_id);
     Model_Admin_Auth::set_login_session($user_id);
     //set login
     unset($_SESSION[$key]);
     Controller_Captcha::clear_status_key("wechat_bind_mobile");
     $redirect = self::get_redirect_url();
     return array("message" => "绑定成功", "redirect" => $redirect);
 }