萤火商城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类
微信类