You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.1 KiB
127 lines
3.1 KiB
<?php
|
|
|
|
/**
|
|
* 短信类
|
|
* @Author : Kin
|
|
* @Date : 2019-04-09
|
|
* @Email : txg@huamill.com
|
|
*/
|
|
|
|
namespace service;
|
|
|
|
class SendSms
|
|
{
|
|
|
|
/**
|
|
* 短信服务商apikey
|
|
* @var string
|
|
*/
|
|
private static $apikey = '';
|
|
|
|
/**
|
|
* 发送的短信号码
|
|
* @var int
|
|
*/
|
|
private static $mobile = 0;
|
|
|
|
/**
|
|
* 发送的短信内容
|
|
* @var string
|
|
*/
|
|
private static $text = '';
|
|
|
|
/**
|
|
* 短信服务商请求地址
|
|
* @var string
|
|
*/
|
|
private static $url = '';
|
|
|
|
/**
|
|
* 发送短信
|
|
* @param string $mobile 手机号
|
|
* @param int $type 短信类型 1:验证码 2:系统通知 [默认:1]
|
|
* @return
|
|
* 类型:验证码、通知类型
|
|
* 条数:多条、单条
|
|
*/
|
|
public static function send($arr = [], $mobile = '', $url = '', $text = '')
|
|
{
|
|
//初始化赋值
|
|
self::$apikey = $arr['apikey'];
|
|
self::$url = $url;
|
|
self::$text = $text;
|
|
self::$mobile = $mobile;
|
|
switch ($arr['id']) {
|
|
case 2:
|
|
return self::sendChuangLan();
|
|
break;
|
|
default:
|
|
return self::sendYunPian();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 【云片短信服务端】发送短信
|
|
* @param string $mobile 手机号
|
|
* @param int $type 短信类型 1:验证码 2:系统通知 [默认:1]
|
|
* @return
|
|
* 类型:验证码、通知类型
|
|
* 条数:多条、单条
|
|
*/
|
|
public static function sendYunPian()
|
|
{
|
|
$_header = [
|
|
'Accept:application/json;charset=utf-8',
|
|
'Content-Type:application/x-www-form-urlencoded;charset=utf-8',
|
|
];
|
|
|
|
$_post = [
|
|
'apikey' => self::$apikey,
|
|
'mobile' => self::$mobile,
|
|
'text' => self::$text,
|
|
];
|
|
return HttpService::post(self::$url, $_post, 30, $_header);
|
|
}
|
|
|
|
/**
|
|
* 【创蓝短信服务端】发送短信
|
|
* @param string $mobile 手机号
|
|
* @param int $type 短信类型 1:验证码 2:系统通知 [默认:1]
|
|
* @return
|
|
* 类型:验证码、通知类型
|
|
* 条数:多条、单条
|
|
*/
|
|
public static function sendChuangLan()
|
|
{
|
|
$_header = [
|
|
'Accept:application/json;charset=utf-8',
|
|
'Content-Type:application/x-www-form-urlencoded;charset=utf-8',
|
|
];
|
|
|
|
$_post = [
|
|
'apikey' => self::$apikey,
|
|
'mobile' => self::$mobile,
|
|
'text' => self::$text,
|
|
];
|
|
return HttpService::post(self::$url, $_post, 30, $_header);
|
|
}
|
|
|
|
/**
|
|
* 查询发送记录
|
|
* 类型:单个号码或All
|
|
*/
|
|
public function query()
|
|
{
|
|
$_header = [
|
|
'Accept:application/json;charset=utf-8',
|
|
'Content-Type:application/x-www-form-urlencoded;charset=utf-8',
|
|
];
|
|
$_post = [
|
|
'apikey' => '6435f609be3dad56dc1854d49b3f12bc',
|
|
'start_time' => '2013-08-11 00:00:00',
|
|
'end_time' => '2019-08-11 00:00:00',
|
|
];
|
|
$_data = HttpService::post('https://sms.yunpian.com/v2/sms/get_record.json', $_post, 30, $_header);
|
|
}
|
|
|
|
}
|
|
|