| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- /**
- * 支付宝授权服务
- * Class AuthService
- * Author SHUI
- * @package alipayAop
- */
- define('AOP_SDK_DIR', __DIR__);
- require_once AOP_SDK_DIR . '/AopSdk.php';
- require_once AOP_SDK_DIR . '/AlipayConfig.php';
- require_once AOP_SDK_DIR . '/aop/AopClient.php';
- require_once AOP_SDK_DIR . '/aop/SignData.php';
- require_once AOP_SDK_DIR . '/aop/request/AlipaySystemOauthTokenRequest.php';
- class AuthService {
- public function getAlipayOauthUrl() {
- $param = [
- 'apiname' => 'com.alipay.account.auth',
- 'method' => 'alipay.open.auth.sdk.code.get',
- 'app_id' => AlipayConfig::APPID,
- 'app_name' => 'mc',
- 'biz_type' => 'openservice',
- 'pid' => AlipayConfig::PID,
- 'product_id' => 'APP_FAST_LOGIN',
- 'scope' => 'kuaijie',
- 'target_id' => md5(uniqid()),
- 'auth_type' => 'AUTHACCOUNT',
- 'sign_type' => 'RSA2',
- ];
-
- $aopClient = new \AopClient;
- $paramStr = $aopClient->getSignContent($param);
- $param['sign'] = $aopClient->alonersaSign($paramStr, AlipayConfig::APPPRIVATEKEY, 'RSA2');
- return $aopClient->getSignContentUrlencode($param);
- }
- public function getUseridFromAlipay($code) {
- $aop = new \AopClient;
- $aop->gatewayUrl = AlipayConfig::GATEWAY;
- $aop->appId = AlipayConfig::APPID;
- $aop->rsaPrivateKey = AlipayConfig::APPPRIVATEKEY;
- $aop->alipayrsaPublicKey = AlipayConfig::ALIPAYPUBLICKEY;
- $aop->apiVersion = '1.0';
- $aop->signType = 'RSA2';
- $aop->postCharset = 'UTF-8';
- $aop->format = 'json';
- $request = new \AlipaySystemOauthTokenRequest;
- $request->setGrantType('authorization_code');
- $request->setCode($code);
- $result = $aop->execute($request);
- $responseNode = str_replace('.', '_', $request->getApiMethodName()) . '_response';
- $userid = property_exists($result, $responseNode) ? $result->$responseNode->user_id : 0;
- return $userid;
- }
- }
|