待发短信

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

4001-021-502

工作时间

9:00-21:00

PHP云人才系统V4.3版短信插件开发

前段时间小编为大家介绍了php云人才的短信插件开发,今天发现php云人才的版本升级了,短信接口也需要重新替换了,所以写了这一篇4.3版本的短信插件开发,使用的短信接口还是我们短信宝短信群发平台的接口,我们短信宝短信群发平台稳定可靠,速度也很快,注册就送免费测试条数。

首先我们要更换后台的显示界面文件。打开模版文件,替换一下模版文件。打开项目/app/template/admin/admin_msg_config.html,都修改代码35~83行,修改代码如下:

?
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
  <form action="" method="post">
    <table width="100%" class="table_form">
         <tr>
            <th width="200">参数说明:</th>
            <td>参数值</td>
         </tr>
                <tr class="admin_table_trbg">
            <th width="200">是否开启:</th>
            <td>
                                <input id="sy_msg_isopen_1" type="radio" {yun:}if $config.sy_msg_isopen=='1'{/yun}checked=""{yun:}/if{/yun} value="1" name="sy_msg_isopen">
                                <label for="sy_msg_isopen_1">开启</label>
                                <input id="sy_msg_isopen_2" type="radio" {yun:}if $config.sy_msg_isopen!='1'{/yun}checked=""{yun:}/if{/yun} value="2" name="sy_msg_isopen">
                                <label for="sy_msg_isopen_2">关闭</label>
                        </td>
        </tr>
        <tr class="admin_table_trbg">
            <th width="200">短信宝用户名:</th>
            <td><input class="input-text tips_class" type="text" name="sy_msguser" id="sy_msguser" value="{yun:}$config.sy_msguser{/yun}" size="30" maxlength="255" />  </td>
        </tr>
                 <tr>
            <th width="200">短信宝密码:</th>
            <td><input class="input-text tips_class" type="password" name="sy_msgpw" id="sy_msgpw" value="{yun:}$config.sy_msgpw{/yun}" size="30" maxlength="255"/>  </td>
        </tr>
        <tr class="admin_table_trbg">
            <th width="200">短信签名:</th>
            <td><input class="input-text tips_class" type="text" name="sy_msgkey" id="sy_msgkey" value="{yun:}$config.sy_msgkey{/yun}" size="50" maxlength="255"/> <span class="admin_web_tip">短信的签名,3-8个字符</span></td>   
        </tr>
        <tr>
            <th width="200">单次号码量:</th>
            <td><input class="input-text input_text_rp" type="text" name="sy_msgsendnum" id="sy_msgsendnum" value="{yun:}$config.sy_msgsendnum{/yun}" size="30" maxlength="255"/>条    <span class="admin_web_tip">最小数为1。</span></td>
        </tr
                 <tr  class="admin_table_trbg">
            <th width="200">同一IP一天发送短信:</th>
            <td><input class="input-text  input_text_rp" type="text" name="ip_msgnum" id="ip_msgnum" value="{yun:}$config.ip_msgnum{/yun}" size="30" maxlength="255"/>条</td>
        </tr>
                 <tr>
            <th width="160">同一手机号一天发送短信:</th>
            <td><input class="input-text input_text_rp" type="text" name="moblie_msgnum" id="moblie_msgnum" value="{yun:}$config.moblie_msgnum{/yun}" size="30" maxlength="255"/>条        <span class="admin_web_tip">同一手机号日上限为5条</span></td>        
        </tr>
        <tr  class="admin_table_trbg">
            <th width="200">购买短信:</th>
            <td><a href="http://www.smsbao.com" target="_blank" style=" color:#CC3300; text-decoration:underline; "> 购买短信地址</a></td>
         </tr>
                   <tr>
            <td colspan="2" align="center"><input class="admin_submit4" id="config" type="button" name="msgconfig" value="提交" />&nbsp;&nbsp;<input class="admin_submit4" type="reset" value="重置" /></td>
        </tr>
    </table>
    <input type="hidden" id="pytoken" name="pytoken" value="{yun:}$pytoken{/yun}">
    </form>

经过替换后后台显示页面是我们短信宝的了,下面我们进行修改短信发送接口类,打开项目/app/public/common.php,修改sendSMS和postSMS这两个方法,修改代码如下:

?
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
  function sendSMS($uid,$pwd,$key,$mobile,$content,$time='',$mid='',$info=array()){
                $data_msg["uid"]=$info['uid'];
                $data_msg["name"]=$info['name'];
                $data_msg["cuid"]=$info['cuid'];
                if($info['cname']){
                        $data_msg["cname"]=$info['cname'];
                }else{
                        $data_msg["cname"]="系统";
                }
                $data_msg["moblie"]=$mobile;
                $data_msg["ctime"]=time();
                $data_msg["content"]=$content;
                $data array(
                        'u'=>$uid,
                        'p'=>md5(strtolower($pwd)),
                        'key'=>$key,
                        'm'=>$mobile,
                        'c'=>iconv('GB2312''UTF-8''【'.$key.'】'.$content),
                        'time'=>$time,
                        'mid'=>$mid
                        );
 
                $re$this->postSMS("msgsend",$data);
                $this->warning('5');
                if(trim($re) =='0'){
                        $data_msg['state']="1";
                        $data_msg['ip']=fun_ip_get();
                        $this->MODEL()->insert_into("moblie_msg",$data_msg); 
                        return "发送成功!";
                }else{
                        $result=array("-1"=>"参数不全","30"=>'用户名密码错误',"40"=>'账号不存在',"41"=>'余额不足',"42"=>'账号过期',"43"=>'IP地址限制',"50"=>'内容含有敏感词',"51"=>'手机号码不正确');
                        $data_msg["state"]="0";
                        $this->MODEL()->insert_into("moblie_msg",$data_msg);
                        if($result[$re]){
                                return "发送失败!状态:".$result[$re];
                        }else{
                                return "发送失败!状态:".$re;
                        }
                }
        }
        function postSMS($type="msgsend",$data=''){
                $data['content'] = str_replace(array(" "," ","\t","\n","\r"),array("","","","",""),$data['content']);
                $url='http://api.smsbao.com/sms';
            $url.='?u='.$data['u'].'&p='.$data['p'].'&m='.$data['m'].'&c='.$data['c'].'&time='.$data['time'].'';
            if(function_exists('file_get_contents')){
                    $file_contents 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);
                    $file_contents = curl_exec($ch);
                    curl_close($ch);
            }
            return $file_contents;
        }

经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:

报备一下短信宝的VIP模版,这样就可以走短信宝的优质通道,并且免审核了,短信内容3~5秒就可送达。
开源插件

最新更新

电商类

CMS类

微信类

文章标签