待发短信

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

4001-021-502

工作时间

9:00-21:00

Yuncart开源网店系统短信接口替换

Yuncart是一套易与企业内部系统CRM、ERP等集成的php商城系统。开源,永久免费,适合多人同时进行二次开发,小编对这套系统还是比较了解的,今天小编就以替换短信接口为例,为大家讲解一下如何进行二次开发,我们今天讲解的1.0版本,使用的接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。

我们首先替换后台显示界面,打开项目\data\dwoocompiled\admin\message_index.html.d20121219.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/* template head */
/* end template head */ ob_start(); /* template body */ ;
echo Dwoo_Plugin_include($this, 'head.html', array (
));?>
 
<div id="wrap">
        <?php echo Dwoo_Plugin_include($this, 'left.html', array (
));?>
 
        <div id="maincont">
                <b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
                <form action="<?php echo url('admin', 'message', 'messagesave');?>" method="post" name="submitform" id="submitform">
                <div id="main_c">
                        <div id="infotab">
                                <ul>
                                        <li class="cur"><a href="javascript:void(0)" id="a_email" onclick="$.oper.jstab('a_email');return false;">邮件</a></li>
                                        <li><a href="javascript:void(0)" id="a_sms" onclick="$.oper.jstab('a_sms');return false;">短信</a></li>
                                </ul>
                        </div>
                        <ul class="bk" id="foremail">
                                <li>
                                        <label><em>*</em>服务器IP:</label>
                                        <p>
                                                <input class="input_tx" value="<?php echo def((isset($this->scope["messageset"]["smtphost"]) ? $this->scope["messageset"]["smtphost"]:null));?>" name="smtphost" id="smtphost" type="text"/>
                                        </p>
                                </li>
                                <li>
                                        <label><em>*</em>服务器端口:</label>
                                        <p>
                                                <input class="input_tx" value="<?php echo def((isset($this->scope["messageset"]["smtpport"]) ? $this->scope["messageset"]["smtpport"]:null));?>" name="smtpport" id="smtpport" type="text"/>
                                        </p>
                                </li>
 
                                <li>
                                        <label><em>*</em>发件人邮箱:</label>
                                        <p>
                                                <input class="input_tx" value="<?php echo def((isset($this->scope["messageset"]["smtpuser"]) ? $this->scope["messageset"]["smtpuser"]:null));?>" name="smtpuser" id="smtpuser" type="text"/>
                                        </p>
                                </li>
 
                                <li>
                                        <label><em>*</em>发件人密码:</label>
                                        <p>
                                                <input class="input_tx" value="<?php echo def((isset($this->scope["messageset"]["smtppass"]) ? $this->scope["messageset"]["smtppass"]:null));?>" name="smtppass" id="smtppass" type="text"/>
                                        </p>
                                </li>
 
                                <li>
                                        <label>测试邮箱:</label>
                                        <p>
                                                <input class="input_tx" value="" name="testemail" id="testemail" type="text"/>
                                                <a href="javascript:void(0);" onclick="jscheck('email');return false;" class="bt_style2">检测</a>
                                        </p>
                                </li>
 
                        </ul>
 
                        <ul class="bk none" id="forsms">
                         <li>
                                        <label><em>*</em>短信宝用户名:</label>
                                        <p>
                                                <input class="input_tx" value="<?php echo def((isset($this->scope["messageset"]["smsphone"]) ? $this->scope["messageset"]["smsphone"]:null));?>" name="smsphone"  id="smsphone" type="text" />
                                                (<a href="https://www.smsbao.com/reg" target="_blank">立即申请</a>)
                                        </p>
                                </li>
                                <li>
                                        <label><em>*</em>短信宝密码:</label>
                                        <p>
                                                <input class="input_tx" value="<?php echo def((isset($this->scope["messageset"]["smspass"]) ? $this->scope["messageset"]["smspass"]:null));?>" name="smspass" id="smspass" type="text" />
                                        </p>
                                </li>
                                <li>
                                        <label><em>*</em>短信签名:</label>
                                        <p>
                                                <input class="input_tx" value="<?php echo def((isset($this->scope["messageset"]["smssign"]) ? $this->scope["messageset"]["smssign"]:null));?>" name="smssign" id="smssign" type="text" />
                                        </p>
                                </li>
                                <li>
                                        <label>测试手机:</label>
                                        <p>
                                                <input class="input_tx" value="" name="testsms" id="testsms" type="text"/>
                                                <a href="javascript:void(0);" onclick="jscheck('sms');return false;" class="bt_style2">检测</a>
                                        </p>
                                </li>
                                <?php if ((isset($this->scope["messageset"]["smsphone"]) ? $this->scope["messageset"]["smsphone"]:null) && (isset($this->scope["messageset"]["smspass"]) ? $this->scope["messageset"]["smspass"]:null) && ! (isset($this->scope["user"]) ? $this->scope["user"] : null)) {
?>
                                <li>
                                        <label>提示:</label>
                                        <p>
                                                该用户不合法,或短信服务器出错
                                        </p>
                                </li>
                                <?php
}?>
 
                                <?php if ((isset($this->scope["user"]) ? $this->scope["user"] : null)) {
?>
                                <li>
                                        <label>统计:</label>
                                        <p>剩余短信:<?php echo $this->scope["user"];?> 条</p>
                                </li>
                                <?php
}?>
 
                        </ul>
                        <div class="bt_bk2">
                                <a href="javascript:void(0);" class="btn" onclick="jssubmit();return false;"><span>保存</span></a>
                        </div>
                </div>
                </form>
                <b class="b4b"></b><b class="b3b"></b><b class="b2b"></b><b class="b1b"></b>
        </div>
