KingttoGateway.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 KingttoGateWay.
  18. *
  19. * @see http://www.kingtto.cn/
  20. */
  21. class KingttoGateway extends Gateway
  22. {
  23. use HasHttpRequest;
  24. const ENDPOINT_URL = 'http://101.201.41.194:9999/sms.aspx';
  25. const ENDPOINT_METHOD = 'send';
  26. /**
  27. * @param PhoneNumberInterface $to
  28. * @param MessageInterface $message
  29. * @param Config $config
  30. *
  31. * @return \Psr\Http\Message\ResponseInterface|array|string
  32. *
  33. * @throws GatewayErrorException
  34. */
  35. public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config)
  36. {
  37. $params = [
  38. 'action' => self::ENDPOINT_METHOD,
  39. 'userid' => $config->get('userid'),
  40. 'account' => $config->get('account'),
  41. 'password' => $config->get('password'),
  42. 'mobile' => $to->getNumber(),
  43. 'content' => $message->getContent(),
  44. ];
  45. $result = $this->post(self::ENDPOINT_URL, $params);
  46. if ('Success' != $result['returnstatus']) {
  47. throw new GatewayErrorException($result['message'], $result['remainpoint'], $result);
  48. }
  49. return $result;
  50. }
  51. }