TPshop是用thinkphp开发的一款免费开源网店系统,二次开发非常方便,代码清晰简洁,通俗易懂,丰富的插件和多套模板支持,易扩展,是目前国内首家最为完善的开源商城系统。系统支持多语言版本,操作简单,安全稳定,是广大用户二次开发的最佳选择,小编今天就以新增短信接口为例为大家讲解一下如何进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先我们打开项目:\application\admin\view\system\sms.html文件,替换45~73行左右的代码
| 
						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 | <dlclass="row"> <dtclass="tit">  <labelfor="sms_platform">选择短信平台</label>   </dt>   <ddclass="opt">   <selectname="sms_platform"id="sms_platform">     <optionvalue="1"<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> | 
接着打开项目:\application\common\logic\SmsLogic.php文件,替换realSendSms方法
| 
						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 |  privatefunctionrealSendSms($mobile, $smsSign, $smsParam, $templateCode,$msg)    {        $type= (int)$this->config['sms_platform'] ?: 0;        switch($type) {            case0:                $result= $this->sendSmsByAlidayu($mobile, $smsSign, $smsParam, $templateCode);                break;            case1:                $result= $this->sendSmsByAliyun($mobile, $smsSign, $smsParam, $templateCode);                break;            case2:                //重新组装发送内容, 将变量内容组装成:  13800138006##张三格式                foreach($smsParamas$k=> $v){                    $contents[] = $v;                }                $content= implode($contents, "##");                $result= $this->sendSmsByCloudsp($mobile, $smsSign, $content, $templateCode);                break;            case3:                $result= $this->sendSmsBySmsbao($mobile,$smsSign,$smsParam,$templateCode,$msg);                break;            default:                $result= ['status'=> -1, 'msg'=> '不支持的短信平台'];        }                return$result;    } | 
接着增加发送短信的sendSmsBySmsbao方法
| 
						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 | /**     * 发送短信(短信宝)     * @param $mobile  手机号码     * @param $code    验证码     * @return bool    短信发送成功返回true失败返回false     */    privatefunctionsendSmsBySmsbao($mobile,$smsSign,$smsParam,$templateCode,$msg)    {        $user= $this->config['sms_appkey'];        $pass= $this->config['sms_secretKey'];        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类
微信类