NewSMSService.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace crmeb\services;
  3. use think\facade\Db;
  4. /**
  5. * 短信服务
  6. * Class SMSService
  7. * @package crmeb\services
  8. */
  9. class NewSMSService
  10. {
  11. //验证码
  12. const VERIFICATION_CODE = 518076;
  13. //支付成功
  14. const PAY_SUCCESS_CODE = 520268;
  15. //发货提醒
  16. const DELIVER_GOODS_CODE = 520269;
  17. //确认收货提醒
  18. const TAKE_DELIVERY_CODE = 520271;
  19. //管理员下单提醒
  20. const ADMIN_PLACE_ORDER_CODE = 520272;
  21. //管理员退货提醒
  22. const ADMIN_RETURN_GOODS_CODE = 520274;
  23. //管理员支付成功提醒
  24. const ADMIN_PAY_SUCCESS_CODE = 520273;
  25. //管理员确认收货
  26. const ADMIN_TAKE_DELIVERY_CODE = 520422;
  27. /**
  28. * get: 发送短信验证码
  29. * path: sendSmsCode
  30. * method: sendSmsCode
  31. * param: phone - {string} 手机号
  32. */
  33. public static function send($phone, array $param, $template = "DEFAULT")
  34. {
  35. $code = $param['code'];
  36. $target = 'http://www.qunfaduanxin.vip/api/send';
  37. $target2 = 'http://api.sms654.com/smsUTF8.aspx';
  38. // $target = "http://cf.51welink.com/submitdata/Service.asmx/g_Submit";
  39. $company = '优交坊';
  40. $company2 = '优交坊';
  41. switch ($template) {
  42. case 'REGISTER':
  43. $content = sprintf('【%s】您的注册验证码为:%d 。验证码有效期为%d分钟,请尽快填写!', $company2, $code, 5);
  44. break;
  45. case 'LOGIN':
  46. $content = sprintf('【%s】您的登录验证码为:%d 。验证码有效期为%d分钟,请尽快填写!', $company2, $code, 5);
  47. break;
  48. case 'RESET':
  49. $content = sprintf('【%s】您正在修改登陆密码,验证码为:%d 。验证码%d分钟内有效,如非本人操作请忽略!', $company2, $code, 5);
  50. break;
  51. case 'RESET_2':
  52. $content = sprintf('【%s】您正在修改交易密码,验证码为:%d 。验证码%d分钟内有效,如非本人操作请忽略!', $company2, $code, 5);
  53. break;
  54. case 'TRADE':
  55. $content = sprintf('【%s】您的本次操作需要验证码,验证码为:%d 。验证码%d分钟内有效,如非本人操作请忽略!', $company2, $code, 5);
  56. break;
  57. case 'START_TRADE':
  58. $content = sprintf('【%s】你的购买订单已经有卖家接单,请及时查看处理,并在30分钟内完成付款。', $company);
  59. break;
  60. case 'END_TRADE':
  61. $content = sprintf('【%s】你的出售订单买家成功向你付款,请及时确认并放行。', $company);
  62. break;
  63. case 'SUCCESS_TRADE':
  64. $content = sprintf('【%s】你的出售订单系统已付款,请确认,如有疑问请联系客服。', $company);
  65. break;
  66. case 'RECHARGE':
  67. $content = sprintf('【%s】您已成功充值%s,请查收。', $company, $param['mark']);
  68. break;
  69. case 'EXTRACT':
  70. $content = sprintf('【%s】您的提币申请已通过,请查收。', $company);
  71. break;
  72. case 'EXTRACT_FAIL':
  73. $content = sprintf('【%s】您的提币申请已被驳回,驳回原因:%s,请尽快查看并处理', $company, $param['mark']);
  74. break;
  75. default:
  76. $content = sprintf('您的验证码为:%d 。验证码有效期为%d分钟,请尽快填写!【%s】', $code, 1, $company2);
  77. break;
  78. }
  79. $post_data = [
  80. 'username' => '16520929823',
  81. 'password' => strtoupper(md5('16520929823')),
  82. 'gwid' => 'geyjla16',
  83. 'mobile' => $phone,
  84. 'message' => $content,
  85. ];
  86. $post_data2 = [
  87. 'type' => 'send',
  88. 'username' => '16520929823',
  89. 'password' => strtoupper(md5('16520929823')),
  90. 'gwid' => '9e3cdfdd',
  91. 'mobile' => $phone,
  92. 'message' => $content,
  93. 'rece' => 'json',
  94. ];
  95. //// $post_data = "sname=dlycwl01&spwd=ycwl123456&scorpid=&sprdid=1012818&sdst=" . $phone . "&smsg=" . rawurlencode($content);
  96. // $post_data = "?username=16520929823&password=" . strtoupper(md5('6520929823')) . "&gwid=c2i00vx1&mobile=" . $phone . "&message=" . $content;
  97. // $gets = self::post($post_data, $target);
  98. // var_dump($target . $post_data);
  99. if ($template == 'EXTRACT_FAIL' || $template == 'EXTRACT' || $template == 'RECHARGE' || $template == 'SUCCESS_TRADE' || $template == 'END_TRADE' || $template == 'START_TRADE')
  100. $gets = do_request($target, $post_data);
  101. else {
  102. $gets = do_request($target2, $post_data2);
  103. }
  104. // var_dump($gets);
  105. @file_put_contents('sms.log', json_encode($gets), FILE_APPEND);
  106. if (substr($gets, 0, 7) == 'success' || (isset(json_decode($gets, true)['returnstatus']) && json_decode($gets, true)['returnstatus'] == 'success')) {
  107. return ['status' => 200, 'msg' => '短信发送成功'];
  108. } else {
  109. return ['status' => 400, 'msg' => '发送失败' . $gets];
  110. }
  111. }
  112. // //第三方短信平台
  113. // private static function post($data, $target)
  114. // {
  115. // $url_info = parse_url($target);
  116. // $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  117. // $httpheader .= "Host:" . $url_info['host'] . "\r\n";
  118. // $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
  119. // $httpheader .= "Content-Length:" . strlen($data) . "\r\n";
  120. // $httpheader .= "Connection:close\r\n\r\n";
  121. // //$httpheader .= "Connection:Keep-Alive\r\n\r\n";
  122. // $httpheader .= $data;
  123. //
  124. // $fd = fsockopen($url_info['host'], 80);
  125. // fwrite($fd, $httpheader);
  126. // $gets = "";
  127. // while (!feof($fd)) {
  128. // $gets .= fread($fd, 128);
  129. // }
  130. // fclose($fd);
  131. // if ($gets != '') {
  132. // $start = strpos($gets, '<?xml');
  133. // if ($start > 0) {
  134. // $gets = substr($gets, $start);
  135. // }
  136. // }
  137. // return $gets;
  138. // }
  139. }