RefillOil.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace refill\suhc;
  3. require_once(BASE_HELPER_PATH . '/refill/suhc/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 $card_type,int $amount,array $other)
  14. {
  15. $params['cardno'] = $card_no;
  16. if($card_type == mtopcard\PetroChinaCard) {
  17. $params['cardtype'] = "PetroChina";
  18. }
  19. elseif($card_type == mtopcard\SinopecCard) {
  20. $params['cardtype'] = "Sinoepc";
  21. }
  22. else {
  23. Log::record("RefillOil req_params err params",Log::DEBUG);
  24. }
  25. $params['amt'] = $amount;
  26. $params['onlystr'] = $other['order_sn'];
  27. $params['notifyurl'] = config::NOTIFY_URL;
  28. $params['orgid'] = config::ORGID;
  29. // $params['storeid'] = $this->store();
  30. return $params;
  31. }
  32. private function sign($params)
  33. {
  34. $content = '';
  35. ksort($params);
  36. foreach ($params as $key => $val){
  37. $content .= "{$key}={$val}&";
  38. }
  39. $content .= "key=".config::KEY;
  40. return md5($content);
  41. }
  42. public function add($card_no,$card_type,$amount,$input)
  43. {
  44. $params = $this->req_params($card_no,$card_type,$amount,$input);
  45. $sign = $this->sign($params);
  46. $params['sign'] = $sign;
  47. $resp = http_request(config::ORDER_URL,$params,'POST',false, config::ExtHeaders);
  48. if($resp === false) {
  49. return [false,'系统错误'];
  50. }
  51. else
  52. {
  53. Log::record($resp,Log::DEBUG);
  54. $resp = json_decode($resp,true);
  55. if($resp['state'] == 0) {
  56. return [true,$resp['data']];
  57. }
  58. else {
  59. return [false,$resp['msg']];
  60. }
  61. }
  62. }
  63. public function query($refill_info)
  64. {
  65. $params['batchid'] = $refill_info['ch_trade_no'];
  66. $params['orgid'] = config::ORGID;
  67. $params['cardno'] = $refill_info['card_no'];
  68. $params['onlystr'] = $refill_info['order_sn'];
  69. $sign = $this->sign($params);
  70. $params['sign'] = $sign;
  71. $resp = http_request(config::ORDER_QUERY_URL,$params,'POST',false,config::ExtHeaders);
  72. if($resp === false) {
  73. return [false,'系统错误'];
  74. }
  75. else
  76. {
  77. Log::record($resp,Log::DEBUG);
  78. $resp = json_decode($resp,true);
  79. if($resp['state'] == 0) {
  80. $order_state = '';
  81. if ($resp['status'] == 2) {
  82. $order_state = ORDER_STATE_SUCCESS;
  83. } elseif ($resp['status'] == 3) {
  84. $order_state = ORDER_STATE_CANCEL;
  85. } elseif ($resp['status'] == 0){
  86. $order_state = ORDER_STATE_SEND;
  87. }
  88. if (empty($order_state)) {
  89. return [false, $resp['data']];
  90. }
  91. return [true, $order_state];
  92. }
  93. else {
  94. return [false,$resp['msg']];
  95. }
  96. }
  97. }
  98. private function store()
  99. {
  100. $count = count(config::STOREIDS);
  101. $pos = mt_rand(0,$count - 1);
  102. return config::STOREIDS[$pos];
  103. }
  104. }