待发短信

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

4001-021-502

工作时间

9:00-18:00

阿狸子V3.2新增短信宝短信接口

阿狸子订单管理系统 是基于ThinkPHP开发的微信商城系统,是一款极简的PHP订单系统,支持货到付款,微信支付,非常不错,简介大方,适合做百度推广、联盟推广,高效快捷,后台功能齐全,小编今天就以替换短信接口为例带大家进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用

1:打开项目:Public\Common\alizi.setting.php 修改136行

?
1
2
3
4
5
6
7
'sms_setting' => array(
    'sms_send'=> array('name'=>'短信发送','options'=>array('0'=>'关闭','1'=>'启用',),'tags'=>'select','decription'=>'','width'=>30,'height'=>0,'separator'=>0,),
    'sms_admin'=> array('name'=>'通知对象','value'=>1,'options'=>array('0'=>'只通知客户','1'=>'只通知管理员','2'=>'同时通知管理员和客户',),'tags'=>'select','decription'=>'','width'=>35,'height'=>0,'separator'=>0,),
    'sms_admin_mobile'=> array('name'=>'','options'=>'','tags'=>'text','decription'=>'请填写管理员手机号,多个号码请用英文逗号隔开','width'=>30,'height'=>0,'separator'=>0,),
    'sms_account'=> array('name'=>'短信宝账号','options'=>'','tags'=>'text','decription'=>'','width'=>30,'height'=>0,'separator'=>0,),
    'sms_password'=> array('name'=>'短信宝密码','options'=>'','tags'=>'text','decription'=>'','width'=>30,'height'=>0,'separator'=>0,),
),

2:打开项目:Admin\Lib\Action\IndexAction.class.php 修改余额方法 大概47行

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public function smsBalance(){
        header('Content-type: application/json');
        $aliziConfig = S('aliziConfig');
        if(empty($aliziConfig['sms_account']) || empty($aliziConfig['sms_password'])){
            $json = json_encode(array('status'=>0,'data'=>0));
        }else{
            $data = array(
                //'method'=>'balance',
                'u'=>$aliziConfig['sms_account'],
                'p'=>md5($aliziConfig['sms_password'])
                //'url'=>"http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}",
            );
            $url="https://www.smsbao.com/query?";
            $result=file_get_contents($url.http_build_query($data));
            $result=explode(',',$result);
            $json=json_encode(array('status'=>0,'data'=>$result[1]));
            //$json = http( C('ALIZI_API').'/sms/', 'POST', $data );
        }
        die($json);
    }

3:打开项目:Admin\Lib\Action\OrderAction.class.php 修改发送函数 大概663行

?
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
function smsSend($order_id,$order_status=0){
        
        $orders = M('Order')->where(array('id'=>array('IN',$order_id)))->select();
        $express = C('DELIVERY');
        if($orders){
            foreach($orders as $order){
                $item = M('Item')->where('id='.$order['item_id'])->field('id,sms_send')->find();
                $sms = json_decode($item['sms_send'],true);
                
                if(!empty($sms[$order_status]['content'])){
                    $replace = array(
                        '#title#'     => $order['item_name'],
                        '#params#'     => $order['item_params'],
                        '#name#'     => $order['name'],
                        '#mobile#'     => $order['mobile'],
                        '#quantity#'     => $order['quantity'],
                        '#price#'     => $order['total_price'],
                        '#express#'     => $express[$order['delivery_name']],
                        '#expressNum#'     => $order['delivery_no'],
                        '#orderNum#'     => $order['order_no'],
                        '#payUrl#'     => shortUrl($this->aliziHost.'Api/pay.php?id='.$order['order_no']),
                        '#confirmUrl#'     => $this->aliziHost.(C('URL_MODEL')==2?'a/'.$order['order_no']:'Api/confirm.php?id='.$order['order_no']),
                    );
                    $id[] = $order['id'];
                    $mobile[] = $order['mobile'];
                    $content[] = urlencode(str_replace(array_keys($replace),array_values($replace),$sms[$order_status]['content']));
                }
            }
            if(count($orders)==1){
                $method = 'single';
                $mobile = $mobile[0];
                $content = urldecode($content[0]);
            }else{
                $method = 'multi';
                $mobile = implode(',',$mobile);
                $content = implode(',',$content);
            }
            
            $aliziConfig = parent::aliziConfig();
            $data = array(
                'method'=>$method,
                'account'=>$aliziConfig['sms_account'],
                'password'=>$aliziConfig['sms_password'],
                'mobile'=>$mobile,
                'content'=>$content,
            );
            $smsapi = "http://api.smsbao.com/";
            $user = $data['account']; //短信平台帐号
            $pass = md5($data['password']); //短信平台密码
            $content= '【'.$aliziConfig['title'].'】'.$data['content'];"短信内容";//要发送的短信内容
            $phone = $data['mobile'];//要发送短信的手机号码
            $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
            $result =file_get_contents($sendurl);
            $ret = [];
            if ($result == 0) {
                $ret['data'] = array(array('status'=>1,'mobile'=>$phone,'content'=>$content));
            }else{
                $ret = 0;
            }
            $i = 0;
            if(!empty($ret['data'])){
                foreach($ret['data'] as $k=>$li){
                    if($li['status']==1){
                        $i++;
                        $sendData = array(
                            'order_id'=>$id[$k],
                            'order_status'=>$order_status,
                            'mobile'=>$li['mobile'],
                            'sent_content'=>$li['content'],
                            'sent_time'=>date('Y-m-d H:i:s'),
                            'sent_status'=>1,
                        );
                        M('Sent')->add($sendData);
                    }
                }
            }
            
            if($i>0){
                $status = 1;
                $msg = "发送成功{$i}条";
            }else{
                $status = 0;
                $msg = "发送失败";
            }
            $this->ajaxReturn(null,$msg,$status);   
        }else{
            $this->ajaxReturn(null,'请选择订单',0);
        }
        
    }

