123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace refill\shantong;
- require_once(BASE_HELPER_RAPI_PATH . '/shantong/config.php');
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function req_params(int $phone, int $amount, string $order_sn)
- {
- $params['mobile'] = $phone;
- $params['perValue'] = $amount;
- $params['orderId'] = $order_sn;
- $params['orderDate'] = date("Y-m-d H:i:s");
- $params['agentId'] = config::AGENT_ID;
- $params['transactionPin'] = config::transactionPin;
- $params['notifyUrl'] = config::NOTIFY_URL;
- return $params;
- }
- public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
- {
- $params = config::pub_params();
- $data = $this->req_params($card_no, $amount, $input['order_sn']);
- $params['reqData'] = json_encode($data);
- $params['sign'] = config::sign($params);
- $params = json_encode($params);
- $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders, $net_errno);
- if (empty($resp)) {
- return [false, '系统错误', true];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- $code = $resp['code'];
- if (empty($resp)) {
- return [false, '系统错误', true];
- } elseif ($code === 1) {
- return [true, $resp['data']['businessOrderId'], false];
- } else {
- return [false, $resp['msg'], false];
- }
- }
- }
- public function query($refill_info)
- {
- $params = config::pub_params();
- $data['orderId'] = $refill_info['order_sn'];
- $data['agentId'] = config::AGENT_ID;
- $data['transactionPin'] = config::transactionPin;
- $params['reqData'] = json_encode($data);
- $params['sign'] = config::sign($params);
- $params = json_encode($params);
- $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- elseif($resp['code'] === 1)
- {
- $status = $resp['data']['orderStatus'];
- if ($status === 3) {
- $updata['official_sn'] = $resp['data']['ispVoucherId'];
- Model('refill_order')->edit($refill_info['order_id'], $updata);
- $order_state = ORDER_STATE_SUCCESS;
- } elseif ($status === 99) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif ($status === 1 || $status === 2) {
- $order_state = ORDER_STATE_SEND;
- } else {
- return [false, $status];
- }
- return [true, $order_state];
- }
- else
- {
- return [false, $resp['msg']];
- }
- }
- }
- public function balance()
- {
- $params = config::pub_params();
- $data['agentId'] = config::AGENT_ID;
- $data['transactionPin'] = config::transactionPin;
- $params['reqData'] = json_encode($data);
- $params['sign'] = config::sign($params);
- $params = json_encode($params);
- $resp = http_post_data(config::BALANCE_URL, $params , config::ExtHeaders);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- } elseif ($resp['code'] === 1) {
- return [true, $resp['data']['currentBalance']];
- } else {
- return [false, $resp['msg']];
- }
- }
- }
- }
|