1. 登录支付宝开放平台(蚂蚁金服开放平台)。https:
2. 进入开发者中心,创建应用,并申请应用上线。
3. 签约-获取会员信息功能。
4. 设置 授权回调路径 和 接口加签方式(选择RSA2(SHA256)密钥) 密钥 生成 需要下载支付宝提供的生成工具。 下载工具链接 : https:
5. 下载支付宝SDK https:
6. 获取code。
<?php
namespace Admin\Controller;
use Think\Controller;
class AliclubController extends Controller {
public function index(){
$appid ='生活号应用的appid';
$url='**************';
$redirect_uri = urlencode($url);
$url ='https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id='.$appid.'&scope=auth_base&redirect_uri='.$redirect_uri;
header("Location:".$url);
}
public function receive(){
header("Content-type:text/html;charset=utf-8");
vendor('alipayclub.AopSdk');
vendor('alipayclub.aop.AopClient');
vendor('alipayclub.aop.request.AlipaySystemOauthTokenRequest');
vendor('alipayclub.aop.request.AlipayUserUserinfoShareRequest');
$code = $_GET['auth_code'];
$appid = $_GET['appid'];
$rsaPrivateKey = "你的应用私钥";
$alipayrsaPublicKey = "你的支付宝公钥";
$aop = new \AopClient();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $appid;
$aop->rsaPrivateKey = $rsaPrivateKey;
$aop->alipayrsaPublicKey = $alipayrsaPublicKey;
$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";
var_dump($result);exit;
$access_token = $result->$responseNode->access_token;
$request_a = new \AlipayUserInfoShareRequest();
$result_a = $aop->execute ($request_a,$access_token);
$responseNode_a = str_replace(".", "_", $request_a->getApiMethodName()) . "_response";
var_dump($result_a);
$user_id = $result_a->$responseNode_a->user_id;
$headimgurl = $result_a->$responseNode_a->avatar;
$nick_name = $result_a->$responseNode_a->nick_name;
}
}