RefillPhone.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace refill\xunao;
  3. require_once(BASE_HELPER_RAPI_PATH . '/xunao/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['supplierId'] = config::USER_ID;
  15. $params['orderNo'] = $order_sn;
  16. $params['company'] = config::operator[$card_type];
  17. $params['amount'] = $amount;
  18. $params['phoneNo'] = $phone;
  19. $params['notifyUrl'] = config::NOTIFY_URL;
  20. return $params;
  21. }
  22. public function add($card_no, $card_type, $amount, $params,&$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['supplierId'] = config::USER_ID;
  30. $params['orderNo'] = $refill_info['order_sn'];
  31. $params['phoneNo'] = $refill_info['card_no'];
  32. $params['company'] = config::operator[$refill_info['card_type']];
  33. $params['sign'] = $this->sign($params);
  34. $params = json_encode($params);
  35. $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
  36. if (empty($resp)) {
  37. return [false, '系统错误'];
  38. }
  39. else
  40. {
  41. Log::record($resp, Log::DEBUG);
  42. $resp = json_decode($resp, true);
  43. if (empty($resp)) {
  44. return [false, '系统错误'];
  45. }
  46. elseif ($resp['code'] == 200)
  47. {
  48. $status = intval($resp['data']['status']);
  49. if ($status === 2) {
  50. $updata['official_sn'] = $resp['data']['ticketNo'];
  51. Model('refill_order')->edit($refill_info['order_id'], $updata);
  52. $order_state = ORDER_STATE_SUCCESS;
  53. } elseif ($status === 3) {
  54. $order_state = ORDER_STATE_CANCEL;
  55. } elseif (in_array($status, [0,1])) {
  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($data)
  72. {
  73. $str = "";
  74. ksort($data);
  75. foreach($data as $k => $v){
  76. if($this->check_empty($v) === false){
  77. $str .= $v;
  78. }
  79. }
  80. return md5($str.config::KEY);
  81. }
  82. }