function initialize() { if (!$this->fetched) { $config =& get_config(); $assetUrl = $config['asset_service'] . $this->node['AssetID']; $curl = new Curl(); $curl->create($assetUrl); $curl->option(CURLOPT_HEADER, true); $curl->option(CURLOPT_NOBODY, true); $response = $curl->execute(); if ($response) { $headers = http_parse_headers($response); $this->size = $headers['Content-Length']; $this->contentType = $headers['Content-Type']; if (isset($headers['ETag'])) { $this->etag = $headers['ETag']; } else { if (isset($headers['Etag'])) { $this->etag = $headers['Etag']; } else { $this->etag = ''; } } } else { log_message('error', "InventoryFile: Failed to fetch headers from {$assetUrl}"); } $this->fetched = true; } }
function create_asset($assetID, $creatorID, $contentType, $filename) { $CI =& get_instance(); $CI->load->library('Curl'); $CI->load->helper('path'); $filename = rtrim(set_realpath($filename), '/'); $params = array('AssetID' => $assetID, 'CreatorID' => $creatorID, 'Asset' => "@{$filename};type={$contentType}"); echo 'Posting ' . $filename . ' to ' . $CI->config->item('asset_service') . '<br/>'; $curl = new Curl(); $curl->create($CI->config->item('asset_service')); $curl->option(CURLOPT_POST, TRUE); $curl->option(CURLOPT_POSTFIELDS, $params); $curl->http_method('post'); $response = json_decode($curl->execute(), TRUE); if (!isset($response)) { $response = array('Message' => 'Invalid or missing response. ' . $curl->error_string); } return $response; }
/** * 退款流程 * * @param array $order_id * @param array $payment * @param decimal $refund_amount */ public function refund($order, $payment, $refund_amount = 0) { global $db, $ecs; //获取pay_log记录 $sql = "SELECT * FROM " . $ecs->table('pay_log') . " WHERE order_id = '{$order['order_id']}' AND pay_id = '{$order['pay_id']}' AND is_paid = 1 ORDER BY log_id DESC LIMIT 1"; $log = $db->getRow($sql); if (empty($log)) { return false; } $wxtk = read_config('wxtoken'); $payment = array_merge($payment, $wxtk); $amount = $refund_amount > 0 && $refund_amount < $log['order_amount'] ? $refund_amount : $log['order_amount']; $refund = array('appid' => $payment['appid'], 'mch_id' => $payment['wxpay_mchid'], 'op_user_id' => $payment['wxpay_mchid'], 'nonce_str' => rands(32), 'out_refund_no' => $order['order_sn'], 'out_trade_no' => $order['order_sn'], 'refund_fee' => $amount * 100, 'total_fee' => $log['order_amount'] * 100, 'transaction_id' => $log['outer_sn']); $refund['sign'] = $this->sign($refund, $payment['wxpay_key']); // 调用微信退款接口 require_once ROOT_PATH . 'include/cls_curl.php'; $curl = new Curl(array('server' => 'https://api.mch.weixin.qq.com', 'ssl_verify_peer' => FALSE)); $curl->option(CURLOPT_SSLCERTTYPE, 'PEM'); $curl->option(CURLOPT_SSLCERT, ROOT_PATH . '../data/cert/wxpay_cert.pem'); $curl->option(CURLOPT_SSLKEYTYPE, 'PEM'); $curl->option(CURLOPT_SSLKEY, ROOT_PATH . '../data/cert/wxpay_key.pem'); $xml = array2xml($refund); //echo htmlspecialchars($xml);exit; $response = $curl->post('secapi/pay/refund', $xml, 'xml'); // 检查错误 if ($response['return_code'] == 'FAIL' || $response['result_code'] == 'FAIL') { $response['paytype'] = 'wxpay'; $response['order_id'] = $order['order_id']; insert_error_log('refund', $response, __FILE__); return false; } //pay_log 插入退款记录 insert_pay_log($order['order_id'], $amount, $order['pay_id'], PAY_ORDER, 3); return true; }