-
Notifications
You must be signed in to change notification settings - Fork 0
/
YouzanYunService.php
40 lines (34 loc) · 1.01 KB
/
YouzanYunService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Service;
use Exception;
use Youzan\Open\Token;
class YouzanYunService
{
protected $config = [];
public function __construct()
{
$this->config = [
'type' => 'self',
'kdtId' => '0000',
'clientId' => '00000',
'clientSecret' => '0000',
'api' => [
'version' => '3.0.0',
'getTrade' => 'youzan.trade.get',
'createPayQRCode' => 'youzan.pay.qrcode.create',
],
];
}
protected function getAccessToken()
{
$clientId = $this->config['clientId'];
$clientSecret = $this->config['clientSecret'];
$type = $this->config['type'];
$keys = [
'kdt_id' => $this->config['kdtId']
];
$accessToken = (new Token($clientId, $clientSecret))->getToken($type, $keys);
if (!isset($accessToken['access_token'])) throw new Exception('wrong server pay config');
return $accessToken['access_token'];
}
}