Drupal基于SMS Framework模块新增短信接口
2018-03-13编辑人: 短信宝小编
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 SMSBAOdescription = Provides SMSBAO integration for SMS Framework.core = 7.xpackage = SMS Frameworkdependencies[] = smsconfigure = admin/smsframework/gateways;Information added by Drupal.org packaging script on 2018-03-13version = "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(https://www.smsbao.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 "https://www.smsbao.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秒就可送达。
开源插件
最新更新
- Muucmf内容管理系统新增短信宝短信插件
- BadouCMS新增短信宝短信插件
- CRMEB新增短信宝短信插件
- Fastadmin新增短信宝短信插件
- SparkShop(星火商城)新增短信宝短信插件
- YZMCMS内容管理系统短信宝短信插件
- 星聚合登录系统新增短信宝短信插件
- Mccms内容系统新增短信宝短信插件
- Cscms音乐门户系统新增短信宝插件
- EyouCMS系统新增短信宝短信插件
电商类
- ShopXO商城系统短信插件安装说明
- CRMEB新增短信宝短信插件
- SparkShop(星火商城)新增短信宝短信插件
- DBshop短信宝插件
- likeshop新增短信宝短信插件
- Jshop新增短信宝短信插件
- DSShop单店铺商城系统短信宝短信插件
- iWebShop商城系统新增短信宝短信插件
- DSO2O外卖系统新增短信宝短信插件
- IdeaCMS商城系统新增短信宝短信插件
CMS类
- PbootCMS新增短信宝短信插件
- Muucmf内容管理系统新增短信宝短信插件
- BadouCMS新增短信宝短信插件
- CRMEB新增短信宝短信插件
- Fastadmin新增短信宝短信插件
- YZMCMS内容管理系统短信宝短信插件
- Mccms内容系统新增短信宝短信插件
- Cscms音乐门户系统新增短信宝插件
- EyouCMS系统新增短信宝短信插件
- emlog新增短信宝短信插件
微信类
文章标签






