TestRefill.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. require_once(BASE_HELPER_PATH . '/refill/beixt/RefillCallBack.php');
  12. class TestRefill extends TestCase
  13. {
  14. public static function setUpBeforeClass(): void
  15. {
  16. Base::run_util();
  17. }
  18. public function testFactory()
  19. {
  20. $providers = refill\RefillFactory::instance()->find_providers(100,mtopcard\SinopecCard);
  21. if(empty($providers)) return false;
  22. $input = [
  23. 'order_sn' => '200649600557717656',
  24. 'notifyurl' => "https://www.xyzshops.cn/mobile/signature.php"
  25. ];
  26. foreach ($providers as $provider) {
  27. $resp = $provider->add("1000111100021211884",mtopcard\SinopecCard,100,$input);
  28. }
  29. }
  30. public function testRefillPhone()
  31. {
  32. // $providers = new \refill\beixt\RefillPhone();
  33. // $resp = $providers->add(18500608333,50,'200649600557718888');
  34. //{"ack":"success","message":{"order_number":13281474,"charged_amount":"48.750","shipping_status":"5","shipping_status_desc":"未发货"}}
  35. //$_POST='{"order_number":13281474,"shipping_status":1,"shipping_status_desc":"已发货","shipping_status_message":"","sign":"05863f9931ed69a70e456222f057dfdd","voucher":"110103307162012081746340295254","vouchertype":"","voucherurl":"","tradeNo":"200649600557718888"}';
  36. $params['order_number'] = 13281474;
  37. $params['shipping_status'] = 1;
  38. $params['shipping_status_desc'] = '已发货';
  39. $params['shipping_status_message'] = '';
  40. $params['sign'] = '05863f9931ed69a70e456222f057dfdd';
  41. $params['voucher'] = '110103307162012081746340295254';
  42. $params['vouchertype'] = '';
  43. $params['voucherurl'] = '';
  44. $params['tradeNo'] = '200649600557718888';
  45. $ret = refill\RefillFactory::instance()->notify('beixt',$params);
  46. }
  47. public function testAddoil()
  48. {
  49. // $req_url = 'https://www.xyzshops.cn/mobile/index.php';
  50. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  51. $req_url = BASE_SITE_URL . '/mobile/index.php';
  52. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  53. $params = ['mchid' => 1,
  54. 'cardno' => '1000111100020445281',
  55. 'amount' => "100",
  56. "act"=>"refill",
  57. "op"=>"add",
  58. 'order_sn' => "13281476",
  59. 'notifyurl'=> $notifyurl];
  60. $resp = $this->send_md5($req_url,$params);
  61. }
  62. public function testGoods()
  63. {
  64. // $req_url = 'https://www.xyzshops.cn/mobile/index.php';
  65. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  66. $req_url = BASE_SITE_URL . '/mobile/index.php';
  67. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  68. $params = ['mchid' => 1,
  69. "act"=>"refill",
  70. "op"=>"goods"];
  71. $resp = $this->send_md5($req_url,$params);
  72. }
  73. public function testQuery()
  74. {
  75. // $req_url = 'https://www.xyzshops.cn/mobile/index.php';
  76. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  77. $req_url = BASE_SITE_URL . '/mobile/index.php';
  78. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  79. $params = ['mchid' => 1,
  80. "act"=>"refill",
  81. "op"=>"query",
  82. 'order_sn' => "13281476"];
  83. $resp = $this->send_md5($req_url,$params);
  84. }
  85. public function testRemoveSession()
  86. {
  87. $resp = http_request(BASE_SITE_URL . "/mobile/signature.php",[],'POST');
  88. }
  89. public function testAddPhoe()
  90. {
  91. $params = ['mchid' => 10088,
  92. 'cardno' => '15120035568',
  93. 'amount' => "50",
  94. "act"=>"refill",
  95. "op"=>"add",
  96. 'order_sn' => "13281475",
  97. 'notifyurl'=> BASE_SITE_URL . "/mobile/beixt_notify.php"];
  98. $this->send($params);
  99. }
  100. public function testSuhcCB()
  101. {
  102. // $notifyurl = BASE_SITE_URL . "/mobile/refill_suhc.php";
  103. $notifyurl = "https://www.xyzshops.cn/mobile/refill_suhc.php";
  104. // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php";
  105. $params = ['onlystr' => '920660917672249741',
  106. 'amt' => 100,
  107. 'jdno'=>'',
  108. 'notifyurl' => $notifyurl,
  109. 'cardtype' => 'Sinoepc',
  110. 'batchid' => 18512,
  111. 'cardno' => '1000111100020445281',
  112. 'orgid' => '1590993600',
  113. 'status' => 2];
  114. $sign = $this->md5_sign($params);
  115. $params['sign'] = $sign;
  116. $resp = http_request($notifyurl,$params,'POST');
  117. Log::record($resp,Log::DEBUG);
  118. }
  119. protected function check_empty($value)
  120. {
  121. if (!isset($value))
  122. return true;
  123. if ($value === null)
  124. return true;
  125. if (trim($value) === "")
  126. return true;
  127. return false;
  128. }
  129. private function md5_sign($params)
  130. {
  131. ksort($params);
  132. $body = "";
  133. $i = 0;
  134. foreach ($params as $k => $v)
  135. {
  136. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
  137. {
  138. if ($i == 0) {
  139. $body .= "{$k}" . "=" . urldecode($v);
  140. } else {
  141. $body .= "&" . "{$k}" . "=" . urldecode($v);
  142. }
  143. $i++;
  144. }
  145. }
  146. $body .= "&key=7yDCLS6S2KzSAJQOUc3vsa";
  147. return md5($body);
  148. }
  149. public function testCallMech()
  150. {
  151. $logic = Logic('queue');
  152. $logic->NotifyMerchantComplete(['order_id' => 289]);
  153. }
  154. private function send($url,$params)
  155. {
  156. $mchid = $params['mchid'];
  157. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  158. $key = file_get_contents($pri_key);
  159. $pri = openssl_get_privatekey($key);
  160. $body = $this->body($params);
  161. openssl_sign($body, $signed, $pri);
  162. $sign = base64_encode($signed);
  163. $params['sign'] = $sign;
  164. $resp = http_request($url,$params,'POST');
  165. Log::record("resp:{$resp}",Log::DEBUG);
  166. }
  167. private function send_md5($url,$params)
  168. {
  169. $body = $this->body($params);
  170. $body .= "&key=1ff02223b771c0414468c8892151c602";
  171. $params['sign'] = md5($body);
  172. $resp = http_request($url,$params,'POST');
  173. Log::record("resp:{$resp}",Log::DEBUG);
  174. return $resp;
  175. }
  176. public function testCardType()
  177. {
  178. $cardno = '1000111100021211884';
  179. $ret = preg_match( '/^1[0-9]{18}$/',$cardno,$matches);
  180. }
  181. public function testMtrand()
  182. {
  183. }
  184. public function testHttpRefill()
  185. {
  186. $mchid = '000001';
  187. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  188. $key = file_get_contents($pri_key);
  189. $pri = openssl_get_privatekey($key);
  190. $params = ['MCHID' => $mchid,'cardno' => '1000111100021211884','amt' => "100","act"=>"refill","op"=>"addoil"];
  191. $body = $this->body($params);
  192. openssl_sign($body, $signed, $pri);
  193. $sign = base64_encode($signed);
  194. $params['sign'] = $sign;
  195. $resp = http_request(BASE_SITE_URL . "/mobile/index.php",$params,'POST');
  196. }
  197. private function body($params)
  198. {
  199. ksort($params);
  200. $stringToBeSigned = "";
  201. $i = 0;
  202. foreach ($params as $k => $v)
  203. {
  204. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1))
  205. {
  206. if ($i == 0) {
  207. $stringToBeSigned .= "{$k}" . "=" . urlencode($v);
  208. } else {
  209. $stringToBeSigned .= "&" . "{$k}" . "=" . urlencode($v);
  210. }
  211. $i++;
  212. }
  213. }
  214. return $stringToBeSigned;
  215. }
  216. private function checkEmpty($value)
  217. {
  218. if (!isset($value))
  219. return true;
  220. if ($value === null)
  221. return true;
  222. if (trim($value) === "")
  223. return true;
  224. return false;
  225. }
  226. public function testKsort()
  227. {
  228. $age= ["Peter"=>"35","Ben"=>"37","Joe"=>"43"];
  229. ksort($age);
  230. foreach($age as $x=>$x_value)
  231. {
  232. echo "Key=" . $x . ", Value=" . $x_value;
  233. echo "<br>";
  234. }
  235. }
  236. public function testip(){
  237. $model_merchant = Model('merchant');
  238. $merchant_info = $model_merchant->getMerchantInfo(array('mchid' => 1));
  239. $ipwhitelist = unserialize($merchant_info['ip_white_list']);
  240. $res = json_encode($ipwhitelist);
  241. }
  242. }