企微短剧业务系统

ApplicationMsgService.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Service;
  3. use App\Models\AuthorizeCorp;
  4. class ApplicationMsgService
  5. {
  6. /**
  7. * 发送应用消息-文本消息
  8. * */
  9. public static function sendTextMsg($corpid, $content, $toUsers='', $toParties='', $toTags='', $safe=0, $enableIdTrans=0, $enableDuplicateCheck=0, $duplicateCheckInterval=1800)
  10. {
  11. $corpInfo = AuthorizeCorp::select(['agent_id'])->where('corpid', $corpid)->first();
  12. if(empty($corpInfo) || (empty($toUsers) && empty($toParties) && empty($toTags))) {
  13. return false;
  14. }
  15. $postData = [
  16. 'msgtype' => 'text',
  17. 'agentid' => $corpInfo->agent_id,
  18. 'text' => ['content' => $content],
  19. 'safe' => $safe,
  20. 'enable_id_trans' => $enableIdTrans,
  21. 'enable_duplicate_check' => $enableDuplicateCheck,
  22. 'duplicate_check_interval' => $duplicateCheckInterval
  23. ];
  24. if(!empty($toUsers)) {
  25. $postData['touser'] = implode('|', $toUsers);
  26. }
  27. if(!empty($toParties)) {
  28. $postData['toparty'] = implode('|', $toParties);
  29. }
  30. if(!empty($toTags)) {
  31. $postData['totag'] = implode('|', $toTags);
  32. }
  33. # 获取accessToken
  34. $accessToken = AuthorizeCorp::getAccessToken($corpid, '发送应用消息-文本消息');
  35. $requestUri = config('qyWechat.send_app_msg');
  36. $requestUri .= $accessToken;
  37. $response = HttpService::httpPost($requestUri, json_encode($postData));
  38. $responseData = json_decode($response, true);
  39. return $responseData;
  40. }
  41. }