待发短信

在线客服
产品支持 短信宝客服
合作渠道 渠道合作
服务咨询

4001-021-502

工作时间

9:00-21:00

DSShop单店铺商城系统新增短信宝短信接口

DSSHOP是基于DSMall(B2B2C商城)分离出来的单店铺B2C商城系统,基于国内优秀开源框架THinkPHP、打造出的一套开源的B2C电子商务系统。今天小编就以DSShop单店铺1.5版本的替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。

首先打开项目:\application\admin\view\message\mobile.html 文件,替换17~31行代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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"/>
        <a href="https://www.smsbao.com/reg" target="_blank" class="btn btn-blue btn-mini">立即申请</a>
    </td>
    <td class="vatop tips"></td>
</tr>

接着打开项目:\application\admin\controller\Message.php文件,替换mobile方法

?
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
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('https://www.smsbao.com/query?u='.$list_config['smscf_wj_username'].'&p='.md5($list_config['smscf_wj_key']),'get');
                $smscf_wj_num explode(','$smscf_wj_num);
                if ($smscf_wj_num[0] == 0) {
                    $smscf_wj_num $smscf_wj_num[1];
                }else{
                    $smscf_wj_num = 0;
                }
            }
            $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文件,替换mysend_sms方法

?
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
 private function mysend_sms($mobile$content)
    {
        $user_id = config('smscf_wj_username'); // 这里填写用户名
        $key = config('smscf_wj_key'); // 这里填接口安全密钥
        if (!$mobile || !$content || !$user_id || !$key)
            return false;
        if (is_array($mobile)) {
            $mobile = implode(","$mobile);
        }
        $url "http://api.smsbao.com/sms?u=".$user_id.'&p='.md5($key).'&m='.$mobile.'&c='.$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秒就可送达。

另外:我们已经开发好完整的DSShop商城系统短信宝插件,点击此链接 下载及查看安装流程。

开源插件

最新更新

电商类

CMS类

微信类

文章标签