PHP单例模式例程

来源:互联网 发布:js字符串contains 编辑:程序博客网 时间:2024/05/17 01:48

<?php

class FreeContentSmsSender
{
    private static $_instance;
    var $ch = NULL;
    var $uri = "http://xx";
    var $signature = "【xx】";
    var $pid = "xx";
    var $time = "xx";
    
    public static function getInstance(){    
        if(!(self::$_instance instanceof self)){    
            self::$_instance = new self;
            self::$_instance->ch = curl_init();  
        }    
        return self::$_instance;    
    }    
        
    public function send($message, $mobile)
    {
        $data = "account=xx&password=xx&content={$message}{$this->signature}&mobile={$mobile}&time={$this->time}&pid={$this->pid}";
        curl_setopt ( $this->ch, CURLOPT_URL, $this->uri );
        curl_setopt ( $this->ch, CURLOPT_POST, 1 );
        curl_setopt ( $this->ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $this->ch, CURLOPT_RETURNTRANSFER, 1 );        
        curl_setopt ( $this->ch, CURLOPT_POSTFIELDS, $data );
        $response = curl_exec ( $this->ch );
    }

};

$sender = FreeContentSmsSender::getInstance();
$sender->send("儿童节快乐。", "13912345678");

?>


以上技术应用于最优质的水果的鲜果篮

0 0
原创粉丝点击