app申请授权如何办理支付宝官方文档https://docs.open.alipay.com/...APICloud文档https://docs.apicloud.com/Cli...根据文档整理php代码仅供参考获取授权数据信息最小版本授权请求参数返回apiname=com.alipay.account.auth&app_id=2016051801417322&app_name=mc&auth_type=AUTHACCOUNT&biz_type=openservice&method=alipay.open.auth.sdk.code。get&pid=2088221932028920&product_id=APP_FAST_LOGIN&scope=auth_user&sign_type=RSA&target_id=61ef37122e104d148c855d14e9bf90e2&sign=m6K7Dz4CxPAgLn2uwIjGSmgRcOBYtHcqaYqLc85/C6PCqoIu6tUHDmx5/hb0xy+dMCdQoFcQWKRGzBl040g/6avD/PhOUSUi9Cmtd2HxSzEEjk7LuFn9QrpAmcM7/tub+K/G/2rQp9ce8FY2RCbJ/sFDA09M5B+2gqzy9Qkc5fE=/***获取授权数据*/publicfunctionget_auth_data(){$appid='1111';//商家账户appid$sign_type='RSA2';$targetId=mt_rand(000000,999999);//此处随机访问$data=['apiname'=>'com.alipay.account.auth','method'=>'alipay.open.auth.sdk.code.get','app_id'=>$appid,//支付宝分配给开发者的应用ID'app_name'=>'mc','biz_type'=>'openservice','pid'=>'11111',//已签约的支付宝账户对应的支付宝唯一用户号,由2088开头的16位纯数字组成,登录你的支付宝用户信息,可以找到'product_id'=>'APP_FAST_LOGIN',//标识授权类型,取值range:AUTHACCOUNT代表授权;LOGIN表示登录'scope'=>'kuaijie','target_id'=>$targetId,//商户标识用户授权请求的ID,该值在商户端应该是唯一的'auth_type'=>'AUTHACCOUNT',//授权类型AUTHACCOUNT:AuthorizationLOGIN:login'sign_type'=>$sign_type,//签名算法类型];//读取配置信息$aop=new\AopClient;$aop->gatewayUrl="https://openapi.alipay.com/gateway.do";$aop->appId='1111111';//支付宝分配给开发者的AppID$aop->rsaPrivateKey='1111111';//支付宝私钥$aop->format="json";$aop->charset="UTF-8";$aop->signType="RSA2";$aop->alipayrsaPublicKey='1111111';//支付宝公钥$sign=$aop->generateSign($data,$sign_type);//生成sing这里用到的打包好的支付宝demo$sign=urlencode($sign);ksort($数据);$str='';foreach($dataas$k=>$v){$str.=$k.'='.$v.'&';}$str.='sign='.$sign;/*var_dump($str);退出;*/$str.='sign='.$sign;/*var_dump($str);exit;*/return$str;//返回前端进行授权处理!}如果前端没有提供上面第二种方案/***获取授权数据**/publicfunctionget_data(){$targetId=mt_rand(000000,999999);$data=['appId'=>'1111',//商户账号appid'targetId'=>$targetId,//商户ID'partner'=>'1111',//支付宝唯一用户号'rsaPriKey'=>'1111',//商户私钥'authType'=>'AUTHACCOUNT',//AUTHACCOUNT:AuthorizationLOGIN:login'rsa2'=>true,signaturemethod];返回$数据;}前端授权会得到这样一个回调数据返回结果示例resultStatus=9000memo="Processingsucceeded"result="success=true&auth_code=d9d1b5acc26e461dbfcb6974c8ff5E64&result_code=200&user_id=2088003646494707"然后调用alipay.system.oauth.token获取授权令牌接口使用文档https://docs.open.alipay.com/...functionauth_user($uid,$authorization_code=''){$config=$config->toArray()[0];$aop=new\AopClient();$aop->gatewayUrl='https://openapi.alipay.com/gateway.do';$aop->appId='111111';//支付宝分配给开发者的AppID$aop->rsaPrivateKey='11111';//支付宝私钥$aop->alipayrsaPublicKey='11111';//支付宝公钥$aop->apiVersion='1.0';$aop->signType='RSA2';$aop->postCharset='UTF-8';$aop->format='json';$request=new\AlipaySystemOauthTokenRequest();$request->setGrantType("authorization_code");//当值为authorization_code时,表示用code交换;当值为refresh_token时,表示用refresh_token交换$request->setCode($authorization_code);//包含的授权码前端返回的数据,用户授权应用后,他得到TS//$request->setRefreshToken("12121212121");//刷新refreshtoken,这是上次交换accesstoken时得到的。参考refresh_token字段和输出参数的代码校验选择一个$result=$aop->execute($request);$responseNode=str_replace(".","_",$request->getApiMethodName())。“_回复”;$resultCode=$result->$responseNode->code;if(!empty($resultCode)&&$resultCode==10000){$alipay_user_id=$result['user_id'];//获取用户唯一的支付宝IDreturnself::memeber_update($uid,$alipay_user_id);//将其保存在您的数据中}else{returnfalse;}}然后剩下的就是大家自由发挥和加点研究了。网页版只有h5授权页面在支付宝客户端使用,否则会报错官方文档https://docs.alipay.com/fw/ap...也可以获取auth_code/**获取授权data**/publicfunctionget_auth_url(){$appid='11111'//开发者应用的app_id$redirect_uri='http://www.baidu.com/api/authnotify';//回调页面为转义url链接(url必须以http或https开头),例如:http%3A%2F%2Fexample.com开发者在请求前需要到开发者中心对应的应用中配置授权回调地址。$redirect_uri=UrlEncode($redirect_uri);$application_type='MOBILEAPP';//$url="https://openauth.alipay.com/oauth2/appToAppBatchAuth.htm?app_id={$appid}&application_type={$application_type}&redirect_uri={$redirect_uri}";返回$网址;}在回调地址页面得到如下结果{"alipay_system_oauth_token_response":{"access_token":"111","user_id":"111","alipay_user1_1":","expires_in":300,"re_expires_in":300,"refresh_token":"11"},"sign":"1111"}
