RefillPhone.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace refill\wantong;
  3. require_once(BASE_HELPER_RAPI_PATH . '/wantong/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, int $card_type, string $order_sn)
  13. {
  14. $params['uid'] = config::UID;
  15. $params['order_no'] = $order_sn;
  16. $params['order_type'] = 1;
  17. $params['mobile_type'] = config::operator[$card_type];
  18. $params['phone_number'] = $phone;
  19. $params['face_value'] = intval($amount * 100);
  20. $params['notify_url'] = config::NOTIFY_URL;
  21. return $params;
  22. }
  23. public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
  24. {
  25. refill\util::send_normal($params['order_sn']);
  26. return [true , '',false];
  27. }
  28. public function query($refill_info)
  29. {
  30. $params['uid'] = config::UID;
  31. $params['order_no'] = $refill_info['order_sn'];
  32. $content = $params['uid'] . $params['order_no'] . config::KEY;
  33. $params['sign'] = md5($content);
  34. $resp = http_request(config::QUERY_URL, $params, 'POST', false);
  35. if (empty($resp)) {
  36. return [false, '系统错误'];
  37. }
  38. else
  39. {
  40. Log::record($resp, Log::DEBUG);
  41. $resp = json_decode($resp, true);
  42. if (empty($resp)) {
  43. return [false, '系统错误'];
  44. }
  45. elseif ($resp['code'] == 200)
  46. {
  47. $status = $resp['data']['statusId'];
  48. if ($status == 4) {
  49. $updata['ch_trade_no'] = $resp['data']['serialNumber'];
  50. $updata['official_sn'] = $resp['data']['mobileOrderNo'];
  51. Model('refill_order')->edit($refill_info['order_id'], $updata);
  52. $order_state = ORDER_STATE_SUCCESS;
  53. } elseif (in_array($status, [0, 1, 9])) {
  54. $order_state = ORDER_STATE_CANCEL;
  55. } elseif (in_array($status, [2, 5, 6])) {
  56. $order_state = ORDER_STATE_SEND;
  57. } else {
  58. return [false, $resp['msg']];
  59. }
  60. return [true, $order_state];
  61. }
  62. else {
  63. return [false, $resp['msg']];
  64. }
  65. }
  66. }
  67. public function balance()
  68. {
  69. return [false, '暂无余额接口'];
  70. }
  71. private function sign($params)
  72. {
  73. $key = config::KEY;
  74. $content = $params['uid'] . $params['order_no'] . $params['phone_number'] . $params['face_value'] . $key;
  75. return md5($content);
  76. }
  77. }