4:打开项目:Home\Lib\Action\AliziAction.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
function send_sms($mobile,$content){
        $config = $this->aliziConfig();
        $data = array(
            'method'=>'single',
            'account'=>$config['sms_account'],
            'apikey'=>$config['sms_password'],
            'mobile'=>$mobile,
            'content'=>$content,
        );
 
        $smsapi = "http://api.smsbao.com/";
        $user = $data['account']; //短信平台帐号
        $pass = md5($data['apikey']); //短信平台密码
        $content= '【'.$this->aliziConfig['title'].'】'.$data['content'];"短信内容";//要发送的短信内容
        $phone = $data['mobile'];//要发送短信的手机号码
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl);
        $rs = [];
        if ($result == 0){
            $rs['status'] = 1;
        }else{
            $rs['status'] = 0;
        }
        return $rs;
 
    }

5:打开项目:Home\Lib\Action\ApiAction.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
private function sendSMS($order_id){
        if(empty($this->aliziConfig['sms_send'])){
            return array('status'=>0);
        }
        $order = M('Order')->where(array('id'=>$order_id))->find();
        if(empty($order)) return array('status'=>0);
 
        
        $item = M('Item')->where('id='.$order['item_id'])->field('id,sms_send')->find();
        $sms = json_decode($item['sms_send'],true);
        $status=$order['status'];
        if($sms[$status]['status']==1 && !empty($sms[$status]['content'])){
            //发送内容替换
            $express = C('DELIVERY');
 
            $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' 'http://';
            $aliziHost = $http_type.$_SERVER['HTTP_HOST'].C('ALIZI_ROOT');
            $confirmUrl = $aliziHost.(C('URL_MODEL')==2?'a/'.$order['order_no']:'Api/confirm.php?id='.$order['order_no']);
            
            $mobiles = $order['mobile'];
            if(!empty($this->aliziConfig['sms_admin_mobile'])){
                switch ($this->aliziConfig['sms_admin']) {
                    case '1': $mobiles = $this->aliziConfig['sms_admin_mobile'];break;
                    case '2': $mobiles .= ','.$this->aliziConfig['sms_admin_mobile'];break;
                }
            }
            
            $replace = array(
                '{[AliziTitle]}'     => $order['item_name'],
                '{[AliziParams]}'     => $order['item_params'],
                '{[AliziName]}'     => $order['name'],
                '{[AliziQuantity]}'     => $order['quantity'],
                '{[AliziPrice]}'     => $order['total_price'],
                '{[AliziExpress]}'     => $express[$order['delivery_name']],
                '{[AliziExpressNum]}'     => $order['delivery_no'],
                '{[AliziConfirmUrl]}'     => $confirmUrl,
 
                '#title#'     => $order['item_name'],
                '#params#'     => $order['item_params'],
                '#name#'     => $order['name'],
                '#mobile#'     => $order['mobile'],
                '#quantity#'     => $order['quantity'],
                '#price#'     => $order['total_price'],
                '#express#'     => $express[$order['delivery_name']],
                '#expressNum#'     => $order['delivery_no'],
                '#confirmUrl#'     => $confirmUrl,
                '#payUrl#'     => shortUrl($this->aliziHost.'Api/pay.php?id='.$order['order_no']),
                '#orderNum#'     => $order['order_no'],
            );
            $content = str_replace(array_keys($replace),array_values($replace),$sms[$status]['content']);
 
            $url="http://api.smsbao.com/sms?";
            $param['u']=$this->aliziConfig['sms_account'];
            $param['p']=md5($this->aliziConfig['sms_password']);
            $param['m']=$order['mobile'];
            $param['c']='【'.$this->aliziConfig['title'].'】'.$content;
            $rs=file_get_contents($url.http_build_query($param));
            if($rs == "0"){
                $sendData = array(
                    'order_id'=>$order_id,
                    'order_status'=>$order['status'],
                    'mobile'=>$mobiles,
                    'sent_content'=>$content,
                    'sent_time'=>date('Y-m-d H:i:s'),
                    'sent_status'=>1,
                );
                M('Sent')->add($sendData);
            }
        }
    }

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

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

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

开源插件

最新更新

电商类

CMS类

微信类

文章标签