| <?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; | 
|     } | 
| } |