|
@@ -0,0 +1,156 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\jumithird;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/jumithird/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function goods($quality, int $amount, int $card_type, $regin_no, $other)
|
|
|
+ {
|
|
|
+ [$goods_id, $price] = parent::goods($quality, $amount, $card_type, $regin_no, $other);
|
|
|
+ if ($goods_id <= 0) return [0, 0];
|
|
|
+
|
|
|
+ $store_id = $this->mStoreID;
|
|
|
+ $pcode = $other['product_code'];
|
|
|
+ $thrid_refill = Model('thrid_refill');
|
|
|
+ $product = $thrid_refill->getProviderProduct($store_id, $goods_id, $pcode);
|
|
|
+ if (empty($product)) {
|
|
|
+ Log::record("cannot find provider's produce where name={$this->mName}, goods_id = {$goods_id} pcode={$pcode}", Log::ERR);
|
|
|
+ return [0, 0];
|
|
|
+ } else {
|
|
|
+ return [$goods_id, ncPriceFormat($product['channel_amount'])];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getProductCode($goods_id, $sys_pcode)
|
|
|
+ {
|
|
|
+ $thrid_refill = Model('thrid_refill');
|
|
|
+ $product = $thrid_refill->getProviderProduct(111, $goods_id, $sys_pcode);
|
|
|
+ if (empty($product)) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return $product['channel_code'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $phone, int $amount, string $order_sn, string $product_code)
|
|
|
+ {
|
|
|
+ $params['mch_no'] = config::MCH_ID;
|
|
|
+ $params['order_no'] = $order_sn;
|
|
|
+ $params['product_id'] = $product_code;
|
|
|
+ $params['money'] = $amount;
|
|
|
+ $params['account'] = $phone;
|
|
|
+ $params['notify_url'] = config::NOTIFY_URL;
|
|
|
+
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
|
|
|
+ {
|
|
|
+ $order_sn = $params['order_sn'];
|
|
|
+ $goods_id = intval($params['goods_id']);
|
|
|
+ $product_code = $this->getProductCode($goods_id, $params['product_code']);
|
|
|
+
|
|
|
+ $params = $this->req_params($card_no, $amount, $order_sn, $product_code);
|
|
|
+ $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'] === '0000') {
|
|
|
+ return [true, $resp['data']['channel_order_no'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['mch_no'] = config::MCH_ID;
|
|
|
+ $params['order_no'] = $refill_info['order_sn'];
|
|
|
+ $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'] == '0000') {
|
|
|
+ $status = intval($resp['data']['status']);
|
|
|
+ if ($status === 1) {
|
|
|
+ $updata['official_sn'] = $resp['data']['official_sn'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($status === 3) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif (in_array($status, [0, 2])) {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['mch_no'] = config::MCH_ID;
|
|
|
+ $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'] == '0000') {
|
|
|
+ return [true, $resp['data']['money']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $content = '';
|
|
|
+ ksort($params);
|
|
|
+ foreach ($params as $key => $val) {
|
|
|
+ $content .= "{$key}={$val}&";
|
|
|
+ }
|
|
|
+ $content .= "token=" . config::Token;
|
|
|
+
|
|
|
+ return md5($content);
|
|
|
+ }
|
|
|
+}
|