public static function getAmazonProduct($id, $locale) { $paa = ConfigParserLib::get('amazon', 'paa'); $aws = ConfigParserLib::get('amazon', 'aws'); // The region you are interested in $endpoint = $paa['marketplace'][$locale]; $uri = "/onca/xml"; $params = array("Service" => "AWSECommerceService", "Operation" => "ItemLookup", "AWSAccessKeyId" => $aws['access_key_id'], "AssociateTag" => $paa['associate_tag'], "ItemId" => $id, "IdType" => "ASIN", "ResponseGroup" => "Images,ItemAttributes,Offers", "Version" => "2011-08-01"); // Set current timestamp if not set if (!isset($params["Timestamp"])) { $params["Timestamp"] = gmdate('Y-m-d\\TH:i:s\\Z'); } // Sort the parameters by key ksort($params); $pairs = array(); foreach ($params as $key => $value) { array_push($pairs, rawurlencode($key) . "=" . rawurlencode($value)); } // Generate the canonical query $canonical_query_string = join("&", $pairs); // Generate the string to be signed $string_to_sign = "GET\n" . $endpoint . "\n" . $uri . "\n" . $canonical_query_string; // Generate the signature required by the Product Advertising API $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $aws['secret_key'], true)); // Generate the signed URL $url = 'http://' . $endpoint . $uri . '?' . $canonical_query_string . '&Signature=' . rawurlencode($signature); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $content = curl_exec($ch); $xml = simplexml_load_string($content); return array('amazon_cn_id' => $id, 'name' => strval($xml->Items->Item->ItemAttributes->Title), 'img' => strval($xml->Items->Item->ImageSets->ImageSet->LargeImage->URL), 'price' => $xml->Items->Item->OfferSummary->LowestNewPrice->Amount / 100); }
/** * 从字符串获得written_language_tag,如果不在映射表中,则返回默认的tag */ public static function getWltFromStr($str) { $wlt_map = ConfigParserLib::get('language', 'written_language_tag_map'); if (isset($wlt_map[strtolower($str)])) { return $wlt_map[strtolower($str)]; } else { return ConfigParserLib::get('language', 'default_written_language_tag'); } }
public static function getWrittenLanguageTag() { $user_wlt = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; $map = ConfigParserLib::get('language', 'written_languages_tag_map'); if (!empty($user_wlt) && isset($map[strtolower($user_wlt)])) { return $map[strtolower($user_wlt)]; } return ConfigParserLib::get('language', 'default_written_language_tag'); }
public function __construct() { if (empty($this->db)) { $db_engine = ConfigParserLib::get('db', 'using_db_engine'); $db_engine_class_name = StrLib::underlineToClassName($db_engine . 'DbEngine'); $db_server_name = ConfigParserLib::get('db', 'db_engine_to_server_name_map[\'' . $db_engine . '\']'); $db_config = ConfigParserLib::get('system', 'db_servers[\'' . $db_server_name . '\']'); $this->db = new $db_engine_class_name($db_config); } }
function encodeFilterUri($uri_data, $where = array()) { $map = ConfigParserLib::get('category', 'category_map'); $uri_position = ConfigParserLib::get('product/' . $uri_data['category_name'], 'uri_position'); $where_uri = implode('-', array_values($where)); if (empty($where) || 0 < preg_match('/^1-1-(00\\-)+00$/', $where_uri)) { $where_uri = ''; } return '/' . $uri_data['group_name'] . '/' . array_search($uri_data['category_name'], $map) . '/' . $where_uri; }
/** * api POST /qiniu/auth * * @example shell curl -d 'uri=http://ec4.images-amazon.com/images/I/61j8Hc4SVXL._SX425_.jpg' -H 'Accept:application/json; version=0.2' 'http://api.shaixuan.org/qiniu/fetch' * */ public function fetch() { try { $bucket = 'com-163-sinkcup-img-agc'; $qiniuConfig = ConfigParserLib::get('system', 'qiniu'); $auth = new Qiniu\Auth($qiniuConfig['accessKey'], $qiniuConfig['secretKey']); $ext = 'jpg'; $newFilename = md5($_POST['uri']) . '.' . $ext; $bucketMgr = new Qiniu\Storage\BucketManager($auth); $bucketMgr->fetch($_POST['uri'], $bucket, 'shaixuan/' . $newFilename); return array('filename' => $newFilename); } catch (Exception $e) { $error = array('code' => '202', 'msg' => ''); throw new ControllerException(json_encode($error)); } }
public function router($uri) { if (0 < preg_match('/^\\/products\\/\\w+\\/basic$/', $uri)) { $tmp = explode('/', $uri); $map = ConfigParserLib::get('category', 'category_map'); $category_name = $map[$tmp[2]]; $this->product_model = new ProductModel($category_name, self::$written_language_tag); switch (strtolower($_SERVER['REQUEST_METHOD'])) { case 'get': return $this->getBasic(); break; } } if (0 < preg_match('/^\\/products\\/\\w+$/', $uri)) { $tmp = explode('/', $uri); $map = ConfigParserLib::get('category', 'category_map'); $category_name = $map[$tmp[2]]; $this->product_model = new ProductModel($category_name, self::$written_language_tag); switch (strtolower($_SERVER['REQUEST_METHOD'])) { case 'post': return $this->add(); break; } } if (0 < preg_match('/^\\/products\\/\\w+\\/[0-9]+$/', $uri)) { $tmp = explode('/', $uri); $id = $tmp[3]; $map = ConfigParserLib::get('category', 'category_map'); $category_name = $map[$tmp[2]]; $this->product_model = new ProductModel($category_name, self::$written_language_tag); switch (strtolower($_SERVER['REQUEST_METHOD'])) { case 'get': return $this->get($id); break; case 'put': return $this->update($id); break; } } $error = array('code' => '501', 'msg' => '没有这个功能'); throw new ControllerException(json_encode($error)); }
<?php $v['group'] = ConfigParserLib::get('group/' . $uri_data['group_name'], 'nav[\'' . $written_language_tag . '\']'); //$output[] = 'group_hidden_categories_nav';
<?php $params = array('get' => $_GET); //$map = ConfigParserLib::get('category', 'category_map'); $v['product'] = FdHelperLib::crudApi('products/' . array_search($uri_data['category_name'], $map) . '/basic', $written_language_tag, $params); //$v['product'] = FdHelperLib::crudApi('products/' . array_search($uri_data['category_name'], $map) . '/' . $uri_data['id'], $written_language_tag, $params); $v['filter_rows'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'rows'); $v['attribute_value'] = FdHelperLib::crudApi('categories/' . $uri_data['category_name'] . '/attributes', $written_language_tag); $v['unlimited'] = ConfigParserLib::get('wlp', 'wlp[\'' . $written_language_tag . '\'][\'unlimited\']'); $v['attribute_name_wlp'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'attribute_name_wlp[\'' . $written_language_tag . '\']'); $v['category_name_wlp'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'name[\'' . $written_language_tag . '\']'); $uri_position = ConfigParserLib::get('product/' . $uri_data['category_name'], 'uri_position'); $v['uri_where'] = array(); $v['title'] = $v['category_name_wlp'] . ' '; $v['detail_attribute'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'detail_attribute'); $v['detail_attribute_name_wlp'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'detail_attribute_name_wlp[\'' . $written_language_tag . '\']'); //$output[] = 'filter';
} else { $page_num = $v['uri_where']['page_num']; } if (!isset($v['uri_where']['order_by']) || strval($v['uri_where']['order_by']) === '00') { $order_by = 1; $v['uri_where']['order_by'] = 1; } $tmp = array(); foreach ($v['uri_where'] as $key => $value) { if ($value !== '00') { $tmp[$key] = $value; } } unset($tmp['page_num']); $tmp['skip'] = (intval($page_num) - 1) * $page_size; $tmp['limit'] = $page_size; //$tmp['need'] = $page_size; //todo fields $order_by_conf = ConfigParserLib::get('product/' . $uri_data['category_name'], 'order_by'); $v['order_by_title_tail_wlp'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'order_by_title_tail_wlp[\'' . $written_language_tag . '\']'); foreach ($order_by_conf as $attribute_name => $data) { if (isset($data[$v['uri_where']['order_by']])) { $tmp['order_by'] = $attribute_name; $tmp['order_desc'] = $data[$v['uri_where']['order_by']] == 'desc' ? '1' : 0; $v['title'] .= ' ' . $v['order_by_title_tail_wlp'][$attribute_name][$data[$v['uri_where']['order_by']]]; break; } } $params = array('get' => $tmp); $map = ConfigParserLib::get('category', 'category_map'); $v['products_preview'] = FdHelperLib::crudApi('products/' . array_search($uri_data['category_name'], $map) . '/basic', $written_language_tag, $params); //$output[] = 'products_preview';
<?php $v['filter_rows'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'rows'); $v['attribute_value'] = FdHelperLib::crudApi('categories/' . $uri_data['category_name'] . '/attributes', $written_language_tag); $v['unlimited'] = ConfigParserLib::get('wlp', 'wlp[\'' . $written_language_tag . '\'][\'unlimited\']'); $v['attribute_name_wlp'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'attribute_name_wlp[\'' . $written_language_tag . '\']'); $v['attribute_name_title_tail_wlp'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'attribute_name_title_tail_wlp[\'' . $written_language_tag . '\']'); $v['category_name_wlp'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'name[\'' . $written_language_tag . '\']'); $uri_position = ConfigParserLib::get('product/' . $uri_data['category_name'], 'uri_position'); $v['uri_where_array'] = explode('-', $uri_data['where']); $v['uri_where'] = array(); //第一个是页码 $v['uri_where']['page_num'] = !empty($v['uri_where_array'][0]) ? $v['uri_where_array'][0] : 1; //第2个是排序 $v['uri_where']['order_by'] = isset($v['uri_where_array'][1]) ? $v['uri_where_array'][1] : 1; //筛选参数从第3个开始。这样以后加参数不会导致旧uri无效。 //比如1-2-0-0,加个参数1-2-0-0-0,以前的uri还有效。 //如果页面放在最后,就坏了。0-0-2-1,加个参数变成0-0-0-2-1,以前的uri无效了。 $v['title'] = $v['category_name_wlp'] . ' '; foreach ($uri_position as $position => $attribute_name) { $p = $position + 2; $v['uri_where'][$attribute_name] = isset($v['uri_where_array'][$p]) ? $v['uri_where_array'][$p] : '00'; if (isset($v['uri_where_array'][$p]) && $v['uri_where_array'][$p] !== '00') { $tail = isset($v['attribute_name_title_tail_wlp'][$attribute_name]) ? $v['attribute_name_title_tail_wlp'][$attribute_name] : ''; if (isset($v['attribute_value'][$attribute_name][$v['uri_where_array'][$p]])) { //是单选,api给了文字,显示 $v['title'] .= ' ' . $v['attribute_value'][$attribute_name][$v['uri_where_array'][$p]] . $tail; } else { //是多选,api不给值,自己显示文字 $v['title'] .= ' ' . $v['attribute_name_wlp'][$attribute_name] . $tail; }
public static function getProductUri($category_name, $id) { $map = ConfigParserLib::get('category', 'category_map'); return '/' . array_search($category_name, $map) . '/' . $id; }
<?php $tmp = scandir(dirname(__FILE__) . '/../conf/group/'); foreach ($tmp as $one) { if (stripos($one, '.conf') !== false) { $tmp2 = explode('.', $one); $v['groups'][$tmp2[0]] = ConfigParserLib::get('group/' . $tmp2[0], 'nav[\'' . $written_language_tag . '\']'); } }
<?php $v['attribute_name_wlp'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'attribute_name_wlp[\'' . $written_language_tag . '\']'); $v['order_by'] = ConfigParserLib::get('product/' . $uri_data['category_name'], 'order_by'); //$output[] = 'order_by';