You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
class DdAuth {
|
|
|
|
|
|
public function getToken($code) {
|
|
|
|
$params = array (
|
|
'app_key' => $this->appKey,
|
|
'method' => 'token.create',
|
|
'timestamp' => date('Y-m-d H:i:s'),
|
|
'v' => 2,
|
|
'param_json' => json_encode([
|
|
'code' => $code,
|
|
'grant_type' => 'authorization_code',
|
|
])
|
|
);
|
|
$params['sign'] = $this->createSign($params);
|
|
|
|
$url = $this->buildUrl($this->tokenUrl, $params);
|
|
$url = $this->transferChars($url);
|
|
|
|
$json = $this->curl($url);
|
|
$resp = json_decode($json, true);
|
|
return $resp['data'];
|
|
}
|
|
|
|
|
|
private function createSign($sysParams) {
|
|
ksort($sysParams);
|
|
|
|
$md5Str = '';
|
|
foreach ($sysParams as $key => $val) {
|
|
$md5Str .= $key . $val;
|
|
}
|
|
|
|
$md5Str = $this->appSecret . $md5Str . $this->appSecret;
|
|
return md5($md5Str);
|
|
}
|
|
|
|
|
|
private function buildUrl($url, $requestParams) {
|
|
$params = '';
|
|
foreach ($requestParams as $key => $val) {
|
|
$params .= $key . '=' . $val . '&';
|
|
}
|
|
$params = substr($params, 0 , -1);
|
|
|
|
$url = $url . '?' . $params;
|
|
|
|
return $url;
|
|
}
|
|
|
|
|
|
private function transferChars($url) {
|
|
return str_replace(['"', ' '], ['%22', '%20'], $url);;
|
|
}
|
|
} |