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商城系統的短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類