123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace refill\lifang_normal;
- require_once(BASE_HELPER_RAPI_PATH . '/lifang_normal/config.php');
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
- {
- $input = [
- 'amount' => $amount,
- 'outOrderId' => $order_sn,
- 'phoneNumber' => $phone,
- 'requestDate' => config::time_stamp(),
- 'callBackUrl' => config::NOTIFY_URL
- ];
- $params = config::gen_params($input,config::add_keys);
- return $params;
- }
- //[$state, $errmsg, $neterr]
- public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
- {
- $params = $this->add_params($card_no, $amount, $params['order_sn'], $card_type);
- if(empty($params)) {
- return [false, '提单参数不符合', false];
- }
- $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $net_errno);
- if (empty($resp)) {
- return [false, '系统错误', true];
- }
- else
- {
- /// 订单状态,0 充值中 1 充值成功 9 充值失败 6 存疑(人工核实)
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误', true];
- } elseif ($resp['code'] === 200) {
- return [true, $resp['orderId'], false];
- } else {
- return [false, $resp['msg'], false];
- }
- }
- }
- public function query($refill_info): array
- {
- $input = [
- 'outOrderId' => $refill_info['order_sn'],
- 'requestDate' => config::time_stamp()
- ];
- $params = config::gen_params($input,config::query_keys);
- $resp = http_request(config::QUERY_URL, $params , 'POST');
- if (empty($resp)) {
- return [false, '系统错误', ''];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误', ''];
- }
- $code = intval($resp['code']);
- if ($code === 200)
- {
- $val = $resp['data'];
- $status = intval($val['status']);
- $official_sn = '';
- //订单状态,0 充值中 1 充值成功 9 充值失败 6 存疑(人工核实)
- if ($status == 1) {
- Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['orderId'],'official_sn' => $official_sn]);
- $order_state = ORDER_STATE_SUCCESS;
- }
- elseif ($status == 9) {
- Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['orderId']]);
- $order_state = ORDER_STATE_CANCEL;
- }
- else {
- $order_state = ORDER_STATE_SEND;
- }
- return [true, $order_state, $official_sn];
- }
- elseif($code === 80001 and (time() - $refill_info['commit_time']) >= 300) {
- return [true, ORDER_STATE_NOEXIST, ''];
- }
- else {
- return [false, $resp['msg']];
- }
- }
- }
- public function balance(): array
- {
- $input = [
- 'requestDate' => config::time_stamp()
- ];
- $params = config::gen_params($input,config::balance_keys);
- $resp = http_request(config::BALANCE_URL, $params , 'POST');
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- } elseif ($resp['code'] === 200) {
- return [true, ncPriceFormat($resp['data']['leftBalance'])];
- } else {
- return [false, $resp['msg']];
- }
- }
- }
- }
|