|
@@ -0,0 +1,144 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\juhu;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/juhu/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 $card_type, $amount, string $order_sn)
|
|
|
+ {
|
|
|
+ $params['phone'] = $phone;
|
|
|
+ $params['product_id'] = $amount;
|
|
|
+ $params['notify_url'] = config::NOTIFY_URL;
|
|
|
+ $params['tradeNo'] = $order_sn;
|
|
|
+ $params['type'] = config::operator[$card_type];
|
|
|
+
|
|
|
+ return json_encode($params);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
|
|
|
+ {
|
|
|
+ $order_sn = $params['order_sn'];
|
|
|
+ $params = $this->req_params($card_no, $card_type, $amount, $order_sn);
|
|
|
+ $time = time();
|
|
|
+ $api_user_name = config::API_USER_NAME;
|
|
|
+ $sign = $this->sign($time);
|
|
|
+
|
|
|
+ $header = [
|
|
|
+ 'Content-Type: application/json',
|
|
|
+ "API-USER-NAME: {$api_user_name}",
|
|
|
+ "API-NAME: OrderCreate",
|
|
|
+ "API-TIMESTAMP: {$time}",
|
|
|
+ "API-SIGNATURE: {$sign}",
|
|
|
+ ];
|
|
|
+ $resp = http_post_data(config::REQUEST_URL, $params, $header, $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['ack'] == 'success') {
|
|
|
+ return [true, $resp['message']['order_number'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['message'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['tradeNo'] = $refill_info['order_sn'];
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ $api_user_name = config::API_USER_NAME;
|
|
|
+ $sign = $this->sign($time);
|
|
|
+
|
|
|
+ $header = [
|
|
|
+ 'Content-Type: application/json',
|
|
|
+ "API-USER-NAME: {$api_user_name}",
|
|
|
+ "API-NAME: OrderQuery",
|
|
|
+ "API-TIMESTAMP: {$time}",
|
|
|
+ "API-SIGNATURE: {$sign}",
|
|
|
+ ];
|
|
|
+
|
|
|
+ $resp = http_post_data(config::REQUEST_URL, json_encode($params), $header);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ } else {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ } elseif ($resp['ack'] === 'success') {
|
|
|
+ $data = $resp['order'];
|
|
|
+ if ($data['shipping_status'] === '1') {
|
|
|
+ $updata['official_sn'] = strtolower($data['voucher']) == 'null' ? '' : $data['voucher'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif (in_array($data['shipping_status'], ['0', '3', '4'], true)) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif (in_array($data['shipping_status'], ['2', '5'], true)) {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $resp['message']];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['message']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $time = time();
|
|
|
+ $api_user_name = config::API_USER_NAME;
|
|
|
+ $sign = $this->sign($time);
|
|
|
+
|
|
|
+ $header = [
|
|
|
+ 'Content-Type: application/json',
|
|
|
+ "API-USER-NAME: {$api_user_name}",
|
|
|
+ "API-NAME: BalanceQuery",
|
|
|
+ "API-TIMESTAMP: {$time}",
|
|
|
+ "API-SIGNATURE: {$sign}",
|
|
|
+ ];
|
|
|
+
|
|
|
+ $resp = http_post_data(config::REQUEST_URL, '', $header);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ } else {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ } elseif ($resp['ack'] === 'success') {
|
|
|
+ return [true, $resp['balance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['message']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($time)
|
|
|
+ {
|
|
|
+ $ip = config::API_IP;
|
|
|
+ $cert = config::API_CERT;
|
|
|
+ $content = $ip . $time . $cert;
|
|
|
+
|
|
|
+ return md5($content);
|
|
|
+ }
|
|
|
+}
|