RefillOil.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace refill\bdt;
  3. require_once(BASE_HELPER_RAPI_PATH . '/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,&$net_errno = 0)
  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, $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'] == 200) {
  59. return [true, $resp['msg'], false];
  60. } else {
  61. return [false, $resp['msg'], false];
  62. }
  63. }
  64. }
  65. public function query($refill_info)
  66. {
  67. }
  68. }