RefillPhone.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace refill\rsanfang;
  3. require_once(BASE_HELPER_RAPI_PATH . '/rsanfang/config.php');
  4. use refill;
  5. use Log;
  6. use mtopcard;
  7. class RefillPhone extends refill\IRefillThird
  8. {
  9. public function __construct($cfgs)
  10. {
  11. parent::__construct($cfgs);
  12. }
  13. private function getProductCode($goods_id, $sys_pcode)
  14. {
  15. $thrid_refill = Model('thrid_refill');
  16. $store_id = $this->mStoreID;
  17. $product = $thrid_refill->getProviderProduct($store_id, $goods_id, $sys_pcode);
  18. if (empty($product)) {
  19. return false;
  20. } else {
  21. return $product['channel_code'];
  22. }
  23. }
  24. private function req_params(int $phone, int $amount, $card_type, string $order_sn, $channel_code): array
  25. {
  26. return [];
  27. }
  28. public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
  29. {
  30. $order_sn = $params['order_sn'];
  31. $goods_id = intval($params['goods_id']);
  32. $channel_code = $this->getProductCode($goods_id, $params['product_code']);
  33. if (empty($channel_code)) {
  34. return [false, '产品有误', false];
  35. }
  36. [$validate, $card_type, $regin_no, $isTransfer, $card_state, $black] = mtopcard\valid_phone($card_no);
  37. $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $channel_code);
  38. if (empty($params)) {
  39. return [false, '产品面值有误', false];
  40. }
  41. $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
  42. if (empty($resp))
  43. {
  44. return [false, '网络错误', true];
  45. }
  46. else
  47. {
  48. $resp = json_decode($resp, true);
  49. if (empty($resp))
  50. {
  51. return [false, '网络错误', true];
  52. }
  53. else
  54. {
  55. return [true, '', false];
  56. }
  57. }
  58. }
  59. public function query($refill_info): array
  60. {
  61. $params = [];
  62. $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
  63. if (empty($resp))
  64. {
  65. return [false, '网络错误', ''];
  66. }
  67. else
  68. {
  69. Log::record($resp, Log::DEBUG);
  70. $resp = json_decode($resp, true);
  71. if (empty($resp))
  72. {
  73. return [false, '网络错误', ''];
  74. }
  75. else
  76. {
  77. return [true, ORDER_STATE_SUCCESS, ''];
  78. }
  79. }
  80. }
  81. public function balance(): array
  82. {
  83. $params = [];
  84. $resp = http_request(config::ORDER_URL, $params , 'POST');
  85. if (empty($resp)) {
  86. return [false, '系统错误'];
  87. }
  88. else
  89. {
  90. Log::record($resp, Log::DEBUG);
  91. $resp = json_decode($resp, true);
  92. if (empty($resp)) {
  93. return [false, '系统错误'];
  94. } else {
  95. return [true, 0];
  96. }
  97. }
  98. }
  99. }