待发短信

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

4001-021-502

工作时间

9:00-21:00

脉客多悬赏系统新增短信宝短信接口

脉客多是一个免费开源、提供兼职,调查问卷、数据采集集成一体化系统。小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
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' => "请输入正确的手机号码"];
            }
            $smsapi = "http://api.smsbao.com/";
            $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类

微信类

文章标签