Sms.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * 手机短信类
  4. */
  5. namespace sendmsg;
  6. class Sms
  7. {
  8. /*
  9. * 发送手机短信
  10. * @param unknown $mobile 手机号
  11. * @param unknown $content 短信内容
  12. */
  13. public function send($mobile, $content)
  14. {
  15. return $this->mysend_sms($mobile, $content);
  16. }
  17. /*
  18. 您于{$send_time}绑定手机号,验证码是:{$verify_code}。【{$site_name}】
  19. -1 没有该用户账户
  20. -2 接口密钥不正确 [查看密钥]不是账户登陆密码
  21. -21 MD5接口密钥加密不正确
  22. -3 短信数量不足
  23. -11 该用户被禁用
  24. -14 短信内容出现非法字符
  25. -4 手机号格式不正确
  26. -41 手机号码为空
  27. -42 短信内容为空
  28. -51 短信签名格式不正确接口签名格式为:【签名内容】
  29. -6 IP限制
  30. 大于0 短信发送数量
  31. http://utf8.api.smschinese.cn/?Uid=本站用户名&Key=接口安全秘钥&smsMob=手机号码&smsText=验证码:8888
  32. */
  33. private function mysend_sms($mobile, $content)
  34. {
  35. $user_id = urlencode(config('smscf_wj_username')); // 这里填写用户名
  36. $key = urlencode(config('smscf_wj_key')); // 这里填接口安全密钥
  37. if (!$mobile || !$content || !$user_id || !$key)
  38. return false;
  39. if (is_array($mobile)) {
  40. $mobile = implode(",", $mobile);
  41. }
  42. $mobile=urlencode($mobile);
  43. $content=urlencode($content);
  44. $url = "http://utf8.api.smschinese.cn/?Uid=" . $user_id . "&Key=" . $key . "&smsMob=" . $mobile . "&smsText=" . $content;
  45. if (function_exists('file_get_contents')) {
  46. $res = file_get_contents($url);
  47. }
  48. else {
  49. $ch = curl_init();
  50. $timeout = 5;
  51. curl_setopt($ch, CURLOPT_URL, $url);
  52. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  53. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  54. $res = curl_exec($ch);
  55. curl_close($ch);
  56. }
  57. if ($res >0) {
  58. return true;
  59. }
  60. // return false;
  61. return true;
  62. }
  63. }