脈客多是一個免費開源、提供兼職,調查問卷、數據采集集成一體化系統。小編對他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
1:打開項目: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
|
/** 生成驗證碼 */ if ( ! $old_code ) { $sms_verify_code = random_string( 'numeric' , 6); /** 發送驗證碼 */ 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:打開項目:application\libraries 在當前目錄下創建Smsbao目錄 并且在Smsbao目錄下創建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(); /** 不開啟發送短信功能默認返回成功 */ if ( $ this ->CI->config->item( 'open_send_sms' ) == 'N' ) { return [ 'status' => TRUE, 'msg' => "已關閉發送短信功能" ]; } /** @var 判斷手機號碼格式 $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; } /** 手機號碼格式不正確 */ if (empty($new_phone)) { return [ 'status' => FALSE, 'msg' => "請輸入正確的手機號碼" ]; } $user = $ this ->accessKeyId; //短信平臺帳號 $pass = md5($ this ->accessKeySecret); //短信平臺密碼 $content= '【' .$ this ->sign. '】' . "您的驗證碼{$data['code']},該驗證碼5分鐘內有效,請勿泄漏于他人." ; //要發送的短信內容 $mobile = implode( ',' , (array)$new_phone); //要發送短信的手機號碼 $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$mobile. "&c=" .urlencode($content); /** 對數據進行數組處理 */ $reason = $ this ->curl($sendurl); if ($reason === '0' ) { $result[ 'msg' ] = '發送成功' ; $result[ 'status' ] = TRUE; } else { $result[ 'msg' ] = '發送失敗' ; $result[ 'status' ] = false ; } /** 短信發送記錄 */ $ 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; } /** * 發送短信 * @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 請求 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; } } |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的脈客多系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類