|
@@ -0,0 +1,147 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\weisanhuo_normal;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/weisanhuo_normal/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $card_no, int $card_type, string $order_sn, int $amount): array
|
|
|
+ {
|
|
|
+ $params['outTradeNo'] = $order_sn;
|
|
|
+ $params['secretId'] = config::SECRET_ID;
|
|
|
+ $params['account'] = $card_no;
|
|
|
+
|
|
|
+ $product_id = config::ProductIdS[$card_type][$amount] ?? false;
|
|
|
+ if ($product_id === false){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $params['packageCode'] = $product_id;
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
|
|
|
+ {
|
|
|
+ $params = $this->req_params($card_no, $card_type, $params['order_sn'], $amount);
|
|
|
+ if (empty($params)){
|
|
|
+ return [false, '产品编码错误', false];
|
|
|
+ }
|
|
|
+
|
|
|
+ $sign = config::sign($params,['outTradeNo']);
|
|
|
+ $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];
|
|
|
+ }
|
|
|
+ if ($resp['success'] === false){
|
|
|
+ return [false, $resp['returnMessage'], false];
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = $resp['data']['status'];
|
|
|
+ if ($status == 'waiting') {
|
|
|
+ return [true, $resp['data']['inTradeNo'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['data']['statusDesc'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info): array
|
|
|
+ {
|
|
|
+ $params['secretId'] = config::SECRET_ID;
|
|
|
+ $params['outTradeNo'] = $refill_info['order_sn'];
|
|
|
+ $sign = config::sign($params, ['outTradeNo']);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::QUERY_URL, $params, 'GET');
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', ''];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp))
|
|
|
+ {
|
|
|
+ return [false, '网络错误', ''];
|
|
|
+ }
|
|
|
+ elseif ($resp['success'] === true)
|
|
|
+ {
|
|
|
+ $offical_sn = '';
|
|
|
+
|
|
|
+ if(!empty($resp['data']))
|
|
|
+ {
|
|
|
+ $status = $resp['data']['status'];
|
|
|
+ if ($status == 'success') {
|
|
|
+ $offical_sn = $resp['data']['operatorTradeNo'];
|
|
|
+ $ch_trade_no = $resp['data']['inTradeNo'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $offical_sn,'ch_trade_no' => $ch_trade_no]);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($status == 'failed') {
|
|
|
+ $ch_trade_no = $resp['data']['inTradeNo'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $ch_trade_no]);
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif ($status == 'waiting') {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $status, $offical_sn];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $order_state, $offical_sn];
|
|
|
+ }
|
|
|
+ elseif ((time() - $refill_info['commit_time']) >= 600) {
|
|
|
+ return [true, ORDER_STATE_NOEXIST, $offical_sn];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [true, ORDER_STATE_SEND, $offical_sn];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return [false, $resp['returnMessage'], ''];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance(): array
|
|
|
+ {
|
|
|
+ $params['secretId'] = config::SECRET_ID;
|
|
|
+
|
|
|
+ $sign = config::sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::BALANCE_URL, $params);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ } else {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if ($resp['success'] === true) {
|
|
|
+ return [true, $resp['data']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['returnMessage']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|