Skip to content
This repository was archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
更新缓存时间为2小时;缓存内容改为所有主要参数
Browse files Browse the repository at this point in the history
  • Loading branch information
mybsdc committed Nov 2, 2019
1 parent 75791a8 commit dc443aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/Console/Pusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ public function handle()
Text::send($username, $priceText);

if (CatDiscount::$success) { // 正确返回了价格文言
/*$realUrl = CatDiscount::$standardUrl;
$token = md5(uniqid(microtime() . mt_rand(), true));
$allParams = CatDiscount::$allParams;

// 缓存商品地址
Redis::setex($token, config('urlTtl'), $realUrl);
Redis::setex($token, config('urlTtl'), json_encode($allParams));

// 价格走势截图
$imgFile = sprintf('%s.png', $token);
Expand All @@ -138,7 +138,7 @@ public function handle()
// 发送价格变动图片
if (file_exists($imgFile)) {
Image::send($username, $imgFile);
}*/
}
}

// TODO 保存数据到redis 以username作为键(若已存在则直接覆盖,且过期时间延长至2小时)
Expand Down
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
],
],

'urlTtl' => 3600 * 24 * 2, // 缓存有效期2天
'urlTtl' => 3600 * 2, // 缓存有效期2小时

/**
* 价格折线截图宽高
Expand Down
16 changes: 8 additions & 8 deletions libs/CatDiscount.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class CatDiscount
protected static $rtErrorMsg = '';

/**
* @var string 标准URL,也可能为null,可外部访问
* @var array 价格接口所有主要参数,缓存到redis后期会用到
*/
public static $standardUrl;
public static $allParams = [];

/**
* @var bool 整个处理流程是否完全完成
Expand Down Expand Up @@ -236,13 +236,14 @@ public static function getPrice($origStr = '')
return false;
}

self::$allParams = $allParams = [ // 构造参数并更新属性值
'zan_goods_id' => $goodsDetail['zan_goods_id'], // 若调最近半年价格接口,京东此参数应对应jd_zan_goods_id
'price' => $goodsDetail['price'],
'url' => $goodsDetail['url']
];
$response = Curl::post(
self::GET_ALL_HISTORICAL_PRICE_URL, // 直接获取最近一年价格,不再调用最近半年价格接口
[
'zan_goods_id' => $goodsDetail['zan_goods_id'], // 若调最近半年价格接口,京东此参数应对应jd_zan_goods_id
'price' => $goodsDetail['price'],
'url' => $goodsDetail['url']
],
$allParams,
self::MMZ_IOS_APP
);
$response = json_decode($response, true);
Expand Down Expand Up @@ -285,7 +286,6 @@ public static function getStandardUrl($origStr = '')
}

$rt = $response['data']['url_info'];
self::$standardUrl = $rt['url']; // 标准地址后期会被缓存

return [
'url' => $rt['url'],
Expand Down

0 comments on commit dc443aa

Please sign in to comment.