TestRefill.php 8.9 KB

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