待发短信

在线客服
产品支持 短信宝客服
合作渠道 渠道合作
服务咨询

4001-021-502

工作时间

9:00-21:00

WSTMart电子商务系统短信接口替换

WSTMart电子商务系统是基于ThinkPHP5.0开发的B2B2C综合电子商务系统,安装此程序要确保PHP版本高于5.4,最好5.5(支持PHP7),因为是thinkphp框架,所以二开比较方便,注释也清晰,小编对于此系统还是比较了解的,今天小编就以替换短信接口为例为大家讲解一下如何进行二次开发,我们今天讲解的是2.0版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。

进行接口替换我们首先进行修改短信配置界面,打开项目\wstmart\admin\view\sysconfigs\config1.html 文件,大约在41-77行左右,修改如下代码:

?
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
    <tr>
             <td colspan='2' class='head-ititle'>短信服务器设置</td>
          </tr>
          <tr>
             <th>开启手机验证:</th>
             <td>
             <label>
                 <input type='radio' id='smsOpen1' name='smsOpen' class='ipt' value='1' {if $object['smsOpen']==1}checked{/if}/>是
             </label>
             <label>
                 <input type='radio' id='smsOpen0' name='smsOpen' class='ipt' value='0' {if $object['smsOpen']==0}checked{/if}/>否
             </label>
             </td>
          </tr>
          <tr>
             <th>短信宝账号:</th>
             <td><input type="text" id='smsKey' class='ipt' value="{$object['smsKey']}" maxLength='100'/>&nbsp;&nbsp;还没有帐号?点击<a target='_blank' href='http://www.smsbao.com/reg'>注册</a></td>
          </tr>
          <tr>
             <th>短信宝密码:</th>
             <td><input type="text" id='smsPass' class='ipt' value="{$object['smsPass']}" maxLength='100'/></td>
          </tr>
          <tr>
             <th>号码每日发送数:</th>
             <td><input type="text" id='smsLimit' class='ipt' value="{$object['smsLimit']}" maxLength='100'/></td>
          </tr>
          <tr>
             <th>开启短信发送验证码:</th>
             <td>
             <label>
                 <input type='radio' id='smsVerfy1' class='ipt' name='smsVerfy' value='1' {if $object['smsVerfy']==1}checked{/if}/>是
             </label>
             <label>
                 <input type='radio' id='smsVerfy0' class='ipt' name='smsVerfy' value='0' {if $object['smsVerfy']==0}checked{/if}/>否
             </label>
             </td>
          </tr>

经过上面的替换,后台显示页面就是短信宝的了,接下来我们去增加我们短信宝的接口代码,打开项目\wstmart\common\common\function.php 文件,增加以下代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * 短信宝短信服务商
 * @param string $phoneNumer  手机号码
 * @param string $content     短信内容
 */
function SmsbaoSMS($phoneNumer,$content){
        $url 'http://api.smsbao.com/sms?u='.WSTConf("CONF.smsKey").'&p='.md5(WSTConf("CONF.smsPass")).'&m='.$phoneNumer.'&c='.$content;
        $ch=curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//设置否输出到页面
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30 ); //设置连接等待时间
        curl_setopt($ch, CURLOPT_ENCODING, "gzip" );
        $data=curl_exec($ch);
        curl_close($ch);
        return $data;
}

最后我们去修改调用接口的文件,打开项目\wstmart\common\model\LogSms.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace wstmart\common\model;
/**
 
 * 短信日志类
 */
class LogSms extends Base{
 
        /**
         * 写入并发送短讯记录
         */
        public function sendSMS($smsSrc,$phoneNumber,$content,$smsFunc,$verfyCode){
                $USER = session('WST_USER');
                $userId empty($USER)?0:$USER['userId'];
                $ip = request()->ip();
                //检测短信验证码验证是否正确
                if(WSTConf("CONF.smsVerfy")==1){
                        $smsverfy = input("post.smsVerfy");
                        $rs = WSTVerifyCheck($smsverfy);
                        if(!$rs){
                                return WSTReturn("验证码不正确!",-2);
                        }
                }
                //检测是否超过每日短信发送数
                $date date('Y-m-d');
                $smsRs $this->field("count(smsId) counts,max(createTime) createTime")
                                           ->where(["smsPhoneNumber"=>$phoneNumber])
                                   ->whereTime('createTime''between', [$date.' 00:00:00'$date.' 23:59:59'])->find();
                if($smsRs['counts']>(int)WSTConf("CONF.smsLimit")){
                        return WSTReturn("请勿频繁发送短信验证!");
                }
                if($smsRs['createTime'] !='' && ((time()-strtotime($smsRs['createTime']))<120)){
                        return WSTReturn("请勿频繁发送短信验证!");
                }
                //检测IP是否超过发短信次数
                $ipRs $this->field("count(smsId) counts,max(createTime) createTime")
                                         ->where(["smsIP"=>$ip])
                                         ->whereTime('createTime''between', [$date.' 00:00:00'$date.' 23:59:59'])->find();
                if($ipRs['counts']>(int)WSTConf("CONF.smsLimit")){
                        return WSTReturn("请勿频繁发送短信验证!");
                }
                if($ipRs['createTime']!='' && ((time()-strtotime($ipRs['createTime']))<120)){
                        return WSTReturn("请勿频繁发送短信验证!");
                }
 
                $code = SmsbaoSMS($phoneNumber,$content);
                $data array();
                $data['smsSrc'] = $smsSrc;
                $data['smsUserId'] = $userId;
                $data['smsPhoneNumber'] = $phoneNumber;
                $data['smsContent'] = $content;
                $data['smsReturnCode'] = $code;
                $data['smsCode'] = $verfyCode;
                $data['smsIP'] = $ip;
                $data['smsFunc'] = $smsFunc;
                $data['createTime'] = date('Y-m-d H:i:s');
                $this->data($data)->save();
                if(intval($code) == 0){
                        return WSTReturn("短信发送成功!",1);
                }else{
                        return WSTReturn("短信发送失败!");
                }
        }
}

好了,经过以上的替换,短信宝的短信平台已经替换成功了,我们去进行发送测试:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。

另外:我们已经开发好完整的WSTMart电子商务系统短信宝插件,点击此链接 下载及查看安装流程。

开源插件

最新更新

电商类

CMS类

微信类

文章标签