Skip to content

Commit

Permalink
Merge pull request #128 from toplan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
toplan authored Jun 29, 2017
2 parents c33e516 + 4c9a33a commit 621ab03
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
18 changes: 12 additions & 6 deletions src/phpsms/agents/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,20 @@ public function formatMobile(array $list)
*/
public function curlPost($url, array $params = [], array $opts = [])
{
$params = $this->params($params);
if (!array_key_exists(CURLOPT_POSTFIELDS, $opts)) {
$opts[CURLOPT_POSTFIELDS] = $params;
$options = [
CURLOPT_POST => true,
CURLOPT_URL => $url,
];
foreach ($opts as $key => $value) {
if ($key !== CURLOPT_POST && $key !== CURLOPT_URL) {
$options[$key] = $value;
}
}
if (!array_key_exists(CURLOPT_POSTFIELDS, $options)) {
$options[CURLOPT_POSTFIELDS] = $this->params($params);
}
$opts[CURLOPT_POST] = true;
$opts[CURLOPT_URL] = $url;

return self::curl($opts);
return self::curl($options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/phpsms/agents/AliyunAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function createParams(array $params)
'Version' => '2016-09-27',
'AccessKeyId' => $this->accessKeyId,
'SignatureMethod' => 'HMAC-SHA1',
'Timestamp' => date('Y-m-d\TH:i:s\Z'),
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'SignatureVersion' => '1.0',
'SignatureNonce' => uniqid(),
], $params);
Expand Down
22 changes: 11 additions & 11 deletions src/phpsms/agents/LuosimaoAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@
*/
class LuosimaoAgent extends Agent implements ContentSms, VoiceCode
{
protected static $smsUrl = 'http://sms-api.luosimao.com/v1/send.json';
protected static $voiceCodeUrl = 'http://voice-api.luosimao.com/v1/verify.json';

public function sendContentSms($to, $content)
{
// 签名必须在最后面
if ($content && !preg_match('/】$/', $content)) {
preg_match('/【([0-9a-zA-Z\W]+)】/', $content, $matches);
if (isset($matches[0])) {
if ($content && preg_match('/(【[\\s\\S]*】)/', $content, $matches)) {
if (isset($matches[0]) && strlen($matches[0])) {
$content = str_replace($matches[0], '', $content) . $matches[0];
}
}
$url = 'http://sms-api.luosimao.com/v1/send.json';
$result = $this->curlPost($url, [
$result = $this->curlPost(self::$smsUrl, [
'mobile' => $to,
'message' => $content,
], [
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "api:key-$this->apikey",
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "api:key-{$this->apikey}",
]);
$this->setResult($result);
}

public function sendVoiceCode($to, $code)
{
$url = 'http://voice-api.luosimao.com/v1/verify.json';
$result = $this->curlPost($url, [
$result = $this->curlPost(self::$voiceCodeUrl, [
'mobile' => $to,
'code' => $code,
], [
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "api:key-$this->voiceApikey",
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "api:key-{$this->voiceApikey}",
]);
$this->setResult($result);
}
Expand Down

0 comments on commit 621ab03

Please sign in to comment.