海盗云商是采用PHP+MySQL方式运行的开源电子商务网店程序。轻架构,高效率简易开发,助你快速搭建并轻松管理网店站点,便于二次开发,小编对于这款产品还是比较了解的,今天就以替换短信接口为例,一步一步的带领大家如何进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快。注册就送测试短信,推荐大家使用。
进行接口替换我们首先需要修改后台模版文件,打开项目/system/module/notify/library/driver/sms/config.xml,修改代码如下:
| 
						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 | <?xmlversion="1.0"encoding="ISO-8859-1"?><root>        <itemid="code"><![CDATA[sms]]></item>        <itemid="name"><![CDATA[短信宝通知系统]]></item>        <itemid="description"><![CDATA[包含手机注册验证、找回密码、余额变动通知、充值成功短信通知、订单发货短信通知、确认订单短信通知、付款成功短信通知、下单成功短信通知]]></item>        <itemid="dataline"><![CDATA[2015-05-25 14:57:09]]></item>        <itemid="version"><![CDATA[1.0]]></item>    <itemid="sort"><![CDATA[2]]></item>    <itemid="ignore"><![CDATA[email_validate,goods_arrival]]></item>        <itemid="vars">                <itemid="sms_name">                        <itemid="name"><![CDATA[短信宝用户名]]></item>                        <itemid="type"><![CDATA[text]]></item>                        <itemid="value"><![CDATA[]]></item>                        <itemid="tips"><![CDATA[请填写在短信宝注册的用户名,尚未注册短信宝的,请点击 <a href='http://www.smsbao.com' target='_blank'><strong>免费注册</strong></a> ]]></item>                </item>                <itemid="sms_pwd">                        <itemid="name"><![CDATA[短信宝账户密码]]></item>                        <itemid="type"><![CDATA[password]]></item>                        <itemid="value"><![CDATA[]]></item>                        <itemid="tips"><![CDATA[请填写短信宝账户密码 ]]></item>                </item>                <itemid="sms_sign">                        <itemid="name"><![CDATA[短信签名]]></item>                        <itemid="type"><![CDATA[text]]></item>                        <itemid="value"><![CDATA[]]></item>                        <itemid="tips"><![CDATA[设置短信签名如,一般为3-8个字符,如:海盗云商 ]]></item>                </item>        </item></root> | 
接下来我们修改模版文件,打开项目/system/module/notify/library/driver/sms/template.inc.php文件,修改代码为:
| 
						1 
						2 
						3 
						4 
						5 
						6 
						7 
						8 
						9 
						10 
						11 
						12 
						13 
						14 
						15 | <p class="notice">您正在编辑 <em id="content-label"class="text-main">loading</em> 通知模板 </p>                                <?php foreach($hooksas$tk=>$tv):?>        <div id='edit_<?php echo $tk?>'style="display: none;">                <div class="form-group">                        <span class="label"></span>                        <div class="">                                <input type='text'name='<?php echo $tk?>[template_id]'class='input hd-input'value='<?php echo trim($template['template'][$tk]['template_id'])?>'/>                        </div>                </div>        </div>        <?php endforeach;?> | 
修改配置模版的代码文件,打开项目/system/module/notify/control/admin_control.class.php文件中的,template方法,代码如下:
| 
						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 | /* 配置模板 */        publicfunctiontemplate() {                $notify= $this->service->fetch_by_code($_GET['code']);                $hooks= array(                        'after_register'=>'注册成功',                        'register_validate'=>'注册验证',                        'mobile_validate'=>'手机验证',                        'email_validate'=>'邮箱验证',                        'forget_pwd'=>'找回密码',                        'money_change'=>'余额变动',                        'recharge_success'=>'充值成功',                        'order_delivery'=>'订单发货',                        'confirm_order'=>'确认订单',                        'pay_success'=>'付款成功',                        'create_order'=>'下单成功',                        'goods_arrival'=>'商品到货',                );                //$replace = $this->service->template_replace();                $ignore= explode(',', $notify['ignore']);                foreach($ignoreas$k=> $v) {                        unset($hooks[$v]);                }                if(checksubmit('dosubmit')) {                        $template= array();                        $enabled= array();                        foreach($hooksas$k=> $v) {                                $template[$k] = str_replace($replace,array_keys($replace),$_GET[$k]);                        }                        $enabled= $_GET['enabled'];                        $_GET['template'] = unit::json_encode($template);                        $_GET['enabled'] = json_encode($enabled);                        $_GET['name'] = $notify['name'];                        $result= $this->temlage_service->update($_GET);                        if($result=== false) showmessage($this->temlage_service->error);                        showmessage(lang('upload_message_success','notify/language'),url('index'));                }else{                        $template= $this->temlage_service->fetch_by_code($_GET['code']);                        foreach($template['template'] as$k=> $temp) {                                $template['template'][$k] = str_replace(array_keys($replace),$replace,$temp);                        }                        //单独处理短信                        if($_GET['code'] == 'sms'){                                $cloud= $this->load->service('admin/cloud');                                $data= $cloud->getsmstpl();                                $template= $data['result'] ? array_merge($template,$data['result']) : $template;                                $sms_num= $cloud->getsmsnum();                                $this->load->librarys('View')->assign('sms_num',$sms_num);                        }                        $this->load->librarys('View')->assign('notify',$notify)->assign('hooks',$hooks)->assign('replace',$replace)->assign('ignore',$ignore)->assign('template',$template)->display('notify_template');                }        } | 
接下来我们需要修改发送队列文件,打开项目/library/queue.class.php文件,修改add方法,代码为:
| 
						1 
						2 
						3 
						4 
						5 
						6 
						7 
						8 
						9 
						10 
						11 
						12 
						13 
						14 |  /* 加入队列 */    publicfunctionadd($type= 'email', $method, $params, $sort= 100) {        $params= (is_array($params) && !empty($params)) ? json_encode($params) : $params;        $data= array(            'type'=> $type,            'method'=> $method,            'params'=> $params,            'dateline'=> TIMESTAMP,            'sort'=> (int) $sort        );     model('notify/queue','service')->config($data)->send();              returntrue;        } | 
最后我们修改短信接口文件,打开项目/module/notify/library/driver/sms/sms.class.php,修改send方法,代码为:
| 
						1 
						2 
						3 
						4 
						5 
						6 
						7 
						8 
						9 
						10 
						11 
						12 
						13 
						14 
						15 
						16 
						17 
						18 
						19 
						20 
						21 |   publicfunctionsend(){                $params= array();                $param= array();                $params['tpl_id'] = $this->sms['tpl_id'];                $param['m'] = $this->sms['mobile'];                $params['tpl_vars'] = $this->sms['tpl_vars'];                $params['sms_sign'] = $this->config['configs']['sms_sign'];                $param['u'] = $this->config['configs']['sms_name'];                $param['p'] = MD5($this->config['configs']['sms_pwd']);                $tpl_vals=[];                foreach($params['tpl_vars'] as$key=>$val){                        $new_key='{'.$key.'}';                        $tpl_vals[$new_key]=$val;                }                $param['c']="【{$params['sms_sign']}】".strtr($params['tpl_id'],$tpl_vals);                                $send= ($r== '0') ? TRUE : FALSE;                return$this->_notify($send);        } | 
	好了,经过以上的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行发送测试:
	
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,并且免审核了,短信内容3~5秒就可送达。
最新更新
电商类
CMS类
微信类