脈客多是一個(gè)免費(fèi)開源、提供兼職,調(diào)查問卷、數(shù)據(jù)采集集成一體化系統(tǒng)。小編對(duì)他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進(jìn)行二次開發(fā),使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶短信群發(fā)平臺(tái)的接口非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試短信,推薦大家使用。
1:打開項(xiàng)目:application\controllers\Send.php 修改大概170行左右
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
/** 生成驗(yàn)證碼 */ if( ! $old_code ) { $sms_verify_code = random_string('numeric', 6); /** 發(fā)送驗(yàn)證碼 */ if ($action == 'phone') { $this->load->library('Smsbao/sms', NULL, 'smsbao_sms'); $result = $this->smsbao_sms->send($account, [ 'code' => $sms_verify_code ], $code_type)['status']; } elseif($action == 'email') { $result = send_email($account, $code_type, [ 'code' => $sms_verify_code, 'web_name' => $this->config->item( 'web_name' ), ]); } |
2:打開項(xiàng)目:application\libraries 在當(dāng)前目錄下創(chuàng)建Smsbao目錄 并且在Smsbao目錄下創(chuàng)建Sms.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
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');class Sms{ private $accessKeyId; private $accessKeySecret; private $sign; public $connectTimeout = 3000;//3秒 public $readTimeout = 80000;//80秒 protected $time; public function __construct() { $this->CI =& get_instance(); $this->CI->load->config('api', true); $this->accessKeyId = trim($this->CI->config->item('smsbao_key_id', 'api')); $this->accessKeySecret = trim($this->CI->config->item('smsbao_key_secret', 'api')); $this->sign = trim($this->CI->config->item('smsbao_sign', 'api')); } public function send($phone, $data = [], $action = 'verify') { $this->time = now(); /** 不開啟發(fā)送短信功能默認(rèn)返回成功 */ if ( $this->CI->config->item('open_send_sms') == 'N' ) { return ['status' => TRUE, 'msg' => "已關(guān)閉發(fā)送短信功能"]; } /** @var 判斷手機(jī)號(hào)碼格式 $new_phone */ $new_phone = []; if (stripos($phone, ',') !== FALSE) { $phone = explode(',', $phone); foreach ($phone AS $k => $p) { if (is_phone($p)) { $new_phone[] = $p; } } } elseif (is_phone($phone)) { $new_phone[] = $phone; } /** 手機(jī)號(hào)碼格式不正確 */ if (empty($new_phone)) { return ['status' => FALSE, 'msg' => "請(qǐng)輸入正確的手機(jī)號(hào)碼"]; } $user = $this->accessKeyId; //短信平臺(tái)帳號(hào) $pass = md5($this->accessKeySecret); //短信平臺(tái)密碼 $content='【'.$this->sign.'】'."您的驗(yàn)證碼{$data['code']},該驗(yàn)證碼5分鐘內(nèi)有效,請(qǐng)勿泄漏于他人.";//要發(fā)送的短信內(nèi)容 $mobile = implode(',', (array)$new_phone);//要發(fā)送短信的手機(jī)號(hào)碼 $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$mobile."&c=".urlencode($content); /** 對(duì)數(shù)據(jù)進(jìn)行數(shù)組處理 */ $reason = $this->curl($sendurl); if ($reason === '0') { $result['msg'] = '發(fā)送成功'; $result['status'] = TRUE; } else { $result['msg'] = '發(fā)送失敗'; $result['status'] = false; } /** 短信發(fā)送記錄 */ $this->CI->load->model('sms/logsm', 'sms_logs'); foreach ($new_phone AS $phone) { $logs = [ 'phone' => $phone, 'contents' => $content, 'status' => ($reason==='0' ? 1 : 0 ), 'send_time' => $this->time, ]; $this->CI->sms_logs->save($logs); } return $result; } /** * 發(fā)送短信 * @param $url * @author Bob * @return mixed * @throws Exception */ public function curl ($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); if ($this->readTimeout) { curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout); } if ($this->connectTimeout) { curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout); } //https 請(qǐng)求 if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); } $reponse = curl_exec($ch); if (curl_errno($ch)) { throw new Exception(curl_error($ch), 0); } curl_close($ch); return $reponse; }} |
經(jīng)過上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開發(fā)好完整的脈客多系統(tǒng)短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類