|
@@ -0,0 +1,129 @@
|
|
|
+<?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 url_request($params, $action)
|
|
|
+ {
|
|
|
+ $params['action'] = $action;
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+ $params['agentAccount'] = config::ACCOUNT;
|
|
|
+ $params = json_encode($params);
|
|
|
+
|
|
|
+ $url = config::API_URL;
|
|
|
+ return http_post_data($url, $params, config::ExtHeaders, $net_errno);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $phone,int $amount, string $order_sn)
|
|
|
+ {
|
|
|
+ $params['orderId'] = $order_sn;
|
|
|
+ $params['chargeAcct'] = $phone;
|
|
|
+ $params['chargeCash'] = $amount;
|
|
|
+ $params['chargeType'] = 0;
|
|
|
+ $params['retUrl'] = urlencode(config::NOTIFY_URL);
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
|
|
|
+ {
|
|
|
+ $params = $this->req_params($card_no, $amount, $params['order_sn']);
|
|
|
+ $resp = $this->url_request($params,'CZ');
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ } elseif (intval($resp['errorCode']) === 1) {
|
|
|
+ return [true, $resp['chargeId'], false];
|
|
|
+ } elseif (in_array($resp['errorCode'], [-992, -993, -994, -995, -996, -997, -998])) {
|
|
|
+ $net_errno = $resp['errorCode'];
|
|
|
+ return [false, $resp['errorDesc'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['errorDesc'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $resp = $this->url_request($refill_info['order_sn'],'CX');
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ } elseif (intval($resp['errorCode']) === 1) {
|
|
|
+ $status = $resp['orderStatuInt'];
|
|
|
+ if (in_array($status, [11, 16])) {
|
|
|
+ $updata['official_sn'] = $resp['transo'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif (in_array($status, [20, 21, 26])) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif (in_array($status, [0, 1, 2, 6])) {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $resp['errorDesc']];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ } elseif (intval($resp['errorCode']) === -201 && (time() - $refill_info['commit_time'] >= 180)) {
|
|
|
+ return [true, ORDER_STATE_NOEXIST];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['errorDesc']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $resp = $this->url_request([],'YE');
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ } elseif (intval($resp['errorCode']) === 1) {
|
|
|
+ return [true, $resp['agentBalance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['errorDesc']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $json_str = json_encode($params);
|
|
|
+ $content = $json_str . config::KEY;
|
|
|
+ return md5($content);
|
|
|
+ }
|
|
|
+}
|