123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Service;
- use App\Log;
- use App\Models\AuthorizeCorp;
- use App\Models\CustomerDetails;
- use App\Models\DjUser;
- use App\RedisModel;
- use App\Service\ChatGroup\ChatGroupService;
- class TemplateCallbackService
- {
- /**
- * 回调数据处理
- * */
- public static function responseCommand($msgStr)
- {
- try {
- if(!empty($msgStr)) {
- $msgObj = simplexml_load_string($msgStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- $infoType = trim($msgObj->Event);
- if(empty($infoType)) {
- $infoType = trim($msgObj->InfoType);
- }
- $suiteId = trim($msgObj->SuiteId);
- $suiteTicket = trim($msgObj->SuiteTicket);
- switch ($infoType) {
- case 'suite_ticket': // 推送suite_ticket
- $result = MsgService::receiveSuiteTicket($suiteId, $suiteTicket);
- break;
- case 'create_auth': // 企业微信应用市场发起授权场景下授权成功通知
- $component = config('qyWechat.suite_info');
- $suiteSecret = $component['app_template_secret'];
- $authCode = trim($msgObj->AuthCode);
- $result = RedisModel::lPush(AuthorizeCorp::AUTH_CORP_RDS, json_encode(array('corpid' => $suiteId, 'secret' => $suiteSecret, 'auth_code' => $authCode)));
- break;
- case 'change_contact': // 通讯录事件回调
- $result = RedisModel::lPush(DjUser::CHANGE_CONTACT_RDS, json_encode(['data' => $msgStr]));
- if(!$result) {
- Log::logError('通讯录事件回调入队列失败', [
- 'data' => $msgStr
- ], 'ChangeContact');
- }
- // $result = ContactService::changeContactEvent($msgObj);
- break;
- case 'change_external_contact': // 外部客户事件回调
- $result = RedisModel::lPush(CustomerDetails::CHANGE_EXTERNAL_CONTACT_RDS, json_encode(['data' => $msgStr]));
- Log::logInfo('回调数据插入【Playlet::ChangeExternalContactList】队列完成', ['data' => $msgStr]);
- if(!$result) {
- Log::logError('外部客户事件回调入队列失败', [
- 'data' => $msgStr
- ], 'ChangeExternalContact');
- }
- // $result = ExternalUserService::changeExternalContactEvent($msgObj);
- break;
- case 'change_external_chat':
- $result = ChatGroupService::templateCallBack($msgStr);
- // $result = RedisModel::lPush(CustomerDetails::CHANGE_EXTERNAL_CONTACT_RDS, json_encode(['data' => $msgStr]));
- // Log::logInfo('回调数据插入【Playlet::ChangeExternalChatList】队列完成', ['data' => $msgStr]);
- if(!$result) {
- Log::logError('客户群变更事件回调处理失败', [
- 'data' => $msgStr
- ], 'ChangeExternalChat');
- }
- break;
- case 'change_external_tag':
- $result = TagService::templateCallBack($msgStr);
- break;
- default:
- $result = true;
- }
- } else {
- # 写入日志
- Log::logError($msgStr, [], 'responseTemplate');
- return false;
- }
- } catch (\Exception $e) {
- Log::logError('处理回调数据发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'data' => $msgStr
- ], 'responseTemplate');
- return false;
- }
- return $result;
- }
- }
|