<?php
namespace lib\sms;

class ziYouYun {
	private $u;
	private $p;
	private $url;
	function __construct($url,$u, $p){
        $this->u = $u;
        $this->p = $p;
        $this->url = $url;
    }
	public function send($phone, $content){
		$post['username'] = $this->u;
		$post['key'] = $this->p;
		$post['phone'] = $phone;
		$post['content'] = $content;
		$post = http_build_query($post);
		$url = $this->url.'/SmsApi';
		$ret = json_decode(get_curl($url,$post),true);
		if(!is_array($ret)){
			$result = array('code' => -1,'msg' => '网站打不开');
		}elseif($ret['error_code'] === 0){
			$result = array('code' => 1,'msg' => $ret['message']);
		}else{
			$result = array('code' => -1,'msg' => $ret['message']);
		}
		return json_encode($result,JSON_UNESCAPED_UNICODE);
	}
}
