iWebShop是一款基于PHP語言及MYSQL數(shù)據(jù)庫開發(fā)的B2B2C多用戶開源免費(fèi)的商城系統(tǒng),系統(tǒng)支持平臺自營和多商家入駐、集成微信商城、手機(jī)商城、移動端APP商城于一體。二次開發(fā)非常方便,小編對他還是比較了解的,今天小編為大家講解iWebShop_5.16版本的短信接口替換,使用的接口是我們短信寶群發(fā)平臺的短信接口,我們短信寶群發(fā)短信平臺非常穩(wěn)定,發(fā)送速度快,注冊還送測試短信,推薦大家使用。
首先打開項(xiàng)目:iwebshop-master\views\sysdm\system\hsms.html文件,替換34~73代碼
|
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
|
<tr> <th>短信平臺:</th> <td> <select name="sms_platform" class="form-control"> <option value="smsbao">短信寶短信平臺【國內(nèi)】</option> <option value="smsbaoWorld">短信寶短信平臺【國際】</option> </select> </td></tr><tr> <th>短信簽名:</th> <td><input type='text' class='form-control' name='sms_sign' pattern='required' alt='' /></td></tr><tr> <th>短信寶賬號:</th> <td><input type='text' class='form-control' name='sms_username' pattern='required' alt='' /> target="_blank">去注冊</a></p> </td></tr><tr> <th>APIKEY:</th> <td><input type='text' class='form-control' name='sms_pwd' pattern='required' alt='' /> <p class="help-block">短信寶APIKEY</p> </td></tr><tr> <th>測試手機(jī)號碼:</th> <td><input type='text' class='form-control' name='mobile' pattern='mobi' empty alt='填寫正確的手機(jī)號碼' /> <p class="help-block">必須先<保存>配置后,在測試短信發(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'>測試短信發(fā)送</span></button> </td></tr> |
接著在plugins\_hsms目錄下新增smsbao.php文件,主是針對國內(nèi)用戶的發(fā)送接口
|
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
|
<?php/** * @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_sign, ); } /** * @brief 發(fā)送短信 * @param string $mobile * @param string $content * @return */ public function send($mobile,$content) { $config = self::getConfig(); $post_data = array( 'u' => $config['username'], 'p' => $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 =>"密碼錯誤", 40 =>"賬號不存在", 41 =>"余額不足", 42 =>"賬號過期", 43 =>"IP地址限制", 50 =>"內(nèi)容含有敏感詞", 51 =>"手機(jī)號碼不正確", ); return isset($messageArray[$code]) ? $messageArray[$code] : "未知錯誤"; }} |
接著在plugins\_hsms目錄下新增smsbaoWorld.php文件,主是針對國際用戶的發(fā)送接口
|
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
116
117
|
<?php/** * @class smsbao * @brief 短信發(fā)送接口 http://api.smsbao.com/sms */class smsbaoWorld extends hsmsBase{ private $countryCode= "61";//國家編號 /** * @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_sign, ); } //處理手機(jī)號碼 private function filterMobile($mobile) { if(stripos($mobile,'0') === 0) { $mobile = substr($mobile,1); } return $mobile; } /** * @brief 發(fā)送短信 * @param string $mobile * @param string $content * @return */ public function send($mobile,$content) { $mobile = $this->filterMobile($mobile); $config = self::getConfig(); date_default_timezone_set('Asia/Shanghai'); $post_data = array( 'u' => $config['username'], 'p' => $config['userpwd'], 'c' => UrlEncode('【'.$config['sign'].'】'.$content), 'm' => UrlEncode('+'.$this->countryCode.$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 =>"密碼錯誤", 40 =>"賬號不存在", 41 =>"余額不足", 42 =>"賬號過期", 43 =>"IP地址限制", 50 =>"內(nèi)容含有敏感詞", 51 =>"手機(jī)號碼不正確", ); return isset($messageArray[$code]) ? $messageArray[$code] : "未知錯誤"; }} |
好了經(jīng)過以上的添加,短信寶的短信平臺已經(jīng)替換成功了,可以正常使用了

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