-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from juvenn/feature/sms-code
支持通用短信发送接口 close #70
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace LeanCloud; | ||
|
||
/** | ||
* SMS | ||
*/ | ||
class SMS { | ||
|
||
/** | ||
* Request SMS code | ||
* | ||
* Besides sending default message with sms code, you can also | ||
* send with a customized template, which though must be submitted | ||
* and approved before sending. | ||
* | ||
* The available of options are: | ||
* | ||
* - `$smsType` (string): "sms" or "voice" | ||
* - `$template` (string): Template name that has been approved | ||
* - `$name` (string): App name | ||
* - `$ttl` (int): Number of minutes before sms code expires | ||
* - `$op` (string): Operation name for the sms code | ||
* | ||
* | ||
* @param string $phoneNumber | ||
* @param array $options | ||
* | ||
* @link https://leancloud.cn/docs/rest_sms_api.html | ||
*/ | ||
public static function requestSmsCode($phoneNumber, | ||
$options=array()) { | ||
forEach ($options as $k => $v) { | ||
if (!isset($options[$k])) { | ||
unset($options[$k]); | ||
} | ||
} | ||
$options["mobilePhoneNumber"] = $phoneNumber; | ||
Client::post("/requestSmsCode", $options); | ||
} | ||
|
||
/** | ||
* Verify SMS code | ||
* | ||
* @param string $phoneNumber | ||
* @param string $smsCode | ||
*/ | ||
public static function verifySmsCode($phoneNumber, $smsCode) { | ||
Client::post("/verifySmsCode/{$smsCode}?mobilePhoneNumber={$phoneNumber}", | ||
null); | ||
} | ||
|
||
} |