配置短信服務(wù)
基于Laravel框架的使用方法
安裝
composer?require?mrgoon/aliyun-sms?dev-master
在
config/app.php
中添加如下代碼
'providers'?=>?[ ????//......此處省略大量代碼 ????/** ?????*?阿里云短信 ?????*/ ????Mrgoon\AliSms\ServiceProvider::class, ], //同時(shí),可以選擇性添加aliases 'aliases'?=>?[ ????//......此處省略大量代碼 ????/** ?????*?阿里云短信 ?????*/ ????'AliSms'=>Mrgoon\AliSms\ServiceProvider::class, ],
添加系統(tǒng)服務(wù)
php?artisan?vendor:publish #這里要選擇對應(yīng)的編號(hào)
上一步會(huì)新增
config/aliyunsms.php
?文件
'access_key'????????=>?env('ALIYUN_ACCESSKEYID'),?//?accessKey 'access_secret'?????=>?env('ALIYUN_ACCESSKEYSECRET'),?//?accessSecret 'sign_name'?????????=>?env('ALIYUN_SMS_SIGN_NAME'),?//?簽名
在
.env
文件中添加環(huán)境變量:
ALIYUN_ACCESSKEYID=your?access?key ALIYUN_ACCESSKEYSECRET=your?secret?key ALIYUN_SMS_SIGN_NAME=sign?name
使用
$aliSms?=?new?AliSms(); $response?=?$aliSms->sendSms('phone?number',?'SMS_code',?['name'=>?'value?in?your?template']); //dump($response);
非laravel框架的使用方法
加載方式通過composer,不變
使用樣例代碼如下:
$config?=?[ ????'access_key'?=>?'your?access?key', ????'access_secret'?=>?'your?access?secret', ????'sign_name'?=>?'your?sign?name', ]; ????$aliSms?=?new?Mrgoon\AliSms\AliSms(); ????$response?=?$sms->sendSms( ????????'phone?number',? ????????'tempplate?code',? ????????['name'=>?'value?in?your?template'],? ????????$config ????);
配置圖片上傳OSS
安裝
composer?require?jacobcyl/ali-oss-storage
在
config/app.php
中添加如下代碼
'providers'?=>?[ ????//......此處省略大量代碼 ????/** ?????*?阿里云OSS ?????*/ ????Jacobcyl\AliOSS\AliOssServiceProvider::class, ], //同時(shí),可以選擇性添加aliases 'aliases'?=>?[ ????//......此處省略大量代碼 ????/** ?????*?阿里云OSS ?????*/ ????'AliOSS'=>Jacobcyl\AliOSS\AliOssServiceProvider::class, ],
編輯配置文件
config/filesystems.php
'default'?=>?env('FILESYSTEM_DRIVER',?'local'), ..... 'disks'?=>?[ .... ????????'oss'?=>?[ ????????????'driver'?=>?'oss', ????????????'access_id'?=>?env('ALIYUN_ACCESSKEYID'), ????????????'access_key'?=>?env('ALIYUN_ACCESSKEYSECRET'), ????????????'bucket'?=>?env('ALIYUN_BUCKET'), ????????????'endpoint'?=>?env('ALIYUN_ENDPOINT'), ????????????//'endpoint_internal'?=>?'<internal?endpoint?[OSS內(nèi)網(wǎng)節(jié)點(diǎn)]?如:oss-cn-shenzhen-internal.aliyuncs.com>', ????????????//'cdnDomain'?=>?'<CDN?domain,?cdn域名>', ????????????'ssl'?=>?false, ????????????'isCName'?=>?false, ????????????'debug'?=>?false, ????????], ????],
在
.env
文件中添加環(huán)境變量:
ALIYUN_ACCESSKEYID=your?access?key ALIYUN_ACCESSKEYSECRET=your?secret?key ALIYUN_BUCKET=your?bucket ALIYUN_ENDPOINT=your?endpoint
配置ueditor + OSS
安裝
composer?require?ilimpid/laravel-u-editor
在
config/app.php
中添加如下代碼
'providers'?=>?[ ????//......此處省略大量代碼 ????/** ?????*?百度編輯器 ?????*/ ????Stevenyangecho\UEditor\UEditorServiceProvider::class, ], //同時(shí),添加aliases 'aliases'?=>?[ ????//......此處省略大量代碼 ????/** ?????*?百度編輯器 ?????*/ ????'UEditor'=>Stevenyangecho\UEditor\UEditorServiceProvider::class, ],
添加系統(tǒng)服務(wù)
php?artisan?vendor:publish
上一步會(huì)新增
config/UEditorUpload.php
?文件
'mode'?=>?'aliyun',//上傳方式,local?為本地???qiniu?為七牛??aliyun為阿里云 'aliyun'?=>?[ ????'accessKeyId'?=>?env('ALIYUN_ACCESSKEYID'), ????'accessKeySecret'?=>?env('ALIYUN_ACCESSKEYSECRET'), ????'endpoint'?=>?env('ALIYUN_ENDPOINT'), ????'url'?=>?'http://'.env('ALIYUN_BUCKET').'.'.env('ALIYUN_ENDPOINT'), ????'bucket'?=>?env('ALIYUN_BUCKET'), ????'directory'?=>?'images/'.date('Ymd',time()), ], //注意:編輯器上傳圖片的時(shí)候會(huì)在本地保存一張,下面配置必須設(shè)置,images必須保持一致 /*?上傳圖片配置項(xiàng)?*/ 'upload'?=>?[ ????/*?上傳保存路徑,可以自定義保存路徑和文件名格式?*/ ????"imagePathFormat"?=>?"/storage/images/{yyyy}{mm}{dd}/{time}{rand:6}",? ],
在
.env
文件中添加環(huán)境變量:
ALIYUN_ACCESSKEYID=your?access?key ALIYUN_ACCESSKEYSECRET=your?secret?key ALIYUN_BUCKET=your?Bucket?key ALIYUN_ENDPOINT=your?Endpoint?key
非laravel-admin使用
@include(UEditor::head) <div?class="col-sm-10"> ????<script?id="ueditor"></script> ????<script> ????????var?ue?=?UE.getEditor("ueditor"); ????????ue.ready(function?()?{ ????????????//由于Laravel有防csrf防偽造攻擊的解決所以加上此行 ????????????ue.execCommand(serverparam,?_token,?{{?csrf_token()?}}); ????????}); ????</script> </div>
基于 laravel-admin 使用
增加組件文件
app/Admin/Extensions/Form/uEditor.php
<?php namespace?App\Admin\Extensions\Form; use?Encore\Admin\Form\Field; class?uEditor?extends?Field { ????//?定義視圖 ????protected?$view?=?'admin.uEditor'; ????//?css資源 ????protected?static?$css?=?[]; ????//?js資源 ????protected?static?$js?=?[ ????????'laravel-u-editor/ueditor.config.js', ????????'laravel-u-editor/ueditor.all.min.js', ????????'laravel-u-editor/lang/zh-cn/zh-cn.js' ????]; ????public?function?render() ????{ ????????$this->script?=?<<<EOT ????????//解決第二次進(jìn)入加載不出來的問題 ????????UE.delEditor("ueditor"); ????????//?默認(rèn)id是ueditor ????????var?ue?=?UE.getEditor('ueditor',?{ ????????????//?自定義工具欄 ????????????toolbars:?[ ????????????????['bold',?'italic',?'underline',?'strikethrough',?'blockquote',?'insertunorderedlist',?'insertorderedlist',?'justifyleft',?'justifycenter',?'justifyright',?'link',?'insertimage',?'source',?'fullscreen'] ????????????], ????????????elementPathEnabled:?false, ????????????enableContextMenu:?false, ????????????autoClearEmptyNode:?true, ????????????wordCount:?false, ????????????imagePopup:?false, ????????????autotypeset:?{indent:?true,?imageBlockLine:?'center'} ????????});? ????????ue.ready(function?()?{ ????????????ue.execCommand('serverparam',?'_token',?'{{?csrf_token()?}}'); ????????}); EOT; ????????return?parent::render(); ????} }
增加視圖文件
resources/views/admin/uEditor.blade.php
<div?class="form-group?{!!?!$errors->has($errorKey)??:?'has-error'?!!}"> ????<label?for="{{$id}}"?class="col-sm-2?control-label">{{$label}}</label> <div?class="col-sm-8"> ????@include('admin::form.error') ????{{--?這個(gè)style可以限制他的高度,不會(huì)隨著內(nèi)容變長?--}} ????<textarea?type='text/plain'?style="height:400px;"?id='ueditor'?id="{{$id}}"?name="{{$name}}"?placeholder="{{?$placeholder?}}"?{!!?$attributes?!!}??class='ueditor'> ????????????{!!?old($column,?$value)?!!} ????????</textarea> ????@include('admin::form.help-block') </div> </div> {{--?注意:如果你實(shí)用script標(biāo)簽有一些奇怪的問題,更換textarea就可以解決了。?--}}
然后注冊進(jìn)laravel-admin,在
app/Admin/bootstrap.php
中添加以下代碼:
<?php /** ?* ?*/ use?App\Admin\Extensions\Form\uEditor; use?Encore\Admin\Form; Form::extend('ueditor',?uEditor::class); //Encore\Admin\Form::forget(['map',?'editor']);
再控制器的
form()
里面調(diào)用
$form->ueditor('content',?'內(nèi)容')->rules('required');
我們專注高端建站,小程序開發(fā)、軟件系統(tǒng)定制開發(fā)、BUG修復(fù)、物聯(lián)網(wǎng)開發(fā)、各類API接口對接開發(fā)等。十余年開發(fā)經(jīng)驗(yàn),每一個(gè)項(xiàng)目承諾做到滿意為止,多一次對比,一定讓您多一份收獲!