RefillOil.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace refill\shengchuang;
  3. require_once(BASE_HELPER_RAPI_PATH . '/shengchuang/config.php');
  4. use refill;
  5. use Log;
  6. class RefillOil extends refill\IRefillOil
  7. {
  8. public function __construct($cfgs)
  9. {
  10. parent::__construct($cfgs);
  11. }
  12. private function req_params(string $card_no, int $amount, array $other)
  13. {
  14. $params['userId'] = config::userId;
  15. $params['commoditySellId'] = config::commoditySellId;
  16. $params['buyNum'] = $amount;
  17. $params['shopOrderId'] = $other['order_sn'];
  18. $params['json'] =json_encode(['sOilId'=>$card_no]);
  19. $params['notifyUrl'] = config::NOTIFY_URL;
  20. return $params;
  21. }
  22. private function sign($params)
  23. {
  24. $content = '';
  25. $key = config::APP_KEY;
  26. ksort($params);
  27. $i = 0;
  28. foreach ($params as $k => $v)
  29. {
  30. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
  31. {
  32. if ($i == 0) {
  33. $content .= "{$k}" . "=" . $v;
  34. } else {
  35. $content .= "&" . "{$k}" . "=" . $v;
  36. }
  37. $i++;
  38. }
  39. }
  40. $content .= md5($key);
  41. return md5($content);
  42. }
  43. public function add($card_no, $card_type, $amount, $input,&$net_errno = 0)
  44. {
  45. $params = $this->req_params($card_no, $amount, $input);
  46. $sign = $this->sign($params);
  47. $params['sign'] = $sign;
  48. $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
  49. if (empty($resp)) {
  50. return [false, '系统错误',true];
  51. }
  52. else
  53. {
  54. Log::record($resp, Log::DEBUG);
  55. $resp = json_decode($resp, true);
  56. if (empty($resp)) {
  57. return [false, '系统错误', true];
  58. } elseif ($resp['code'] == 0) {
  59. return [true, $resp['data']['platformId'], false];
  60. } else {
  61. return [false, $resp['message'], false];
  62. }
  63. }
  64. }
  65. public function query($refill_info)
  66. {
  67. $params['orderId'] = $refill_info['order_sn'];
  68. $params['userId'] = config::userId;
  69. $params['sign'] = $this->sign($params);
  70. $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
  71. if (empty($resp)) {
  72. return [false, '系统错误'];
  73. }
  74. else
  75. {
  76. Log::record($resp, Log::DEBUG);
  77. $resp = json_decode($resp, true);
  78. if (empty($resp)) {
  79. return [false, '系统错误'];
  80. }
  81. elseif ($resp['state'] == 0)
  82. {
  83. $status = $resp['data']['status'];
  84. if (in_array($status, [12,16])) {
  85. $order_state = ORDER_STATE_SUCCESS;
  86. } elseif ($status == 13) {
  87. $order_state = ORDER_STATE_CANCEL;
  88. } elseif ($resp['data']['status'] == 0){
  89. $order_state = ORDER_STATE_SEND;
  90. } else {
  91. return [false, $resp['statusDesc']];
  92. }
  93. return [true, $order_state];
  94. }
  95. else {
  96. return [false, $resp['message']];
  97. }
  98. }
  99. }
  100. public function balance()
  101. {
  102. return [false, '暂无余额接口'];
  103. }
  104. }