/** * Manager stop ongoing activity * * @param $wechatId * @param $activityTypeId * @param $managerId * @return array */ public static final function stopActivity($wechatId, $activityTypeId, $managerId) { $result = self::managerGetActivitySession($wechatId, $activityTypeId, $managerId); if ($result['status'] != ErrorCode::success) { return $result; } $key = $result['param']['key']; $session = $result['param']['session']; $activity = $result['param']['activity']; $result['param'] = null; //将session存储到活动详情表 $detail = new ActivityDetail(); $detail->activity_id = $activity['id']; $detail->session = base64_encode(json_encode($session)); $detail->updated_at = Carbon::now(); $detail->updated_at = Carbon::now(); if (!$detail->save()) { SysLog::info(__FILE__, __METHOD__, __LINE__, 'save activity session failed'); } //删除活动session, 关闭活动 if (Session::has($key)) { Session::remove($key); } Activity::closeActivity($activity); Log::info(PHP_EOL . '[===================================================Session Stop :]' . PHP_EOL . '[activity type:] ' . $activityTypeId . PHP_EOL . '[session key:] ' . $key . PHP_EOL); $result['param'] = ['activity' => $activity, 'session' => $session]; return $result; }
/** * Create validate code and Cache, invalid after 10 minutes * * @param $app * @param $user * @param $mobile * @return bool */ private static function createRegisterCache($app, $user, $mobile) { $key = 'sms-code-' . $app['id'] . $user['id']; if (Cache::has($key)) { Cache::forget($key); } if (isset($mobile)) { $data = ['code' => self::getRandCode(6), 'mobile' => $mobile]; $value = base64_encode(json_encode($data)); $expiresAt = Carbon::now()->addMinutes(10); Cache::put($key, $value, $expiresAt); SysLog::info(__FILE__, __METHOD__, __LINE__, PHP_EOL . '[======================================User Register :]' . PHP_EOL . '[mobile: ] ' . $mobile . PHP_EOL . '[code: ] ' . $data['code'] . PHP_EOL); return true; } return false; }