0
0

Qxsms.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace tools;
  3. /**
  4. * 企信短息发送类
  5. */
  6. class Qxsms{
  7. private $CorpID; //账号
  8. private $Pwd; //密码
  9. private $host = 'http://www.lxqixin.com:8082'; //接口域名
  10. private $error;
  11. public function __construct($config=array())
  12. {
  13. $this->CorpID = isset($config['qx_corpid'])?$config['qx_corpid']:'';
  14. $this->Pwd = isset($config['qx_pwd'])?$config['qx_pwd']:'';
  15. }
  16. /**
  17. * 发送短信
  18. * @param $mobiles 手机号多个以逗号隔开,最多1000个
  19. * @param $content 短信内容
  20. * @return bool true=发送成功 false=发送失败
  21. */
  22. public function send($mobiles,$content){
  23. if(!$this->CorpID){
  24. $this->error = '未填写账号';
  25. return false;
  26. }
  27. if(!$this->Pwd){
  28. $this->error = '未填写密码';
  29. return false;
  30. }
  31. $url = $this->host.'/SendMT/SendMessage?CorpID='.$this->CorpID.'&Pwd='.$this->Pwd.'&Mobile='.$mobiles.'&Content='.urlencode($content);
  32. try{
  33. $ch = curl_init ();
  34. curl_setopt ( $ch, CURLOPT_URL, $url );
  35. curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "GET" );
  36. curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
  37. curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
  38. curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 );
  39. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
  40. $result = curl_exec ( $ch );
  41. curl_close ( $ch );
  42. if(empty($result)){
  43. $this->error = '发送失败';
  44. return false;
  45. }
  46. $result = explode(',',$result);
  47. if(in_array($result[0],array('00','03'))){
  48. return true;
  49. }else{
  50. $this->error = $result;
  51. return false;
  52. }
  53. }catch (\Exception $e){
  54. $this->error = "短信发送失败";
  55. return false;
  56. }
  57. }
  58. public function getError(){
  59. return $this->error;
  60. }
  61. }