colly_wyx
2018-05-09 d3534714ed8f07f19e0a648ab2d07c73d0bed156
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
<?php
 
/**
 * 阿里大于扩展
 */
class Alidayu_Lite{
 
    static $_instance;
 
    public $sign_name = '';
 
    public $templates = array();
 
    public $app_key = '';
 
    public $secretkey = '';
 
    public function __construct(){
        DI()->loader->addDirs('./Library/Alidayu/SDK');
        DI()->loader->addDirs('./Library/Alidayu/SDK/request');
        DI()->loader->addDirs('./Library/Alidayu/SDK/domain');
        $config = DI()->config->get('app.alidayu');
        $this->sign_name = $config['sign_name'];
        $this->templates = $config['templates'];
        $this->app_key = $config['app_key'];
        $this->secretkey = $config['secretkey'];
    }
 
     /**
     * 单例模式
     * @return [type] [description]
     */
    public static function getInstance(){
        if(!(self::$_instance instanceof self)){
            self::$_instance = new self();
        }
        return self::$_instance;
    }
 
    /**
     * 发送验证码
     * @param  [type] $phone         [description]
     * @param  [type] $data        [description]
     * @param  [type] $use_scene [description]
     * @return [type]                [description]
     */
    public function send($phone, $send_json_data, $use_scene){
        if(!empty($use_scene)){
            if(isset($this->templates[$use_scene])){
                return $this->_send($phone, $send_json_data, $this->templates[$use_scene]);
            }   
            else{
                return false;
            }
        }
        else{
            return false;
        }
    }
 
    /**
     * 阿里大于执行发送操作
     * @param  [type] $phone          [description]
     * @param  [type] $send_json_data [description]
     * @param  [type] $template_id    [description]
     * @return [type]                 [description]
     */
    private function _send($phone, $send_json_data, $template_id){
        $topClient = new TopClient();
        $topClient->appkey = $this->app_key;
        $topClient->secretKey = $this->secretkey;
        $req = new AlibabaAliqinFcSmsNumSendRequest();
        $req->setExtend($phone);
        $req->setSmsType('normal');
        $req->setSmsFreeSignName($this->sign_name);
        $req->setSmsParam($send_json_data);
        $req->setRecNum($phone);
        $req->setSmsTemplateCode($template_id);
        $resp = $topClient->execute($req);
        return $resp;
    }
}