TestServer.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. namespace loyalsoft;
  3. include_once __DIR__ . '/AppServer.php';
  4. /**
  5. * Description of TestServer
  6. * UT 测试
  7. * @author jgao
  8. */
  9. class TestServer
  10. {
  11. //put your code here
  12. /**
  13. * 入口函数专用测试
  14. * @param type $req
  15. */
  16. static public function testApi($req)
  17. {
  18. DebugHelper::debug($req);
  19. $app = new AppServer();
  20. $ret = $app->api(new Req($req));
  21. DebugHelper::debug($ret);
  22. }
  23. /**
  24. * 运行环境自检:
  25. * PHP 版本,扩展模块
  26. * redis操作性
  27. * sqldb操作性
  28. */
  29. static function selfTest()
  30. {
  31. // 检查gameOnline状态
  32. echoLine("GAME_ONLINE := " . (GAME_ONLINE ? "True" : "False"));
  33. // 检查phpversion
  34. echoLine('PHP version: ' . PHP_VERSION);
  35. if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) {
  36. echo ('<font color="red">This code request at least PHP version ' #
  37. . REQUIRED_PHP_VERSION . '. </font><br/>\n');
  38. }
  39. echoLine("loaded extensions:"); // 已加载的扩展模块信息
  40. echoLine(var_export(get_loaded_extensions(), true)); # 打印
  41. $required = array('iconv', 'json', 'mcrypt', 'SPL', 'pcre', # # 打算做个检查推荐模块的逻辑呢
  42. 'Reflection', 'session', 'zip', 'zlib', 'PDO', 'openssl',
  43. 'curl', 'mbstring', 'mysqli', 'pdo_mysql', 'redis',
  44. 'sockets', 'xdebug');
  45. // 检查redis地址, 可操作性
  46. if (gMem()->set('test-selftest', "self cheking...")) {
  47. echoLine("Redis check ok!");
  48. } else {
  49. echoLine("Redis check failed!");
  50. echoLine(var_export(config::Inst()->nosql, true));
  51. }
  52. // 检查MySQL地址, 可操作性
  53. if (daoInst()->tableExist('tab_token_gift')) {
  54. echoLine("sqldb test ok");
  55. } else {
  56. echoLine("sqldb test failed!");
  57. echoLine(var_export(config::Inst()->paydb), true);
  58. }
  59. }
  60. // rsa加密传输
  61. public static function testMyRsaCommunication()
  62. {
  63. require_once 'OpenSSLVerify.php'; #Ps. 这个文件和类名没有对应关系.
  64. MyRsa::Test();
  65. echo '<br/>';
  66. MyRsa::testSign();
  67. echo '<br/>';
  68. echo true;
  69. }
  70. public static function testPayDb()
  71. {
  72. global $zoneid;
  73. $zoneid = 1;
  74. $db = CPayInit();
  75. $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');";
  76. $arr = $db->query($SQL);
  77. DebugHelper::var_dump("TestDb:" . $arr);
  78. $db->close();
  79. }
  80. public function testBase32($code)
  81. {
  82. // $code = "r4fismgn";
  83. DebugHelper::debug("code: $code <br/>");
  84. DebugHelper::debug("解码: <br>");
  85. $decode = CipheredBase32::Decode($code);
  86. DebugHelper:: var_dump($decode);
  87. DebugHelper::debug("plat:" . GameConstants::GetPlatStringByActivteCode($decode));
  88. }
  89. public function testMemDelete($key)
  90. {
  91. $mem = gMem();
  92. $res = $mem->delete($key);
  93. return $res;
  94. }
  95. public function testMemSet($key, $value)
  96. {
  97. $mem = gMem();
  98. $res = $mem->set($key, $value);
  99. return $res;
  100. }
  101. public function testVerifySign()
  102. {
  103. $data = 'wanggang';
  104. $sign = 'KGNg2I7kis9vz1p2uzZZ1igj6fVERxvGrQK4zJPGPiEIjdzyZ3bogxG2kMwDn1zjQBlqGqzjcwKhCWf6JVoDT2WPnxYd9O4qF+kaIaMpOq4ZNy+dQL+FnsCRMhl+EV7ejK9RUgw7AkLSqIm3gRdMEiZnHjHk6C2JtHUgLZJ+nyY = ';
  105. $keypath = ROOTDIR . "/Util/key";
  106. // 验证并查找回归密码记录
  107. $myrsa = new MyRsa($keypath);
  108. if ($myrsa->verify($data, $sign)) { // 验证下签名
  109. echo "签名验证成功!";
  110. } else {
  111. echo '验签失败';
  112. }
  113. }
  114. public function testMemGet($key)
  115. {
  116. $mem = gMem();
  117. $res = $mem->get($key);
  118. return $res;
  119. }
  120. // 微秒
  121. public static function microtime_float()
  122. {
  123. echoLine(microsecond());
  124. }
  125. public static function dtCurrent()
  126. {
  127. echoLine(TimeUtil::tsWeek());
  128. $timezone = date_default_timezone_get();
  129. echoLine($timezone);
  130. echoLine(date('Y-m-d H:i:s'));
  131. return date('Y-m-d ') . (date('H') + 8) . date(':i:s');
  132. }
  133. //----------------------------------------------------
  134. public static function efficiencyOfOldLog()
  135. {
  136. /**
  137. * 测试结果说明,采用写本地文件的性能还是略高于写redis数据库的.
  138. */
  139. for ($i = 0; $i < 1000; $i++) {
  140. CLog::pay("我们的祖国像花园,花园里花朵真鲜艳.和暖的阳光照耀着我们,每个人的脸上都笑开颜.");
  141. }
  142. }
  143. public function testRedisGet($key)
  144. {
  145. $mem = gMem();
  146. $ret = $mem->get($key);
  147. DebugHelper:: var_dump($ret);
  148. $mem->close();
  149. return $ret;
  150. }
  151. /**
  152. * 删除某个key
  153. * @param type $key
  154. */
  155. public function testRedisDel($key)
  156. {
  157. $mem = gMem();
  158. $num = $mem->delete($key);
  159. echo $num > 0 ? 'ok' : 'not exist';
  160. $mem->close();
  161. }
  162. public function testRedisLua($key, $value)
  163. {
  164. $mem = gMem();
  165. $script = <<<SCR
  166. if redis.call("get",KEYS[1]) == ARGV[1]
  167. then
  168. return redis.call("del",KEYS[1])
  169. else
  170. return 0
  171. end
  172. SCR;
  173. DebugHelper:: var_dump($script);
  174. $ret = $mem->redis->eval($script, 1, $key, $value);
  175. DebugHelper:: var_dump($ret);
  176. $mem->close();
  177. }
  178. public function testBinSearch($v)
  179. {
  180. $arr = array(1, 2, 3, 4, 4, 11, 12, 124);
  181. $start = 0;
  182. $end = count($arr) - 1;
  183. while ($start <= $end) {
  184. $index = intval(($start + $end) / 2);
  185. if ($v < $arr[$index]) {
  186. $end = $index - 1;
  187. } elseif ($v > $arr[$index]) {
  188. $start = $index + 1;
  189. } else {
  190. echo($index);
  191. return;
  192. }
  193. }
  194. echo($index);
  195. }
  196. public function testArrayInsert()
  197. {
  198. $array = array(1, 2, 3, 4, 11, 12, 124, 1245);
  199. StlUtil::arrayInsert($array, 0, 0);
  200. DebugHelper::debug($array);
  201. }
  202. public function testArrayFunc()
  203. {
  204. $array = ArrayInit();
  205. $array[] = 1;
  206. $array[] = 1;
  207. $array[] = 6;
  208. $array[] = 1;
  209. $index = StlUtil::arrayIndexOf($array, 6);
  210. DebugHelper::debug($index);
  211. }
  212. public function testMD5()
  213. {
  214. $v3 = CV3Init();
  215. $paras = array();
  216. $paras["openid"] = "382E5D8EDB8E6BAE17B9EE44E532631F";
  217. $paras["ep"] = HttpUtil::getClientEP();
  218. $paras["ts"] = now();
  219. $self_url_path = "atomsoft.com";
  220. $sig = $v3->cee_self_sig($paras, $self_url_path);
  221. $v3->close();
  222. DebugHelper::debug($sig);
  223. }
  224. public function tsetIp()
  225. {
  226. DebugHelper::debug(HttpUtil::getClientEP());
  227. }
  228. public function testLogfile()
  229. {
  230. CLog::warn("日志测试", 'log');
  231. }
  232. }