Abstract.php
1.48 KB
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
41
42
43
44
<?php
class YHMAuth_Package_Alimobile_Abstract {
/**
* 通过token获取用户信息,用于支付宝快捷登陆
*/
protected function reqUserInfoByToken($token) {
$client = new YHMAuth_Package_Alimobile_Sdk_MobileClient();
require_once 'YHMAuth/Package/Alimobile/Sdk/request/MobileLoginUserinfoRequest.php';
$req = new MobileLoginUserinfoRequest();
$req->setToken($token);
return $client->execute($req);
}
/**
* 获取长短token,有两种方式,一种通过授权码获取,一种通过$refreshToken(即长token)来获取。
* @param unknown_type $code
* @param unknown_type $refreshToken
* @param unknown_type $grantType refresh_token|authorization_code
*/
protected function reqOauthToken($code, $refreshToken, $grantType) {
require_once "YHMAuth/Package/Alimobile/Sdk/request/AlipaySystemOauthTokenRequest.php";
$client = new YHMAuth_Package_Alimobile_Sdk_AlipayClient();
$req = new AlipaySystemOauthTokenRequest();
$req->setCode($code);
$req->setRefreshToken($refreshToken);
$req->setGrantType($grantType);
return $client->execute($req);
}
/**
* 通过短token获取用户信息
* @param string $accessToken
*/
protected function reqAlipayUserinfo($auth_token) {
require_once 'YHMAuth/Package/Alimobile/Sdk/request/AlipayUserUserinfoShareRequest.php';
$client = new YHMAuth_Package_Alimobile_Sdk_AlipayClient();
$req = new AlipayUserUserinfoShareRequest();
$req->setAuthToken($auth_token);
return $client->execute($req);
}
}