12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace crmeb\services;
- use think\facade\Db;
- /**
- * 短信服务
- * Class SMSService
- * @package crmeb\services
- */
- class OtherSMSService
- {
- public static function send($phone, $str)
- {
- $target = "http://cf.51welink.com/submitdata/Service.asmx/g_Submit";
- $company = sys_config('site_name');
- $content = sprintf('【' . $company . '】' . $str);
- $post_data = "sname=dlycwl01&spwd=ycwl123456&scorpid=&sprdid=1012818&sdst=" . $phone . "&smsg=" . rawurlencode($content);
- $gets = self::post($post_data, $target);
- if ($gets) {
- return ['status' => 200, 'msg' => '短信发送成功'];
- } else {
- return ['status' => 400, 'msg' => '发送失败'];
- }
- }
- //第三方短信平台
- private static function post($data, $target)
- {
- $url_info = parse_url($target);
- $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
- $httpheader .= "Host:" . $url_info['host'] . "\r\n";
- $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
- $httpheader .= "Content-Length:" . strlen($data) . "\r\n";
- $httpheader .= "Connection:close\r\n\r\n";
- //$httpheader .= "Connection:Keep-Alive\r\n\r\n";
- $httpheader .= $data;
- $fd = fsockopen($url_info['host'], 80);
- fwrite($fd, $httpheader);
- $gets = "";
- while (!feof($fd)) {
- $gets .= fread($fd, 128);
- }
- fclose($fd);
- if ($gets != '') {
- $start = strpos($gets, '<?xml');
- if ($start > 0) {
- $gets = substr($gets, $start);
- }
- }
- return $gets;
- }
- }
|