TestRefillPhone.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  9. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  10. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  11. class TestRefillPhone extends TestCase
  12. {
  13. const LocalTest = 1;
  14. const NetTest = 2;
  15. const HomeCuda = 3;
  16. const WorkCuda = 4;
  17. const CurrentTest = self::HomeCuda;
  18. private $mReqHost;
  19. private $mKey;
  20. private $mMchid;
  21. public function __construct(?string $name = null, array $data = [], $dataName = '')
  22. {
  23. parent::__construct($name, $data, $dataName);
  24. if (self::CurrentTest == self::LocalTest) {
  25. $this->mReqHost = BASE_SITE_URL;
  26. $this->mMchid = 1;
  27. $this->mKey = '1ff02223b771c0414468c8892151c602';
  28. }
  29. elseif (self::CurrentTest == self::HomeCuda) {
  30. $this->mReqHost = 'http://192.168.3.104';
  31. $this->mMchid = 1092;
  32. $this->mKey = '210fe406954220f56085997d6a4c5b80';
  33. }
  34. }
  35. public static function setUpBeforeClass() : void
  36. {
  37. Base::run_util();
  38. }
  39. private function requrl() {
  40. return $this->mReqHost . "/mobile/index.php";
  41. }
  42. public function testAdd()
  43. {
  44. $phone = '13911129867';
  45. $amount = 100;
  46. $url = $this->requrl();
  47. $order_sn = $this->make_sn();
  48. $params = ['mchid' => $this->mMchid,
  49. 'cardno' => $phone,
  50. 'amount' => $amount,
  51. "act" => "refill",
  52. "op" => "add",
  53. 'order_sn' => $order_sn,
  54. 'notifyurl' => "http://www.baidu.com"];
  55. $proxy = new refill_proxy($this->mKey);
  56. $resp = $proxy->send($url, $params);
  57. Log::record("resp={$resp}", Log::DEBUG);
  58. }
  59. public function testAddByYaoyou()
  60. {
  61. $phone = '13911129867';
  62. $amount = 100;
  63. $url = $this->requrl();
  64. $order_sn = $this->make_sn();
  65. $params = ['mchid' => 10202,
  66. 'cardno' => $phone,
  67. 'amount' => $amount,
  68. "act" => "refill",
  69. "op" => "add",
  70. 'order_sn' => $order_sn,
  71. 'notifyurl' => "http://www.baidu.com"];
  72. $proxy = new refill_proxy('KxK9f3yaBDOXVwvuOKDozvQ9Mt1CoqRX');
  73. $resp = $proxy->send($url, $params);
  74. Log::record("resp={$resp}", Log::DEBUG);
  75. }
  76. public function testCardQuery()
  77. {
  78. $phone = '13911129867';
  79. // $url = "https://test.xyzshops.cn/vapi/index.php";
  80. $url = "https://ylapi.xyzshops.cn/vapi/index.php";
  81. $params = ['mchid' => $this->mMchid,
  82. 'cardno' => $phone,
  83. "act" => "card",
  84. "op" => "query"];
  85. $proxy = new refill_proxy($this->mKey);
  86. $resp = $proxy->send($url, $params);
  87. }
  88. private function make_sn()
  89. {
  90. return mt_rand(1000, 9999)
  91. . sprintf('%010d', time())
  92. . sprintf('%06d', (float)microtime() * 1000000);
  93. }
  94. public function testMicroTime()
  95. {
  96. [$micro,$time] = explode(' ',microtime());
  97. }
  98. }