DSMall商城_新增短信宝短信接口
发表日期:2018-12-21 文章编辑:短信宝小编 浏览次数:
DSMall基于国内优秀开源框架THinkPHP、打造出的一套开源的B2B2C电子商务系统。小编带着大家一起开发DSMall商城3.0.1的短信宝插件接口。我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先打开项目:\application\admin\view\message\mobile.html文件,替换17~37行左右的代码。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<tr class="noborder"> <td class="required w120">短信宝用户名</td> <td class="vatop rowform"> <input type="text" name="smscf_wj_username" id="smscf_wj_username" value="{$list_config.smscf_wj_username}" class="w200"/> </td> <td class="vatop tips"></td> </tr> <tr class="noborder"> <td class="required w120">短信宝密码</td> <td class="vatop rowform"> <input type="text" name="smscf_wj_key" id="smscf_wj_key" value="{$list_config.smscf_wj_key}" class="w200"/> </td> <td class="vatop tips"></td> </tr> {notempty name='smscf_wj_num'} <tr class="noborder"> <td class="required w120">可用短信条数</td> <td>{$smscf_wj_num}</td> <td class="vatop tips"></td> </tr> |
接着打开项目:\application\admin\controller\Message.php文件,替换50~87行代码。
|
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
|
/** * 短信平台设置 */ public function mobile() { $config_model = model('config'); if (!(request()->isPost())) { $list_config = $config_model->getConfigList(); $smscf_wj_num = ''; if(!empty($list_config['smscf_wj_username'])&&!empty($list_config['smscf_wj_key'])){ //如果配置了信息,可以查看具体可用短信条数 $smscf_wj_num = http_request('http://api.smsbao.com/query?u='.$list_config['smscf_wj_username'].'&p='.md5($list_config['smscf_wj_key']),'get'); if ($smscf_wj_num) { $smscf_wj_num = explode(',', $smscf_wj_num); $smscf_wj_num = $smscf_wj_num[1]; }else{ $smscf_wj_num = ''; } } $this->assign('smscf_wj_num', $smscf_wj_num); $this->assign('list_config', $list_config); $this->setAdminCurItem('mobile'); return $this->fetch('mobile'); } else { $update_array = array(); $update_array['smscf_wj_username'] = input('post.smscf_wj_username'); $update_array['smscf_wj_key'] = input('post.smscf_wj_key'); $update_array['sms_register'] = input('post.sms_register'); $update_array['sms_login'] = input('post.sms_login'); $update_array['sms_password'] = input('post.sms_password'); $result = $config_model->editConfig($update_array); if ($result === true) { $this->log(lang('ds_edit') . lang('mobile_set'), 1); $this->success(lang('ds_common_save_succ')); } else { $this->log(lang('ds_edit') . lang('mobile_set'), 0); $this->error(lang('ds_common_save_fail')); } } } |
最后打开项目:\extend\sendmsg\Sms.php文件,替换35~64行代码。
|
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
|
private function mysend_sms($mobile, $content) { $user_id = urlencode(config('smscf_wj_username')); // 这里填写用户名 $key = urlencode(config('smscf_wj_key')); // 这里填接口安全密钥 if (!$mobile || !$content || !$user_id || !$key) return false; if (is_array($mobile)) { $mobile = implode(",", $mobile); } $mobile=urlencode($mobile); $content=urlencode($content); if (function_exists('file_get_contents')) { $res = file_get_contents($url); } else { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); curl_close($ch); } if ($res == 0) { return true; } return false; } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的DsMall商城系统短信宝插件,点击此链接 下载及查看安装流程。

