RefillOil.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace refill\zzx;
  3. require_once(BASE_HELPER_RAPI_PATH . '/zzx/config.php');
  4. use refill;
  5. use mtopcard;
  6. use Log;
  7. class RefillOil extends refill\IRefillOil
  8. {
  9. public function __construct($cfgs)
  10. {
  11. parent::__construct($cfgs);
  12. }
  13. private function req_params(string $card_no,int $amount,array $other)
  14. {
  15. $params['mid'] = config::MID;
  16. $params['cardNo'] = $card_no;
  17. $params['amount'] = $amount;
  18. $params['orderNum'] = $other['order_sn'];
  19. $params['backUrl'] = urlencode(config::NOTIFY_URL);
  20. return $params;
  21. }
  22. private function sign($params)
  23. {
  24. ksort($params);
  25. $content = '';
  26. foreach ($params as $key => $val)
  27. {
  28. if(empty($val)){
  29. continue;
  30. }
  31. $content .= "{$key}={$val}&";
  32. }
  33. $content .= "key=".config::KEY;
  34. Log::record("body={$content}",Log::DEBUG);
  35. return strtoupper(md5($content));
  36. }
  37. public function add($card_no,$card_type,$amount,$input,&$net_errno = 0)
  38. {
  39. refill\util::send_normal($params['order_sn']);
  40. return [true , '',false];
  41. }
  42. public function query($refill_info)
  43. {
  44. $params['mid'] = config::MID;
  45. $params['orderNum'] = $refill_info['order_sn'];
  46. $params['sign'] = $this->sign($params);
  47. $resp = http_post_data(config::QUERY_URL,json_encode($params),config::ExtHeaders);
  48. if (empty($resp)) {
  49. return [false,'系统错误'];
  50. }
  51. else
  52. {
  53. Log::record($resp,Log::DEBUG);
  54. $resp = json_decode($resp,true);
  55. if (empty($resp)) {
  56. return [false, '系统错误'];
  57. } elseif ($resp['code'] === '0000') {
  58. $order_state = ORDER_STATE_SUCCESS;
  59. } elseif ($resp['code'] === '0004') {
  60. $order_state = ORDER_STATE_CANCEL;
  61. } elseif ($resp['code'] === '0005') {
  62. $order_state = ORDER_STATE_SEND;
  63. } else {
  64. return [false, $resp['msg']];
  65. }
  66. return [true, $order_state];
  67. }
  68. }
  69. public function balance()
  70. {
  71. return [false, '暂无余额接口'];
  72. }
  73. }