RefillPhone.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. refill\util::send_normal($params['order_sn']);
  25. return [true , '',false];
  26. }
  27. public function query($refill_info)
  28. {
  29. $params['appid'] = config::APPID;
  30. $params['morder'] = $refill_info['order_sn'];
  31. $sign = $this->sign($params);
  32. $params['signature'] = $sign;
  33. $resp = http_request(config::QUERY_URL,$params);
  34. if (empty($resp)) {
  35. return [false,'系统错误'];
  36. }
  37. else
  38. {
  39. Log::record($resp,Log::DEBUG);
  40. $resp = json_decode($resp,true);
  41. if (empty($resp)) {
  42. return [false, '返回值错误'];
  43. }
  44. $code = intval($resp['code']);
  45. $status = intval($resp['data']['status']);
  46. if ($code != 1) {
  47. return [false, $resp['info']];
  48. } elseif ($status == 2) {
  49. $order_state = ORDER_STATE_SUCCESS;
  50. $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
  51. Model('refill_order')->edit($refill_info['order_id'], $data);
  52. } elseif ($status == 3) {
  53. $order_state = ORDER_STATE_CANCEL;
  54. } else {
  55. $order_state = ORDER_STATE_SEND;
  56. }
  57. return [true, $order_state];
  58. }
  59. }
  60. public function balance()
  61. {
  62. $params['appid'] = config::APPID;
  63. $sign = $this->sign($params);
  64. $params['signature'] = $sign;
  65. $resp = http_request(config::BALANCE_URL,$params);
  66. if($resp === false) {
  67. return [false, '网络错误'];
  68. }
  69. else {
  70. Log::record($resp, Log::DEBUG);
  71. $resp = json_decode($resp, true);
  72. if (empty($resp)) {
  73. return [false, '网络错误'];
  74. }
  75. elseif($resp['code'] == 1)
  76. {
  77. return [true,$resp['data']['account']];
  78. }
  79. else
  80. {
  81. return [false, $resp['info']];
  82. }
  83. }
  84. }
  85. private function sign($input)
  86. {
  87. $key = config::APPKEY;
  88. $body = config::body($input);
  89. $body .= "&token={$key}";
  90. return strtolower(md5($body));
  91. }
  92. }