/** * Synchroniz account channels, remove disable channels * @param Account $account * @throws ServerErrorHttpException * @return array */ public function syncAccountChannels($accountId) { $channelIds = Channel::getEnableChannelIds($accountId); $channelInfo = ['wechat' => [], 'weibo' => [], 'alipay' => []]; if (empty($channelIds)) { return $channelInfo; } $weChannels = \Yii::$app->weConnect->getAccounts($channelIds); $this->syncWebHookChannels($accountId, $weChannels); $enbaleChannel = []; foreach ($weChannels as $weChannel) { if ($weChannel['channel'] == Account::WECONNECT_CHANNEL_WEIXIN && !empty($weChannel['refreshToken'])) { $channelInfo['wechat'][] = $weChannel; $enbaleChannel[] = $weChannel['id']; } else { if ($weChannel['channel'] == Account::WECONNECT_CHANNEL_WEIXIN && !empty($weChannel['appSecret'])) { $channelInfo['wechat'][] = $weChannel; $enbaleChannel[] = $weChannel['id']; } else { if ($weChannel['channel'] == Account::WECONNECT_CHANNEL_WEIBO) { $weChannel['appkey'] = WEIBO_APP_KEY; $channelInfo['weibo'][] = $weChannel; $enbaleChannel[] = $weChannel['id']; } else { if ($weChannel['channel'] == Account::WECONNECT_CHANNEL_ALIPAY) { $channelInfo['alipay'][] = $weChannel; $enbaleChannel[] = $weChannel['id']; } } } } Channel::updateAll(['$set' => ['name' => $weChannel['name'], 'type' => empty($weChannel['accountType']) ? '' : $weChannel['accountType']]], ['channelId' => $weChannel['id'], 'accountId' => $accountId]); } $disableChannelIds = array_diff($channelIds, $enbaleChannel); if (!empty($disableChannelIds)) { $disableChannelIds = array_values($disableChannelIds); Channel::disableByChannelIds($accountId, $disableChannelIds); } return $channelInfo; }
/** * @return string * @param $channelId, string, channel ID */ public static function getAttentionQrcode($channelId) { $imageUrl = $qrcodeId = ''; $channelInfo = Channel::getEnableByChannelId($channelId); if (empty($channelInfo['qrcodeId'])) { $qrcodeId = Channel::createAttentionQrcode($channelId); if (!empty($qrcodeId)) { Channel::updateAll(['qrcodeId' => $qrcodeId], ['channelId' => $channelId]); } } else { $qrcodeId = $channelInfo['qrcodeId']; } if (!empty($qrcodeId)) { $qrcodeInfo = Yii::$app->weConnect->getQrcode($channelId, $qrcodeId); $imageUrl = $qrcodeInfo['imageUrl']; } return $imageUrl; }