123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace refill\shuoruan;
- require_once(BASE_HELPER_RAPI_PATH . '/shuoruan/config.php');
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function pack_params($params)
- {
- $json_str = json_encode($params);
- $content = $json_str . config::KEY;
- $content = md5($content);
- $req = [];
- $req['sign'] = $content;
- $req['agentAccount'] = config::ACCOUNT;
- $req['busiBody'] = $params;
- return json_encode($req);
- }
- public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
- {
- $params_getter = function ($order_sn,$phone,$amount,$card_type) {
- $params = [];
- $params['orderId'] = $order_sn;
- $params['chargeAcct'] = $phone;
- $params['chargeCash'] = $amount;
- $params['chargeType'] = 0;
- $params['ispName'] = urlencode(config::operator[$card_type]);
- $params['retUrl'] = urlencode(config::NOTIFY_URL);
- $params['action'] = 'CZ';
- return $params;
- };
- $params = $params_getter($params['order_sn'], $card_no, $amount, $card_type);
- $body = $this->pack_params($params);
- $resp = http_post_data(config::API_URL, $body, config::ExtHeaders, $net_errno);
- $resp = iconv('GB2312', 'UTF-8', $resp);
- if (empty($resp)) {
- return [false, '系统错误', true];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误', true];
- } elseif ($resp['errorCode'] === 1) {
- return [true, $resp['chargeId'], false];
- } elseif (in_array($resp['errorCode'], [-992, -993, -994, -995, -996, -997, -998], true)) {
- $net_errno = "HTTP-{$resp['errorCode']}";
- return [false, $net_errno, true];
- } else {
- return [false, $resp['errorDesc'], false];
- }
- }
- }
- public function query($refill_info)
- {
- $params_getter = function ($order_sn) {
- $params = [];
- $params['orderId'] = $order_sn;
- $params['action'] = 'CX';
- return $params;
- };
- $params = $params_getter($refill_info['order_sn']);
- $body = $this->pack_params($params);
- $resp = http_post_data(config::API_URL, $body, config::ExtHeaders, $net_errno);
- $resp = iconv('GB2312', 'UTF-8', $resp);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- } elseif ($resp['errorCode'] === 1) {
- $status = $resp['orderStatuInt'];
- if (in_array($status, ['11', '16'], true)) {
- $order_state = ORDER_STATE_SUCCESS;
- } elseif (in_array($status, ['20', '21', '26'], true)) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif (in_array($status, ['0', '1', '2', '6'], true)) {
- $order_state = ORDER_STATE_SEND;
- } else {
- return [false, $resp['errorDesc']];
- }
- return [true, $order_state];
- } elseif ($resp['errorCode'] === -201 && (time() - $refill_info['commit_time'] >= 180)) {
- return [true, ORDER_STATE_NOEXIST];
- } else {
- return [false, $resp['errorDesc']];
- }
- }
- }
- public function balance()
- {
- $params_getter = function () {
- $params['action'] = 'YE';
- return $params;
- };
- $params = $params_getter();
- $body = $this->pack_params($params);
- $resp = http_post_data(config::API_URL, $body, config::ExtHeaders, $net_errno);
- $resp = iconv('GB2312', 'UTF-8', $resp);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- } elseif ($resp['errorCode'] === 1) {
- return [true, $resp['agentBalance']];
- } else {
- return [false, $resp['errorDesc']];
- }
- }
- }
- }
|