DSShop商城新增短信接口

DSSHOP是基于DSMall(B2B2C商城)分离出来的单店铺B2C商城系统,基于国内优秀开源框架THinkPHP、打造出的一套开源的B2C电子商务系统。今天小编就以最新版本的替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是短信宝短信群发平台的接口,短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先打开项目:application\admin\view\message\mobile.html,替换17~31行左右代码:

         <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="http://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方法:

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://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方法:

 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秒就可送达。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值