SendMessageService.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * 发短信
  4. * @copyright 引擎力
  5. * @author lc
  6. * @since 2020-09-17
  7. */
  8. namespace App\Http\Services;
  9. use GuzzleHttp\Client;
  10. class SendMessageService
  11. {
  12. /**
  13. * 发送短信通知
  14. * @param $mobile
  15. * @param $keyWold
  16. * @param int $type
  17. */
  18. public function sendMessage($mobile, $keyWold, $type = 1)
  19. {
  20. if ($type == 1) {
  21. $tpl = 'SMS_228115546';//亲!后台新增了 {keyword} 关键词 需要进行分析,请及时处理喔~
  22. } elseif ($type == 2) {
  23. $tpl = 'SMS_228117817';//亲!${keyword} 的关键词数据已经生成请在后台查看。
  24. } else {
  25. $tpl = 'SMS_228142587';//亲!您有一条 ${keyword} 的关键词查询任务。
  26. }
  27. $url = 'http://translate.api.yinqingli.net/openapi/Msg/Msg';
  28. $data = [
  29. 'mobile' => $mobile,
  30. 'tpl' => $tpl,
  31. 'TemplateParam' => [
  32. 'keyword' => $keyWold,
  33. ],
  34. ];
  35. $client = new Client();
  36. $response = $client->post($url, [
  37. 'form_params' => $data,
  38. ]);
  39. $response->getBody()->getContents();
  40. }
  41. }