TestServer.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace loyalsoft;
  3. include_once __DIR__ . '/AppServer.php';
  4. require_once __DIR__ . '/../process/ActiveProc/CipheredBase32.php'; # 算法库
  5. /**
  6. * Description of TestServer
  7. * UT 测试
  8. * 约定: 底划线开头的函数为私有函数,不会在黑窗界面出现.
  9. */
  10. class TestServer {
  11. /**
  12. * 入口函数专用测试
  13. * @param type $req
  14. */
  15. static public function testApi($req) {
  16. DebugHelper::debug($req);
  17. $app = new AppServer();
  18. new Req($req);
  19. $ret = $app->api();
  20. DebugHelper::debug($ret);
  21. }
  22. /**
  23. * 运行环境自检:
  24. * PHP 版本,扩展模块
  25. * redis操作性
  26. * sqldb操作性
  27. */
  28. static function selfTest() {
  29. echoLine("phpver: " . PHP_VERSION . PHP_EOL); # 打印下PHP版本
  30. SelfChecker::CheckConfig(); # 进行配置环境检测
  31. }
  32. //----------------------------------------------------
  33. public function testRedisLua($key, $value) {
  34. $mem = gMem();
  35. $script = <<<SCR
  36. if redis.call("get",KEYS[1]) == ARGV[1]
  37. then
  38. return redis.call("del",KEYS[1])
  39. else
  40. return 0
  41. end
  42. SCR;
  43. DebugHelper:: var_dump($script);
  44. $ret = $mem->redis->eval($script, 1, $key, $value);
  45. DebugHelper:: var_dump($ret);
  46. $mem->close();
  47. }
  48. public function testBinSearch($v) {
  49. $arr = array(1, 2, 3, 4, 4, 11, 12, 124);
  50. $start = 0;
  51. $end = count($arr) - 1;
  52. while ($start <= $end) {
  53. $index = intval(($start + $end) / 2);
  54. if ($v < $arr[$index]) {
  55. $end = $index - 1;
  56. } elseif ($v > $arr[$index]) {
  57. $start = $index + 1;
  58. } else {
  59. echo($index);
  60. return;
  61. }
  62. }
  63. echo($index);
  64. }
  65. /**
  66. * 给玩家发邮件
  67. * @param type $uid
  68. * @param type $zoneid
  69. * @param type $items
  70. * @param type $ctx
  71. */
  72. public static function sendUserEmail($uid, $zoneid, $title, $reward, $ctx) {
  73. $mail = new Ins_Email(null, 1, $title, #
  74. $ctx, $reward);
  75. $list = explode(',', $uid);
  76. if (count($list) != 0) {
  77. foreach ($list as $userId) {
  78. EmailProc::InsertMail($zoneid, $userId, $mail);
  79. }
  80. }
  81. echo '邮件已经成功发送';
  82. }
  83. }