RefillOil.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. refill\util::send_normal($params['order_sn']);
  46. return [true , '',false];
  47. }
  48. public function query($refill_info)
  49. {
  50. $params['orderId'] = $refill_info['order_sn'];
  51. $params['userId'] = config::userId;
  52. $params['sign'] = $this->sign($params);
  53. $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
  54. if (empty($resp)) {
  55. return [false, '系统错误'];
  56. }
  57. else
  58. {
  59. Log::record($resp, Log::DEBUG);
  60. $resp = json_decode($resp, true);
  61. if (empty($resp)) {
  62. return [false, '系统错误'];
  63. }
  64. elseif ($resp['state'] == 0)
  65. {
  66. $status = $resp['data']['status'];
  67. if (in_array($status, [12,16])) {
  68. $order_state = ORDER_STATE_SUCCESS;
  69. } elseif ($status == 13) {
  70. $order_state = ORDER_STATE_CANCEL;
  71. } elseif ($resp['data']['status'] == 0){
  72. $order_state = ORDER_STATE_SEND;
  73. } else {
  74. return [false, $resp['statusDesc']];
  75. }
  76. return [true, $order_state];
  77. }
  78. else {
  79. return [false, $resp['message']];
  80. }
  81. }
  82. }
  83. public function balance()
  84. {
  85. return [false, '暂无余额接口'];
  86. }
  87. }