Abstract.php 1.48 KB
<?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);
	}
	
}