123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace crmeb\services;
- use think\facade\Db;
- /**
- * 短信服务
- * Class SMSService
- * @package crmeb\services
- */
- class NewSMSService
- {
- //验证码
- const VERIFICATION_CODE = 518076;
- //支付成功
- const PAY_SUCCESS_CODE = 520268;
- //发货提醒
- const DELIVER_GOODS_CODE = 520269;
- //确认收货提醒
- const TAKE_DELIVERY_CODE = 520271;
- //管理员下单提醒
- const ADMIN_PLACE_ORDER_CODE = 520272;
- //管理员退货提醒
- const ADMIN_RETURN_GOODS_CODE = 520274;
- //管理员支付成功提醒
- const ADMIN_PAY_SUCCESS_CODE = 520273;
- //管理员确认收货
- const ADMIN_TAKE_DELIVERY_CODE = 520422;
- /**
- * get: 发送短信验证码
- * path: sendSmsCode
- * method: sendSmsCode
- * param: phone - {string} 手机号
- */
- public static function send($phone, array $param, $template = "DEFAULT")
- {
- $code = $param['code'];
- $target = 'http://www.qunfaduanxin.vip/api/send';
- $target2 = 'http://api.sms654.com/smsUTF8.aspx';
- // $target = "http://cf.51welink.com/submitdata/Service.asmx/g_Submit";
- $company = '优交坊';
- $company2 = '优交坊';
- switch ($template) {
- case 'REGISTER':
- $content = sprintf('【%s】您的注册验证码为:%d 。验证码有效期为%d分钟,请尽快填写!', $company2, $code, 5);
- break;
- case 'LOGIN':
- $content = sprintf('【%s】您的登录验证码为:%d 。验证码有效期为%d分钟,请尽快填写!', $company2, $code, 5);
- break;
- case 'RESET':
- $content = sprintf('【%s】您正在修改登陆密码,验证码为:%d 。验证码%d分钟内有效,如非本人操作请忽略!', $company2, $code, 5);
- break;
- case 'RESET_2':
- $content = sprintf('【%s】您正在修改交易密码,验证码为:%d 。验证码%d分钟内有效,如非本人操作请忽略!', $company2, $code, 5);
- break;
- case 'TRADE':
- $content = sprintf('【%s】您的本次操作需要验证码,验证码为:%d 。验证码%d分钟内有效,如非本人操作请忽略!', $company2, $code, 5);
- break;
- case 'START_TRADE':
- $content = sprintf('【%s】你的购买订单已经有卖家接单,请及时查看处理,并在30分钟内完成付款。', $company);
- break;
- case 'END_TRADE':
- $content = sprintf('【%s】你的出售订单买家成功向你付款,请及时确认并放行。', $company);
- break;
- case 'SUCCESS_TRADE':
- $content = sprintf('【%s】你的出售订单系统已付款,请确认,如有疑问请联系客服。', $company);
- break;
- case 'RECHARGE':
- $content = sprintf('【%s】您已成功充值%s,请查收。', $company, $param['mark']);
- break;
- case 'EXTRACT':
- $content = sprintf('【%s】您的提币申请已通过,请查收。', $company);
- break;
- case 'EXTRACT_FAIL':
- $content = sprintf('【%s】您的提币申请已被驳回,驳回原因:%s,请尽快查看并处理', $company, $param['mark']);
- break;
- default:
- $content = sprintf('您的验证码为:%d 。验证码有效期为%d分钟,请尽快填写!【%s】', $code, 1, $company2);
- break;
- }
- $post_data = [
- 'username' => '16520929823',
- 'password' => strtoupper(md5('16520929823')),
- 'gwid' => 'geyjla16',
- 'mobile' => $phone,
- 'message' => $content,
- ];
- $post_data2 = [
- 'type' => 'send',
- 'username' => '16520929823',
- 'password' => strtoupper(md5('16520929823')),
- 'gwid' => '9e3cdfdd',
- 'mobile' => $phone,
- 'message' => $content,
- 'rece' => 'json',
- ];
- //// $post_data = "sname=dlycwl01&spwd=ycwl123456&scorpid=&sprdid=1012818&sdst=" . $phone . "&smsg=" . rawurlencode($content);
- // $post_data = "?username=16520929823&password=" . strtoupper(md5('6520929823')) . "&gwid=c2i00vx1&mobile=" . $phone . "&message=" . $content;
- // $gets = self::post($post_data, $target);
- // var_dump($target . $post_data);
- if ($template == 'EXTRACT_FAIL' || $template == 'EXTRACT' || $template == 'RECHARGE' || $template == 'SUCCESS_TRADE' || $template == 'END_TRADE' || $template == 'START_TRADE')
- $gets = do_request($target, $post_data);
- else {
- $gets = do_request($target2, $post_data2);
- }
- // var_dump($gets);
- @file_put_contents('sms.log', json_encode($gets), FILE_APPEND);
- if (substr($gets, 0, 7) == 'success' || (isset(json_decode($gets, true)['returnstatus']) && json_decode($gets, true)['returnstatus'] == 'success')) {
- return ['status' => 200, 'msg' => '短信发送成功'];
- } else {
- return ['status' => 400, 'msg' => '发送失败' . $gets];
- }
- }
- // //第三方短信平台
- // 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;
- // }
- }
|