待发短信

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

4001-021-502

工作时间

9:00-21:00

OpenSNS V6.2.0新增短信宝短信接口

OpenSNS是以社交+动态为核心的开源社交系统,在行业有一定的知名度,多年来深得行业内开发者的喜爱。编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是6.2.0版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
插件目录结构如下
├─SmsBao插件目录
│ ├─config.php 短信宝设置
│ ├─SmsBaoAddon.class.php 短信宝插件信息描述以及核心发送类
其中config.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
<?php
 
return   array_merge( array(
    'switch'=>array(//配置在表单中的键名 ,这个会是config[title]
        'title'=>'是否开启短信宝短信:',//表单的文字
        'type'=>'radio',      //表单的类型:text、textarea、checkbox、radio、select等
        'options'=>array(
            '1'=>'启用',
            '0'=>'禁用',
        ),
        'value'=>'1',
        'tip'=>'默认开启'
    ),
),
    get_option()
);
 
function get_option(){
    $arr['sign'] =
        array(
            'title'=>'短信签名',
            'type'=>'text',
            'value'=>'',
            'tip'=>'(必须配置)'
        );
    return $arr;
}

SmsBaoAddon.class.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
<?php
 
namespace Addons\Smsbao;
 
use Common\Controller\Addon;
 
/**
* 短信宝短信插件
*/
class SmsBaoAddon extends Addon
{
    public $info = array(
        'name' => 'SmsBao',
        'title' => '短信宝',
        'description' => '短信宝短信插件 https://www.smsbao.com',
        'status' => 1,
        'author' => '短信宝小编',
        'version' => '1.0.0'
    );
 
    public  function install()
    {
        return true;
    }
 
    public function uninstall()
    {
        return true;
    }
 
    public function sms()
    {
        return true;
    }
 
    public function sendSms($mobile,$content)
    {  
        $config = get_addon_config('SmsBao');
        $cont = explode('【', $content);
        $data['u'] = modC('SMS_UID','','USERCONFIG');
        $data['p'] = md5(modC('SMS_PWD','','USERCONFIG'));
        $data['m'] = $mobile;
        $data['c'] = '【'.$config['sign'].'】'.$cont['0'];
        $url = 'http://api.smsbao.com/sms';
        $res = $this->post($url,$data);
        return $res;
 
    }
 
 
    private function post($url,$data,$timeout)
    {
           $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            $ret = curl_exec($curl);
            curl_close($curl);
            if($ret == 0) {
                return true;
            else {
                return "发送失败! 状态:" . $ret .' '. $this->getCode($ret['Code']);
            }  
    }
 
    private function getCode($code)
    {
        switch ($code) {
            case 0: return '短信发送成功';
            case -1: return '参数不全';
            case -2: return '服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!';
            case 30: return '密码错误';
            case 40: return '账号不存在';
            case 41: return '余额不足';
            case 42: return '帐户已过期';
            case 43: return 'IP地址限制';
            case 50: return '内容含有敏感词';
        }
 
    }
}

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

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。

另外:我们已经开发好完整的OpenSNS V6.2.0系统短信宝插件,点击此链接 下载及查看安装流程。

开源插件

最新更新

电商类

CMS类

微信类

文章标签