ZzyunGateway.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the overtrue/easy-sms.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Overtrue\EasySms\Gateways;
  11. use Overtrue\EasySms\Contracts\MessageInterface;
  12. use Overtrue\EasySms\Contracts\PhoneNumberInterface;
  13. use Overtrue\EasySms\Exceptions\GatewayErrorException;
  14. use Overtrue\EasySms\Support\Config;
  15. use Overtrue\EasySms\Traits\HasHttpRequest;
  16. /**
  17. * Class RongheyunGateway.
  18. *
  19. * @see https://zzyun.com/
  20. */
  21. class ZzyunGateway extends Gateway
  22. {
  23. use HasHttpRequest;
  24. const ENDPOINT_URL = 'https://zzyun.com/api/sms/sendByTplCode';
  25. /**
  26. * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to
  27. * @param \Overtrue\EasySms\Contracts\MessageInterface $message
  28. * @param \Overtrue\EasySms\Support\Config $config
  29. *
  30. * @return array
  31. *
  32. * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ;
  33. */
  34. public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config)
  35. {
  36. $time = time();
  37. $user_id = $config->get('user_id');
  38. $token = md5($time . $user_id . $config->get('secret'));
  39. $params = [
  40. 'user_id' => $user_id,
  41. 'time' => $time,
  42. 'token' => $token,
  43. 'mobiles' => $to->getNumber(),// 手机号码,多个英文逗号隔开
  44. 'tpl_code' => $message->getTemplate($this),
  45. 'tpl_params' => $message->getData($this),
  46. 'sign_name' => $config->get('sign_name'),
  47. ];
  48. $result = $this->post(self::ENDPOINT_URL, $params);
  49. if ('Success' != $result['Code']) {
  50. throw new GatewayErrorException($result['Message'], $result['Code'], $result);
  51. }
  52. return $result;
  53. }
  54. }