</div>
<?php echo Dwoo_Plugin_include($this, 'foot.html', array (
));?>
 
<script type="text/javascript">
$(function(){
        <?php if ((isset($this->scope["refer"]) ? $this->scope["refer"] : null) == "sms") {
?>
        $("#a_sms").click();
        <?php
}?>
 
});
function jscheck(type) {
        var postdata = {};
        if(type == 'sms') {
                var smsphone        = $.trim($("#smsphone").val()),
                        smspass                = $.trim($("#smspass").val()),
                        smssign                = $.trim($("#smssign").val()),
                        testsms                = $.trim($("#testsms").val());
                if(!smspass || !smspass || !testsms) {
                        jAlert("检测条件不合法");
                        return ;
                }
                postdata = {type:type,smsphone:smsphone,smspass:smspass,testsms:testsms,smssign:smssign};
        } else if(type == "email") {
                var smtphost = $.trim($("#smtphost").val()),
                        smtpport = $.trim($("#smtpport").val()),
                        smtpuser = $.trim($("#smtpuser").val()),
                        smtppass = $.trim($("#smtppass").val()),
                        testemail = $.trim($("#testemail").val());
                if(!smtphost || !smtpport || !smtpuser || !smtppass || !testemail) {
                        jAlert("检测条件不合法");
                        return false;
                }
                postdata = {type:type,smtphost:smtphost,smtpport:smtpport,smtpuser:smtpuser,smtppass:smtppass,testemail:testemail};
        }
        $.util.show();
        $.post("<?php echo url('admin', 'message', 'check');?>",postdata,function(data) {
                $.util.hide();
                if(data == "success") {
                        jAlert("已经发送");
                } else {
                        jAlert(data);
                }
        });
}
</script><?php  /* end template body */
return $this->buffer . ob_get_clean();
?>

