SmsCL.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\expand\controller;
  3. use app\common\service\CLSms;
  4. use app\common\service\HelperService;
  5. use think\Validate;
  6. /**
  7. * 创蓝短信接口
  8. * Class SmsCL
  9. * @package app\expand\controller
  10. */
  11. class SmsCL extends BaseAuth{
  12. private $_Account = null;
  13. public function __construct(){
  14. parent::__construct();
  15. $this->_Account = $this->getKey($this->_apiCode);
  16. //验证是否具有访问这个接口的权限
  17. if(!isset($this->_Account['CL_account'])
  18. || !isset($this->_Account['CL_password'])){
  19. HelperService::returnJson(['code'=>400,'msg'=>'CLSMS interface unauthorized access','data'=>[]]);
  20. }
  21. }
  22. /**
  23. * 发送短信接口
  24. */
  25. public function sendMessage(){
  26. $params = $this->_params;
  27. $rule = [
  28. 'mobile|手机号'=>'require',
  29. 'message|短信内容'=>'require',
  30. ];
  31. $validate = new Validate($rule);
  32. if(!$validate->check($params)){
  33. HelperService::returnJson(['code'=>400,'msg'=>$validate->getError(),'data'=>[]]);
  34. }
  35. $CLSms = new CLSms($this->_Account['CHL_account'],$this->_Account['CHL_password']);
  36. $result = $CLSms->sendSMS($params['mobile'], $params['message']);
  37. $output = @json_decode($result,true);
  38. if($output){
  39. if(isset($output['code']) && $output['code']=='0'){
  40. HelperService::returnJson(['code'=>200,'msg'=>'发送成功','data'=>[]]);
  41. }else{
  42. HelperService::returnJson(['code'=>400,'msg'=>$output['errorMsg'],'data'=>[]]);
  43. }
  44. }
  45. HelperService::returnJson(['code'=>400,'msg'=>'fail','data'=>$result]);
  46. }
  47. }