SmsStatusPuller.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace addons\qcloudsms\library;
  3. use addons\qcloudsms\library\SmsSenderUtil;
  4. /**
  5. * 拉取短信状态类
  6. *
  7. */
  8. class SmsStatusPuller
  9. {
  10. private $url;
  11. private $appid;
  12. private $appkey;
  13. private $util;
  14. /**
  15. * 构造函数
  16. *
  17. * @param string $appid sdkappid
  18. * @param string $appkey sdkappid对应的appkey
  19. */
  20. public function __construct($appid, $appkey)
  21. {
  22. $this->url = "https://yun.tim.qq.com/v5/tlssmssvr/pullstatus";
  23. $this->appid = $appid;
  24. $this->appkey = $appkey;
  25. $this->util = new SmsSenderUtil();
  26. }
  27. /**
  28. * 拉取回执结果
  29. *
  30. * @param int $type 拉取类型,0表示回执结果,1表示回复信息
  31. * @param int $max 最大条数,最多100
  32. * @return string 应答json字符串,详细内容参见腾讯云协议文档
  33. */
  34. private function pull($type, $max)
  35. {
  36. $random = $this->util->getRandom();
  37. $curTime = time();
  38. $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random;
  39. $data = new \stdClass();
  40. $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime);
  41. $data->time = $curTime;
  42. $data->type = $type;
  43. $data->max = $max;
  44. return $this->util->sendCurlPost($wholeUrl, $data);
  45. }
  46. /**
  47. * 拉取回执结果
  48. *
  49. * @param int $max 拉取最大条数,最多100
  50. * @return string 应答json字符串,详细内容参见腾讯云协议文档
  51. */
  52. public function pullCallback($max)
  53. {
  54. return $this->pull(0, $max);
  55. }
  56. /**
  57. * 拉取回复信息
  58. *
  59. * @param int $max 拉取最大条数,最多100
  60. * @return string 应答json字符串,详细内容参见腾讯云协议文档
  61. */
  62. public function pullReply($max)
  63. {
  64. return $this->pull(1, $max);
  65. }
  66. }