ZjSMSServerService.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\api\controller;
  3. use crmeb\services\HttpService;
  4. use think\facade\Db;
  5. /**
  6. * 短信服务
  7. * Class SMSService
  8. * @package crmeb\services
  9. */
  10. class ZjSMSServerService
  11. {
  12. private static $userid = '15889';
  13. private static $username = "yflkj";
  14. private static $passwd = 'yfl831**';
  15. //验证码
  16. const VERIFICATION_CODE = 518076;
  17. //支付成功
  18. const PAY_SUCCESS_CODE = 520268;
  19. //发货提醒
  20. const DELIVER_GOODS_CODE = 520269;
  21. //确认收货提醒
  22. const TAKE_DELIVERY_CODE = 520271;
  23. //管理员下单提醒
  24. const ADMIN_PLACE_ORDER_CODE = 520272;
  25. //管理员退货提醒
  26. const ADMIN_RETURN_GOODS_CODE = 520274;
  27. //管理员支付成功提醒
  28. const ADMIN_PAY_SUCCESS_CODE = 520273;
  29. //管理员确认收货
  30. const ADMIN_TAKE_DELIVERY_CODE = 520422;
  31. /**
  32. * get: 发送短信验证码
  33. * path: sendSmsCode
  34. * method: sendSmsCode
  35. * param: phone - {string} 手机号
  36. */
  37. public static function send($phone, array $param, $template = "VERIFICATION_CODE")
  38. {
  39. $code = $param['code'];
  40. $target = "http://sms.izjun.cn/v2sms.aspx";
  41. $company = sys_config('site_name', '', true);
  42. // $company = "星拼乐";
  43. switch ($template) {
  44. case 'PAY_SUCCESS_CODE':
  45. break;
  46. case 'DELIVER_GOODS_CODE':
  47. break;
  48. case 'TAKE_DELIVERY_CODE':
  49. break;
  50. case 'ADMIN_PLACE_ORDER_CODE':
  51. break;
  52. case 'ADMIN_RETURN_GOODS_CODE':
  53. break;
  54. case 'ADMIN_PAY_SUCCESS_CODE':
  55. break;
  56. case 'ADMIN_TAKE_DELIVERY_CODE':
  57. break;
  58. default:
  59. $content = sprintf('【%s】您的验证码为:%d 。验证码有效期为%d分钟,请尽快填写!', $company, $code, 5);
  60. }
  61. $time = date("YmdHis", time());
  62. $data = [
  63. 'action' => 'send',
  64. 'userid' => self::$userid,
  65. 'timestamp' => $time,
  66. 'sign' => md5(self::$username . self::$passwd . $time),
  67. 'mobile' => $phone,
  68. 'content' => $content,
  69. 'sendTime' => '',
  70. 'extno' => '',
  71. 'rt' => 'json',
  72. ];
  73. $gets = json_decode(HttpService::postRequest($target, $data), true);
  74. if ($gets) {
  75. return ['status' => 200, 'msg' => '短信发送成功'];
  76. } else {
  77. return ['status' => 400, 'msg' => '发送失败'];
  78. }
  79. }
  80. }