1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\expand\controller;
- use app\common\service\CLSms;
- use app\common\service\HelperService;
- use think\Validate;
- /**
- * 创蓝短信接口
- * Class SmsCL
- * @package app\expand\controller
- */
- class SmsCL extends BaseAuth{
- private $_Account = null;
- public function __construct(){
- parent::__construct();
- $this->_Account = $this->getKey($this->_apiCode);
- //验证是否具有访问这个接口的权限
- if(!isset($this->_Account['CL_account'])
- || !isset($this->_Account['CL_password'])){
- HelperService::returnJson(['code'=>400,'msg'=>'CLSMS interface unauthorized access','data'=>[]]);
- }
- }
- /**
- * 发送短信接口
- */
- public function sendMessage(){
- $params = $this->_params;
- $rule = [
- 'mobile|手机号'=>'require',
- 'message|短信内容'=>'require',
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- HelperService::returnJson(['code'=>400,'msg'=>$validate->getError(),'data'=>[]]);
- }
- $CLSms = new CLSms($this->_Account['CHL_account'],$this->_Account['CHL_password']);
- $result = $CLSms->sendSMS($params['mobile'], $params['message']);
- $output = @json_decode($result,true);
- if($output){
- if(isset($output['code']) && $output['code']=='0'){
- HelperService::returnJson(['code'=>200,'msg'=>'发送成功','data'=>[]]);
- }else{
- HelperService::returnJson(['code'=>400,'msg'=>$output['errorMsg'],'data'=>[]]);
- }
- }
- HelperService::returnJson(['code'=>400,'msg'=>'fail','data'=>$result]);
- }
- }
|