|
@@ -0,0 +1,142 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\youhe_new;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/youhe_new/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['partnerno'] = config::PARTNER_NO;
|
|
|
+ $params['orderno'] = $order_sn;
|
|
|
+ $params['amount'] = $amount;
|
|
|
+ $params['chargeacct'] = $phone;
|
|
|
+ $params['accounttype'] = 1;
|
|
|
+ $params['timestamp'] = $this->getMillisecond();
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
|
|
|
+ {
|
|
|
+ $params = $this->req_params($card_no, $amount, $params['order_sn']);
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $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);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ } elseif ($resp['code'] === 'R0000') {
|
|
|
+ return [true, $resp['orderno'], false];
|
|
|
+ } elseif ($resp['code'] === 'R0009') {
|
|
|
+ $net_errno = $resp['code'];
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['partnerno'] = config::PARTNER_NO;
|
|
|
+ $params['customerorder'] = $refill_info['order_sn'];
|
|
|
+ $params['timestamp'] = $this->getMillisecond();
|
|
|
+ $params['sign'] = $this->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'] === 'R0000') {
|
|
|
+ $status = $resp['status'];
|
|
|
+ if ($status === 'Q0000') {
|
|
|
+ $updata['official_sn'] = $resp['transo'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($status === 'Q0001') {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif ($status === 'Q0002') {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $status];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ } elseif (in_array($resp['code'], ['R0011', 'R0012', 'R0018'], true)) {
|
|
|
+ return [true, ORDER_STATE_NOEXIST];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['partnerno'] = config::PARTNER_NO;
|
|
|
+ $params['timestamp'] = $this->getMillisecond();
|
|
|
+ $params['sign'] = $this->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'] === 'R0000') {
|
|
|
+ return [true, $resp['balance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $key = config::KEY;
|
|
|
+ $content = "{$params['partnerno']}||{$key}||{$params['timestamp']}";
|
|
|
+ return md5($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取毫秒级别的时间戳
|
|
|
+ */
|
|
|
+ private function getMillisecond()
|
|
|
+ {
|
|
|
+ $cur = microtime (true);
|
|
|
+ $cur = intval($cur * 1000);
|
|
|
+ return $cur;
|
|
|
+ }
|
|
|
+}
|