SMSService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace crmeb\services;
  3. use think\facade\Db;
  4. /**
  5. * 短信服务
  6. * Class SMSService
  7. * @package crmeb\services
  8. */
  9. class SMSService
  10. {
  11. // 短信账号
  12. private static $SMSAccount;
  13. // 短信token
  14. private static $SMSToken;
  15. public static $status;
  16. // 短信请求地址
  17. private static $SMSUrl = 'https://sms.crmeb.net/api/';
  18. //短信支付回调地址
  19. private static $payNotify;
  20. //验证码
  21. const VERIFICATION_CODE = 518076;
  22. //支付成功
  23. const PAY_SUCCESS_CODE = 520268;
  24. //发货提醒
  25. const DELIVER_GOODS_CODE = 520269;
  26. //确认收货提醒
  27. const TAKE_DELIVERY_CODE = 520271;
  28. //管理员下单提醒
  29. const ADMIN_PLACE_ORDER_CODE = 520272;
  30. //管理员退货提醒
  31. const ADMIN_RETURN_GOODS_CODE = 520274;
  32. //管理员支付成功提醒
  33. const ADMIN_PAY_SUCCESS_CODE = 520273;
  34. //管理员确认收货
  35. const ADMIN_TAKE_DELIVERY_CODE = 520422;
  36. /**
  37. * get: 发送短信验证码
  38. * path: sendSmsCode
  39. * method: sendSmsCode
  40. * param: phone - {string} 手机号
  41. */
  42. public static function send($phone, array $param ,$template="VERIFICATION_CODE")
  43. {
  44. $code = $param['code'];
  45. $target = "http://cf.51welink.com/submitdata/Service.asmx/g_Submit";
  46. $company = sys_config('site_name');
  47. switch ($template)
  48. {
  49. case 'PAY_SUCCESS_CODE':
  50. break;
  51. case 'DELIVER_GOODS_CODE':
  52. break;
  53. case 'TAKE_DELIVERY_CODE':
  54. break;
  55. case 'ADMIN_PLACE_ORDER_CODE':
  56. break;
  57. case 'ADMIN_RETURN_GOODS_CODE':
  58. break;
  59. case 'ADMIN_PAY_SUCCESS_CODE':
  60. break;
  61. case 'ADMIN_TAKE_DELIVERY_CODE':
  62. break;
  63. default:
  64. $content=sprintf('您的注册验证码为:%d 。验证码有效期为%d分钟,请尽快填写!【%s】',$code,5,$company);
  65. }
  66. $post_data = "sname=dlycwl01&spwd=ycwl123456&scorpid=&sprdid=1012818&sdst=".$phone."&smsg=".rawurlencode($content);
  67. $gets = self::post($post_data, $target);
  68. if($gets){
  69. /*
  70. $data['phone'] = $phone;
  71. $data['code'] = $code;
  72. $data['addtime'] = time();
  73. $re = Db::name('sms')->insertGetId($data);*/
  74. return ['status' => 200, 'msg' => '短信发送成功'];
  75. }else{
  76. return ['status' => 400, 'msg' => '发送失败'];
  77. }
  78. }
  79. //第三方短信平台
  80. private static function post($data, $target){
  81. $url_info = parse_url($target);
  82. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  83. $httpheader .= "Host:" . $url_info['host'] . "\r\n";
  84. $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
  85. $httpheader .= "Content-Length:" . strlen($data) . "\r\n";
  86. $httpheader .= "Connection:close\r\n\r\n";
  87. //$httpheader .= "Connection:Keep-Alive\r\n\r\n";
  88. $httpheader .= $data;
  89. $fd = fsockopen($url_info['host'], 80);
  90. fwrite($fd, $httpheader);
  91. $gets = "";
  92. while(!feof($fd)) {
  93. $gets .= fread($fd, 128);
  94. }
  95. fclose($fd);
  96. if($gets != ''){
  97. $start = strpos($gets, '<?xml');
  98. if($start > 0) {
  99. $gets = substr($gets, $start);
  100. }
  101. }
  102. return $gets;
  103. }
  104. }