iWebShop是一款基于PHP語言及MYSQL數據庫開發的B2B2C多用戶商城系統,它可以承載大數據量且性能優良,還可以跨平臺,界面美觀功能豐富,二次開發簡單方便是電商建站首選源碼。小編對他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,我們今天講解的是5.11版本,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用
1:打開項目:views\sysdm\system\hsms.html 新增短信寶頁面
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<div class= "breadcrumbs" id= "breadcrumbs" > <ul class= "breadcrumb" > <li> <i class= "home-icon fa fa-home" ></i> <a href= "#" >系統</a> </li> <li> <a href= "#" >第三方平臺</a> </li> <li class= "active" >短信平臺</li> </ul> </div> <div class= "content" > <form action= "#" method= "post" name= 'sms_conf' > <table class= "table form-table" > <colgroup> <col width= "130px" /> <col /> </colgroup> <tr> <th>說明:</th> <td> 立即接入短信平臺!讓您的客戶把握第一手商城咨詢和訂單動態 <p>商城所用的短信內容模板在【/plugins/_hsms/_hsms.php】文件中,盡量用原始的短信模板,否則會導致短信發送延遲等問題</p> <p>如果想關閉某個短信發送環節,可以直接把相應方法的返回值設置為空</p> </td> </tr> <tr> <th>管理員手機號:</th> <td>【系統】——【網站設置】——【手機號】</td> </tr> <tr> <th>短信平臺:</th> <td> <select name= "sms_platform" class= "form-control" > <option value= "smsbao" >短信寶短信平臺</option> </select> </td> </tr> <tr> <th>短信寶賬號:</th> <td><input type= 'text' class= 'form-control' name= 'sms_username' alt= '' /><p class= "help-block" >填寫短信寶賬號</p></td> </tr> <tr> <th>短信寶密碼:</th> <td><input type= 'text' class= 'form-control' name= 'sms_pwd' pattern= 'required' alt= '' /><p class= "help-block" >填寫短信寶密碼</p></td> </tr> <tr> <th>短信寶簽名:</th> <td><input type= 'text' class= 'form-control' name= 'sms_userid' alt= '' /></td> </tr> <tr> <th>測試手機號碼:</th> <td><input type= 'text' class= 'form-control' name= 'mobile' pattern= 'mobi' empty alt= '填寫正確的手機號碼' /><p class= "help-block" >必須先<保存>配置后,在測試短信發送的功能【可選】</p></td> </tr> <tr> <th></th> <td> <button type= 'button' class= "btn btn-primary" onclick= "submitConfig();" >保存</button> <button class= 'btn btn-primary' type= 'button' onclick= "test_sendhsms(this);" ><span id= 'testmobile' >測試短信發送</span></button> </td> </tr> </table> </form> </div> <script type= 'text/javascript' > jQuery( function () { var formobj = new Form( 'sms_conf' ); formobj.init({echo:JSON::encode($ this ->_siteConfig->getInfo())}); }); //ajax提交信息 function submitConfig() { var sendData = {}; $( 'select,input[name^="sms_"]' ).each( function () { sendData[$( this ).attr( 'name' )] = $( this ).val(); }); $.post( "{url:/system/save_conf}" ,sendData, function (content) { alert( '保存成功' ); }); } //測試短信發送 function test_sendhsms(obj) { $( 'form[name="sms_conf"] input:text' ).each( function (){ $( this ).trigger( 'change' ); }); if ($( 'form[name="sms_conf"] input:text.invalid-text' ).length > 0) { return ; } //按鈕控制 obj.disabled = true ; $( '#testmobile' ).html( '正在測試發送請稍后...' ); var ajaxUrl = '{url:/system/test_sendhsms/random/@random@}' ; ajaxUrl = ajaxUrl.replace( '@random@' ,Math.random()); $.getJSON(ajaxUrl,$( 'form[name="sms_conf"]' ).serialize(), function (content){ obj.disabled = false ; $( '#testmobile' ).html( '測試短信發送' ); alert(content.message); }); } </script> |
2:打開項目:plugins\_hsms 新增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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
<?php /** * @copyright (c) 2016 smsbao.com * @file smsbao.php * @brief **短信發送接口 * @author linf * @date 2016/11/21 11:10:38 * @version 1.0 */ /** * @class smsbao * @brief 短信發送接口 http://api.smsbao.com/sms */ class smsbao extends hsmsBase { /** * @brief 獲取config用戶配置 * @return array */ public function getConfig() { $siteConfigObj = new Config( "site_config" ); return array( 'username' => $siteConfigObj->sms_username, 'userpwd' => $siteConfigObj->sms_pwd, 'sign' => $siteConfigObj->sms_userid, ); } /** * @brief 發送短信 * @param string $mobile * @param string $content * @return */ public function send($mobile,$content) { $config = self::getConfig(); $post_data = array( 'u' => $config[ 'username' ], 'p' => md5($config[ 'userpwd' ]), 'c' => '【' .$config[ 'sign' ]. '】' .$content, 'm' => $mobile, ); $url = $ this ->submitUrl; $string = '' ; foreach ($post_data as $k => $v) { $string .= "$k=" .urlencode($v). '&' ; } $post_string = substr($string,0,-1); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要將結果直接返回到變量里,那加上這句。 $result = curl_exec($ch); return $ this ->response($result); } /** * @brief 解析結果 * @param $result 發送結果 * @return string success or fail */ public function response($result) { if (trim($result) == '0' ) { return 'success' ; } else { return $ this ->getMessage($result); } } /** * @brief 獲取參數 */ public function getParam() { return array( "username" => "用戶名" , "userpwd" => "密碼" , "usersign" => "短信簽名" , ); } //返回消息提示 public function getMessage($code) { $messageArray = array( -1 => "參數不全" , 30 => "密碼錯誤" , 40 => "賬號不存在" , 41 => "余額不足" , 42 => "賬號過期" , 43 => "IP地址限制" , 50 => "內容含有敏感詞" , 51 => "手機號碼不正確" , ); return isset($messageArray[$code]) ? $messageArray[$code] : "未知錯誤" ; } } |
3:打開項目:\classes\hsms.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
public static function send($mobiles, $content, $delay = 1) { if (!$content) { return "短信內容不能為空" ; } if ( $delay == 1 && !isset($_SERVER[ 'HTTP_USER_AGENT' ]) ) { return "非客戶端訪問" ; } if (IClient::getIp() == '' ) { return "ip信息不合法" ; } $mobile_array = explode( "," , $mobiles); foreach ($mobile_array as $key => $val) { if ( false === IValidate::mobi($val)) { unset($mobile_array[$key]); } } if (!$mobile_array) { return "非法手機號碼" ; } if (count($mobile_array) > 200) { return "手機號超過200個" ; } //延遲機制 if ($delay == 1) { $cacheObj = new ICache(); $smsTime = $cacheObj->get( 'smsDelay' .md5($mobiles)); if ($smsTime && time() - $smsTime < self::$sendStep) { return "短信發送頻率太快,請稍候再試..." ; } //更新發送時間 $cacheObj->set( 'smsDelay' .md5($mobiles),time()); } if (self::$smsInstance == null ) { $platform = self::getPlatForm(); switch ($platform) { case "smsbao" : { $classFile = IWeb::$app->getBasePath(). 'plugins/_hsms/smsbao.php' ; require($classFile); self::$smsInstance = new smsbao(); } break ; default : { $classFile = IWeb::$app->getBasePath(). 'plugins/_hsms/smsbao.php' ; require($classFile); self::$smsInstance = new smsbao(); } } } $log = [ "開始記錄" => "短信發送" , "手機號" => $mobiles, "短信內容" => $content]; self::log($log); return self::$smsInstance->send($mobiles, $content); } |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的iWebShop_V5.11系統短信寶插件,點擊此鏈接?下載及查看安裝流
最新更新
電商類
CMS類
微信類