TestSmartCard.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'test');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. require_once(BASE_ROOT_PATH . '/global.php');
  6. require_once(BASE_CORE_PATH . '/lrlz.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. class TestSmartCard extends TestCase
  9. {
  10. public static function setUpBeforeClass(): void
  11. {
  12. Base::run_util();
  13. }
  14. public function testGenChannelCode()
  15. {
  16. $result = [];
  17. $name_count = ['huanxishuyu' => 10];
  18. foreach ($name_count as $name => $count)
  19. {
  20. $codes = $this->gen_code($name,$count);
  21. $result[$name] = $codes;
  22. }
  23. $x = $result;
  24. }
  25. private function gen_code($name,$count)
  26. {
  27. $gendor = function ($str) {
  28. $code = md5($str);
  29. $code = substr($code,0,12);
  30. return $code;
  31. };
  32. $base = 'https://ylapi.xyzshops.cn/chinatelecom/#/starcard?code=';
  33. $result = [];
  34. for ($i = 0; $i < $count; $i++)
  35. {
  36. $key = "{$name}-{$i}";
  37. $code = $gendor($key);
  38. $link = $base . $code;
  39. $result[$key] = ['code' => $code,'link' => $link];
  40. }
  41. return $result;
  42. }
  43. }