topthinkcloud / client
v1.1.6
2024-11-22 13:37 UTC
Requires
- firebase/php-jwt: ^6.1
- php-http/cache-plugin: ^1.7.1
- php-http/client-common: ^2.3
- php-http/discovery: ^1.12
- php-http/httplug: ^2.2
- php-http/multipart-stream-builder: ^1.1.2
- psr/cache: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^1.0
- symfony/options-resolver: >=6.4
- symfony/polyfill-php80: ^1.17
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- http-interop/http-factory-guzzle: ^1.0
- topthink/framework: ^6.0
- yunwuxin/think-notification: ^3.0
- dev-master
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.38
- v1.0.37
- v1.0.36
- v1.0.35
- v1.0.34
- v1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2024-12-22 14:12:55 UTC
README
使用方法
用户授权
$options = new \TopThinkCloud\Options([
'client_id'=>'',
'client_secret'=>'',
]);
$client = new \TopThinkCloud\Client($options);
$oauth = new \TopThinkCloud\OAuth($client);
//获取授权地址
$url = $oauth->getAuthorizeUrl(false); //false 为PC端授权,true为移动端或者单页应用授权
// 引导用户跳转到授权地址,用户授权后会跳转到回调地址,并且会带上code参数
//使用code换取access_token
$accessToken = $oauth->getAccessToken('authorization_code', [
'code' => $code,
]);
//使用access_token获取用户信息
$userInfo = $client->authenticate($accessToken)->currentUser()->info();
服务端调用
$options = new \TopThinkCloud\Options([
'client_id'=>'',
'client_secret'=>'',
]);
$client = new \TopThinkCloud\Client($options);
$oauth = new \TopThinkCloud\OAuth($client);
//使用 Client credentials grant 获取 access_token
$accessToken = $oauth->getAccessToken();
//使用access_token调用api
//创建订单
$result = $client->authenticate($accessToken)->charge()->create([
'order_no' => '', //订单号,必填
'subject' => '', //订单标题,必填
'amount' => '', //订单金额,必填,单位:分
'user_id' => '', //用户ID,为顶想云用户的ID,选填
'return_url' => '', //支付成功后跳转的地址,选填
'notify_url' => '', //支付成功后的回调地址,选填
'revoke_url' => '', //订单撤销后的回调地址,选填
]);
//可以弹出一个新窗口 打开 $result['pay_url'] 进行支付
//关于回调地址的说明
//回调会以post的方式发送数据到回调地址,数据格式为
// {
// "trade_no": "xxxxxx",//交易号
// "order_no": "xxxxx",//订单号
// "amount": 10000, //支付金额
// "sign": "xxx", //签名 可以使用 $client->charge()->verify($data) 来验证签名
// }
//查询订单
$result = $client->authenticate($accessToken)->charge()->query([
'order_no' => '', //订单号
'trade_no' => '', //交易号,二者选一
]);