Skip to content

Commit bc3265f

Browse files
authored
Merge pull request #300 from ankadada/master
Add cloud SMS interface
2 parents 2545e45 + 707c5a2 commit bc3265f

File tree

4 files changed

+416
-3
lines changed

4 files changed

+416
-3
lines changed

docs/sms/example.php

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
require_once("../../autoload.php");
3+
4+
use \Qiniu\Auth;
5+
6+
$ak="xxxx";
7+
$sk="xxxx";
8+
9+
$auth = new Auth($ak, $sk);
10+
$client = new Qiniu\Sms\sms($auth);
11+
12+
//发送信息模块
13+
$template_id="1131792074274775040";
14+
$mobiles=array("18011111111","18011111111");
15+
$code = array('code' => 'code' );
16+
try {
17+
//发送短信
18+
$resp = $client->sendMessage($template_id, $mobiles, $code);
19+
print_r($resp);
20+
} catch (\Exception $e) {
21+
echo "Error:", $e, "\n";
22+
}exit;
23+
//模板模块
24+
$name="tstest001";
25+
$template="tesy001 ${code}";
26+
$type="notification";
27+
$description="tstest001";
28+
$signature_id="1131464448834277376";
29+
$id="1131810682442883072";
30+
31+
try {
32+
//创建模板
33+
$resp = $client->createTemplate($name, $template, $type, $description, $signature_id);
34+
print_r($resp);
35+
//查询模板
36+
$resp = $client->queryTemplate();
37+
print_r($resp);
38+
//修改模板
39+
$resp = $client->updateTemplate($id, $name, $template, $description, $signature_id);
40+
print_r($resp);
41+
//删除模板
42+
$resp = $client->deleteTemplate($id);
43+
print_r($resp);
44+
} catch (\Exception $e) {
45+
echo "Error:", $e, "\n";
46+
}
47+
//签名模块
48+
$signature = 'lfxlive2';
49+
$source = 'enterprises_and_institutions';
50+
$pic="/Users/Desktop/sss.jpg";
51+
$audit_status="passed";
52+
$page=1;
53+
$page_size=1;
54+
$id="1131464448834277376";
55+
56+
try {
57+
//创建签名
58+
$resp = $client->createSignature($signature, $source, $pic);
59+
print_r($resp);
60+
//查询签名
61+
$resp = $client->checkSignature($audit_status);
62+
//修改签名
63+
$resp = $client->updateSignature($id, $signature, $source, $pic);
64+
print_r($resp);
65+
//删除ID
66+
$resp = $client->deleteSignature($id);
67+
print_r($resp);
68+
} catch (\Exception $e) {
69+
echo "Error:", $e, "\n";
70+
}

src/Qiniu/Config.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ final class Config
1414
const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
1515
const ARGUS_HOST = 'argus.atlab.ai';
1616
const CASTER_HOST = 'pili-caster.qiniuapi.com';
17+
const SMS_HOST="https://sms.qiniuapi.com";
1718
const RTCAPI_VERSION = 'v3';
19+
const SMS_VERSION='v1';
1820

1921
// Zone 空间对应的存储区域
2022
public $region;

src/Qiniu/Http/Client.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public static function post($url, $body, array $headers = array())
2525
return self::sendRequest($request);
2626
}
2727

28+
public static function PUT($url, $body, array $headers = array())
29+
{
30+
$request = new Request('PUT', $url, $headers, $body);
31+
return self::sendRequest($request);
32+
}
33+
2834
public static function multipartPost(
2935
$url,
3036
$fields,
@@ -56,6 +62,7 @@ public static function multipartPost(
5662
array_push($data, '');
5763

5864
$body = implode("\r\n", $data);
65+
// var_dump($data);exit;
5966
$contentType = 'multipart/form-data; boundary=' . $mimeBoundary;
6067
$headers['Content-Type'] = $contentType;
6168
$request = new Request('POST', $url, $headers, $body);
@@ -91,12 +98,10 @@ public static function sendRequest($request)
9198
CURLOPT_CUSTOMREQUEST => $request->method,
9299
CURLOPT_URL => $request->url,
93100
);
94-
95101
// Handle open_basedir & safe mode
96102
if (!ini_get('safe_mode') && !ini_get('open_basedir')) {
97103
$options[CURLOPT_FOLLOWLOCATION] = true;
98104
}
99-
100105
if (!empty($request->headers)) {
101106
$headers = array();
102107
foreach ($request->headers as $key => $val) {
@@ -105,7 +110,6 @@ public static function sendRequest($request)
105110
$options[CURLOPT_HTTPHEADER] = $headers;
106111
}
107112
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
108-
109113
if (!empty($request->body)) {
110114
$options[CURLOPT_POSTFIELDS] = $request->body;
111115
}

0 commit comments

Comments
 (0)