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 req_params(string $order_sn, string $product_code,$quantity) { $params['partner'] = config::PARTNER; $params['service'] = 'cardSaleAgent'; $params['format'] = 'json'; $params['orderTime'] = date("YmdHis",time()); $params['partnerOrderNo'] = $order_sn; $params['productNo'] = $product_code; $params['quantity'] = 1; $params['amount'] = $quantity * 100; return $params; } 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) { refill\util::send_test($params['order_sn']); return [true , '',false]; } private function direct_add($card_no, $params, &$net_errno) { $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]); $quantity = intval($params['quantity']); $params = $this->req_params($order_sn,$product_code,$quantity); $params['userName'] = $card_no; $params['bizType'] = '02'; $sign = $this->sign($params); $params['sign'] = $sign; $resp = http_request(config::ORDER_URL, $params, 'GET', false, [], $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['respCode'] == '00') { $notify_data = $this->notify_data_format($resp,true); refill\util::async_notify('suning',$notify_data,1); return [true, $resp['orderNo'], false]; } else { return [false, $resp['message'], false]; } } } private function cardkey_add($params,&$net_errno) { $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]); $quantity = intval($params['quantity']); $params = $this->req_params($order_sn,$product_code,$quantity); $params['bizType'] = '01'; $sign = $this->sign($params); $params['sign'] = $sign; $resp = http_request(config::CARD_ORDER_URL, $params, 'GET', false, [], $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['respCode'] == '00') { $notify_data = $this->notify_data_format($resp, false); refill\util::async_notify('suning', $notify_data, 1); return [true, $resp['orderNo'], false]; } else { return [false, $resp['message'], false]; } } } private function rsa_decode($encrypted) { $ret = openssl_private_decrypt(base64_decode($encrypted), $decrypted, config::PRIVATE_KEY); if ($ret) { $result = json_decode($decrypted, true); return $result; } else { $err = openssl_error_string(); Log::record("suning callback openssl_private_decrypt error={$err}",Log::ERR); return false; } } public function query($refill_info) { return [false, '苏宁三方下单即回调,无需查询接口']; } private function sign($params) { ksort($params); $body = ""; $i = 0; foreach ($params as $k => $v) { if ($i == 0) { $body .= "{$k}={$v}"; } else { $body .= "&{$k}={$v}"; } $i++; } return hash_hmac("sha1", $body, config::APP_KEY); } private function notify_data_format($params,$fdirect): array { $data['order_sn'] = $params['partnerOrderNo']; $data['orderNo'] = $params['orderNo']; $card_list = $params['cardList']; if(count($card_list) == 1) { $item = $params['cardList'][0]; if($fdirect) { $data['card_info'] = ['type' => 'direct','card_no' => $item['cardNo'],'amount' => $item['amount'],'desc' => $item['cardCatalogName']]; } else { $password = $this->rsa_decode($item['password']); $data['card_info'] = ['type' => 'card_key', 'card_no' => $item['cardNo'],'amount' => $item['amount'],'password' => $password, 'desc' => $item['cardCatalogName']]; } } else { $data['card_info'] = []; } return $data; } }