优化代码
This commit is contained in:
@@ -518,6 +518,34 @@ if (!function_exists('exit_data')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('artificialAllotWechatFriend')) {
|
||||
function artificialAllotWechatFriend($friend = [])
|
||||
{
|
||||
if (empty($friend)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//记录切换好友
|
||||
$cacheKey = 'allotWechatFriend';
|
||||
$cacheFriend = $friend;
|
||||
$cacheFriend['time'] = time() + 120;
|
||||
$maxRetry = 5;
|
||||
$retry = 0;
|
||||
do {
|
||||
$cacheFriendData = Cache::get($cacheKey, []);
|
||||
// 去重:移除同friendId的旧数据
|
||||
$cacheFriendData = array_filter($cacheFriendData, function($item) use ($cacheFriend) {
|
||||
return $item['friendId'] !== $cacheFriend['friendId'];
|
||||
});
|
||||
$cacheFriendData[] = $cacheFriend;
|
||||
$success = Cache::set($cacheKey, $cacheFriendData);
|
||||
$retry++;
|
||||
} while (!$success && $retry < $maxRetry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 调试打印变量但不终止程序
|
||||
* @return void
|
||||
|
||||
Reference in New Issue
Block a user