Drupal是使用PHP語言編寫的開源內容管理框架(CMF),它由內容管理系統(CMS)和PHP開發框架(Framework)共同構成,小編對他算是比較了解,今天就以新增短信接口為例帶著大家進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
本次新增接口是基于SMS Framework這個模塊所開發的,所以在開發之前我們要確保Drupal和SMS Framework已經安裝并且可以正常使用,如果未安裝或不能正常使用都會導致短信發送失敗。第一步首先在SMS Framework模塊的modules文件夾下新建一個文件夾,取名為sms_smsbao,在sms_smsbao下新建兩個文件,分別為sms_smsbao.info和sms_smsbao.module文件。sms_smsbao.info中的內容為:
1
2
3
4
5
6
7
8
9
10
11
12
|
name = SMS SMSBAO description = Provides SMSBAO integration for SMS Framework. core = 7.x package = SMS Framework dependencies[] = sms configure = admin/smsframework/gateways ;Information added by Drupal.org packaging script on 2018-03-13 version = "7.x-1.x-dev" core = "7.x" project = "sms_smsbao" datestamp = "1435220283" |
sms_smsbao.module中的內容為:
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
|
<?php /** * @file * Provide SMSBAO(http://www.gjrencai.com/) integration for SMS framework. */ /** * Implements hook_gateway_info(). */ function sms_smsbao_gateway_info() { return array ( 'sms_smsbao' => array ( 'name' => 'SMS SMSBAO' , 'send' => 'sms_smsbao_send' , 'receive' => TRUE, 'configure form' => 'sms_smsbao_admin_form' , // 'send form' => 'sms_smsbao_send_form', ) ); } /** * Implements hook_send(). */ function sms_smsbao_send( $number , $message , $options = array ()) { $status = FALSE; $return_message = t( "No message sent" ); $validation_message = t( "No validation attempted" ); // Validate the message length if ( strlen ( $message ) > 160) { $return_message = t( 'The message you wanted to send is too long and cannot be sent.' ); return array ( 'status' => $status , 'message' => $return_message , 'variables' => NULL, 'validation' => $validation_message , ); } $data = array ( 'm' => trim( $number ), 'c' => trim( $message ), ); $result = _sms_smsbao_gateway_request( $data ); $result = array ( 'status' => $status , 'message' => $return_message , 'variables' => NULL, ); return $result ; } /** * Callback: sms_smsbao_admin_form. */ function sms_smsbao_admin_form( $configuration ) { $form = array (); $form [ 'sms_smsbao_url' ] = array ( '#type' => 'textfield' , '#title' => t( 'SMSBAO GATEWAY URL' ), '#default_value' => isset( $configuration [ 'sms_smsbao_url' ]) ? $configuration [ 'sms_smsbao_url' ] : '' , '#description' => t( 'The custom URL used to access your SMSBAO GATEWAY API. It often looks like "http://www.gjrencai.com".' ), '#required' => TRUE, ); $form [ 'sms_smsbao_cdkey' ] = array ( '#type' => 'textfield' , '#title' => t( 'SMSBAO CDKEY' ), '#default_value' => isset( $configuration [ 'sms_smsbao_cdkey' ]) ? $configuration [ 'sms_smsbao_cdkey' ] : '' , '#description' => t( 'The SMSBAO CDKEY.' ), '#required' => TRUE, ); $form [ 'sms_smsbao_password' ] = array ( '#type' => 'textfield' , '#title' => t( 'SMSBAO Password' ), '#default_value' => isset( $configuration [ 'sms_smsbao_password' ]) ? $configuration [ 'sms_smsbao_password' ] : '' , '#description' => t( 'The password to access SMSBAO' ), '#required' => TRUE, ); $form [ 'sms_smsbao_sign' ] = array ( '#type' => 'textfield' , '#title' => t( 'SMSBAO SIGN' ), '#default_value' => isset( $configuration [ 'sms_smsbao_sign' ]) ? $configuration [ 'sms_smsbao_sign' ] : '' , '#description' => t( 'The SMSBAO SIGN.' ), '#required' => TRUE, ); return $form ; } /** * Implements hook_form_alter(). */ function sms_smsbao_form_sms_admin_gateway_form_alter(& $form , & $form_state ) { $form [ '#validate' ][] = 'sms_smsbao_admin_form_validate' ; } /** * Validate the admin form. */ function sms_smsbao_admin_form_validate( $form , & $form_state ) { $url = $form_state [ 'values' ][ 'sms_smsbao_url' ]; $data = array ( 'u' => $form_state [ 'values' ][ 'sms_smsbao_cdkey' ], 'p' => md5( $form_state [ 'values' ][ 'sms_smsbao_password' ]), ); $params = drupal_http_build_query( $data ); $url = $url . '/query?' . $params ; $result = file_get_contents ( $url ); } /** * Request gateway. * * @param array $data * * @return object */ function _sms_smsbao_gateway_request( $data = array ()) { $gateway = sms_gateways( 'gateways' ); $config = $gateway [ 'sms_smsbao' ][ 'configuration' ]; $list = array ( 'u' => $config [ 'sms_smsbao_cdkey' ], 'p' => md5( $config [ 'sms_smsbao_password' ]), 'm' => $data [ 'm' ], 'c' => '【' . $config [ 'sms_smsbao_sign' ]. '】' . $data [ 'c' ] ); $params = drupal_http_build_query( $list ); $url = $config [ 'sms_smsbao_url' ] . '/sms?' . $params ; $result = file_get_contents ( $url ); return $result ; } |
好了,經過以上的替換,短信寶的短信平臺已經替換成功了,我們去進行發送測試:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,并且免審核了,短信內容3~5秒就可送達。
最新更新
電商類
CMS類
微信類