getProduct(['system_code' => $sys_pcode]); if (empty($product)) { return false; } else { return $product['refill_amount']; } } private function getProductCode($goods_id, $sys_pcode) { $thrid_refill = Model('thrid_refill'); $product = $thrid_refill->getProviderProduct($this->mStoreID,$goods_id,$sys_pcode); if (empty($product)) { return false; } else { return $product['channel_code']; } } 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']); Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]); $amount = $this->getProductAmount($params['product_code']); if(empty($amount)) { return [false, '产品未开启', false]; } $params = $this->req_params($card_no, $amount, $order_sn, $product_code); if(empty($params['szProductId'])) { return [false, '商品编号错误', false]; } $sign = $this->sign($params); $params['szVerifyString'] = $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); $nRtn = $resp['nRtn']; if (empty($resp)) { return [false, '网络错误', true]; } elseif ($nRtn === 0) { return [true, '', false]; } elseif (in_array($nRtn, config::ERR_NOS, true)) { return [false, $resp['szRtnCode'], false]; } elseif (in_array($nRtn, [2050, 999], true)) { $net_errno = "HTTP-{$nRtn}"; return [false, $resp['szRtnCode'], true]; } else { $err = 998; $net_errno = "HTTP-{$err}"; return [false, $resp['szRtnCode'], true]; } } } public function query($refill_info) { $params['szAgentId'] = config::USER_ID; $params['szOrderId'] = $refill_info['order_sn']; $key = config::KEY; $content = "szAgentId={$params['szAgentId']}&szOrderId={$params['szOrderId']}&szKey={$key}"; $params['szVerifyString'] = md5($content); $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, '网络错误']; } $status = $resp['nRtn']; if ($status === 5012) { $updata['official_sn'] = $resp['szRtnMsg']; Model('refill_order')->edit($refill_info['order_id'], $updata); $order_state = ORDER_STATE_SUCCESS; } elseif ($status === 5013) { $order_state = ORDER_STATE_CANCEL; } elseif (in_array($status, [5011,5019],true)) { $order_state = ORDER_STATE_SEND; } elseif ($status === 5005 && (time() - $refill_info['commit_time'] >= 300)) { $order_state = ORDER_STATE_NOEXIST; } else { return [false, $resp['szRtnMsg']]; } return [true, $order_state]; } } public function balance() { $params['szAgentId'] = config::USER_ID; $key = config::KEY; $content = "szAgentId={$params['szAgentId']}&szKey={$key}"; $params['szVerifyString'] = md5($content); $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['nRtn'] === 0) { return [true, $resp['fBalance']]; } else { return [false, $resp['szRtnCode']]; } } } private function sign($params) { $userid = config::USER_ID; $key = config::KEY; $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nMoney={$params['nMoney']}&nSortType={$params['nSortType']}"; $content .= "&nProductClass={$params['nProductClass']}&nProductType={$params['nProductType']}&szTimeStamp={$params['szTimeStamp']}&szKey={$key}"; return md5($content); } }