GZHSendKFMessageService.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Service\WechatPlatform;
  3. use App\Service\Util\Support\Http\HttpRequestService;
  4. use App\Service\Util\Support\Http\WechatURL;
  5. use EasyWeChat\OpenPlatform\Application;
  6. use Illuminate\Support\Facades\Cache;
  7. class GZHSendKFMessageService
  8. {
  9. /**
  10. * 发送文本客服消息
  11. * @param $officialAccount \EasyWeChat\OfficialAccount\Application
  12. * @param $openid
  13. * @param $content
  14. * @param $traceContext
  15. * @return bool
  16. */
  17. public static function sendText($officialAccount, $openid, $content, $traceContext) {
  18. try {
  19. $officialAccount->getClient()
  20. ->postJson('cgi-bin/message/custom/send', [
  21. 'touser' => $openid,
  22. 'msgtype' => 'text',
  23. 'text' => [
  24. 'content' => $content
  25. ]
  26. ])->toArray();
  27. return true;
  28. } catch (\Throwable $exception) {
  29. myLog('KFMessageSend')->error('发送客服消息失败', [
  30. 'openid' => $openid, 'content' => $content,
  31. 'exceptionMsg' => $exception->getMessage(),
  32. 'expTrace' => $exception->getTraceAsString(),
  33. 'traceInfo' => $traceContext->getTraceInfo()
  34. ]);
  35. return false;
  36. }
  37. }
  38. }