TPshop是用thinkphp开发的一款免费开源网店系统,二次开发非常方便,代码清晰简洁,通俗易懂,丰富的插件和多套模板支持,易扩展,是目前国内首家最为完善的开源商城系统。小编今天就以3.5.3版本新增短信接口为例为大家讲解一下如何进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先打开项目:\application\admin\view\system\sms.html文件,替换35行左右代码
| 
						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 | <ddclass="opt">        <selectname="sms_platform"id="sms_platform">            <optionvalue="1"<if condition="$config[sms_platform] eq 1">selected="selected"</if>>阿里云</option>            <optionvalue="2"<if condition="$config[sms_platform] eq 2">selected="selected"</if>>天瑞云</option>            <optionvalue="3"<if condition="$config[sms_platform] eq 3">selected="selected"</if>>短信宝</option>        </select>        <pclass="notic">短信平台选择</p>    </dd></dl><dlclass="row">    <dtclass="tit">        <labelfor="sms_appkey">短信平台[appkey]</label>    </dt>    <ddclass="opt">        <inputid="sms_appkey"name="sms_appkey"value="{$config.sms_appkey}"class="input-txt"type="text"/>        <pclass="notic">短信平台配置appkey/keyid/短信宝用户名</p>    </dd></dl><dlclass="row">    <dtclass="tit">        <labelfor="sms_secretKey">短信平台[secretKey]</label>    </dt>    <ddclass="opt">        <inputid="sms_secretKey"name="sms_secretKey"value="{$config.sms_secretKey}"class="input-txt"type="text"/>        <pclass="notic">短信平台配置secretKey/短信宝密码</p>    </dd></dl><dlclass="row">    <dtclass="tit">        <labelfor="sms_product">公司名/品牌名/产品名</label>    </dt>    <ddclass="opt">        <inputid="sms_product"name="sms_product"value="{$config.sms_product}"class="input-txt"type="text"/>        <pclass="notic">公司名/品牌名/产品名</p>    </dd></dl> | 
接着打开项目:\application\admin\view\sms_template\_sms_template.html文件,替换85~115行代码
| 
						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 | functioncheckForm(){    varsmsSign = $("#addEditSmsTemplate").find("input[name='sms_sign']").val();                 //短信签名    varsmsTplCode = $("#addEditSmsTemplate").find("input[name='sms_tpl_code']").val();      //模板ID    vartplContent = $("#addEditSmsTemplate").find("textarea[name='tpl_content']").val();            //模板内容    varsendscene = $("#send_scene option:selected").val();    if($.trim(smsSign) == '')    {        $("#err_sms_sign").show();        returnfalse;    }    if($.trim(tplContent) == '')    {        $("#err_tpl_content").show();        returnfalse;    }    if(sendscene == -1){        $("#err_send_scene").show();        returnfalse;    }    $('#addEditSmsTemplate').submit();} | 
最后打开项目:\application\common\logic\SmsLogic.php,增加以下代码
| 
						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 | /** * 发送短信(短信宝) * @param $mobile  手机号码 * @param $code    验证码 * @return bool    短信发送成功返回true失败返回false */privatefunctionsendSmsBySmsbao($mobile,$smsSign,$smsParam,$templateCode,$msg){    $user= $this->config['sms_appkey'];    $pass= $this->config['sms_secretKey'];    $url= 'http://api.smsbao.com/sms?u='.$user.'&p='.md5($pass).'&m='.$mobile.'&c=【'.$smsSign.'】'.$msg;    if(function_exists('file_get_contents')) {        $ret= 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);        $ret= curl_exec($ch);        curl_close($ch);    }    if($ret== 0) {        returnarray('status'=> 1, 'msg'=> $ret);    } else{        returnarray('status'=> -1, 'msg'=> $ret);    }} | 
	好了,经过以上的替换,短信宝的短信平台已经替换成功了,可以正常使用了。我们进行测试发送。
	
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的TPshop商城系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类