OtherSMSService.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace crmeb\services;
  3. use think\facade\Db;
  4. /**
  5. * 短信服务
  6. * Class SMSService
  7. * @package crmeb\services
  8. */
  9. class OtherSMSService
  10. {
  11. public static function send($phone, $str)
  12. {
  13. $target = "http://cf.51welink.com/submitdata/Service.asmx/g_Submit";
  14. $company = sys_config('site_name');
  15. $content = sprintf('【' . $company . '】' . $str);
  16. $post_data = "sname=dlycwl01&spwd=ycwl123456&scorpid=&sprdid=1012818&sdst=" . $phone . "&smsg=" . rawurlencode($content);
  17. $gets = self::post($post_data, $target);
  18. if ($gets) {
  19. return ['status' => 200, 'msg' => '短信发送成功'];
  20. } else {
  21. return ['status' => 400, 'msg' => '发送失败'];
  22. }
  23. }
  24. //第三方短信平台
  25. private static function post($data, $target)
  26. {
  27. $url_info = parse_url($target);
  28. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  29. $httpheader .= "Host:" . $url_info['host'] . "\r\n";
  30. $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
  31. $httpheader .= "Content-Length:" . strlen($data) . "\r\n";
  32. $httpheader .= "Connection:close\r\n\r\n";
  33. //$httpheader .= "Connection:Keep-Alive\r\n\r\n";
  34. $httpheader .= $data;
  35. $fd = fsockopen($url_info['host'], 80);
  36. fwrite($fd, $httpheader);
  37. $gets = "";
  38. while (!feof($fd)) {
  39. $gets .= fread($fd, 128);
  40. }
  41. fclose($fd);
  42. if ($gets != '') {
  43. $start = strpos($gets, '<?xml');
  44. if ($start > 0) {
  45. $gets = substr($gets, $start);
  46. }
  47. }
  48. return $gets;
  49. }
  50. }