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($phone, int $amount, string $order_sn) { $params['mId'] = config::MCH_ID; $params['mOrderNo'] = $order_sn; $params['account'] = $phone; $params['subclassType'] = 'DB'; $params['faceAmount'] = $amount; $params['notifyUrl'] = config::NOTIFY_URL; $params['timestamp'] = date("YmdHis"); 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]; } $params = $this->req_params($card_no, $amount, $params['order_sn']); $sign = $this->sign($params); $params['sign'] = $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'] === '0') { return [true, $resp['orderNo'], false]; } elseif ($resp['code'] === 'XN_1000'){ $net_errno = 'HTTP-XN_1000'; return [false, $net_errno, true]; } else { return [false, $resp['msg'], false]; } } } public function query($refill_info) { $params['mId'] = config::MCH_ID; $params['mOrderNo'] = $refill_info['order_sn']; $params['sign'] = $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'] === '0') { $status = intval($resp['status']); if ($status === 1) { $updata['official_sn'] = $resp['content']; Model('refill_order')->edit($refill_info['order_id'], $updata); $order_state = ORDER_STATE_SUCCESS; } elseif ($status === 2) { $order_state = ORDER_STATE_CANCEL; } elseif ($status === 3) { $order_state = ORDER_STATE_SEND; } else { return [false, $status]; } return [true, $order_state]; } else { return [false, $resp['msg']]; } } } public function balance() { $params['mId'] = config::MCH_ID; $params['sign'] = $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'] === '0') { return [true, $resp['balance']]; } else { return [false, $resp['msg']]; } } } private function sign($params) { $content = ''; ksort($params); foreach ($params as $key => $val){ if(false === $this->check_empty($val)) { $content .= "{$key}={$val}&"; } } $content .= "key=".config::Key; return md5($content); } }