<?php
namespace lib\sms;

class DuanXinBao {
	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){
		$statusStr = array(
			"0" => "短信发送成功",
			"-1" => "参数不全",
			"-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
			"30" => "密码错误",
			"40" => "账号不存在",
			"41" => "余额不足",
			"42" => "帐户已过期",
			"43" => "IP地址限制",
			"50" => "内容含有敏感词"
		);
		$post['u'] = $this->u;
		$post['p'] = $this->p;
		$post['m'] = $phone;
		$post['c'] = $content;
		$post = http_build_query($post);
		$url = $this->url.'/sms?'.$post;
		$ret = get_curl($url);
		if($ret == ''){
			$result = array('code' => -1,'msg' => '发送失败'.$ret);
		}elseif($ret == '0'){
			$result = array('code' => 1,'msg' => $statusStr[$ret]);
		}else{
			$result = array('code' => -1,'msg' => $statusStr[$ret]);
		}
		return json_encode($result,JSON_UNESCAPED_UNICODE);
	}
}
