DSMall基于国内优秀开源框架THinkPHP、打造出的一套开源的B2B2C电子商务系统。小编带着大家一起开发DSMall商城3.1.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 | <trclass="noborder">    <tdclass="required w120">短信宝用户名</td>    <tdclass="vatop rowform">        <inputtype="text"name="smscf_wj_username"id="smscf_wj_username"value="{$list_config.smscf_wj_username}"class="w200"/>    </td>    <tdclass="vatop tips"></td></tr><trclass="noborder">    <tdclass="required w120">短信宝密码</td>    <tdclass="vatop rowform">        <inputtype="text"name="smscf_wj_key"id="smscf_wj_key"value="{$list_config.smscf_wj_key}"class="w200"/>    </td>    <tdclass="vatop tips"></td></tr>{notempty name='smscf_wj_num'}<trclass="noborder">    <tdclass="required w120">可用短信条数</td>    <td>{$smscf_wj_num}</td>    <tdclass="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 | publicfunctionmobile() {    $config_model= model('config');    if(!(request()->isPost())) {        $list_config= rkcache('config', true);                $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文件,替换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 
						29 
						30 
						31 
						32 
						33 
						34 
						35 
						36 |  privatefunctionmysend_sms($mobile, $content)    {        $smsbao_user= urlencode(config('smsbao_user')); // 户名        $smsbao_pwd= urlencode(config('smsbao_pass')); // 这里填接口安全密钥        $smsbao_sign= urlencode(config('smsbao_sign'));                 if(!$mobile|| !$content|| !$smsbao_user|| !$smsbao_pwd|| !$smsbao_sign)            returnfalse;        if(is_array($mobile)) {            $mobile= implode(",", $mobile);        }                $mobile=urlencode($mobile);        $content=urlencode($content);        $url= 'http://api.smsbao.com/sms?u='.$smsbao_user.'&p='.md5($smsbao_pwd).'&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) {            returntrue;        }        returnfalse;    }} | 
	经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
	
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的DsMall商城系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类