TestRefill.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. define('APP_ID', 'test');
  3. define('BASE_ROOT_PATH', str_replace('/test/mh', '', dirname(__FILE__)));
  4. require_once(BASE_ROOT_PATH . '/global.php');
  5. require_once(BASE_CORE_PATH . '/lrlz.php');
  6. require_once(BASE_ROOT_PATH . '/fooder.php');
  7. require_once(BASE_HELPER_PATH . '/refill/XYZRefillFactory.php');
  8. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  9. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  10. use PHPUnit\Framework\TestCase;
  11. class TestRefill extends TestCase
  12. {
  13. public static function setUpBeforeClass() : void
  14. {
  15. Base::run_util();
  16. }
  17. public function testStart()
  18. {
  19. $x = 19;
  20. }
  21. public function testDixin()
  22. {
  23. $provider = $this->getProvider('dixin_normal');
  24. $order_sn = $this->make_sn();
  25. $resp = $provider->add(13911129867, 5, 50, ['order_sn' => $order_sn, 'regin_no' => 1]);
  26. $resp = $provider->query(['order_sn' => $order_sn]);
  27. $resp = $provider->balance();
  28. }
  29. public function testDixinCB()
  30. {
  31. $content = '{"order_no":"OD40636475187360296","merchant_no":"0059570753462761433314","recharge_account":"13911129867","recharge_status":4,"complete_time":"2023-11-16 15:12:42","settlement_price":"47.30","total_amount":"50.00","actual_amount":"0.00","create_time":"2023-11-16 15:12:41","custom_tag":"123456","sign":"49b7f9f32a34f1c83dcb0d976f28d061"}';
  32. $provider = $this->getProvider('dixin_normal','RefillCallBack');
  33. $content = json_decode($content,true);
  34. $provider->verify($content);
  35. $provider->notify($content);
  36. }
  37. public function testSuhu()
  38. {
  39. $provider = $this->getProvider('suhu_normal');
  40. $order_sn = $this->make_sn();
  41. $resp = $provider->add(13911129867, 5, 30, ['order_sn' => $order_sn, 'regin_no' => 1]);
  42. $resp = $provider->query(['order_sn' => $order_sn]);
  43. $resp = $provider->balance();
  44. }
  45. public function testSuhuCB()
  46. {
  47. $content = '{"order_no":"OD40636475187360296","merchant_no":"0059570753462761433314","recharge_account":"13911129867","recharge_status":4,"complete_time":"2023-11-16 15:12:42","settlement_price":"47.30","total_amount":"50.00","actual_amount":"0.00","create_time":"2023-11-16 15:12:41","custom_tag":"123456","sign":"49b7f9f32a34f1c83dcb0d976f28d061"}';
  48. $provider = $this->getProvider('suhu_normal','RefillCallBack');
  49. $content = json_decode($content,true);
  50. $provider->verify($content);
  51. $provider->notify($content);
  52. }
  53. public function testSuhuWozhifu()
  54. {
  55. $provider = $this->getProvider('suhu_wozhifu');
  56. $order_sn = $this->make_sn();
  57. $resp = $provider->add(13911129867, 5, 50, ['order_sn' => $order_sn, 'regin_no' => 1]);
  58. $resp = $provider->query(['order_sn' => $order_sn]);
  59. $resp = $provider->balance();
  60. }
  61. public function testSuhuWozhifuCB()
  62. {
  63. $content = '{"order_no":"OD40636475187360296","merchant_no":"0059570753462761433314","recharge_account":"13911129867","recharge_status":4,"complete_time":"2023-11-16 15:12:42","settlement_price":"47.30","total_amount":"50.00","actual_amount":"0.00","create_time":"2023-11-16 15:12:41","custom_tag":"123456","sign":"49b7f9f32a34f1c83dcb0d976f28d061"}';
  64. $provider = $this->getProvider('suhu_wozhifu','RefillCallBack');
  65. $content = json_decode($content,true);
  66. $provider->verify($content);
  67. $provider->notify($content);
  68. }
  69. public function testYushang()
  70. {
  71. $provider = $this->getProvider('yushang_normal');
  72. $order_sn = $this->make_sn();
  73. $resp = $provider->add(13911129867, 5, 50, ['order_sn' => $order_sn, 'regin_no' => 1]);
  74. $resp = $provider->query(['order_sn' => $order_sn]);
  75. $resp = $provider->balance();
  76. }
  77. public function testYushangCB()
  78. {
  79. $_POST= '{"ChargeAccount":"13911129867","ProductCode":"PLM100068","BuyCount":"1","MOrderID":"85661700722959070814","OrderID":"231123150239738000","State":"2","AppKey":"211394653","TimesTamp":"1700723025672","Sign":"86004EF5A40B8D8B30D7454246763DF4","ExtendParam":"{\"OfficialDes\":\"\u624b\u652f\u6e20\u9053\",\"OfficialOrderID\":\"OfficialOrderID001\",\"SellPrice\":16000}","ChargeMsg":""}';
  80. $content = json_decode($_POST,true);
  81. $provider = $this->getProvider('yushang_normal','RefillCallBack');
  82. $provider->verify($content);
  83. $provider->notify($content);
  84. }
  85. public function testLifang()
  86. {
  87. $provider = $this->getProvider('lifang_normal');
  88. $order_sn = $this->make_sn();
  89. // $resp = $provider->add(15652921127, 5, 30, ['order_sn' => $order_sn, 'regin_no' => 1]);
  90. // $resp = $provider->query(['order_sn' => $order_sn]);
  91. // $resp = $provider->balance();
  92. }
  93. public function testLifangCB()
  94. {
  95. $_POST='{"orderId":"S23112800025098","outOrderId":"60201701159853851187","requestDate":"20231128164156","sign":"E172D40D040D26C8226E237ACED8C861","accessToken":"beaf87f8-7c6b-cb8a-98b8-53c207ca9aef","status":"1"}';
  96. $content = json_decode($_POST,true);
  97. $provider = $this->getProvider('lifang_normal','RefillCallBack');
  98. $provider->verify($content);
  99. $provider->notify($content);
  100. }
  101. public function testWensanhuo()
  102. {
  103. $provider = $this->getProvider('weisanhuo_normal');
  104. $order_sn = $this->make_sn();
  105. //$resp = $provider->add(18855414101, 4, 30, ['order_sn' => $order_sn, 'regin_no' => 1]);//30为测试产品
  106. //$resp = $provider->query(['order_sn' => $order_sn]);
  107. $resp = $provider->balance();
  108. }
  109. public function testWensanhuoCB()
  110. {
  111. $_POST='{"orderId":"S23112800025098","outOrderId":"60201701159853851187","requestDate":"20231128164156","sign":"E172D40D040D26C8226E237ACED8C861","accessToken":"beaf87f8-7c6b-cb8a-98b8-53c207ca9aef","status":"1"}';
  112. $content = json_decode($_POST,true);
  113. $provider = $this->getProvider('lifang_normal','RefillCallBack');
  114. $provider->verify($content);
  115. $provider->notify($content);
  116. }
  117. public function testJson()
  118. {
  119. $val = json_encode(['account' => '13911129867']);
  120. }
  121. private function getProvider($name, $type = 'RefillPhone')
  122. {
  123. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  124. if(!file_exists($file)){
  125. Log::record("provider api file=$file not exist.",Log::DEBUG);
  126. return false;
  127. } else {
  128. require_once($file);
  129. Log::record("file=$file load success.",Log::DEBUG);
  130. }
  131. $class_name = "refill\\{$name}\\{$type}";
  132. if (class_exists($class_name, false)) {
  133. $caller = new $class_name([]);
  134. return $caller;
  135. } else {
  136. $error = "Base Error: class {$class_name} isn't exists!";
  137. Log::record($error, Log::ERR);
  138. return false;
  139. }
  140. }
  141. private function make_sn()
  142. {
  143. return mt_rand(1000, 9999)
  144. . sprintf('%010d', time())
  145. . sprintf('%06d', (float)microtime() * 1000000);
  146. }
  147. public function testMillsec()
  148. {
  149. $microtime = intval(microtime(true) * 1000);
  150. }
  151. public function testweisanhuo()
  152. {
  153. $provider = $this->getProvider('weisanhuo');
  154. // $resp = $provider->balance();
  155. // $resp = $provider->add(13699279618, 4, 50, ['order_sn' => $this->make_sn()]);
  156. $resp = $provider->query(['order_sn' => '24271700815859899563-9']);
  157. $post = '{"operatorTradeNo":"","statusDesc":"交易成功","phone":"18780103116","outTradeNo":"202309250000000006","sign":"d793406757c1bb920fe518e9673a28ea","inTradeNo":"202309251766523539","status":"success","reportTime":"1695607732705"}';
  158. $data = json_decode($post, true);
  159. $provider = $this->getProvider('weisanhuo', 'RefillCallBack');
  160. $ret = $provider->verify($data);
  161. // $resp = $provider->notify($data);
  162. }
  163. }