TestRefillCB.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. use refill\gftd\config;
  4. define('APP_ID', 'test');
  5. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  6. require_once(BASE_ROOT_PATH . '/global.php');
  7. require_once(BASE_CORE_PATH . '/lrlz.php');
  8. require_once(BASE_ROOT_PATH . '/fooder.php');
  9. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  10. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  11. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  12. const LocalTest = 1;
  13. const NetTest = 2;
  14. const CurrentTest = NetTest;
  15. class Gftd
  16. {
  17. const APP_ID = 'CAE45C97727DECDF';
  18. const APP_SECRET = '4023D6F779324C21BF8D8FC10A21CFD4';
  19. public function params($params)
  20. {
  21. $params['appid'] = config::APP_ID;
  22. $params['ts'] = time();
  23. $params['signature'] = $this->sign($params);
  24. return $params;
  25. }
  26. public function sign($params)
  27. {
  28. $body = $this->body($params);
  29. $body .= Gftd::APP_SECRET;
  30. return md5($body);
  31. }
  32. protected function check_empty($value)
  33. {
  34. if (!isset($value))
  35. return true;
  36. if ($value === null)
  37. return true;
  38. if (trim($value) === "")
  39. return true;
  40. return false;
  41. }
  42. private function body($params)
  43. {
  44. ksort($params);
  45. $body = "";
  46. $i = 0;
  47. foreach ($params as $k => $v)
  48. {
  49. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
  50. {
  51. if ($i == 0) {
  52. $body .= "{$k}" . "=" . $v;
  53. } else {
  54. $body .= "&" . "{$k}" . "=" . $v;
  55. }
  56. $i++;
  57. }
  58. }
  59. return $body;
  60. }
  61. }
  62. class TestRefillCancel extends TestCase
  63. {
  64. private $mReqHost;
  65. private $mKey;
  66. private $mMchid;
  67. public function __construct(?string $name = null, array $data = [], $dataName = '')
  68. {
  69. parent::__construct($name, $data, $dataName);
  70. if (CurrentTest == LocalTest) {
  71. $this->mReqHost = BASE_SITE_URL;
  72. $this->mMchid = 1;
  73. $this->mKey = '1ff02223b771c0414468c8892151c602';
  74. } else {
  75. $this->mReqHost = 'https://www.xyzshops.cn';
  76. $this->mMchid = 1092;
  77. $this->mKey = '210fe406954220f56085997d6a4c5b80';
  78. }
  79. }
  80. public function testGFTDCancel()
  81. {
  82. $params['channelOrderNumber'] = '930664641391799632';
  83. $params['orderNumber'] = 'GYFL1611297392856576';
  84. $params['message'] = '只能给绑定正确手机号的油卡充值或只能给主卡充值';
  85. $params['status'] = 109;
  86. $prov = new Gftd();
  87. $result = $prov->params($params);
  88. $resp = http_post_data("https://www.xyzshops.cn/mobile/refill_gftd.php",json_encode($result,JSON_UNESCAPED_UNICODE),config::ExtHeaders);
  89. Log::record($resp,Log::DEBUG);
  90. }
  91. public function testGFTDSuccess()
  92. {
  93. #{"channelOrderNumber":"750664483985964632",
  94. #"orderNumber":"GYFL1611139986728407",
  95. #"message":"充值成功",
  96. #"signature":"f0eec4d0ccc1a0b6ec06003a648fd9b4",
  97. #"voucher":"2421012018536345",
  98. #"status":101}
  99. $params['channelOrderNumber'] = '950664986520404793';
  100. $params['orderNumber'] = 'GYFL1611642520980625';
  101. $params['message'] = '充值成功';
  102. $params['status'] = 101;
  103. $params["voucher"] = "2421012614280402";
  104. $prov = new Gftd();
  105. $result = $prov->params($params);
  106. $resp = http_post_data("https://www.xyzshops.cn/mobile/refill_gftd.php",json_encode($result,JSON_UNESCAPED_UNICODE),config::ExtHeaders);
  107. Log::record($resp,Log::DEBUG);
  108. }
  109. public function testBuildQuery()
  110. {
  111. $post = function ()
  112. {
  113. $data = [
  114. 'appKey' => '2023434',
  115. 'number' => '1231232',
  116. 'orderId' => '2324',
  117. 'mobile' => '2343244',
  118. 'reason' => '',
  119. 'amount' => 100,
  120. 'actualAmount' => 100,
  121. 'createdAt' => '2134r32',
  122. 'status' => 'WAIT',
  123. ];
  124. $ch = curl_init();
  125. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  126. curl_setopt($ch, CURLOPT_HEADER, 0);
  127. curl_setopt($ch, CURLOPT_VERBOSE, true);
  128. curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  129. curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
  130. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  131. curl_setopt($ch , CURLOPT_POSTFIELDS, $data);
  132. curl_setopt($ch , CURLOPT_URL, 'http://192.168.1.220/mobile/signature.php');
  133. $response = curl_exec($ch);
  134. curl_close( $ch );
  135. return $response;
  136. };
  137. $x = $post();
  138. }
  139. }
  140. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  141. //docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test