1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Service;
- use App\Models\AuthorizeCorp;
- class ApplicationMsgService
- {
- /**
- * 发送应用消息-文本消息
- * */
- public static function sendTextMsg($corpid, $content, $toUsers='', $toParties='', $toTags='', $safe=0, $enableIdTrans=0, $enableDuplicateCheck=0, $duplicateCheckInterval=1800)
- {
- $corpInfo = AuthorizeCorp::select(['agent_id'])->where('corpid', $corpid)->first();
- if(empty($corpInfo) || (empty($toUsers) && empty($toParties) && empty($toTags))) {
- return false;
- }
- $postData = [
- 'msgtype' => 'text',
- 'agentid' => $corpInfo->agent_id,
- 'text' => ['content' => $content],
- 'safe' => $safe,
- 'enable_id_trans' => $enableIdTrans,
- 'enable_duplicate_check' => $enableDuplicateCheck,
- 'duplicate_check_interval' => $duplicateCheckInterval
- ];
- if(!empty($toUsers)) {
- $postData['touser'] = implode('|', $toUsers);
- }
- if(!empty($toParties)) {
- $postData['toparty'] = implode('|', $toParties);
- }
- if(!empty($toTags)) {
- $postData['totag'] = implode('|', $toTags);
- }
- # 获取accessToken
- $accessToken = AuthorizeCorp::getAccessToken($corpid, '发送应用消息-文本消息');
- $requestUri = config('qyWechat.send_app_msg');
- $requestUri .= $accessToken;
- $response = HttpService::httpPost($requestUri, json_encode($postData));
- $responseData = json_decode($response, true);
- return $responseData;
- }
- }
|