91成人在线播放_欧美一区二区视频在线观看_91精品国产高清久久久久久_国产精品久久亚洲不卡4k岛国


待發短信

在線客服
產品支持 短信寶客服
合作渠道 渠道合作
服務咨詢

4001-021-502

工作時間

9:00-21:00

愛我拍眾籌新增短信寶短信接口

愛我拍眾籌 是小商貸旗下的一個全新的融入互聯網金融元素的多元化眾籌汽車平臺,是全國第一個集買車、賣車、租車、分期、眾籌、投資價值、開網上店鋪經營自己車輛等于一體的生態系統。小編今天就以替換短信接口為例帶大家進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。

下面我們進行開發,打開項目\webapps\www\library的文件夾,創建短信寶接口類文件,代碼如下:

?
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
<?php
/** 短信接口類
 * Class Sms_Library
 */
 
class Sms_Library extends Lowxp_Model{
 
    /** 根據模板發送短信
     * @param $mobile
     * @param $template_code
     * @param $type 1返回短信內容
     * @param $content 發送內容
     * @param array $assignTpl
     */
    function sendSmsTpl($mobile$template_code$type=0, $content=''){
        if(empty($template_code) || empty($mobile)) return false;
 
        $sql "SELECT template_content,status,send_number FROM ###_templates WHERE `type`='sms' AND `status`='1' AND template_code = '$template_code'";
        if($row $this->db->get($sql)){
 
            #模板付值
            $assignTpl $this->smarty->get_template_vars();
            $smarty = smartyTpl();
            if(is_array($assignTpl) && !empty($assignTpl)){
                foreach($assignTpl as $k=>$v){
                    $smarty->assign($k$v);
                }
            }
 
            #獲取模板解析內容
            $content $content?$content:$smarty->fetch($template_code.'.html');
            unset($smarty);
            if($type==1){ return $content; }
 
            $msg $this->sendSms($mobile$content);
            if($msg === true){
                #發送記錄
                $data array(
                    'last_send'    => time(),
                    'send_number'  => intval($row['send_number']) + 1,
                );
                $this->db->save('###_templates',$data,'',array('template_code'=>$template_code));
 
                $data array(
                    'mobile' => $mobile,
                    'content' => $content,
                    'send_time' => time(),
                    'tpl' => $template_code
                );
                $this->db->save('###_sms',$data);
                return true;
            }
            else{
                return $msg; #提示信息
            }
 
        }
        return false;
    }
 
