1: 打开项目:**\\app\\admin\\controller\\sms\\SmsConfig.php 修改大概28行代码** ``` php public function index(){ $type = input('type')!=0?input('type'):0; $tab\_id = input('tab\_id'); if(!$tab\_id) $tab\_id = 1; $this->assign('tab\_id',$tab\_id); $list = ConfigModel::getAll($tab\_id)\->toArray(); $list\[0\]\['info'\] = '短信宝账号'; $list\[0\]\['desc'\] = '短信宝账号'; $list\[1\]\['info'\] = '短信宝密码'; $list\[1\]\['desc'\] = '短信宝密码'; ``` 2: 打开项目:**\\app\\admin\\view\\sms\\sms\_config\\index.php 修改大概56行代码** ``` php <div class="ibox-content"> <div id="app"> <Alert type="success">如果还没有开通短信账号,可以<a target="_blank" href="https://www.smsbao.com/reg" style="color: #0000ff">立即注册</a> </Alert> </div> <div class="p-m m-t-sm" id="configboay"> </div> </div> ``` 3:打开项目:**\\app\\admin\\view\\sms\\sms\_template\_apply\\index.php 修改大概45行代码** ```php <div class="layui-btn-container"> <button type="button" class="layui-btn layui-btn-sm" onclick="$eb.createModalFrame(this.innerText,'{:Url('create')}')">添加模板</button> </div> ``` 4: 打开项目:**\\app\\admin\\controller\\sms\\SmsTemplateApply.php 修改模板相关方法** ```php <?php namespace app\admin\controller\sms; use app\admin\controller\AuthController; use crmeb\services\FormBuilder; use crmeb\services\JsonService; use crmeb\services\SMSService; use crmeb\services\UtilService; use think\facade\Route; use app\admin\model\routine\RoutineTemplate as RoutineModel; /** * 短信模板申请 * Class SmsTemplateApply * @package app\admin\controller\sms */ class SmsTemplateApply extends AuthController { /** * 显示资源列表 * * @return string */ public function index() { // $sms = new SMSService(); // if(!$sms::$status) return $this->failed('请先填写短信配置'); return $this->fetch(); } /** * 异步获取模板列表 */ public function lst() { //重新获取模板 $tem = new RoutineModel(); $lst = $tem->where('status',0)->select()->toArray(); foreach($lst as $k=>$v) { $lst[$k]['id']= $v['id']; $lst[$k]['templateid']= $v['tempid']; $lst[$k]['title']= $v['name']; $lst[$k]['mark']= ""; $lst[$k]['type']= $v['tempkey']; $lst[$k]['status']= 1; $lst[$k]['content']= $v['content']; $lst[$k]['add_time']= date( "Y-m-d H:i", $v['add_time']); } return JsonService::successlayui('',$lst); } /** * 显示创建资源表单页. * * @return string * @throws \FormBuilder\exception\FormBuilderException */ public function create() { $field = [ FormBuilder::input('title','模板名称'), FormBuilder::textarea('text','模板内容示例','【您的短信签名】您的验证码是:{$code},有效期为{$time}分钟。如非本人操作,可不用理会。模板中的{$code}和{$time}需要替换成对应的变量,请开发者知晓。修改此项无效!'), FormBuilder::input('content','模板内容')->type('textarea'), FormBuilder::input('number','模板id'), FormBuilder::radio('type','模板类型',1)->options([['label'=>'验证码','value'=>1],['label'=>'通知','value'=>2],['label'=>'推广','value'=>3]]) ]; $form = FormBuilder::make_post_form('申请短信模板',$field,Route::buildUrl('save'),2); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /** * 保存新建的资源 */ public function save() { $tem = []; $data = UtilService::postMore([ ['title',''], ['content',''], ['type',0], ['number',''] ]); //组装数据 $tem = array( 'tempkey'=>$data['type'], 'name'=>$data['title'], 'content'=>$data['content'], 'tempid'=>$data['number'], 'add_time'=>time() ); if(!strlen(trim($data['title']))) return JsonService::fail('请输入模板名称'); if(!strlen(trim($data['content']))) return JsonService::fail('请输入模板内容'); if(!strlen(trim($data['number']))) return JsonService::fail('请输入模板id'); $id = RoutineModel::insert($tem); if ($id) return JsonService::success('申请成功'); } } ``` 5:打开项目:**\\crmeb\\services\\SMSService.php 修改发送方法** ```php public static function send($phone, $template, array $param) { $ret = []; self::auto(); $teModel = new RoutineTemplate(); $content = $teModel->where('tempid',$template)->find()['content']; foreach($param as $key => $value) { $content = str_replace('{$'."$key".'}',$value,$content); } $statusStr = array( "0" => "短信发送成功", "-1" => "参数不全", "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!", "30" => "密码错误", "40" => "账号不存在", "41" => "余额不足", "42" => "帐户已过期", "43" => "IP地址限制", "50" => "内容含有敏感词" ); $smsapi = "http://api.smsbao.com/"; $user = self::$SMSAccount; //短信平台帐号 $pass = md5(self::$SMSToken); //短信平台密码 $content = $content;//要发送的短信内容 $phone = $phone;//要发送短信的手机号码 $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content); $result = file_get_contents($sendurl) ; $ret["status"] = $result; $ret["msg"] = $statusStr[$result]; return $ret; } ``` 模板ID ```php //验证码 const VERIFICATION_CODE = 518076; //支付成功 const PAY_SUCCESS_CODE = 520268; //发货提醒 const DELIVER_GOODS_CODE = 520269; //确认收货提醒 const TAKE_DELIVERY_CODE = 520271; //管理员下单提醒 const ADMIN_PLACE_ORDER_CODE = 520272; //管理员退货提醒 const ADMIN_RETURN_GOODS_CODE = 520274; //管理员支付成功提醒 const ADMIN_PAY_SUCCESS_CODE = 520273; //管理员确认收货 const ADMIN_TAKE_DELIVERY_CODE = 520422; ```