|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Toplan\PhpSms; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class AlidayuAgent |
|
7
|
|
|
* |
|
8
|
|
|
* @property string $appKey |
|
9
|
|
|
* @property string $secretKey |
|
10
|
|
|
* @property string $smsFreeSignName |
|
11
|
|
|
*/ |
|
12
|
|
|
class AlidayuAgent extends Agent |
|
13
|
|
|
{ |
|
14
|
|
|
public function sendSms($tempId, $to, array $data, $content) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->sendTemplateSms($tempId, $to, $data); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function sendContentSms($to, $content) |
|
20
|
|
|
{ |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function sendTemplateSms($tempId, $to, array $data) |
|
24
|
|
|
{ |
|
25
|
|
|
$sendUrl = 'https://eco.taobao.com/router/rest'; |
|
26
|
|
|
$params = [ |
|
27
|
|
|
'app_key' => $this->appKey, |
|
28
|
|
|
'v' => '2.0', |
|
29
|
|
|
'format' => 'json', |
|
30
|
|
|
'sign_method' => 'md5', |
|
31
|
|
|
'method' => 'alibaba.aliqin.fc.sms.num.send', |
|
32
|
|
|
'timestamp' => date('Y-m-d H:i:s'), |
|
33
|
|
|
'sms_type' => 'normal', |
|
34
|
|
|
'sms_free_sign_name' => $this->smsFreeSignName, |
|
35
|
|
|
'sms_param' => json_encode($data), |
|
36
|
|
|
'rec_num' => $to, |
|
37
|
|
|
'sms_template_code' => $tempId, |
|
38
|
|
|
]; |
|
39
|
|
|
$params['sign'] = $this->generateSign($params); |
|
40
|
|
|
$result = $this->curl($sendUrl, $params, true); |
|
41
|
|
|
$this->genResult($result, 'alibaba_aliqin_fc_sms_num_send_response'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function voiceVerify($to, $code) |
|
45
|
|
|
{ |
|
46
|
|
|
// remain discussion |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function genResult($result, $callbackName) |
|
50
|
|
|
{ |
|
51
|
|
|
if ($result['response']) { |
|
52
|
|
|
$result = json_decode($result['response'], true); |
|
53
|
|
|
if (isset($result[$callbackName]['result']) && $result[$callbackName]['result']['err_code'] === '0') { |
|
54
|
|
|
$this->result['success'] = true; |
|
55
|
|
|
|
|
56
|
|
|
return; |
|
57
|
|
|
} elseif (isset($result['error_response'])) { |
|
58
|
|
|
$this->result['info'] = $result['error_response']['msg'] . '|sub_msg:' . $result['error_response']['sub_msg'] . '|result:' . json_encode($result ?: ''); |
|
59
|
|
|
$this->result['code'] = $result['error_response']['code'] . '_' . $result['error_response']['sub_code']; |
|
60
|
|
|
|
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
$this->result['info'] = '请求失败'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function generateSign($params) |
|
68
|
|
|
{ |
|
69
|
|
|
ksort($params); |
|
70
|
|
|
|
|
71
|
|
|
$stringToBeSigned = $this->secretKey; |
|
72
|
|
|
foreach ($params as $k => $v) { |
|
73
|
|
|
if (is_string($v) && '@' !== substr($v, 0, 1)) { |
|
74
|
|
|
$stringToBeSigned .= "$k$v"; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
unset($k, $v); |
|
78
|
|
|
$stringToBeSigned .= $this->secretKey; |
|
79
|
|
|
|
|
80
|
|
|
return strtoupper(md5($stringToBeSigned)); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|