where('suite_id', $this->suiteId) ->value('suite_ticket_cipher') ?? ''); if ($cipher === '') { throw new RuntimeException('No suite_ticket found. 请先在企业微信服务商后台配置并验证应用指令回调。'); } return QywxPromotionCredentialCipher::decrypt($cipher); } public function setTicket(string $ticket): static { $now = time(); $cipher = QywxPromotionCredentialCipher::encrypt($ticket); $exists = Db::name('qywx_promotion_provider_state')->where('suite_id', $this->suiteId)->find(); if ($exists) { Db::name('qywx_promotion_provider_state')->where('suite_id', $this->suiteId)->update([ 'suite_ticket_cipher' => $cipher, 'ticket_received_at' => $now, 'update_time' => $now, ]); } else { Db::name('qywx_promotion_provider_state')->insert([ 'suite_id' => $this->suiteId, 'suite_ticket_cipher' => $cipher, 'ticket_received_at' => $now, 'create_time' => $now, 'update_time' => $now, ]); } return $this; } }