Example #1
0
 /**
  * {@inheritdoc}
  */
 public function __invoke($next)
 {
     $fromAppId = $this->request['fromAppId'];
     if ($fromAppId) {
         $fromApp = wei()->appRecord()->findOneById($fromAppId);
         $this->wei->env->loadConfigDir('plugins/' . $fromApp['name'] . '/configs');
     }
     return $next();
 }
Example #2
0
 public function testIpTimeLimit()
 {
     wei()->sms->setOption(['maxIpTimes' => 1, 'drivers' => ['logSms']]);
     wei()->sms->resetLimit('13800138001');
     $ret = wei()->sms->send(['mobile' => '13800138000']);
     $this->assertRetSuc($ret);
     $ret = wei()->sms->send(['mobile' => '13800138001']);
     $this->assertRetErr($ret, -3, '很抱歉,您的操作太频繁了,请稍后再试');
 }
Example #3
0
 public function getModelServiceMock($name, $methods = [], array $arguments = [])
 {
     // TODO PHPUnit?空方法会导致其他方法都返回null,
     $methods || ($methods = ['__fake']);
     $model = $this->getServiceMock($name, $methods, $arguments);
     // TODO 通过db服务调用getTableFields会出现错误 Illegal offset type in isset or empty in services/Db.php on line 16
     $fields = wei()->appDb->getTableFields($model->getTable());
     $model->setOption('fields', $fields);
     return $model;
 }
