螢火商城V2.0是全新推出的一款輕量級、高性能、前后端分離的電商系統,支持微信小程序 + H5+ 公眾號 + APP,前后端源碼完全開源,完美支持二次開發。小編對這款軟件還是比較了解的,小編今天就以新增短信接口為例為大家講解一下如何進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
1.首先打開項目app\common\library\sms\Config.php,在58行左右增加以下代碼
1
2
3
4
5
|
'smsbao' => [ 'user' => $smsConfig [ 'engine' ][ 'smsbao' ][ 'user' ], 'password' => $smsConfig [ 'engine' ][ 'smsbao' ][ 'password' ], 'sign_name' => $smsConfig [ 'engine' ][ 'smsbao' ][ 'sign' ], ], |
2.接著打開項目app\common\library\sms\Driver.php,修改 sendSms 方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
public function sendSms(string $acceptPhone , string $templateCode , array $templateParams ): bool { // 實例化EasySms $easySmsConfig = Config::getEasySmsConfig( $this ->smsConfig); $easySms = new EasySms( $easySmsConfig ); $content = str_replace ( '${' . array_keys ( $templateParams )[0]. '}' , array_values ( $templateParams )[0], $templateCode ); if ( $this ->gateway == 'smsbao' ) { $content = "【" . $this ->smsConfig[ 'engine' ][ 'smsbao' ][ 'sign' ]. "】" . $content ; } try { // 執行發送短信 $result = $easySms ->send( $acceptPhone , [ 'content' => $content , 'template' => $templateCode , 'data' => $this ->getSmsTemplateData( $templateParams ), ]); // 短信發送成功的錯誤處理 $sendStatus = $this ->resultHandle( $result ); } catch (NoGatewayAvailableException $e ) { // 短信發送異常的錯誤處理 $sendStatus = false; $this ->exceptionHandle( $e ); } // 記錄日志 helper::logInfo( '發送短信' , [ 'gateway' => $this ->smsConfig[ 'default' ], 'acceptPhone' => $acceptPhone , 'templateCode' => $templateCode , 'templateParams' => $templateParams , 'sendStatus' => $sendStatus ? 'true' : 'false' , 'sendErrMsg' => $this ->getError(), ]); // 存在異常時拋錯 $sendStatus === false && throwError( $this ->getError()); return $sendStatus ; } |
3.接著打開項目app\common\model\store\Setting.php,在228行左右增加以下代碼
1
2
3
4
5
6
7
8
|
// 短信寶 'smsbao' => [ 'name' => '短信寶短信' , 'user' => '' , 'password' => '' , 'sign' => '螢火商城' // 短信簽名 ], |
好了經過以上的添加,短信寶的短信平臺已經替換成功了,可以正常使用了
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的螢火商城系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類