Tinshop是一套企業級的商城系統,產品靈活,易于進行二次開發。今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
首先打開項目:\protected\classes\Menu.php文件,增加一下代碼
1
2
|
'/admin/config_sms' => array ( 'name' => '短信配置' , 'parent' => 'config' ), |
然后打開項目:\protected\classes\文件夾,新增一個文件Sms.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
45
|
<?php class Sms { private $option = array (); public function __construct() { $this ->init(); } public function init() { $config = Config::getInstance(); $sms = $config ->get( 'sms' ); $this ->option = $sms ; } public function send_sms( $phone , $body , $senderInfo = '' ){ $statusStr = array ( "0" => "短信發送成功" , "-1" => "參數不全" , "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!" , "30" => "密碼錯誤" , "40" => "賬號不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內容含有敏感詞" ); $user = $this ->option[ 'email_host' ]; $pass = $this ->option[ 'email_ssl' ]; $sing = $this ->option[ 'email_port' ]; $user = $user ; //短信平臺帳號 $pass = md5( $pass ); //短信平臺密碼 $content = '【' . $sing . '】' . $body ; //要發送的短信內容 $phone = $phone ; //要發送短信的手機號碼 $sendurl = $smsapi . "sms?u=" . $user . "&p=" . $pass . "&m=" . $phone . "&c=" .urlencode( $content ); $result = file_get_contents ( $sendurl ) ; echo $result ; } } |
打開項目:\protected\controllers\ucenter.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
public function send_objcode() { $account = Req::args( 'account' ); $activateObj = Session::get( 'activateObj' ); $sendAble = true; $haveTime = 120; if (isset( $activateObj [ 'time' ]) ){ $time = $activateObj [ 'time' ]; $haveTime = time() - $time ; if ( $haveTime <= 120){ $sendAble = false; } } if ( $sendAble ){ $code = CHash::random(6, 'int' ); if (Validator::email( $account )){ $mail = new Mail(); $flag = $mail ->send_email( $account , '您的郵箱身份核實驗證碼' , "核實郵箱驗證碼:" . $code ); if (! $flag ){ $info = array ( 'status' => 'fail' , 'msg' => '郵件發送失敗請聯系管理人員' ); } else { $activateObj = array ( 'time' =>time(), 'code' => $code , 'obj' => $account ); Session::set( 'activateObj' , $activateObj ); $info = array ( 'status' => 'success' ); } } else if (Validator::mobi( $account )){ $sms = new Sms(); $flag = $sms ->send_sms( $account , "您的手機核實手機驗證碼:" . $code ); if ( $flag == 0){ $activateObj = array ( 'time' => time(), 'code' => $code , 'obj' => $account ); Session::set( 'activateObj' , $activateObj ); $info = array ( 'status' => 'success' , 'msg' => '短信發送成功' ); } else { $info = array ( 'status' => 'fail' , 'msg' => '手機發送失敗請聯系管理人員' ); } // $sms = SMS::getInstance(); // if($sms->getStatus()){ // $result = $sms->sendCode($account,$code); // if($result['status']=='success'){ // $info = array('status'=>'success','msg'=>$result['message']); // $activateObj = array('time'=>time(),'code'=>$code,'obj'=>$account); // Session::set('activateObj',$activateObj); // $info = array('status'=>'success'); // }else{ // $info = array('status'=>'fail','msg'=>$result['message']); // } // }else{ // $info = array('status'=>'fail','msg'=>'系統沒有開啟手機驗證功能!'); // } } else { $info = array ( 'status' => 'fail' , 'msg' => '除郵箱及手機號外,不支持發送!' ); } } else { $info = array ( 'status' => 'fail' , 'msg' => '還有' .(120 - $haveTime ). '秒后可發送!' ); } $info [ 'haveTime' ] = (120 - $haveTime ); echo JSON::encode( $info ); } |
打開項目:\protected\services\config.php,增加一下代碼
1
2
3
4
5
6
7
8
9
10
11
12
|
public function sms() { $sms = array ( 'email_sendtype' =>Req::args( 'sms_sendtype' ), 'sms_account' =>Req::args( 'sms_account' ), 'sms_password' =>Req::args( 'sms_password' ), 'sms_sing' =>Req::args( 'sms_sing' ), ); $this ->config->set( 'sms' , $sms ); return true; } |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的ThinyShop系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類