待发短信

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

4001-021-502

工作时间

9:00-21:00

ECJIA到家V1.4.2短信插件开发

ECJia移动商城系统(EC+)是一款基于移动互联网的商城应用服务产品,拥有执行效率高、上手轻松、管理便捷等一系列优点。前段时间小编为大家介绍了这款软件如何开发短信插件,版本不一样插件也就不一样了,今天小编为大家讲解一下ECJIA1.4.2这个版本的短信插件该如何开发,短信接口使用的是我们短信宝短信群发平台,我们短信宝短信群发平台极其稳定,而且短信发送速度相当快捷,验证码和订单通知在3~5秒就能收到,用户体验非常好,注册就送测试短信。

1.4.2这个版本我们只需要修改项目\content\system\classes\ecjia_sms.class.php文件就可以了,这个文件是ecjia短信发送类,我们修改如下代码:

?
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
 
 
/**
 * ECJIA SMS
 */
defined('IN_ECJIA'or exit('No permission resources.');
 
/* 短信模块主类 */
class ecjia_sms {
    const HOST      = 'http://api.smsbao.com/sms?';
    const SEND      = 'method=Submit';
    const BALANCE   = 'method=GetNum';
    const PASSWORD  = 'method=ChangePassword';
    
    private $_account;
    private $_password;
    private $_auth;
    private $_sender;
    private $_message;
    private $_type;
    private $_sms;
    
    protected $to array();
    private $response_code array(
        '0'  => 'SUCCESS - Message Sent.',
        '30' => '密码错误',
        '40' => '账号不存在',
        '41' => '余额不足',
        '42' => '账号过期',
        '43' => 'IP地址限制',
        '50' => '内容含有敏感词',
        '51' => '手机号码不正确'
    );
    
    /**
     * Create SMS instance
     *
     * @return  void
     */
    public static function make()
    {
        return new static();
    }
 
    public function __construct($account = null, $password = null) 
    {
        /* 直接赋值 */
        $this->_account  = $account $account : ecjia::config('sms_user_name');
        $this->_password = $password $password : MD5(ecjia::config('sms_password'));
        $this->_type = 1;
        $this->_sender = '';
        $this->_auth = $this->getAuthParams();
    }
    
    public function setNumber($number) {
        $this->addAnNumber($number);
        return $this;
    }
    
    public function getNumber()
    {
        return $this->_to;
    }
    
    /**
     * 添加信息
     * 如果内容有url需要过滤,可以使用rawurlencode方法
     * @param unknown $msg
     * @return string
     */
    public function setMessage($msg)
    {
        $this->_message = $msg;
        return $this;
    }
    
    public function getMessage()
    {
        return $this->_message;
    }
    
    public function viewSMSParams()
    {
        return $this->getSMSParams();
    }
    
    public function normalize($number)
    {
        return $this->normalizeNumber($number);
    }
    
    public function send()
    {
        $response array();
        
        $result $this->sendSMS( is_array($this->_to) ? $this->formatNumber($this->_to) : $this->_to );
        $response['raw'] = $result;
        $response['code'] = $result=='0'?2:$result;
        $response['description'] = $this->response_code["$result"];
        return $response;
    }
    
    private function sendSMS($mobile) {
        $url = self::HOST ;
        $params $this->_auth;
        $params['c']  = $this->_message;
        $params['m']   = $mobile;
        return $this->curl( $url$params );
    }
    
    public function balance()
    {
        $response array();
        
        $url "https://www.smsbao.com/query?";
        $params $this->_auth;
        $result $this->curl( $url$params );
                $info=explode(",",trim($result));
        
        $response['num'] = $info[1];
        $response['code'] = 2;
        $response['description'] = $info->msg;
        
        return $response;
    }
    
    private function addAnNumber($number)
    {
        if (is_array($number)) {
            foreach ($number as $num)
            {
                $this->_to[] = $num;
            }
        else {
            $this->_to[] = $number;
        }
    
    }
    
    private function normalizeNumber($number$countryCode = 86)
    {
        if (isset($number)) {
            $number = trim($number);
            $number str_replace("+"""$number);
            preg_match( '/(0|\+?\d{2})(\d{8,9})/'$number$matches);
            if ((int) $matches[1] === 0 ) {
                $number $countryCode $matches[2];
            }
        }
        return $number;
    }
    
    private function formatNumber($number)
    {
        $format "";
        if (is_array($number)) {
            $format = implode(";"$number);
        }
        return $format;
    }
    
    private function getInfo($result)
    {
        $result_arr = RC_Xml::to_array($result);
        
        $info new stdClass();
        $info->code     =  $result_arr['code'][0];
        $info->msg      = $result_arr['msg'][0];
        
        if (isset($result_arr['smsid'])) {
            $info->smsid = $result_arr['smsid'][0];
        }
        
        if (isset($result_arr['num'])) {
            $info->num   = $result_arr['num'][0];
        }
         
        return $info;
    }
    
    private function getAuthParams()
    {
        $params['u']  = $this->_account;
        $params['p'] = $this->_password;
        return $params;
    }
    
    private function getSMSParams()
    {
        $params['m']   = $this->formatNumber($this->_to);
        $params['c']  = $this->_message;
        return $params;
    }
    
    private function getAnswer( $code )
    {
        if ( isset( $this->response_code[$code] ) ) {
            return $this->response_code[$code];
        }
    }
    
    private function curl( $url$params array() )
    {
        
        $ch = curl_init();
        $options array(
            CURLOPT_RETURNTRANSFER  => TRUE,
            CURLOPT_URL             => $url,
            CURLOPT_HEADER          => false,
            CURLOPT_ENCODING        => "",
            CURLOPT_POST            => 1,
            CURLOPT_POSTFIELDS      => $params,
            CURLOPT_SSL_VERIFYHOST  => 0,
            CURLOPT_SSL_VERIFYPEER  => false,
        );
        curl_setopt_array( $ch$options );
        $result = curl_exec( $ch );
        curl_close( $ch );
    
        return $result;
    }
    
}

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


 

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

最新更新

电商类

CMS类

微信类

文章标签