where('id', 'eq', $id)->update(['wx_msg_id' => $wx_msg_id]); $this->success('成功'); } catch (Exception $exception) { LogService::error("[ SendMessage ] [ handWxMsgId ] " . $exception->getMessage()); $this->error($exception->getMessage()); } } else { $this->error('更新wx_msg_id失败'); } } /** * 删除两天前的标签 */ public function handDelTags() { $sendChannelMessageModel = new SendChannelMessage(); $timestamp = strtotime(date("Y-m-d", strtotime("-2 day"))); $res = $sendChannelMessageModel->field('distinct channel_id')->where('createtime', '<=', $timestamp)->select(); if ($res) { foreach ($res as $k => $item) { $channel_id = $item['channel_id']; $adminConfig = new AdminConfig(); $adminInfo = $adminConfig->getAdminInfoAll($channel_id); try { $wechat = new WeChatObject($adminInfo); $officialAccount = $wechat->getOfficialAccount(); if (!empty($officialAccount) && $officialAccount->user_tag) { $tagslist = $officialAccount->user_tag->list(); if (!empty($tagslist['tags'])) { foreach ($tagslist['tags'] as $k => $tag) { // 找到匹配的tag if (preg_match('/^h_job_/', trim($tag['name']))) { // 解析tag中的日期,比较大小 $tag_arr = explode('_', $tag['name']); if (!empty($tag_arr[2]) && $tag_arr[2] < date('Ymd', $timestamp)) { $res = $officialAccount->user_tag->delete($tag['id']); echo 'Success:' . $res; } } } } } } catch (\Exception $exception) { echo $exception->getMessage(); LogService::error($exception->getMessage()); } } } } /** * 查看渠道下的所有Tag标签 * @param $channel_id * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException */ public function handListTags($channel_id) { $adminConfig = new AdminConfig(); $adminInfo = $adminConfig->getAdminInfoAll($channel_id); $wechat = new WeChatObject($adminInfo); $officialAccount = $wechat->getOfficialAccount(); $list = $officialAccount->user_tag->list(); return $list; } }