chuanglanSMS.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace common\components;
  3. /**
  4. * 创蓝短信接口
  5. */
  6. class chuanglanSMS{
  7. const SENDURL='http://smsbj1.253.com/msg/send/json';
  8. const QUERYURL='http://222.73.117.138:7891/bi';
  9. const ISENDURL='http://222.73.117.140:8044/mt';
  10. const IQUERYURL='http://222.73.117.140:8044/bi';
  11. private $_sendUrl=''; // 发送短信接口url
  12. private $_queryBalanceUrl=''; // 查询余额接口url
  13. private $_un; // 账号
  14. private $_pw; // 密码
  15. /**
  16. * 构造方法
  17. * @param string $account 接口账号
  18. * @param string $password 接口密码
  19. */
  20. public function __construct($account,$password){
  21. $this->_un=$account;
  22. $this->_pw=$password;
  23. }
  24. /* ========== 业务模块 ========== */
  25. /**
  26. * 短信发送
  27. * @param string $phone 手机号码
  28. * @param string $content 短信内容
  29. * @param integer $isreport 是否需要状态报告
  30. * @return void
  31. */
  32. public function send($phone,$content,$isreport=0){
  33. $requestData=array(
  34. 'un'=>$this->_un,
  35. 'pw'=>$this->_pw,
  36. 'sm'=>$content,
  37. 'da'=>$phone,
  38. 'rd'=>$isreport,
  39. 'dc'=>15,
  40. 'rf'=>2,
  41. 'tf'=>3,
  42. );
  43. $url=chuanglanSMS::SENDURL.'?'.http_build_query($requestData);
  44. return $this->_request($url);
  45. }
  46. /**
  47. * 国际短信发送
  48. * @param string $phone 手机号码
  49. * @param string $content 短信内容
  50. * @param integer $isreport 是否需要状态报告
  51. * @return void
  52. */
  53. public function sendInternational($phone,$content,$isreport=0){
  54. $requestData=array(
  55. 'un'=>$this->_un,
  56. 'pw'=>$this->_pw,
  57. 'sm'=>$content,
  58. 'da'=>$phone,
  59. 'rd'=>$isreport,
  60. 'rf'=>2,
  61. 'tf'=>3,
  62. );
  63. $url=chuanglanSMS::ISENDURL.'?'.http_build_query($requestData);
  64. return $this->_request($url);
  65. }
  66. /**
  67. * 查询余额
  68. * @return String 余额返回
  69. */
  70. public function queryBalance(){
  71. $requestData=array(
  72. 'un'=>$this->_un,
  73. 'pw'=>$this->_pw,
  74. 'rf'=>2
  75. );
  76. $url=chuanglanSMS::QUERYURL.'?'.http_build_query($requestData);
  77. return $this->_request($url);
  78. }
  79. /**
  80. * 查询余额
  81. * @return String 余额返回
  82. */
  83. public function queryBalanceInternational(){
  84. $requestData=array(
  85. 'un'=>$this->_un,
  86. 'pw'=>$this->_pw,
  87. 'rf'=>2
  88. );
  89. $url=chuanglanSMS::IQUERYURL.'?'.http_build_query($requestData);
  90. return $this->_request($url);
  91. }
  92. /* ========== 业务模块 ========== */
  93. /* ========== 功能模块 ========== */
  94. /**
  95. * 请求发送
  96. * @return string 返回状态报告
  97. */
  98. private function _request($url){
  99. $ch=curl_init();
  100. curl_setopt($ch,CURLOPT_HEADER,0);
  101. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  102. curl_setopt($ch,CURLOPT_URL,$url);
  103. $result=curl_exec($ch);
  104. curl_close($ch);
  105. return $result;
  106. }
  107. /* ========== 功能模块 ========== */
  108. }