RefillOil.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace refill\bdt;
  3. require_once(BASE_HELPER_PATH . '/refill/bdt/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['payType'] = 1001;
  18. }
  19. elseif($card_type == mtopcard\SinopecCard) {
  20. $params['payType'] = 1002;
  21. }
  22. else {
  23. Log::record("RefillOil req_params err params",Log::DEBUG);
  24. }
  25. $params['amount'] = $amount;
  26. $params['cardOwnerOrderNo'] = $other['order_sn'];
  27. $params['notifyUrl'] = config::NOTIFY_URL;
  28. $params['cardOwnerAccount'] = config::CardOwnerAccount;
  29. $params['date'] = date("Y-m-d H:i:s");
  30. $params['ip'] = config::API_IP;
  31. return $params;
  32. }
  33. private function sign($params)
  34. {
  35. $content = '';
  36. ksort($params);
  37. foreach ($params as $key => $val){
  38. $content .= "{$key}={$val}&";
  39. }
  40. $content .= "key=".config::KEY;
  41. return strtoupper(md5($content));
  42. }
  43. public function add($card_no,$card_type,$amount,$input)
  44. {
  45. $params = $this->req_params($card_no,$card_type,$amount,$input);
  46. $sign = $this->sign($params);
  47. $params['sign'] = $sign;
  48. $resp = http_request(config::ORDER_URL,$params,'POST',false, config::ExtHeaders);
  49. if($resp === false) {
  50. return [false,'系统错误'];
  51. }
  52. else
  53. {
  54. Log::record($resp,Log::DEBUG);
  55. $resp = json_decode($resp,true);
  56. if($resp['code'] == 200) {
  57. return [true,$resp['msg']];
  58. }
  59. else {
  60. return [false,$resp['msg']];
  61. }
  62. }
  63. }
  64. public function query($refill_info)
  65. {
  66. }
  67. }