<?php
namespace lib\sms;

class yfSms {
	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" => "未输入参数",
			"1" => "余额不足",
			"2" => "用户不存在",
			"3" => "KEY错误",
			"4" => "发送失败",
			"5" => "签名不存在",
			"6" => "签名审核未通过",
			"7" => "当前发信短信已达到上限",
			"8" => "有违规词",
			"9" => "用户已封禁",
			"10" => "未实名认证"
		);
		$post['u'] = $this->u;
		$post['p'] = md5($this->p);
		$post['m'] = $phone;
		$post['c'] = $content;
		$post = http_build_query($post);
		$url = $this->url.'/sms';
		$ret = get_curl($url,$post);
		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);
	}
}
