Skip to content

Add cloud SMS interface #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions docs/sms/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
require_once("../../autoload.php");

use \Qiniu\Auth;

$ak="xxxx";
$sk="xxxx";

$auth = new Auth($ak, $sk);
$client = new Qiniu\Sms\sms($auth);

//发送信息模块
$template_id="1131792074274775040";
$mobiles=array("18011111111","18011111111");
$code = array('code' => 'code' );
try {
//发送短信
$resp = $client->sendMessage($template_id, $mobiles, $code);
print_r($resp);
} catch (\Exception $e) {
echo "Error:", $e, "\n";
}exit;
//模板模块
$name="tstest001";
$template="tesy001 ${code}";
$type="notification";
$description="tstest001";
$signature_id="1131464448834277376";
$id="1131810682442883072";

try {
//创建模板
$resp = $client->createTemplate($name, $template, $type, $description, $signature_id);
print_r($resp);
//查询模板
$resp = $client->queryTemplate();
print_r($resp);
//修改模板
$resp = $client->updateTemplate($id, $name, $template, $description, $signature_id);
print_r($resp);
//删除模板
$resp = $client->deleteTemplate($id);
print_r($resp);
} catch (\Exception $e) {
echo "Error:", $e, "\n";
}
//签名模块
$signature = 'lfxlive2';
$source = 'enterprises_and_institutions';
$pic="/Users/Desktop/sss.jpg";
$audit_status="passed";
$page=1;
$page_size=1;
$id="1131464448834277376";

try {
//创建签名
$resp = $client->createSignature($signature, $source, $pic);
print_r($resp);
//查询签名
$resp = $client->checkSignature($audit_status);
//修改签名
$resp = $client->updateSignature($id, $signature, $source, $pic);
print_r($resp);
//删除ID
$resp = $client->deleteSignature($id);
print_r($resp);
} catch (\Exception $e) {
echo "Error:", $e, "\n";
}
2 changes: 2 additions & 0 deletions src/Qiniu/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ final class Config
const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
const ARGUS_HOST = 'argus.atlab.ai';
const CASTER_HOST = 'pili-caster.qiniuapi.com';
const SMS_HOST="https://sms.qiniuapi.com";
const RTCAPI_VERSION = 'v3';
const SMS_VERSION='v1';

// Zone 空间对应的存储区域
public $region;
Expand Down
10 changes: 7 additions & 3 deletions src/Qiniu/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public static function post($url, $body, array $headers = array())
return self::sendRequest($request);
}

public static function PUT($url, $body, array $headers = array())
{
$request = new Request('PUT', $url, $headers, $body);
return self::sendRequest($request);
}

public static function multipartPost(
$url,
$fields,
Expand Down Expand Up @@ -56,6 +62,7 @@ public static function multipartPost(
array_push($data, '');

$body = implode("\r\n", $data);
// var_dump($data);exit;
$contentType = 'multipart/form-data; boundary=' . $mimeBoundary;
$headers['Content-Type'] = $contentType;
$request = new Request('POST', $url, $headers, $body);
Expand Down Expand Up @@ -91,12 +98,10 @@ public static function sendRequest($request)
CURLOPT_CUSTOMREQUEST => $request->method,
CURLOPT_URL => $request->url,
);

// Handle open_basedir & safe mode
if (!ini_get('safe_mode') && !ini_get('open_basedir')) {
$options[CURLOPT_FOLLOWLOCATION] = true;
}

if (!empty($request->headers)) {
$headers = array();
foreach ($request->headers as $key => $val) {
Expand All @@ -105,7 +110,6 @@ public static function sendRequest($request)
$options[CURLOPT_HTTPHEADER] = $headers;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

if (!empty($request->body)) {
$options[CURLOPT_POSTFIELDS] = $request->body;
}
Expand Down
Loading