where(['status'=>[MapKeyEnum::STATUS_WAIT,MapKeyEnum::STATUS_USE]])->order(['status'=>'desc','id'=>'desc'])->column('key'); //设置缓存 Cache::set('TENCENT_MAP_KEY', $tencentMapKey); if (empty($tencentMapKey)) { return ''; } } //删除一个key if ($isDelete) { //删除缓存 Cache::delete('TENCENT_MAP_KEY'); //移除第一个key $tencentMapKey = is_array($tencentMapKey) ? $tencentMapKey : [$tencentMapKey]; array_shift($tencentMapKey); if (empty($tencentMapKey)) { return ''; } //设置缓存 $tencentMapKey = is_array($tencentMapKey) ? $tencentMapKey : [$tencentMapKey]; Cache::set('TENCENT_MAP_KEY', $tencentMapKey); } //更新key状态 MapKey::where(['key'=>$tencentMapKey[0]])->update(['status'=>MapKeyEnum::STATUS_USE]); return $tencentMapKey[0]; } /** * @notes 校验返回结果 * @param $result * @return bool * @author ljj * @date 2024/9/20 上午10:33 */ public static function checkResult($result) : bool { if (!isset($result['status']) || $result['status'] === 0) { return true; } else { //从缓存读取腾讯地图key $tencentMapKey = Cache::get('TENCENT_MAP_KEY'); $tencentMapKey = is_array($tencentMapKey) ? $tencentMapKey : [$tencentMapKey]; //更新key状态 MapKey::where(['key'=>$tencentMapKey[0]])->update(['status'=>MapKeyEnum::STATUS_ABNORMAL,'error_info'=>json_encode($result)]); if (count($tencentMapKey) <= 1) { //删除缓存 Cache::delete('TENCENT_MAP_KEY'); return true; } return false; } // 120-此key每秒请求量已达到上限 121-此key每日调用量已达到上限 190-无效的KEY 199-此key未开启webservice功能 311-key格式错误 // if (!in_array($result['status'],[120,121,190,199,311])) { // return true; // } } }