支付宝小程序登陆

https://openclub.alipay.com/read.php?tid=7395&fid=66php

上面是官方案例json

直接到第二步,引入框架tp3,会有冲突 C 由于支付宝SDK里面也定义了一个C,把支付宝的C随便改一下,没有影响的api

直接引用app

vendor('AlipaySDK.AopSdk');

1.获取access_token  https://docs.open.alipay.com/api_9/alipay.system.oauth.token框架

php示例:post

$aop = new AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = 'your app_id';
$aop->rsaPrivateKey = '请填写开发者私钥去头去尾去回车,一行字符串';
$aop->alipayrsaPublicKey='请填写支付宝公钥,一行字符串';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='GBK';
$aop->format='json';
$request = new AlipaySystemOauthTokenRequest ();
$request->setGrantType("authorization_code");
$request->setCode("4b203fe6c11548bcabd8da5bb087a83b");
$request->setRefreshToken("201208134b203fe6c11548bcabd8da5bb087a83b");
$result = $aop->execute ( $request); 

$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";
} else {
echo "失败";
}

{
    "alipay_system_oauth_token_response": {
        "user_id": "2088102150477652",
        "access_token": "20120823ac6ffaa4d2d84e7384bf983531473993",
        "expires_in": "3600",
        "refresh_token": "20120823ac6ffdsdf2d84e7384bf983531473993",
        "re_expires_in": "3600"
    }
}

2.获取用户信息  https://docs.open.alipay.com/api_2/alipay.user.info.sharecode

$aop = new AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = 'your app_id';
$aop->rsaPrivateKey = '请填写开发者私钥去头去尾去回车,一行字符串';
$aop->alipayrsaPublicKey='请填写支付宝公钥,一行字符串';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='GBK';
$aop->format='json';
$request = new AlipayUserInfoShareRequest ();
$result = $aop->execute ( $request , $accessToken ); 

$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";


{
    "alipay_user_info_share_response": {
        "code": "10000",
        "msg": "Success",
        "user_id": "2088102104794936",
        "avatar": "http://tfsimg.alipay.com/images/partner/T1uIxXXbpXXXXXXXX",
        "province": "安徽省",
        "city": "安庆",
        "nick_name": "支付宝小二",
        "is_student_certified": "T",
        "user_type": "1",
        "user_status": "T",
        "is_certified": "T",
        "gender": "F"
    },
    "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}
相关文章
相关标签/搜索