whereNotNull('notify_user_id') ->whereBetween('notify_at', [$now->copy()->startOfDay(), $now->copy()->endOfDay()]) ->get(); $app = EasyWeChat::officialAccount(); $app->setAccessToken(new \App\Services\WechatOfficialAccessToken( appId: $app->getAccount()->getAppId(), secret: $app->getAccount()->getSecret(), cache: $app->getCache(), httpClient: $app->getHttpClient(), stable: $app->getConfig()->get('use_stable_access_token', false), )); $api = $app->getClient(); // 微信公众号关联账户 $users = UserSocialite::where('user_type', (new AdminUser)->getMorphClass())->where('type', SocialiteType::WxOfficial)->whereIn('user_id', $list->pluck('notify_user_id'))->get(); foreach ($list as $item) { $user = $users->firstWhere('user_id', $item->notify_user_id); if ($user) { $response = $api->postJson('/cgi-bin/message/template/send', [ 'touser' => $user->openid, 'template_id' => '', 'url' => url('/h5/pages/record/detail?id=' . $item->id), 'data' => [] ]); if ($response->isFailed()) { logger('病历记录: 通知, 模板消息发送, 失败', $response->toArray(false)); continue; } $item->update(['is_notified' => 1]); } } } }