智簡魔方業務管理系統是一套基于PHP+MYSQL構建開源免費的業務管理系統。具有豐富的插件市場,今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
插件目錄結構如下
├─smsbao插件目錄
│ ├─config
│ │ ├─smsTemplate.php 相關短信模板
│ ├─config.php 短信寶設置
│ ├─Smsbao.php 短信寶插件信息描述以及核心發送類
下面具體給大家說一下每個文件的作用及代碼,
1:打開項目:config/smsTemplate.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
|
<?php return [ [ 'title' => '驗證碼' , 'content' => '驗證碼{code},5分鐘內有效!請勿泄漏于他人' , 'name' => 'code' ], [ 'title' => '用戶登錄' , 'content' => '您的賬號{account}成功登錄系統,如不是本人操作請及時修改密碼' , 'name' => 'client_login_success' ], [ 'title' => '用戶注冊' , 'content' => '{account},感謝您支持{system_website_name}' , 'name' => 'client_register_success' ], [ 'title' => '客戶更改手機' , 'content' => '您的手機號被改為:{client_phone},請注意賬戶安全' , 'name' => 'client_change_phone' ], [ 'title' => '客戶更改密碼' , 'content' => '您的密碼被改為:{client_password},請注意賬戶安全' , 'name' => 'client_change_password' ], [ 'title' => '訂單創建' , 'content' => '您已下單,訂單:{order_id}(訂單號),請及時支付' , 'name' => 'order_create' ], [ 'title' => '產品開通中' , 'content' => '您的產品:{product_name}(產品名稱)正在開通,請耐心等待' , 'name' => 'host_pending' ], [ 'title' => '開通成功' , 'content' => '您的產品:{product_name}(產品名稱),已開通可使用' , 'name' => 'host_active' ], [ 'title' => '產品暫停通知' , 'content' => '您的產品:{product_name}(產品名稱),由于{product_suspend_reason},已停用' , 'name' => 'host_suspend' ], [ 'title' => '產品解除暫停通知' , 'content' => '您的產品:{product_name}(產品名稱),已解除暫停' , 'name' => 'host_unsuspend' ], [ 'title' => '產品刪除通知' , 'content' => '您的產品:{product_name}(產品名稱),由于到期未續費,已刪除' , 'name' => 'host_terminate' ], [ 'title' => '產品升降級' , 'content' => '您已成功升級產品{product_name},感謝您的支持' , 'name' => 'host_upgrad' ], [ 'title' => '第一次續費提醒' , 'content' => '您的產品:{product_name}(產品名稱),還有{renewal_first}天到期,請及時續費' , 'name' => 'host_renewal_first' ], [ 'title' => '第二次續費提醒' , 'content' => '您的產品:{product_name}(產品名稱),還有{renewal_second}天到期,請及時續費' , 'name' => 'host_renewal_second' ], [ 'title' => '逾期付款第一次提醒' , 'content' => '您的產品:{product_name}(產品名稱)已到期,將會刪除,請及時續費' , 'name' => 'host_overdue_first' ], [ 'title' => '逾期付款第二次提醒' , 'content' => '您的產品:{product_name}(產品名稱)已到期,將會刪除,請及時續費' , 'name' => 'host_overdue_second' ], [ 'title' => '逾期付款第三次提醒' , 'content' => '您的產品:{product_name}(產品名稱)已到期,將會刪除,請及時續費' , 'name' => 'host_overdue_third' ], [ 'title' => '訂單未付款通知' , 'content' => '您的訂單:{order_id}(訂單號)尚未支付,金額{order_amount},請及時支付' , 'name' => 'order_overdue' ], [ 'title' => '訂單金額修改' , 'content' => '您的訂單:{order_id}(訂單號)金額修改為{order_amount},請及時支付' , 'name' => 'admin_order_amount' ], [ 'title' => '訂單支付通知' , 'content' => '您的訂單:{order_id}(訂單號)支付成功,支付金額為:{order_amount}元' , 'name' => 'order_pay' ], [ 'title' => '充值成功通知' , 'content' => '充值成功,本次充值金額為:{order_amount}元' , 'name' => 'order_recharge' ], ]; |
2:打開項目:config.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
|
<?php /* * */ return [ 'user' => [ 'title' => '短信寶賬號' , 'type' => 'text' , 'value' => '' , 'tip' => '' , ], 'pass' => [ 'title' => '短信寶密碼' , 'type' => 'text' , 'value' => '' , 'tip' => '' , ], 'sign' => [ 'title' => '短信寶簽名' , 'type' => 'text' , 'value' => '' , 'tip' => '' , ], ]; |
3:打開項目: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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
<?php namespace sms\Smsbao; use app\common\lib\Plugin; class Smsbao extends Plugin { # 基礎信息 public $info = array( 'name' => 'Smsbao' , 'title' => '短信寶短信' , 'description' => '短信寶短信' , 'status' => 1, 'author' => '短信寶' , 'version' => '1.0' , ); # 插件安裝 public function install() { //導入模板 $smsTemplate= []; if (file_exists(__DIR__. '/config/smsTemplate.php' )){ $smsTemplate = require __DIR__. '/config/smsTemplate.php' ; } return $smsTemplate; } # 插件卸載 public function uninstall() { return true ; //卸載成功返回true,失敗false } #獲取國內模板 public function getCnTemplate($params) { $data[ 'status' ]= 'success' ; $data[ 'template' ][ 'template_status' ]=2; return $data; } #創建國內模板 public function createCnTemplate($params) { $data[ 'status' ]= 'success' ; $data[ 'template' ][ 'template_status' ]=2; return $data; } #修改國內模板 public function putCnTemplate($params) { $data[ 'status' ]= 'success' ; $data[ 'template' ][ 'template_status' ]=2; return $data; } #刪除國內模板 public function deleteCnTemplate($params) { $data[ 'status' ]= 'success' ; return $data; } #發送國內短信 public function sendCnSms($params) { $content=$ this ->templateParam($params[ 'content' ],$params[ 'templateParam' ]); $param[ 'content' ]=$ this ->templateSign($params[ 'config' ][ 'sign' ]).$content; $param[ 'mobile' ]=trim($params[ 'mobile' ]); $resultTemplate= $ this ->APIHttpRequestCURL( 'cn' ,$param,$params[ 'config' ]); if ($resultTemplate[ 'status' ]== "success" ){ $data[ 'status' ]= "success" ; $data[ 'content' ]=$content; } else { $data[ 'status' ]= "error" ; $data[ 'content' ]=$content; $data[ 'msg' ]=$resultTemplate[ 'msg' ]; } return $data; } #獲取國際模板 public function getGlobalTemplate($params) { $data[ 'status' ]= 'success' ; $data[ 'template' ][ 'template_status' ]=2; return $data; } #創建國際模板 public function createGlobalTemplate($params) { $data[ 'status' ]= 'success' ; $data[ 'template' ][ 'template_status' ]=2; return $data; } #修改國際模板 public function putGlobalTemplate($params) { $data[ 'status' ]= 'success' ; $data[ 'template' ][ 'template_status' ]=2; return $data; } #刪除國際模板 public function deleteGlobalTemplate($params) { $data[ 'status' ]= 'success' ; return $data; } #發送國際短信 public function sendGlobalSms($params) { $content=$ this ->templateParam($params[ 'content' ],$params[ 'templateParam' ]); $param[ 'content' ]=$ this ->templateSign($params[ 'config' ][ 'sign' ]).$content; $param[ 'mobile' ]=trim($params[ 'mobile' ]); $resultTemplate= $ this ->APIHttpRequestCURL( 'global' ,$param,$params[ 'config' ]); if ($resultTemplate[ 'status' ]== "success" ){ $data[ 'status' ]= "success" ; $data[ 'content' ]=$content; } else { $data[ 'status' ]= "error" ; $data[ 'content' ]=$content; $data[ 'msg' ]=$resultTemplate[ 'msg' ]; } return $data; } # 以下函數名自定義 private function APIHttpRequestCURL($sms_type= 'cn' ,$params,$config){ if ($sms_type== 'cn' ){ $phone = $params[ 'mobile' ]; } else if ($sms_type== "global" ){ $phone = urlencode($params[ 'mobile' ]); } $statusStr = array( "0" => "短信發送成功" , "-1" => "參數不全" , "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!" , "30" => "密碼錯誤" , "40" => "賬號不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內容含有敏感詞" , "51" => "手機號碼不正確" ); $user = $config[ 'user' ]; //短信平臺帳號 $pass = md5($config[ 'pass' ]); //短信平臺密碼 $content= $params[ 'content' ]; //要發送的短信內容 $sendurl = $url. "?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); $result =file_get_contents($sendurl) ; //短信發送成功返回True,失敗返回false if ($result == '0' ) { return array( 'status' => "success" , 'msg' => $statusStr[$result]); } else { return array( 'status' => "error" , 'msg' => $statusStr[$result] . '. Code: ' . $result); } } private function templateParam($content,$templateParam){ foreach ($templateParam as $key => $para) { $content = str_replace( '{' . $key . '}' , $para, $content); //模板中的參數替換 } return $content; } private function templateSign($sign){ $sign = str_replace( "【" , "" ,$sign); $sign = str_replace( "】" , "" ,$sign); $sign = "【" .$sign. "】" ; return $sign; } } |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的智簡魔方業務系統V10短信寶插件,點擊此鏈接?下載及查看安裝流
最新更新
電商類
CMS類
微信類