RefillPhone.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace refill\beixt;
  3. require_once(BASE_HELPER_RAPI_PATH . '/beixt/config.php');
  4. use refill;
  5. use Log;
  6. class RefillPhone extends refill\IRefillPhone
  7. {
  8. public function __construct($cfgs)
  9. {
  10. parent::__construct($cfgs);
  11. }
  12. private function req_params(int $phone, int $amount ,string $order_sn)
  13. {
  14. $params['phone'] = $phone;
  15. $params['product_id'] = $amount;
  16. $params['tradeNo'] = $order_sn;
  17. $params['notify_url'] = config::NOTIFY_URL;
  18. return json_encode($params);
  19. }
  20. public function add($card_no, $card_type,$amount,$params)
  21. {
  22. $order_sn = $params['order_sn'];
  23. $params = $this->req_params($card_no,$amount,$order_sn);
  24. $time = time();
  25. $api_user_name = config::API_USER_NAME;
  26. $sign = $this->sign($time);
  27. $header = [
  28. 'Content-Type: application/json',
  29. "API-USER-NAME: {$api_user_name}",
  30. "API-NAME: OrderCreate",
  31. "API-TIMESTAMP: {$time}",
  32. "API-SIGNATURE: {$sign}",
  33. ];
  34. $resp = http_post_data(config::REQUEST_URL,$params,$header);
  35. if($resp === false) {
  36. return [false,'系统错误',true];
  37. }
  38. else
  39. {
  40. Log::record($resp,Log::DEBUG);
  41. $resp = json_decode($resp,true);
  42. if($resp['ack'] == 'success') {
  43. return [true,$resp['message']['order_number'], false];
  44. }
  45. else {
  46. return [false,$resp['message'], false];
  47. }
  48. }
  49. }
  50. public function query($refill_info)
  51. {
  52. $params['order_number'] = $refill_info['ch_trade_no'];
  53. $params['tradeNo'] = $refill_info['order_sn'];
  54. $time = time();
  55. $api_user_name = config::API_USER_NAME;
  56. $sign = $this->sign($time);
  57. $header = [
  58. 'Content-Type: application/json',
  59. "API-USER-NAME: {$api_user_name}",
  60. "API-NAME: OrderQuery",
  61. "API-TIMESTAMP: {$time}",
  62. "API-SIGNATURE: {$sign}",
  63. ];
  64. $resp = http_post_data(config::REQUEST_URL,json_encode($params),$header);
  65. if($resp === false) {
  66. return [false,'系统错误'];
  67. }
  68. else
  69. {
  70. Log::record($resp,Log::DEBUG);
  71. $resp = json_decode($resp,true);
  72. if($resp['ack'] == 'success') {
  73. return [true,$resp['message']];
  74. }
  75. else {
  76. return [false,$resp['message']];
  77. }
  78. }
  79. }
  80. private function sign($time)
  81. {
  82. $ip = config::API_IP;
  83. $cert = config::API_CERT;
  84. $content = $ip.$time.$cert;
  85. return md5($content);
  86. }
  87. }