    /** 發送短信 基礎函數
     * @param $mobile
     * @param $content
     * @param array $cfg
     */
    function sendSms($mobile$content$cfg array()){
        $config $this->setting->value("'sms_open','sms_type','sms_username','sms_password','site_name','sms_mod'");
        if(!$config['sms_open']) return false;
 
        if($cfg && is_array($cfg)) {
            $config $cfg;
        }
 
        #文件日志
        $this->load->library('dir');
        $log date('Y-m-d H:i:s')." | ".getIP()." | ".$mobile." | ".$content."\r\n";
        $this->dir->filePutContents(AppDir."data/sms_log_".$config['sms_username'].".log",$log,'ab+');
 
        /******上海互億*****/
        if($config['sms_type'] == 1){
            $target "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
            //替換成自己的測試賬號,參數順序和wenservice對應
            $post_data "account=".$config['sms_username']."&password=".md5($config['sms_password'])."&md5=1&mobile=".$mobile."&content=".urlencode($content);
            $gets = '<?xml version="1.0" encoding="utf-8"?>
                    <SubmitResult xmlns="http://106.ihuyi.cn/">
                    <code>0</code>
                    <msg>調試成功</msg>
                    </SubmitResult>';
            if($config['sms_mod'] == 0){
                $gets $this->curlPost($post_data$target);
            }
 
            $gets_arr $this->xmlToArray($gets);
            //$this->dir->filePutContents(AppDir."data/sms_log_".$config['sms_username'].".log",'發送狀態:'.$gets_arr['SubmitResult']['msg']."\r\n",'ab+');
 
            if ($gets_arr['SubmitResult']['code'] == 2){
                return true;
            }else{
                return $gets_arr['SubmitResult']['msg'];
            }
        }
        /******上海互億 end*****/
        /******容聯云通訊*****/
        elseif($config['sms_type'] == 2){
            include_once(AppDir.'library/CCPRestSDK.php');
            // 初始化REST SDK
            //$serverIP = 'sandboxapp.cloopen.com';
            $serverIP 'app.cloopen.com';
            $serverPort '8883';
            $softVersion '2013-12-26';
            //語音接口配置帳號
            $accountSid $this->site_config['voice_sid'];
            $accountToken $this->site_config['voice_token'];
            $appId $this->site_config['voice_appid'];
 
            $rest new REST($serverIP,$serverPort,$softVersion);
            $rest->setAccount($accountSid,$accountToken);
            $rest->setAppId($appId);
 
            //解析模板變量與模板ID
            $assignTpl $this->smarty->get_template_vars();
            $content explode('|'$content);
            $tempId = 0;
            $array array();
            if($content){
                $i = 0;
                foreach($content as $k=>$v){
                    $v = trim($v);
                    if($v){
                        if($i==0){ $tempId $v; }
                        else{
                            if(isset($assignTpl[$v])){
                                $array[] = $assignTpl[$v];
                                if($v=='verify_code'){
                                    $array[] = '5';
                                }
                            }
                        }
                        $i++;
                    }
                }
            }
 
            $result $rest->sendTemplateSMS($mobile,$array,$tempId);
            if($result == NULL ) {
                return 'result error!';
            }
            $result = (array$result;
            if($result['statusCode']!=0) {
                return $result['statusMsg'];
            }else{
                return true;
            }
        }elseif($config['sms_type'] == 3){
            $url 'http://api.smsbao.com/sms?u='.$config['sms_username']."&p=".md5($config['sms_password'])."&m=".$mobile."&c=".urlencode($content);
            $ret file_get_contents($url);
            if ($ret == 0) {
                return true;
            else {
                return $ret;
            }
            
        }
        /******容聯云通訊 end*****/
        else{ #TODO:其它接口擴展
            return false;
        }
    }
 
    /** 生成短信隨機驗證碼
     * @return string
     */
    function getVerifyCode() {
        $length = 6;
        PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
        $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
        return $hash;
    }
 
    /** 遠程連接
     * @param $curlPost
     * @param $url
     * @return mixed
     */
    function curlPost($curlPost,$url){
        //set_time_limit(60);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
        curl_setopt($curl, CURLOPT_NOBODY, true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
        $return_str = curl_exec($curl);
        curl_close($curl);
        return $return_str;
    }
 
    /** 簡單解析xml
     * @param $xml
     * @return mixed
     */
    function xmlToArray($xml){
        $reg "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
        $arr array();
        if(preg_match_all($reg$xml$matches)){
            $count count($matches[0]);
            for($i = 0; $i $count$i++){
                $subxml$matches[2][$i];
                $key $matches[1][$i];
                if(preg_match( $reg$subxml )){
                    $arr[$key] = $this->xmlToArray( $subxml );
                }else{
                    $arr[$key] = $subxml;
                }
            }
        }
        return @$arr;
    }
 
}

接著我們在項目\webapps\www\controller的控制器目錄下創建申請短信接口安裝的數據庫文件:

?
1
UPDATE `zz_config` SET `tip`='推薦接口 申請短信接口賬號,請點擊這里(<a href="http://www.gjrencai.com/reg" target="_blank">短信寶短信</a>)</br>云通訊調用其它接口中語音驗證碼的三個帳號,切換到云通訊后需要到短信模板按提示重新編輯模板', `step`='{"options":"上海互憶|1\\r\\n云通訊|2\\r\\n短信寶|3","fieldtype":"tinyint","numbertype":"1","labelwidth":"","default":"1"}' WHERE (`varname`='sms_type') AND (`title`='短信平臺') AND (`group`='sms')

接著在\webapps\www\controller目錄下創建短信接口安裝文件,代碼如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
<?php
        include(AppDir.'/config/database.php');
        $sql file_get_contents(AppDir . '/controller/smsbao.sql');
        $comm = mysqli_connect($config['host'],$config['user'],$config['pass'],$config['dbname']) or die('Access Deny!(DB)');
        $obj = mysqli_query($comm,$sql);
        if ($obj) {
            echo '<h4>短信寶插件安裝成功,請刪除webapps\www\controller\smsbao.php和smsbao.sql文件。';
        else {
            echo '請聯系短信寶客服。';
        }
        
       exit;

經過以上的替換,短信寶的短信平臺已經替換成功了,我們去后臺進行查看:

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。

另外:我們已經開發好完整的愛我拍眾籌短信寶插件,點擊此鏈接 下載及查看安裝流程。

開源插件

最新更新

電商類

CMS類

微信類

文章標簽