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
|
<dl class="row"> <dt class="tit"> <label for="sms_platform">选择短信平台</label> </dt> <dd class="opt"> <select name="sms_platform" id="sms_platform"> <option value="1" <if condition="$config[sms_platform] eq 3">selected="selected"</if>>短信宝</option> </select> <p class="notic">短信平台选择</p> </dd></dl><dl class="row"> <dt class="tit"> <label for="sms_appkey">短信平台[appkey](短信宝用户名)</label> </dt> <dd class="opt"> <input id="sms_appkey" name="sms_appkey" value="{$config.sms_appkey}" class="input-txt" type="text"/> <p class="notic">短信平台配置appkey/keyid/短信宝用户名</p> </dd></dl><dl class="row"> <dt class="tit"> <label for="sms_secretKey">短信平台[secretKey](短信宝密码)</label> </dt> <dd class="opt"> <input id="sms_secretKey" name="sms_secretKey" value="{$config.sms_secretKey}" class="input-txt" type="text"/> <p class="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
|
private function realSendSms($mobile, $smsSign, $smsParam, $templateCode,$msg) { $type = (int)$this->config['sms_platform'] ?: 0; switch($type) { case 0: $result = $this->sendSmsByAlidayu($mobile, $smsSign, $smsParam, $templateCode); break; case 1: $result = $this->sendSmsByAliyun($mobile, $smsSign, $smsParam, $templateCode); break; case 2: //重新组装发送内容, 将变量内容组装成: 13800138006##张三格式 foreach ($smsParam as $k => $v){ $contents[] = $v; } $content = implode($contents, "##"); $result = $this->sendSmsByCloudsp($mobile, $smsSign, $content, $templateCode); break; case 3: $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 */ private function sendSmsBySmsbao($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) { return array('status' => 1, 'msg' => $ret); } else { return array('status' => -1, 'msg' => $ret); } } |
好了,经过以上的替换,短信宝的短信平台已经替换成功了,可以正常使用了。我们进行测试发送。

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的TPshop商城系统短信宝插件,点击此链接 下载及查看安装流程。
- 上一篇:YzmCMS-新增短信宝短信接口 下一篇:PHPOK企业站新增短信宝短信接口

