You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.2 KiB

6 years ago
  1. <?php
  2. namespace App\Http\Service;
  3. /**
  4. * 短信宝
  5. */
  6. class Smsbao
  7. {
  8. private $user_name;
  9. private $password;
  10. private $smsapi = "http://api.smsbao.com/";
  11. private $status_str = array(
  12. "0" => "短信发送成功",
  13. "-1" => "参数不全",
  14. "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
  15. "30" => "密码错误",
  16. "40" => "账号不存在",
  17. "41" => "余额不足",
  18. "42" => "帐户已过期",
  19. "43" => "IP地址限制",
  20. "50" => "内容含有敏感词"
  21. );
  22. public function __construct($user_name, $password)
  23. {
  24. $this->user_name = $user_name;
  25. $this->password = $password;
  26. }
  27. /**
  28. * 国内短信
  29. *
  30. * @param string $sms_content 要发送的短信内容
  31. * @param string $sms_phone 接收的手机号,单发:15205201314,群发:15205201314,15205201315,群发时多个手机号以逗号分隔,一次不要超过99个号码
  32. * return string
  33. */
  34. public function sms($sms_content, $sms_phone)
  35. {
  36. $user = $this->user_name; //短信平台帐号
  37. $pass = md5($this->password); //短信平台密码
  38. $content = $sms_content; //要发送的短信内容
  39. $phone = $sms_phone; //要发送短信的手机号码
  40. $sendurl = $this->smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
  41. $result = file_get_contents($sendurl) ;
  42. return $this->status_str[$result];
  43. }
  44. /**
  45. * 国际短信
  46. *
  47. * @param string $sms_content 要发送的短信内容
  48. * @param string $sms_phone 接收的手机号,单发:+60901234567,群发:+60901234567,+60901234567,群发时多个手机号以逗号分隔,一次不要超过99个号码,注:国际号码需包含国际地区前缀号码,格式必须是"+"号开头("+"号需要urlencode处理,如:urlencode("+60901234567")否则会出现格式错误)
  49. * return string
  50. */
  51. public function wsms($sms_content, $sms_phone)
  52. {
  53. $user = $this->user_name; //短信平台帐号
  54. $pass = md5($this->password); //短信平台密码
  55. $content = $sms_content; //要发送的短信内容
  56. $phone = $sms_phone; //要发送短信的手机号码
  57. $sendurl = $this->smsapi."wsms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
  58. $result = file_get_contents($sendurl) ;
  59. return $this->status_str[$result];
  60. }
  61. /**
  62. * 语音验证码发送
  63. *
  64. * @param string $sms_code 发送的验证码
  65. * @param string $sms_phone 目标手机号码
  66. * return string
  67. */
  68. public function voice($sms_code, $sms_phone)
  69. {
  70. $user = $this->user_name; //短信平台帐号
  71. $pass = md5($this->password); //短信平台密码
  72. $content = $sms_code; //要发送的短信内容
  73. $phone = $sms_phone; //要发送短信的手机号码
  74. $sendurl = $this->smsapi."voice?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
  75. $result = file_get_contents($sendurl) ;
  76. return $this->status_str[$result];
  77. }
  78. }