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'); $store_id = $this->mStoreID; $product = $thrid_refill->getProviderProduct($store_id, $goods_id, $sys_pcode); if (empty($product)) { return false; } else { return $product['channel_code']; } } private function req_params(int $phone, string $order_sn) { $params['UserId'] = config::USER_ID; $params['TimesTamp'] = $this->getMillisecond(); $params['Count'] = 1; $params['UserOrderId'] = $order_sn; $params['Account'] = $phone; $params['ClientIP'] = config::API_IP; $params['NotifyUrl'] = config::NOTIFY_URL; return $params; } public function add($card_no, $card_type, $amount, $params,&$net_errno = 0) { return [true, '', false]; // $params = $this->req_params($card_no, $params['order_sn']); // $goods_id = intval($params['goods_id']); // $channel_code = $this->getProductCode($goods_id, $params['product_code']); // if(empty($channel_code)) { // return [false, '产品有误', false]; // } // $params['ProductNumber'] = $channel_code; // $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['OutOrderID'], false]; // } elseif ($resp['Code'] === -170 || $resp['Code'] === -180){ // $net_errno = "HTTP-{$resp['Code']}"; // return [false, $net_errno, true]; // } else { // return [false, $resp['Msg'], false]; // } // } } public function query($refill_info) { $params['UserId'] = config::USER_ID; $params['TimesTamp'] = $this->getMillisecond(); $params['UserOrderId'] = $refill_info['order_sn']; $content = "{$params['UserId']}{$params['TimesTamp']}{$params['UserOrderId']}".config::Key; $params['Sign'] = strtoupper(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, '系统错误']; } elseif ($resp['Code'] === 0) { $status = $resp['Data']['OrderStatus']; if ($status === 2) { $order_state = ORDER_STATE_SUCCESS; } elseif ($status === 3) { $order_state = ORDER_STATE_CANCEL; } elseif ($status === 1) { $order_state = ORDER_STATE_SEND; } else { return [false, $status]; } return [true, $order_state]; } elseif ($resp['Code'] === -240 && (time() - $refill_info['commit_time'] >= 600)) { return [true, ORDER_STATE_NOEXIST]; } else { return [false, $resp['Msg']]; } } } public function balance() { $params['UserId'] = config::USER_ID; $params['TimesTamp'] = $this->getMillisecond(); $content = "{$params['UserId']}{$params['TimesTamp']}".config::Key; $params['Sign'] = strtoupper(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['Code'] === 0) { return [true, $resp['Data'][0]['Balance'] / 10000]; } else { return [false, $resp['Msg']]; } } } private function sign($params) { $key = config::Key; $content = "{$params['UserId']}{$params['Count']}{$params['NotifyUrl']}{$params['Account']}{$params['ClientIP']}{$params['UserOrderId']}{$params['ProductNumber']}"; $content .= "{$params['TimesTamp']}{$key}"; return strtoupper(md5($content)); } private function getMillisecond() { $cur = microtime (true); $cur = intval($cur * 1000); return $cur; } }