$chatType, 'external_userid' => $externalUserIds, 'chat_id_list' => $chatIdList, 'sender' => $sender, 'text' => [ 'content' => $content ], 'attachments' => $attachments ]; $requestUri = config('qyWechat.send_message'); $requestUri .= $accessToken; $response = HttpService::httpPost($requestUri, json_encode($postData)); $responseData = json_decode($response, true); # 发起重试 if($response===false || !isset($responseData['errcode']) || in_array($responseData['errcode'], [-1, 45009, 45033, 40007])) { // 企微系统繁忙,发起重试 if($retry < 10) { sleep(1); Log::logInfo('企微系统繁忙,发起重试', [ 'corpid' => $corpid, 'postData' => $postData, 'retry' => $retry, 'response' => $response ], 'AddMassMsgTemplate'); $retry++; if(isset($responseData['errcode']) && $responseData['errcode'] == 40007) { // 企微返回素材media_id异常,重新处理附件信息 $attachments = MaterialService::radarAttachment($attachments, $corpid, $sender, 2, $ruleId, 1); } return MassMsgCreateService::addMsgTemplate($corpid, $externalUserIds, $sender, $content, $attachments, $ruleId, $retry, $chatType, $chatIdList); } } Log::logInfo('创建群发消息返回结果', [ 'postData' => $postData, 'retry' => $retry, 'corpid' => $corpid, 'response' => $responseData ], 'MassMsgSend'); return $responseData; } /** * 获取企业群发成员执行结果 * @param $corpid string 授权方企业微信id * @param $msgId string 群发消息的id * @param $sender string 外部联系人的userid * @param $limit integer 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值 * @param $cursor string 上次请求返回的next_cursor,用于分页请求(见官方文档) * @param $retry integer 重试次数,默认为0 * */ public static function getMassMsgSendResult($corpid, $msgId, $sender, $limit, $cursor, $retry=0) { # 获取SuiteAccessToken $accessToken = AuthorizeCorp::getAccessToken($corpid, '获取企业群发成员执行结果'); if(empty($accessToken)) { // Todo::令牌获取失败,发送报警 return false; } $postData = [ 'msgid' => $msgId, 'userid' => $sender, 'limit' => $limit, 'cursor' => $cursor ]; # 获取外部联系人详情信息API $getExternalContactUri = config('qyWechat.mass_msg_send_result'); $getExternalContactUri .= $accessToken; $response = HttpService::httpPost($getExternalContactUri, json_encode($postData)); $responseData = json_decode($response, true); Log::logInfo('获取企业群发成员执行结果', [ 'postData' => $postData, 'retry' => $retry, 'corpid' => $corpid, 'response' => $responseData ], 'getMassMsgSendResult'); if(isset($responseData['errcode']) && $responseData['errcode']) { if($retry <=5) { $retry++; MassMsgCreateService::getMassMsgSendResult($corpid, $msgId, $sender, $limit, $cursor, $retry); } Log::logError('企业群发成员执行结果获取失败', $responseData, 'GetMassMsgSendResult'); return false; } return $responseData; } }