RefillPhone.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace refill\beixt;
  3. require_once(BASE_HELPER_PATH . '/refill/beixt/config.php');
  4. use refill;
  5. use Log;
  6. class RefillPhone
  7. {
  8. private function req_params(int $phone, int $amount ,string $order_sn)
  9. {
  10. $params['phone'] = $phone;
  11. $params['product_id'] = $amount;
  12. $params['tradeNo'] = $order_sn;
  13. $params['notify_url'] = config::NOTIFY_URL;
  14. return json_encode($params);
  15. }
  16. public function add($phone,$amount,$order_sn)
  17. {
  18. $params = $this->req_params($phone,$amount,$order_sn);
  19. $time = time();
  20. $api_user_name = config::API_USER_NAME;
  21. $sign = $this->sign($time);
  22. $header = [
  23. 'Content-Type: application/json',
  24. "API-USER-NAME: {$api_user_name}",
  25. "API-NAME: OrderCreate",
  26. "API-TIMESTAMP: {$time}",
  27. "API-SIGNATURE: {$sign}",
  28. ];
  29. $resp = http_post_data(config::REQUEST_URL,$params,$header);
  30. if($resp === false) {
  31. return [false,'系统错误'];
  32. }
  33. else
  34. {
  35. Log::record($resp,Log::DEBUG);
  36. $resp = json_decode($resp,true);
  37. if($resp['state'] == 0) {
  38. return [true,$resp['data']];
  39. }
  40. else {
  41. return [false,$resp['msg']];
  42. }
  43. }
  44. }
  45. private function sign($time)
  46. {
  47. $ip = config::API_IP;
  48. $cert = config::API_CERT;
  49. $content = $ip.$time.$cert;
  50. return md5($content);
  51. }
  52. }