/** * 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; }
/** * Delete test wechat account * * <b>Request Type</b>: POST<br/><br/> * <b>Request Endpoint</b>:http://{server-domain}/api/management/channel/delete-test-wechat<br/><br/> * <b>Content-type</b>: application/json<br/><br/> * <b>Summary</b>: This api is used to delete test wechat account. * <br/><br/> * * <b>Request Params:</b> * <pre> * { * "accountId": "55546fc8e4b0d8376000b858" * } * </pre> */ public function actionDeleteTestWechat() { $wechatAccountId = $this->getParams('accountId'); $accountId = $this->getAccountId(); if (empty($wechatAccountId)) { throw new BadRequestHttpException(\Yii::t('common', 'parameters_missing')); } $result = Yii::$app->weConnect->deleteAccount($wechatAccountId); Channel::disableByChannelIds($accountId, [$wechatAccountId]); return $result; }