likeshop是一款开源的企业级B2C电商系统,前端uni-app架构,极致节省开发成本,一次研发,多端发布。后端ThinkPHP架构,国内最流行的PHP研发框架,易用易学,好二开。小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
前提:需先执行以下sql
1
|
INSERT INTO `ls_sms_config` ( `name`, `describe`, `sign`, `app_key`, `secret_key`, `status`, `del`) VALUES ( '短信宝' , '短信宝短信服务' , '' , '' , '' , '0' , '0' ); |
1:打开项目:application\common\behavior\SmsSend.php 修改run方法
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
37
38
39
40
41
42
43
44
|
public function run($params) { try { $params[ 'scene' ] = $params[ 'key' ]; $ this ->sms_key = $params[ 'key' ]; $ this ->sms_params = $params[ 'params' ]; $ this ->mobile = $params[ 'mobile' ]; $result = $ this ->getSmsConfig($params[ 'key' ]); if ( true !== $result) { return $result; } $ this ->sms_log = new SmsLog(); //短信内容 $ this ->setSmsContent(); //短信验证码 $ this ->setSmsCode(); //增加短信记录 $ this ->createSmsLog(); //增加通知记录 $ this ->notice_id = NoticeLogic::addNoticeLog($params, $ this ->sms, NoticeSetting::SMS_NOTICE, $ this ->content); $alisms = new Alisms($ this ->config); $res = $alisms->setMobile($ this ->mobile) ->setTemplateCode($ this ->sms[ 'template_code' ]) ->setTemplateParam($ this ->sms_params) ->sendSms(); if (isset($res[ 'Code' ]) && $res[ 'Code' ] == 'OK' ) { $send_status = SmsLog::send_success; $ this ->updateSmsLog($send_status, $res); return true ; } else { $send_status = SmsLog::send_fail; $ this ->updateSmsLog($send_status, $res); $message = $res[ 'Message' ] ?? $res; throw new Exception( '短信配置错误:' . $message); } } catch (\Exception $e) { NoticeLogic::updateNotice($ this ->notice_id, $e->getMessage()); } } |
2:打开项目:application\common\serve 新增 SmsBao.php
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
37
38
39
40
41
42
43
44
|
public function run($params) { try { $params[ 'scene' ] = $params[ 'key' ]; $ this ->sms_key = $params[ 'key' ]; $ this ->sms_params = $params[ 'params' ]; $ this ->mobile = $params[ 'mobile' ]; $result = $ this ->getSmsConfig($params[ 'key' ]); if ( true !== $result) { return $result; } $ this ->sms_log = new SmsLog(); //短信内容 $ this ->setSmsContent(); //短信验证码 $ this ->setSmsCode(); //增加短信记录 $ this ->createSmsLog(); //增加通知记录 $ this ->notice_id = NoticeLogic::addNoticeLog($params, $ this ->sms, NoticeSetting::SMS_NOTICE, $ this ->content); $alisms = new Alisms($ this ->config); $res = $alisms->setMobile($ this ->mobile) ->setTemplateCode($ this ->sms[ 'template_code' ]) ->setTemplateParam($ this ->sms_params) ->sendSms(); if (isset($res[ 'Code' ]) && $res[ 'Code' ] == 'OK' ) { $send_status = SmsLog::send_success; $ this ->updateSmsLog($send_status, $res); return true ; } else { $send_status = SmsLog::send_fail; $ this ->updateSmsLog($send_status, $res); $message = $res[ 'Message' ] ?? $res; throw new Exception( '短信配置错误:' . $message); } } catch (\Exception $e) { NoticeLogic::updateNotice($ this ->notice_id, $e->getMessage()); } } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的likeshop系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类