首页 > 代码库 > eamilcar之短信发送
eamilcar之短信发送
<?php
class sms_send{
/**
*短信模板添加
*/
function sms_add(){
//短信签名
$data[‘sign‘] = ‘emailcar‘;
//短信标题
$data[‘title‘] = ‘您的测试短信2‘;
//短信内容
$data[‘content‘] = ‘这是我的模板内容2‘;
//emailcar平台账号
$data[‘api_user‘] = ‘‘;
//emailcar平台密码
$data[‘api_pwd‘] = ‘‘;
$url = ‘http://www.emailcar.net/sms/tpl_add‘;
return $this->send_emailcar($url,$data);
}
/**
*短信模板获取
*/
function sms_get(){
$data[‘api_user‘] = ‘‘;
$data[‘api_pwd‘] = ‘‘;
//短信模板id(需要查询的模板/调用添加模板时返回的id)
$data[‘id‘] = ‘273‘;
$url = ‘http://www.emailcar.net/sms/tpl_get‘;
return $this->send_emailcar($url,$data);
}
/**
*短信发送
*/
function send(){
$data[‘api_user‘] = ‘‘;
$data[‘api_pwd‘] = ‘‘;
//短信模板id
$data[‘template_id‘] = ‘274‘;
//短信模板内容,如果为空则默认模板id对应的内容
$data[‘sms_template‘] = ‘‘;
/*手机号码。传一个号码时默认为触发,传两个以及两个以上为群发,
两个以上手机号码用英文逗号隔开*/
$data[‘mobiles‘] = ‘‘;
$url = ‘http://www.emailcar.net/sms/send‘;
return $this->send_emailcar($url,$data);
}
/**
*远程调用接口
*/
function send_emailcar($url,$data){
header("content-type:text/html;charset=utf-8");
$postdata = http://www.mamicode.com/http_build_query(
$data
);
$opts = array(
‘http‘=>array(
‘method‘=>‘POST‘,
‘header‘=>‘Content-type: application/x-www-form-urlencoded‘,
‘content‘=>$postdata
),
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
return $result;
}
}
//调用短信模板添加并且打印返回值
$obj = new sms_send();
echo $obj->send();
eamilcar之短信发送