好了显示的界面已经是我们短信宝的了,我们去修改保存接口配置文件,打开项目\include\admin\message.class.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
defined('IN_CART'or die;
/**
 *
 * 邮件短信设置
 
 */
class Message extends Base{
        /**
         *
         * 邮件短信设置
         
         */
        public function index() {
                $this->data["refer"]          = isset($_GET["refer"])?trim($_GET["refer"]):'email';
                $this->data["messageset"] = DB::getDB()->selectkv("config","key","val","type='messageset'");
                if(!empty($this->data["messageset"]["smsphone"]) && !empty($this->data["messageset"]["smspass"])) {
                        include_once COMMONPATH .  "/sms.class.php";
                        $sms new Sms($this->data["messageset"]["smsphone"],$this->data["messageset"]["smspass"]);
                        $this->data['user'] = $sms->getUser();
                }
                $this->output("message_index");
        }
 
        /**
         *
         * 保存邮件 对应messageset
         
         */
        public function messagesave() {
                //接受参数
                $data["smtphost"]                = trim($_POST["smtphost"]);
                $data["smtpport"]                = trim($_POST["smtpport"]);
                $data["smtpuser"]                = trim($_POST["smtpuser"]);
                $data["smtppass"]                = trim($_POST["smtppass"]);
                $data["smsphone"]                = trim($_POST["smsphone"]);
                $data["smspass"]                = trim($_POST["smspass"]);
                $data["smssign"]                = trim($_POST["smssign"]);
                
                //替换配置
                $replacedata array();
                foreach($data as $key=>$val) {
                        $replacedata[] = array("key"=>$key,"val"=>$val,"type"=>'messageset');
                }
                $this->adminlog("al_message");
                if($replacedata) DB::getDB()->replaceMulti("config",$replacedata);
 
                $this->setHint(__("set_success",__('messageset')));
        }
 
        /**
         *
         * 检测短信是否正确
         
         */
        public function check() {
                $type          = trim($_POST["type"]);
                $ret          = false;
                if($type == "email") {
                        $smtphost  = trim($_POST["smtphost"]);
                        $smtpport  = trim($_POST["smtpport"]);
                        $smtpuser  = trim($_POST["smtpuser"]);
                        $smtppass  = trim($_POST["smtppass"]);
                        $testemail = trim($_POST["testemail"]);
                        require COMMONPATH. "/send.class.php";
                        $sendmail         new SendEmail($smtphost,$smtpport,$smtpuser,$smtppass);
                        $subject         = __("testemail");
                        $content         = __("testemail");
                        $ret                 $sendmail->send($testemail,$subject,$content);
                        exit($ret?"success":$sendmail->getError());
 
                else if($type == "sms") {
                        $smsphone = trim($_POST["smsphone"]);
                        $smspass  = trim($_POST["smspass"]);
                        $smssign  = trim($_POST["smssign"]);
                        $testsms  = trim($_POST["testsms"]);
 
                        include_once COMMONPATH . "/sms.class.php";
                        $sms                new Sms($smsphone,$smspass,$smssign);
                        $content        = __("testsms");
                        $ret                $sms->send($testsms,$content);
                        exit($ret?"success":$sms->getError());
                }
        }
        
        /**
         *
         * 模版设置 
         
         */
        public function tplset() {
                $this->data["message_list"] = DB::getDB()->select("message_set","*");
                $this->output("messagetpl_index");
        }
 
        /**
         *
         * 保存模版设置 
         
         */
        public function tplsetsave() {
                $codes                $_POST["code"];
                $emails                = isset($_POST["email"])?$_POST["email"]:array();
                $mobiles        = isset($_POST["mobile"])?$_POST["mobile"]:array();
                $letters        = isset($_POST["letter"])?$_POST["letter"]:array();
                
                foreach($codes as $code) {
                        $email        = isset($emails[$code]) ? intval($emails[$code]) : 0;
                        $mobile        = isset($mobiles[$code]) ? intval($mobiles[$code]) : 0;
                        $letter = isset($letters[$code]) ? intval($letters[$code]) : 0;
                        DB::getDB()->update("message_set",array("email"=>$email,"mobile"=>$mobile,"letter"=>$letter),"code='$code'");
                }
                $this->adminlog("al_message_tpl");
                $this->setHint(__("set_success",__('messagetpl')),"message_tplset");
        }
 
        /**
         *
         * 修改模版 
         
         */
         public function tpledit() {
                if(ispostreq()) {
                        $code                = trim($_POST["code"]);
                        $content        str_replace(array("{","}"),array("{","}"),trim($_POST["content"]));
                        $method                = trim($_POST["method"]);
                        !in_array($method,array("mobile","email","letter")) && $method 'mobile';
                        
                        $this->adminlog("al_message_tpl2",array("code"=>$code,"method"=>__($method)));
                        DB::getDB()->update("message_set","{$method}cont='$content'","code='$code'");
                        $this->setHint(__("set_success",__('tpl')),"message_tplset");
                else {
                        $method                        = trim($_GET["method"]);
                        $code                        = trim($_GET["code"]);
                        !in_array($method,array('mobile','email','letter')) && $method 'mobile';
                        
                        $field $method."cont";
                        $this->data['tpl']                = DB::getDB()->selectrow("message_set","text,$field","code='$code'"); //如果模版不存在
                        $this->data['code']                = $code;
                        $this->data['field']        = $field;
                        $this->data['method']        = $method;
 
                        $this->data['leftcur']        = "message_tplset";
                        $this->output("messagetpl_oper");
                }
         }
}

接下来我们去修改调用短信接口的文件,打开项目\include\common\send.class.php 文件,修改SendSms类,修改代码为:

?
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
class SendSms {
        
        
        var $sms;
        
        /**
         *
         * 构造函数,确定smtp信息
         
         */
        public function __construct() {
                $smsphone = getConfig('smsphone');
                $smspass  = getConfig('smspass');
                $smssign  = getConfig('smssign');
                include_once COMMONPATH."/sms.class.php";
                $this->sms = new Sms($smsphone,$smspass,$smssign);
        }
        
        /**
         *
         * 发送
         
         */
        public function send($phone,$content) {
                return $this->sms->send($phone,$content,$smssign);
        }
 
        public function getError() {
                return $this->sms->getError();
        }
}

最后我们去修改短信接口文件,打开项目\include\common\sms.class.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
 
defined('IN_CART'or die;
 
require_once COMMONPATH . "/http.class.php";
 
/**
 *
 *
 * 短信发送类
 *
 */
class Sms {
        
        protected $http;        //http访问类
        
        protected $url                "http://api.smsbao.com"; //sms短信接口
        
        protected $smsphone        ""//sms登录手机号
 
        protected $smspass        "";//sms登录密码
 
        protected $smssign        "";//sms签名
        
        protected $error                "";
        /**
         *
         *
         * 构造函数
         *
         */
        public function __construct($smsphone "",$smspass "",$smssign "") {
                $this->http = new Http();
                $this->smsphone = $smsphone;
                $this->smspass  = md5($smspass);
                $this->smssign  = $smssign;
        }
        
        /**
         *
         *
         * 验证用户是否正确,如果正确,返回用户信息,
         *
         */
        public function getUser() {
                if(!$this->smsphone || !$this->smspass) return null;
                $ret $this->http->post($this->url ."/query",array("u"=>$this->smsphone,"p"=>$this->smspass));
                $ret explode(','$ret);
                return $ret['1'];
        }
        
        /**
         *
         *
         * 发送短信
         *
         */
        public function send($phone,$content) {
                if(!$this->smsphone || !$this->smspass) return null;
                $ret $this->http->post($this->url."/sms",array("u"=>$this->smsphone,"p"=>$this->smspass,"m"=>$phone,"c"=>"【".$this->smssign."】".$content));
                if($ret == 0) {
                        return true;
                }else{
                        $this->error = $ret;
                }
                return false;
        }
        
        /**
         *
         *
         * 发送短信
         *
         */
        public function getError() {
                return $this->error;
        
}

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

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

最新更新

电商类

CMS类

微信类

文章标签