iWebShop是一款基于PHP語(yǔ)言及MYSQL數(shù)據(jù)庫(kù)開(kāi)發(fā)的B2B2C多用戶開(kāi)源免費(fèi)的商城系統(tǒng),系統(tǒng)支持平臺(tái)自營(yíng)和多商家入駐、集成微信商城、手機(jī)商城、移動(dòng)端APP商城于一體。二次開(kāi)發(fā)非常方便,小編對(duì)他還是比較了解的,今天小編為大家講解iWebShop_5.1版本的短信接口替換,使用的接口是我們短信寶群發(fā)平臺(tái)的短信接口,我們短信寶群發(fā)短信平臺(tái)非常穩(wěn)定,發(fā)送速度快,注冊(cè)還送測(cè)試短信,推薦大家使用。
首先我們打開(kāi)項(xiàng)目\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>說(shuō)明:</th> <td> 還沒(méi)有注冊(cè)短信寶短信平臺(tái)的用戶,請(qǐng)點(diǎn)擊 <p>商城所用的短信內(nèi)容模板在【/classes/smstemplate.php】文件中,盡量用原始的短信模板,否則會(huì)導(dǎo)致短信發(fā)送延遲等問(wèn)題</p> <p>如果想關(guān)閉某個(gè)短信發(fā)送環(huán)節(jié),可以直接把相應(yīng)方法的返回值設(shè)置為空</p> </td> </tr> <tr> <th>管理員手機(jī)號(hào):</th> <td>【系統(tǒng)】——【網(wǎng)站設(shè)置】——【手機(jī)號(hào)】</td> </tr> <tr> <th>短信平臺(tái):</th> <td> <select name="sms_platform" class="form-control"> <option value="smsbao">短信寶短信平臺(tái)</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個(gè)字符)</p></td> </tr> <tr><th>測(cè)試手機(jī)號(hào)碼:</th> <td><input type='text' class='form-control' name='mobile' pattern='mobi' empty alt='填寫(xiě)正確的手機(jī)號(hào)碼' /><p class="help-block">必須先<保存>配置后,在測(cè)試短信發(fā)送的功能【可選】</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'>測(cè)試短信發(fā)送</span></button> </td> </tr> </table> </form></div> |
接著我們打開(kāi)項(xiàng)目\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 "短信內(nèi)容不能為空"; } if( $delay == 1 && !isset($_SERVER['HTTP_USER_AGENT']) ) { return "非客戶端訪問(wèn)"; } 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 "非法手機(jī)號(hào)碼"; } if(count($mobile_array) > 200) { return "手機(jī)號(hào)超過(guò)200個(gè)"; } //延遲機(jī)制 if($delay == 1) { $cacheObj = new ICache(); $smsTime = $cacheObj->get('smsDelay'.md5($mobiles)); if($smsTime && time() - $smsTime < self::$sendStep) { return "短信發(fā)送頻率太快,請(qǐng)稍候再試..."; } //更新發(fā)送時(shí)間 $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); } |
最后我們?cè)陧?xiàng)目\plugins\hsms\目錄下創(chuàng)建名為smsbao.php的PHP文件,內(nèi)容編輯為以下代碼:
|
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 **短信發(fā)送接口 * @author linf * @date 2016/11/21 11:10:38 * @version 1.0 */ /** * @class smsbao * @brief 短信發(fā)送接口 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 發(fā)送短信 * @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); //如果需要將結(jié)果直接返回到變量里,那加上這句。 $result = curl_exec($ch); return $this->response($result); } /** * @brief 解析結(jié)果 * @param $result 發(fā)送結(jié)果 * @return string success or fail */ public function response($result) { if(trim($result) =='0') { return 'success'; } else { return $this->getMessage($result); } } /** * @brief 獲取參數(shù) */ public function getParam() { return array( "username" => "用戶名", "userpwd" => "密碼", "usersign" => "短信簽名", ); } //返回消息提示 public function getMessage($code) { $messageArray = array( -1 =>"參數(shù)不全", 30 =>"密碼錯(cuò)誤", 40 =>"賬號(hào)不存在", 41 =>"余額不足", 42 =>"賬號(hào)過(guò)期", 43 =>"IP地址限制", 50 =>"內(nèi)容含有敏感詞", 51 =>"手機(jī)號(hào)碼不正確", ); return isset($messageArray[$code]) ? $messageArray[$code] : "未知錯(cuò)誤"; }} |
好了,經(jīng)過(guò)以上的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行發(fā)送測(cè)試:

報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開(kāi)發(fā)好完整的iwebshop商城系統(tǒng)短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類