ShopXO是国内领先的商城系统提供商,为企业提供php商城系统、微信商城、小程序。是一款100%开放源码的PHP电商系统,基于ThinkPHP5.1 版本开发,容易扩展。今天小编就以替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先打开项目:\application\admin\view\default\sms\nav.html文件,替换以下代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<ul class="am-nav am-nav-pills table-nav m-b-10"> <li {{if $nav_type eq 'sms'}}class="am-active"{{/if}} data-type="sms"> <a href="{{:MyUrl('admin/sms/index', ['type'=>'sms'])}}">短信设置</a> </li> <li {{if $nav_type eq 'message'}}class="am-active"{{/if}} data-type="message"> <a href="{{:MyUrl('admin/sms/index', ['type'=>'message'])}}">消息模板</a> </li></ul><div class="am-alert am-alert-warning am-radius" data-am-alert> <button type="button" class="am-close">×</button></div> |
接着在项目:\application\index\controller目录下创建名为: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
|
<?phpnamespace app\index\controller;use think\Db;/*** */class Smsbao extends Common{ public function __construct() { parent::__construct(); } public function index() { $data['name'] = '短信宝用户名'; $data['describe'] = '短信宝用户名'; $data['error_tips'] = '请填写短信宝用户名'; $datas['name'] = '短信宝密码'; $datas['describe'] = '短信宝密码'; $datas['error_tips'] = '请填写短信宝密码'; $list = Db::name('Config')->where('only_tag','common_sms_apikey')->update($data); $lists = Db::name('Config')->where('only_tag','common_sms_apisecret')->update($datas); echo "<h4>短信宝插件安装完成</h4>"; }} |
最后打开项目:\extend\base\Sms.php文件,替换SendCode方法。
|
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
|
public function SendCode($mobile, $code, $template_code) { // 是否频繁操作 if(!$this->IntervalTimeCheck()) { $this->error = '防止造成骚扰,请勿频繁发送'; return false; } $content = str_replace('code',$code,$template_code); $url = 'http://api.smsbao.com/sms?u='.$this->accessKeyId.'&p='.md5($this->accessKeySecret).'&m='.$mobile.'&c=【'.$this->signName.'】'.$content; $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 ); $result = curl_exec ( $ch ); curl_close ( $ch ); if ($result != 0) { $this->error = $result; return false; } // 种session $this->KindofSession($code); return true;} |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的shopxo商城系统的短信宝插件,点击此链接 下载及查看安装流程。