Example #4
0
 public function indexAction($req)
 {
     // 构造基本的查询
     $areas = wei()->appDb('areas')->select('id AS value, name AS label')->asc('id')->andWhere(['parentId' => (int) $req['parentId']]);
     // 排除指定的区域
     if ($req['exceptIds'] && is_array($req['exceptIds'])) {
         $placeholders = array_fill(0, count($req['exceptIds']), '?');
         $areas->andWhere('id NOT IN(' . implode(', ', $placeholders) . ')', $req['exceptIds']);
     }
     $areas = $areas->fetchAll();
     return $this->suc(['data' => $areas]);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function sendTplSms($mobile, $tplId, array $data)
 {
     $param = get_defined_vars();
     // 1. 调用官方类库发送
     $ucpaas = $this->getUcpaas(['accountsid' => $this->accountSid, 'token' => $this->accountToken]);
     $response = $ucpaas->templateSMS($this->appId, $mobile, $tplId, implode(',', $data));
     $result = json_decode($response, true);
     // 2. 处理发送结果
     if ($result != null && $result['resp']['respCode'] == '000000') {
         return ['code' => 1, 'message' => '发送成功'];
     }
     wei()->logger->alert('Ucpaas短信发送失败', ['param' => $param, 'result' => $result, 'response' => $response]);
     return ['code' => -1, 'message' => '发送失败'];
 }
Example #6
0
 public function indexAction($req)
 {
     // 支持编号和名称两种参数
     if (!is_numeric($req['parentId'])) {
         $parentId = wei()->appDb('regions')->select('id')->fetchColumn(['name' => $req['parentId']]);
     } else {
         $parentId = (int) $req['parentId'];
     }
     // 构造基本的查询
     $regions = wei()->appDb('regions')->select('id AS value, name AS label')->desc('sort')->andWhere(['parentId' => $parentId]);
     // 排除指定的区域
     if ($req['exceptIds'] && is_array($req['exceptIds'])) {
         $placeholders = array_fill(0, count($req['exceptIds']), '?');
         $regions->andWhere('id NOT IN(' . implode(', ', $placeholders) . ')', $req['exceptIds']);
     }
     $regions = $regions->fetchAll();
     return $this->suc(['data' => $regions]);
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function sendContentSms($mobile, $content)
 {
     // 1. 调用接口
     $http = wei()->http(['url' => 'http://sms.bechtech.cn/Api/send/data/json', 'dataType' => 'json', 'throwException' => false, 'data' => ['accesskey' => $this->accessKey, 'secretkey' => $this->secretKey, 'mobile' => $mobile, 'content' => urlencode($content)]]);
     // 2. 记录日志
     $res = $http->getResponse();
     $msg = '短信:' . $content . ' 结果:' . var_export($http->isSuccess(), true) . ' code: ' . var_export($res, true);
     wei()->logger->info($msg);
     // 3. 处理HTTP请求失败
     if (!$http->isSuccess()) {
         return ['code' => -1, 'message' => '很抱歉,系统繁忙,请稍后再试'];
     }
     // 4. 处理业务结果
     if ('01' == $res['result']) {
         return ['code' => 1, 'message' => '发送成功'];
     } else {
         return ['code' => -$res['result'], 'message' => $this->messages[$res['result']] ?: '系统繁忙'];
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function __invoke($next)
 {
     // 1. 游客页面一律不用登录
     $page = $this->app->getControllerAction();
     if ($this->isBelongPages($page, $this->guestPages)) {
         return $next();
     }
     // 2. 触发用户初始化事件,允许插件初始化用户
     $res = wei()->event->until('userInit');
     /** @var \Wei\Response $res */
     if ($res) {
         $this->logger->info('Got response after user init, response header is', $res->getHeaderString());
         return $res;
     }
     // 3. 如果是后台页面,验证登录态和用户权限
     $isLogin = wei()->curUser->isLogin();
     if ($this->isAdminPage()) {
         // 如果未登录,跳转到登录页面
         if (!$isLogin) {
             return $this->redirectLogin($this->getAdminLoginUrl());
         }
         // 后台登录无权限,跳转到登录页面,并展示提示
         if (!wei()->curUser->isAdmin()) {
             return $this->redirectLogin($this->getAdminLoginUrl('很抱歉,您没有权限查看当前页面'));
         }
         if (!$this->isBelongPages($page, $this->adminGuestPages)) {
             // 触发后台权限检查事件
             $res = wei()->event->until('adminAuth', [$page, wei()->curUser]);
             if ($res) {
                 return $res;
             }
         }
     }
     // 3. 跳转到登录页面
     if (!$isLogin) {
         return $this->redirectLogin($this->url('users/login'));
     }
     return $next();
 }
Example #9
0
 public function __invoke($next)
 {
     if (!$this->validUsers) {
         return $this->responseNotAuthorized();
     }
     $username = $this->request->getServer('PHP_AUTH_USER');
     $password = $this->request->getServer('PHP_AUTH_PW');
     // 检查用户名是否有效
     if (!in_array($username, $this->validUsers)) {
         return $this->responseNotAuthorized();
     }
     // 查找用户
     $user = wei()->user()->find(['username' => $username]);
     if (!$user) {
         return $this->responseNotAuthorized();
     }
     // 校验密码
     $validated = $user->verifyPassword($password);
     if (!$validated) {
         return $this->responseNotAuthorized();
     }
     return $next();
 }
Example #10
0
 public function testSetGetUcpaas()
 {
     wei()->ucpaas->setUcpaas(null);
     $ucpaas = wei()->ucpaas->getUcpaas(['token' => '']);
     $this->assertInstanceOf('Ucpaas', $ucpaas);
 }
Example #11
0
 public function testGetOneByIdButPluginNotExists()
 {
     $this->setExpectedException('Exception', 'Plugin "not-exists" not found', 404);
     wei()->plugin->getOneById('not-exists');
 }
Example #12
0
 /**
  * Repo: 根据应用ID获取应用数据库名称
  *
  * @param int $id
  * @return string
  */
 public function getDbName($id)
 {
     if (!$this->dbNames[$id]) {
         $record = wei()->appRecord()->findById($id);
         $this->dbNames[$id] = $record['name'];
     }
     return $this->dbNames[$id];
 }
Example #13
0
 /**
  * 从数据库中查找用户加载到当前记录中
  */
 protected function loadDbUser()
 {
     if ($this->isLoaded() || !$this->isLogin()) {
         return;
     }
     $id = $this['id'];
     $user = wei()->user()->cache()->tags(false)->setCacheKey($this->getRecordCacheKey($id))->findOrInitById($id);
     $this->loadRecordData($user);
 }
Example #14
0
File: Sms.php Project: miaoxing/sms
 /**
  * 重置指定手机的频率限制
  *
  * @param string $mobile
  * @return $this
  */
 public function resetLimit($mobile)
 {
     wei()->counter->remove($this->getMobileKey($mobile));
     wei()->counter->remove($this->getIpKey());
     return $this;
 }
Example #15
0
 /**
  * @param array|\ArrayAccess $req
  * @return array
  */
 public function updatePassword($req)
 {
     // 1. 校验
     $validator = wei()->validate(['data' => $req, 'rules' => ['oldPassword' => [], 'password' => ['minLength' => 6], 'passwordConfirm' => ['equalTo' => $req['password']]], 'names' => ['oldPassword' => '旧密码', 'password' => '新密码', 'passwordConfirm' => '重复密码'], 'messages' => ['passwordConfirm' => ['equalTo' => '两次输入的密码不相等']]]);
     if (!$validator->isValid()) {
         return $this->err($validator->getFirstMessage());
     }
     // 2. 验证旧密码
     if ($this['password'] && $this['salt']) {
         $isSuc = $this->verifyPassword($req['oldPassword']);
         if (!$isSuc) {
             return $this->err('旧密码输入错误!请重新输入');
         }
     }
     // 3. 更新新密码
     $this->setPlainPassword($req['password']);
     $this->save();
     return $this->suc();
 }
Example #16
0
use Wei\Db;
require 'vendor/autoload.php';
$files = ['config.php', 'tests/config.php', 'tests/config-local.php'];
// Add configuration file for CI
foreach (['TRAVIS', 'WERCKER'] as $ci) {
    if (getenv($ci)) {
        $files[] = 'config-' . strtolower($ci) . '.php';
    }
}
$config = [];
foreach ($files as $file) {
    if (stream_resolve_include_path($file)) {
        $config = array_replace_recursive($config, require $file);
    }
}
$wei = wei($config);
// 初始化数据库
$db = $wei->db;
$db->executeUpdate('CREATE DATABASE IF NOT EXISTS app;');
$db->useDb('app');
if (isset($config['test']['skipSql']) && $config['test']['skipSql']) {
    return;
}
// TODO 待更新为migration模式?
// 1. 获取各插件的SQL文件
$sqlFiles = [];
foreach ($wei->plugin->getAll() as $plugin) {
    $basePath = $plugin->getBasePath();
    $sqlFiles = array_merge($sqlFiles, glob(($basePath ?: '.') . '/docs/*.sql'));
}
// 2. 逐个运行
Example #17
0
 public function eventsAction()
 {
     return $this->suc(['data' => wei()->plugin->getEvents()]);
 }
Example #18
0
<?php

namespace miaoxing\plugin\docs {
    /**
     * @property    \Miaoxing\Plugin\Service\Tester $tester
     * @method      \Miaoxing\Plugin\Service\Tester tester()
     */
    class AutoComplete
    {
    }
}
namespace {
    /** @var \Miaoxing\Plugin\Service\Plugin $plugin */
    $plugin = wei()->plugin;
    /** @var \Wei\Event $event */
    $event = wei()->event;
    /**
     * @return \miaoxing\plugin\docs\AutoComplete
     */
    function wei()
    {
    }
}
Example #19
0
 public function testSendTplSms()
 {
     $ret = wei()->bech->sendTplSms(13800138000, 123, []);
     $this->assertRetErr($ret, -1, '不支持模板短信');
 }
 /**
  * 运行任务
  *
  * @param string $name
  * @param array $data
  * @return array
  */
 protected function runJob($name, array $data = [])
 {
     $parts = explode('/', $name);
     $action = array_pop($parts);
     $controller = implode('/', $parts);
     return wei()->tester()->login(1)->controller($controller)->action($action)->request($data)->json()->exec()->response();
 }
Example #21
0
 /**
  * {@inheritdoc}
  */
 protected function loadData($offset)
 {
     if (!$this->loaded && !$this->isNew) {
         if ($this->table !== 'user') {
             wei()->statsD->increment('record.loadData.' . $this->table);
         }
     }
     parent::loadData($offset);
 }
Example #22
0
 /**
  * 获取客户端唯一标识
  *
  * @return string
  */
 public function getIdentifier()
 {
     return wei()->curUser['id'] ?: $this->request->getServer('REMOTE_ADDR');
 }
Example #23
0
 public function testSendContentSms()
 {
     $ret = wei()->logSms->sendContentSms(13800138000, 'test');
     $this->assertRetSuc($ret);
 }