螢火商城V2.0是全新推出的一款輕量級(jí)、高性能、前后端分離的電商系統(tǒng),支持微信小程序 + H5+ 公眾號(hào) + APP,前后端源碼完全開(kāi)源,完美支持二次開(kāi)發(fā)。小編對(duì)這款軟件還是比較了解的,小編今天就以新增短信接口為例為大家講解一下如何進(jìn)行二次開(kāi)發(fā),我們使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶短信群發(fā)平臺(tái)非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試短信,推薦大家使用。
1.首先打開(kāi)項(xiàng)目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.接著打開(kāi)項(xiàng)目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 { // 實(shí)例化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 { // 執(zhí)行發(fā)送短信 $result = $easySms->send($acceptPhone, [ 'content' => $content, 'template' => $templateCode, 'data' => $this->getSmsTemplateData($templateParams), ]); // 短信發(fā)送成功的錯(cuò)誤處理 $sendStatus = $this->resultHandle($result); } catch (NoGatewayAvailableException $e) { // 短信發(fā)送異常的錯(cuò)誤處理 $sendStatus = false; $this->exceptionHandle($e); } // 記錄日志 helper::logInfo('發(fā)送短信', [ 'gateway' => $this->smsConfig['default'], 'acceptPhone' => $acceptPhone, 'templateCode' => $templateCode, 'templateParams' => $templateParams, 'sendStatus' => $sendStatus ? 'true' : 'false', 'sendErrMsg' => $this->getError(), ]); // 存在異常時(shí)拋錯(cuò) $sendStatus === false && throwError($this->getError()); return $sendStatus; } |
3.接著打開(kāi)項(xiàng)目app\common\model\store\Setting.php,在228行左右增加以下代碼
|
1
2
3
4
5
6
7
8
|
// 短信寶'smsbao' => [ 'name' => '短信寶短信', 'user' => '', 'password' => '', 'sign' => '螢火商城' // 短信簽名], |
好了經(jīng)過(guò)以上的添加,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了

報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開(kāi)發(fā)好完整的螢火商城系統(tǒng)短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類