123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- namespace loyalsoft;
- include_once __DIR__ . '/AppServer.php';
- /**
- * Description of TestServer
- * UT 测试
- * @author jgao
- */
- class TestServer
- {
- //put your code here
- /**
- * 入口函数专用测试
- * @param type $req
- */
- static public function testApi($req)
- {
- DebugHelper::debug($req);
- $app = new AppServer();
- $ret = $app->api(new Req($req));
- DebugHelper::debug($ret);
- }
- /**
- * 运行环境自检:
- * PHP 版本,扩展模块
- * redis操作性
- * sqldb操作性
- */
- static function selfTest()
- {
- // 检查gameOnline状态
- echoLine("GAME_ONLINE := " . (GAME_ONLINE ? "True" : "False"));
- // 检查phpversion
- echoLine('PHP version: ' . PHP_VERSION);
- if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) {
- echo ('<font color="red">This code request at least PHP version ' #
- . REQUIRED_PHP_VERSION . '. </font><br/>\n');
- }
- echoLine("loaded extensions:"); // 已加载的扩展模块信息
- echoLine(var_export(get_loaded_extensions(), true)); # 打印
- $required = array('iconv', 'json', 'mcrypt', 'SPL', 'pcre', # # 打算做个检查推荐模块的逻辑呢
- 'Reflection', 'session', 'zip', 'zlib', 'PDO', 'openssl',
- 'curl', 'mbstring', 'mysqli', 'pdo_mysql', 'redis',
- 'sockets', 'xdebug');
- // 检查redis地址, 可操作性
- if (gMem()->set('test-selftest', "self cheking...")) {
- echoLine("Redis check ok!");
- } else {
- echoLine("Redis check failed!");
- echoLine(var_export(config::Inst()->nosql, true));
- }
- // 检查MySQL地址, 可操作性
- if (daoInst()->tableExist('tab_token_gift')) {
- echoLine("sqldb test ok");
- } else {
- echoLine("sqldb test failed!");
- echoLine(var_export(config::Inst()->paydb), true);
- }
- }
- // rsa加密传输
- public static function testMyRsaCommunication()
- {
- require_once 'OpenSSLVerify.php'; #Ps. 这个文件和类名没有对应关系.
- MyRsa::Test();
- echo '<br/>';
- MyRsa::testSign();
- echo '<br/>';
- echo true;
- }
- public static function testPayDb()
- {
- global $zoneid;
- $zoneid = 1;
- $db = CPayInit();
- $SQL = "INSERT IGNORE INTO `tab_rankuserlog_1` (`id`, `cash`, `oid`, `info`, `insertDatetime`, `lastUpdatetime`) VALUES (NULL, '1', '2', '3', CURRENT_TIMESTAMP, '2015-11-24 00:00:00');";
- $arr = $db->query($SQL);
- DebugHelper::var_dump("TestDb:" . $arr);
- $db->close();
- }
- public function testBase32($code)
- {
- // $code = "r4fismgn";
- DebugHelper::debug("code: $code <br/>");
- DebugHelper::debug("解码: <br>");
- $decode = CipheredBase32::Decode($code);
- DebugHelper:: var_dump($decode);
- DebugHelper::debug("plat:" . GameConstants::GetPlatStringByActivteCode($decode));
- }
- public function testMemDelete($key)
- {
- $mem = gMem();
- $res = $mem->delete($key);
- return $res;
- }
- public function testMemSet($key, $value)
- {
- $mem = gMem();
- $res = $mem->set($key, $value);
- return $res;
- }
- public function testVerifySign()
- {
- $data = 'wanggang';
- $sign = 'KGNg2I7kis9vz1p2uzZZ1igj6fVERxvGrQK4zJPGPiEIjdzyZ3bogxG2kMwDn1zjQBlqGqzjcwKhCWf6JVoDT2WPnxYd9O4qF+kaIaMpOq4ZNy+dQL+FnsCRMhl+EV7ejK9RUgw7AkLSqIm3gRdMEiZnHjHk6C2JtHUgLZJ+nyY = ';
- $keypath = ROOTDIR . "/Util/key";
- // 验证并查找回归密码记录
- $myrsa = new MyRsa($keypath);
- if ($myrsa->verify($data, $sign)) { // 验证下签名
- echo "签名验证成功!";
- } else {
- echo '验签失败';
- }
- }
- public function testMemGet($key)
- {
- $mem = gMem();
- $res = $mem->get($key);
- return $res;
- }
- // 微秒
- public static function microtime_float()
- {
- echoLine(microsecond());
- }
- public static function dtCurrent()
- {
- echoLine(TimeUtil::tsWeek());
- $timezone = date_default_timezone_get();
- echoLine($timezone);
- echoLine(date('Y-m-d H:i:s'));
- return date('Y-m-d ') . (date('H') + 8) . date(':i:s');
- }
- //----------------------------------------------------
- public static function efficiencyOfOldLog()
- {
- /**
- * 测试结果说明,采用写本地文件的性能还是略高于写redis数据库的.
- */
- for ($i = 0; $i < 1000; $i++) {
- CLog::pay("我们的祖国像花园,花园里花朵真鲜艳.和暖的阳光照耀着我们,每个人的脸上都笑开颜.");
- }
- }
- public function testRedisGet($key)
- {
- $mem = gMem();
- $ret = $mem->get($key);
- DebugHelper:: var_dump($ret);
- $mem->close();
- return $ret;
- }
- /**
- * 删除某个key
- * @param type $key
- */
- public function testRedisDel($key)
- {
- $mem = gMem();
- $num = $mem->delete($key);
- echo $num > 0 ? 'ok' : 'not exist';
- $mem->close();
- }
- public function testRedisLua($key, $value)
- {
- $mem = gMem();
- $script = <<<SCR
- if redis.call("get",KEYS[1]) == ARGV[1]
- then
- return redis.call("del",KEYS[1])
- else
- return 0
- end
- SCR;
- DebugHelper:: var_dump($script);
- $ret = $mem->redis->eval($script, 1, $key, $value);
- DebugHelper:: var_dump($ret);
- $mem->close();
- }
- public function testBinSearch($v)
- {
- $arr = array(1, 2, 3, 4, 4, 11, 12, 124);
- $start = 0;
- $end = count($arr) - 1;
- while ($start <= $end) {
- $index = intval(($start + $end) / 2);
- if ($v < $arr[$index]) {
- $end = $index - 1;
- } elseif ($v > $arr[$index]) {
- $start = $index + 1;
- } else {
- echo($index);
- return;
- }
- }
- echo($index);
- }
- public function testArrayInsert()
- {
- $array = array(1, 2, 3, 4, 11, 12, 124, 1245);
- StlUtil::arrayInsert($array, 0, 0);
- DebugHelper::debug($array);
- }
- public function testArrayFunc()
- {
- $array = ArrayInit();
- $array[] = 1;
- $array[] = 1;
- $array[] = 6;
- $array[] = 1;
- $index = StlUtil::arrayIndexOf($array, 6);
- DebugHelper::debug($index);
- }
- public function testMD5()
- {
- $v3 = CV3Init();
- $paras = array();
- $paras["openid"] = "382E5D8EDB8E6BAE17B9EE44E532631F";
- $paras["ep"] = HttpUtil::getClientEP();
- $paras["ts"] = now();
- $self_url_path = "atomsoft.com";
- $sig = $v3->cee_self_sig($paras, $self_url_path);
- $v3->close();
- DebugHelper::debug($sig);
- }
- public function tsetIp()
- {
- DebugHelper::debug(HttpUtil::getClientEP());
- }
- public function testLogfile()
- {
- CLog::warn("日志测试", 'log');
- }
- }
|