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 getProductAmount($sys_pcode) { $thrid_refill = Model('thrid_refill'); $product = $thrid_refill->getProduct(['system_code' => $sys_pcode]); if (empty($product)) { return false; } else { return $product['refill_amount']; } } private function req_params(int $phone, int $amount, int $card_type, string $order_sn) { $params['merchantId'] = config::merchantId; $params['outTradeNo'] = $order_sn; $params['productId'] = config::PRODUCT[$card_type][$amount]; $params['account'] = $phone; $params['num'] = 1; $params['amount'] = $amount; $params['callbackUrl'] = config::NOTIFY_URL; return $params; } public function add($card_no, $card_type, $amount, $params,&$net_errno = 0) { $amount = $this->getProductAmount($params['product_code']); if(empty($amount)) { return [false, '产品未开启', false]; } $order_sn = $params['order_sn']; $params = $this->req_params($card_no, $amount, $card_type, $order_sn); if(empty($params['skuCode'])) { return [false, '商品编号错误', false]; } $sign = $this->sign($params); $params['verifyString'] = $sign; $resp = http_request(config::ORDER_URL, $params, 'POST', false, 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'] === 200) { return [true, $resp['data']['sysOrderNo'], false]; } else { return [false, $resp['msg'], false]; } } } public function query($refill_info) { $params['clientId'] = config::clientId; $params['clientOrderNo'] = $refill_info['order_sn']; $params['verifyString'] = $this->sign($params); $resp = http_request(config::QUERY_URL, $params, 'POST', false, 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'] === 200) { $data = $resp['data']; $status = $data['status']; if ($status === '4') { $updata['official_sn'] = $data['officialOrderNo']; Model('refill_order')->edit($refill_info['order_id'], $updata); $order_state = ORDER_STATE_SUCCESS; } elseif ($status === '3') { $order_state = ORDER_STATE_CANCEL; } elseif ($status === '0' || $status === '2') { $order_state = ORDER_STATE_SEND; } else { return [false, $resp['msg']]; } return [true, $order_state]; } elseif ($resp['code'] === -9 && (time() - $refill_info['commit_time'] >= 600)) { return [true, ORDER_STATE_NOEXIST]; } else { return [false, $resp['msg']]; } } } public function balance() { $params['clientId'] = config::clientId; $params['verifyString'] = $this->sign($params); $resp = http_request(config::BALANCE_URL, $params, 'POST', false, 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'] === 200) { return [true, $resp['data']['balance']]; } else { return [false, $resp['msg']]; } } } private function sign($params) { ksort($params); $str = urldecode(http_build_query($params)); $str .= '&key=' . config::Key; return md5($str); } }