shopwind是一款免費開源的輕量級電商系統。穩(wěn)定的架構內核,基于Yii2深度開發(fā),代碼開源,遵循Apache2.0協議,完善的開發(fā)文檔,功能模塊化,拒絕臃腫繁雜,源碼易讀方便二次開發(fā),豐富的API接口,數據通訊安全加簽,可以滿足任何功能插件開發(fā)的需要。小編對他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發(fā),我們今天講解的是v4.8版本,使用的短信接口是我們短信寶短信群發(fā)平臺的短信接口,我們短信寶短信群發(fā)平臺的接口非常穩(wěn)定,發(fā)送速度快,注冊就送測試短信,推薦大家使用。
打開 shopwind/common/plugins/sms 新增短信寶smsbao目錄
插件的目錄結構如下:
├─smsbao插件目錄
│ ├─plugin.info.php 短信插件配置信息
│ ├─SDK.php 繼承系統短信基類
│ ├─smsbao.plugin.php 短信寶核心發(fā)送短信類
1:下面具體給大家說一下每個文件的作用及代碼,plugin.info.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
|
<?phpnamespace common\plugins\sms\smsbao;use yii;use yii\helpers\Url;use common\library\Language;/** * @Id smsbao.plugin.php 2025.6.5 $ * @author smsbao */return array( 'code' => 'smsbao', 'name' => '短信寶', 'desc' => '短信寶為全國各大開源軟件提供全面的短信支持10年積累,專注提供更好的短信服務穩(wěn)定,快是我們不變的追求!。<a href="http://www.gjrencai.com/" target="_blank">接口申請</a>', 'author' => 'SMSBAO', 'version' => '1.0', 'buttons' => array( array( 'label' => Language::get('manage'), 'url' => Url::toRoute(['sms/index']) ) ), 'config' => array( 'uid' => array( 'type' => 'text', 'text' => '短信寶賬號' ), 'ApiKey' => array( 'type' => 'text', 'text' => 'API Key' ), 'scene' => array( 'name' => 'config[scene]', 'type' => 'checkbox', 'text' => '啟用場景', 'items' => array( 'register' => '用戶注冊', 'find_password' => '找回密碼' ) ) )); |
2:SDK.php 為繼承系統短信基類文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?phpnamespace common\plugins\sms\smsbao;use yii;use yii\base\InvalidConfigException;/** * @Id smsbao.plugin.php 2025.6.5 $ * @author smsbao */class SDK {} |
3:smsbao.plugin.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
<?phpnamespace common\plugins\sms\smsbao;use yii;use common\models\SmsTemplateModel;use common\library\Basewind;use common\library\Language;use common\plugins\BaseSms;/** * @Id smsbao.plugin.php 2025.6.5 $ * @author smsbao */class Smsbao extends BaseSms{ /** * 網關地址 * @var string $gateway */ /** * 短信實例 * @var string $code */ protected $code = 'smsbao'; protected $smbaostatus = [ "0" => "短信發(fā)送成功", "-1" => "參數不全", "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!", "30" => "密碼錯誤", "40" => "賬號不存在", "41" => "余額不足", "42" => "帳戶已過期", "43" => "IP地址限制", "50" => "內容含有敏感詞"]; /** * 發(fā)送短信 * @param bool $valid 發(fā)送頻次等的校驗,如果是系統發(fā)送的短信,可以適當的不做該校驗以確保發(fā)送成功 */ public function send($valid = true) { if(!$this->verify()) { return false; } if($valid === true && !$this->validSend()) { return false; } // 發(fā)送的短信信息校驗 if($this->validData() == false) { return false; } $result = $this->submit(); if($result == '0') { $codekey = $this->insert($result); return $codekey; } $this->errors = $this->smbaostatus[$result]; $this->insert(0, $this->errors); return false; } /** * 測試短信發(fā)送 */ public function testsend($content = '') { $this->content = $content; $result = $this->submit(); if($result == '0') { return true; } $this->errors = $this->smbaostatus[$result]; return false; } /** * 執(zhí)行短信發(fā)生 */ private function submit() { $url = $this->gateway.'sms?u='.$this->config['uid'].'&p='.$this->config['ApiKey'] . '&m=' . $this->receiver . '&c=' . urlencode('【'.$this->signName.'】'.$this->content); return Basewind::curl($url); } /** * 檢測是否配置 * @var boolean $force 是否驗證短信模板內容 */ public function verify($force = true) { if(!$this->config['uid']) { $this->errors = '短信設置錯誤'; return false; } if(!$this->config['ApiKey']) { $this->errors = '短信設置錯誤'; return false; } // 如果是驗證非具體短信場景,可以不用驗證短信模板 // 比如某個地方僅僅需要判斷密鑰是否配置,從而進行開關控制 if(!$force) { return true; } // 傳遞具體短信場景參數,則驗證短信模板 if(($template = $this->getTemplate()) === false) { return false; } if(!$template || empty($template->content)) { $this->errors = Language::get('The "content" property must be set'); return false; } if(empty($template->signName)) { $this->errors = Language::get('The "signName" property must be set'); return false; } // 此處為必須賦值,避免無法發(fā)送短信 $this->templateId = $template->templateId; $this->signName = $template->signName; $this->content = $this->getContent($template); return true; } } |
好了經過以上的添加,短信寶的短信平臺已經替換成功了,可以正常使用了

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