iWebShop是一款基于PHP語言及MYSQL數據庫開發的B2B2C多用戶開源免費的商城系統,系統支持平臺自營和多商家入駐、集成微信商城、手機商城、移動端APP商城于一體。二次開發非常方便,小編對他還是比較了解的,今天小編為大家講解iWebShop_5.1版本的短信接口替換,使用的接口是我們短信寶群發平臺的短信接口,我們短信寶群發短信平臺非常穩定,發送速度快,注冊還送測試短信,推薦大家使用。
首先我們打開項目\views\sysdm\system\hsms.html文件,替換14~67行左右的代碼,代碼如下:
|
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
|
<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>商城所用的短信內容模板在【/classes/smstemplate.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' pattern='required' 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' pattern='required' alt='' /><p class="help-block">短信簽名(3-8個字符)</p></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> |
接著我們打開項目\classes\hsms.php文件,替換 send的方法,代碼如下:
|
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
|
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(); } } } return self::$smsInstance->send($mobiles, $content); } |
最后我們在項目\plugins\hsms\目錄下創建名為smsbao.php的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] : "未知錯誤"; }} |
好了,經過以上的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行發送測試:

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的iwebshop商城系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類