• 4001-021-502
您的位置:短信宝 > 技术分享 > 小猪oto生活通V14.17新增短信宝短信接口
小猪oto生活通V14.17新增短信宝短信接口
发表日期:2019-09-12    文章编辑:短信宝小编    浏览次数:

小猪CMS已是当前php软件市场上的领跑者了,是一款开源的电商系统,包含微信小程序、支付宝小程序、APP、公众号和H5端,为大中小企业提供移动电子商务优秀的解决方案。今天我就来带大家来做一次替换短信接口的工作。短信接口使用的是短信宝短信平台的短信接口,小伙伴一定会问为什么使用短信宝作为案例呢?原因很简单,因为短信宝的平台极其稳定,而且短信发送速度相当快捷,验证码和订单通知在3~5秒就能收到,用户体验非常好,所以我们公司一直和短信宝保持着合作关系,小伙伴们也可以去短信宝的官网(http://www.smsbao.com)注册一个账号,还有免费的短信条数送呢。

打开项目 \cms\Lib\ORG\Sms.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
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
public function sendSms($data = array(), $send_time = '', $charset = 'utf-8', $id_code = '')
    {
        if ($data) {
            $type = isset($data['type']) ? $data['type'] : 'meal';
            $sendto = isset($data['sendto']) ? $data['sendto'] : 'user';
            $mer_id = isset($data['mer_id']) ? intval($data['mer_id']) : 0;
            $store_id = isset($data['store_id']) ? intval($data['store_id']) : 0;
            $uid = isset($data['uid']) ? intval($data['uid']) : 0;
            if (empty($mer_id)) return 'mer_id is null';
            $content = isset($data['content']) ? Sms::_safe_replace($data['content']) : '';
            if (empty($content)) return 'send content is null';
            $mobile = isset($data['mobile']) ? $data['mobile'] : '';
            $phone_array = explode(',', $mobile);
            $mobile = $pre = '';
            foreach ($phone_array as $phone) {
                if (Sms::checkmobile($phone)) {
                    $mobile .= $pre . $phone;
                    $pre = ',';
                }
            }
            if (empty($mobile)) return 'phone is right';
            
            $data = array(
                    //'topdomain' => C('config.sms_server_topdomain'),
                    'u' => trim(C('config.sms_name')),
                    'p' => md5(trim(C('config.sms_key'))),
                    //'token' => $mer_id . 'o2opigcms',
                    'm' => $mobile,
                    'c' => "【".trim(C('config.sms_sign'))."】".$content
            );
            
            $post = '';
            foreach ($data as $k => $v) {
                $post .= $k . '=' . $v .'&';
            }
    
            $smsapi_senturl = 'http://api.smsbao.com/sms?';
            $return = file_get_contents($smsapi_senturl.http_build_query($data));
            $statusStr = array(
                        "0" => "短信发送成功",
                        "-1" => "参数不全",
                        "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
                        "30" => "密码错误",
                        "40" => "账号不存在",
                        "41" => "余额不足",
                        "42" => "帐户已过期",
                        "43" => "IP地址限制",
                        "50" => "内容含有敏感词"
                        );
            //$arr = explode('#', $return);
            $send_time = $send_time ? $send_time : time();
            
            //增加到本地数据库
            $row = array('mer_id' => $mer_id, 'uid' => $uid, 'store_id' => $store_id, 'time' => $send_time, 'phone' => $mobile, 'text' => $content, 'status' => $arr[0], 'type' => $type, 'sendto' => $sendto);
            D('Sms_record')->add($row);
            return $statusStr[$return];
        else return false;
        
        exit;
        if (C('sms_key') != '' && C('sms_key') != 'key') {
            $companyid=0;
            
            if(!(strpos($token,'_') === FALSE)) {
                $sarr = explode('_',$token);
                $token = $sarr[0];
                $companyid = intval($sarr[1]);
            }
            if (!$mobile) {
                $companyWhere = array();
                $companyWhere['token'] = $token;
                if ($companyid) {
                    $companyWhere['id'] = $companyid;
                }
                $company = M('Company')->where($companyWhere)->find();
                $mobile = $company['mp'];
            }
            //
            $thisWxUser = M('Wxuser')->where(array('token' => Sms::_safe_replace($token)))->find();
            $thisUser = M('Users')->where(array('id' => $thisWxUser['uid']))->find();
            if ($token == 'admin') {
                $thisUser = array('id'=>0);
                $thisWxUser = array('uid' => 0,'token' => $this->token);
            }
            $get_url="http://api.smsbao.com/query?u=".trim(C('config.sms_name'))."&p=".md5(trim(C('config.sms_key')));
            $num_smsbao=file_get_contents($get_url);
            $num_smsbao=str_replace("\n""", $num_smsbao);
            $num_smsbao_res=explode(",",$num_smsbao);
            //$num_smsbao_res[1]
            if ($num_smsbao_res[1] < 1 || $num_smsbao==30||$num_smsbao==40||$num_smsbao==41||$num_smsbao==42){
                return '已用完或者未购买短信包';
                exit();
            else {
                //
                //短信发送状态
                if(is_array($mobile)){
                    $mobile = implode(",", $mobile);
                }
    
                $content = Sms::_safe_replace($content);
                $data = array(
                    //'topdomain' => C('config.sms_server_topdomain'),
                    'u' => trim(C('config.sms_name')),
                    'p' => md5(trim(C('config.sms_key'))),
                    //'token' => $mer_id . 'o2opigcms',
                    'm' => $mobile,
                    'c' => "【".trim(C('config.sms_sign'))."】".$content
                );
                $post = '';
                foreach ($data as $k => $v) {
                    $post .= $k . '=' . $v .'&';
                }
    
                $smsapi_senturl = 'http://api.smsbao.com/sms?';
    
                $return = file_get_contents($smsapi_senturl.http_build_query($data));//Sms::_post($smsapi_senturl, 0, $post);
                 $statusStr = array(
                        "0" => "短信发送成功",
                        "-1" => "参数不全",
                        "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
                        "30" => "密码错误",
                        "40" => "账号不存在",
                        "41" => "余额不足",
                        "42" => "帐户已过期",
                        "43" => "IP地址限制",
                        "50" => "内容含有敏感词"
                        );
                //$arr = explode('#', $return);
                //$this->statuscode = $arr[0];
                //增加到本地数据库
                if ($mobile) {
                    $row = array('uid' => $thisUser['id'], 'token' => $thisWxUser['token'], 'time' => time(), 'mp' => $mobile, 'text' => $content, 'status' => $this->statuscode, 'price' => C('sms_price'));
                    M('Sms_record')->add($row);
                    if (intval($this->statuscode) == 0 && $token != 'admin'){
                        M('Users')->where(array('id' => $thisWxUser['uid']))->setDec('smscount');
                    }
                }
                //end
                return $statusStr[$return];
            }
        }
    }

打开项目:\cms\Lib\Action\Index 新建一个smsbaoAction.class.php文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
/*
 *短信宝插件
 *
 */
 
class smsbaoAction extends BaseAction {
    public function index(){
        $row = array('name' => 'sms_name''type' =>'type=text&validate=required:true''value' => 'smsbao''info' =>'短信宝用户名''desc' =>'你在短信宝注册的用户名''tab_id' =>'0''tab_name'=>'','gid'=>'15','sort'=>'12','status'=>'1');
        $add=M('config')->add($row);
        echo "<h4>小猪o2o短信宝短信插件安装成功,请删除install_smsbao.php文件</h4>";
    }
}
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。

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

另外:我们已经开发好完整的小猪oto生活通V14.17系统短信宝插件,点击此链接 下载及查看安装流程。

短信宝-做更好用的短信验证码短信营销短信群发服务平台。超过9,000个网站始终信任短信宝。通过稳定快捷的短信,短信宝帮助他们缩短了90%的人工服务处理时间,同时降低了81%由于通讯故障导致的废单率,一切变得轻松可控!

Copyright © 2010-2014 smsbao.com All Rights Reserved
上海子橙电子科技有限公司 沪ICP备14008182号-2 上海市松江区广富林路658弄215号

展开