mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\PrintModule\Pdd;
|
|
|
|
use GuzzleHttp\Client;
|
|
use Illuminate\Support\Facades\Log as LogFile;
|
|
|
|
class Ktt
|
|
{
|
|
protected $clientId = '24f25877aca447c5830a6aa896301d5e';
|
|
protected $clientSecret = '59b6f4bd402c6423878a8f4ef1bde28359c1f05a';
|
|
protected $callBackUrl = 'http://erp.chutang66.com/pdd/ship';
|
|
|
|
public function auth($code)
|
|
{
|
|
$accessToken = $this->getAccessTokenWithCode($code);
|
|
LogFile::info('电子面单应用授权: ' . json_encode($accessToken, 256));
|
|
}
|
|
|
|
protected function getAccessTokenWithCode($code)
|
|
{
|
|
$type = 'pdd.pop.auth.token.create';
|
|
$res = $this->doRequest($type, ['code' => $code]);
|
|
|
|
return $res['pop_auth_token_create_response'];
|
|
}
|
|
|
|
public function doRequest($type, $appendParams = [], $url = 'https://gw-api.pinduoduo.com/api/router')
|
|
{
|
|
$publicParams = [
|
|
'type' => $type,
|
|
'client_id' => $this->clientId,
|
|
'timestamp' => time()
|
|
];
|
|
$publicParams = array_merge($publicParams, $appendParams);
|
|
$publicParams['sign'] = $this->getSign($publicParams);
|
|
|
|
return $this->formDataPostRequest($url, $publicParams);
|
|
}
|
|
|
|
protected function getSign($params)
|
|
{
|
|
ksort($params);
|
|
$str = '';
|
|
foreach ($params as $key => $val) {
|
|
$str .= $key . $val;
|
|
}
|
|
$str = $this->clientSecret . $str . $this->clientSecret;
|
|
|
|
return strtoupper(md5($str));
|
|
}
|
|
|
|
protected function formDataPostRequest($url, $params)
|
|
{
|
|
$method = 'POST';
|
|
$headers = [
|
|
'headers' => ['Content-type' => 'application/x-www-form-urlencoded;charset=UTF-8'],
|
|
'form_params' => $params
|
|
];
|
|
$res = (new Client())->request($method, $url, $headers);
|
|
return json_decode($res->getBody()->getContents(), true);
|
|
}
|
|
}
|