<?php/** * 启瑞云短信接口Demo(utf-8) */class SendDemo{ const SENDURL = 'http://api.qirui.com:7891/mt'; private $apiKey; private $apiSecret; /** * 构造方法 * @param string $apiKey 接口账号 * @param string $apiSecret 接口密码 */ public function __construct($apiKey, $apiSecret) { $this->apiKey = $apiKey; $this->apiSecret = $apiSecret; } /** * 短信发送 * @param string $phone 手机号码 * @param string $content 短信内容 * @param integer $isreport 是否需要状态报告 * @return void */ public function send($phone, $content, $isreport = 0) { $requestData = array( 'un' => $this->apiKey, 'pw' => $this->apiSecret, 'sm' => $content, 'da' => $phone, 'rd' => $isreport, 'dc' => 15, 'rf' => 2, 'tf' => 3, ); $url = self::SENDURL . '?' . http_build_query($requestData); return $this->request($url); } /** * 请求发送 * @return string 返回发送状态 */ private function request($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); return $result; } } //实例化类,测试发送 //接口账号(apiKey)$apiKey = '2288**0010';//接口密钥(piSecret)$apiSecret = 'ae2600e9456f5b0b3ab8';//接受短信的手机号码$phone = '15100000000';//短信内容(【签名】+短信内容),发送短信需要预先申请报备短信签名,控制台>接口短信>签名报备$content = '【启瑞云】您的验证码是:4852'; $sms = new SendDemo($apiKey, $apiSecret);$result = $sms->send($phone, $content); print_r($result ); |
√ 短信接口 :
1)短信内容一定要带签名,签名放在短信内容的最前面;
2)签名格式:【***】,签名内容为三个汉字以上(包括三个);
3)短信内容不允许双签名,即短信内容里只有一个"【】";
4)短信签名先申请报备后使用,控制台>接口短信>签名报备;