RefillPhone.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace refill\feinimoshu_hf;
  3. require_once(BASE_HELPER_RAPI_PATH . '/feinimoshu_hf/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 $card_no, int $amount, string $order_sn)
  13. {
  14. $params['appid'] = config::APPID;
  15. $params['notify'] = config::NOTIFY_URL;
  16. $params['card'] = $card_no;
  17. $params['order'] = $order_sn;
  18. $params['cash'] = $amount;
  19. $params['proid'] = 10012;
  20. return $params;
  21. }
  22. public function add($card_no, $card_type,$amount,$input,&$net_errno = 0)
  23. {
  24. $order_sn = $input['order_sn'];
  25. $params = $this->req_params($card_no,$amount,$order_sn);
  26. $sign = $this->sign($params);
  27. $params['signature'] = $sign;
  28. $resp = http_request(config::ORDER_URL,$params,'GET',false,[],$net_errno);
  29. if (empty($resp)) {
  30. return [false,'系统错误',true];
  31. }
  32. else
  33. {
  34. Log::record($resp, Log::DEBUG);
  35. $resp = json_decode($resp, true);
  36. if (empty($resp)) {
  37. return [false, '系统错误', true];
  38. } elseif ($resp['code'] == 1) {
  39. return [true, $resp['data']['order'], false];
  40. } else {
  41. return [false, $resp['info'], false];
  42. }
  43. }
  44. }
  45. public function query($refill_info)
  46. {
  47. $params['appid'] = config::APPID;
  48. $params['morder'] = $refill_info['order_sn'];
  49. $sign = $this->sign($params);
  50. $params['signature'] = $sign;
  51. $resp = http_request(config::QUERY_URL,$params);
  52. if (empty($resp)) {
  53. return [false,'系统错误'];
  54. }
  55. else
  56. {
  57. Log::record($resp,Log::DEBUG);
  58. $resp = json_decode($resp,true);
  59. if (empty($resp)) {
  60. return [false, '返回值错误'];
  61. }
  62. $code = intval($resp['code']);
  63. $status = intval($resp['data']['status']);
  64. if ($code != 1) {
  65. return [false, $resp['info']];
  66. } elseif ($status == 2) {
  67. $order_state = ORDER_STATE_SUCCESS;
  68. $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
  69. Model('refill_order')->edit($refill_info['order_id'], $data);
  70. } elseif ($status == 3) {
  71. $order_state = ORDER_STATE_CANCEL;
  72. } else {
  73. $order_state = ORDER_STATE_SEND;
  74. }
  75. return [true, $order_state];
  76. }
  77. }
  78. public function balance()
  79. {
  80. $params['appid'] = config::APPID;
  81. $sign = $this->sign($params);
  82. $params['signature'] = $sign;
  83. $resp = http_request(config::QUERY_URL,$params);
  84. if($resp === false) {
  85. }
  86. else {
  87. }
  88. }
  89. private function sign($input)
  90. {
  91. $key = config::APPKEY;
  92. $body = config::body($input);
  93. $body .= "&token={$key}";
  94. return strtolower(md5($body));
  95. }
  96. }