支付宝获取页面静态授权
<?phpif(empty($_GET['auth_code'])){echo 'window.location.href = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2016112703399275&scope=auth_base&redirect_uri=https://group.gre
·
<?php
if(empty($_GET['auth_code'])){
echo '<script>window.location.href = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2016112703399275&scope=auth_base&redirect_uri=https://group.greenmangodata.com/gpd.php";</script>';
}else{
$pri_key=<<<END
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAvKixX4XSpfdv0uYg0h5TezeFY00L7Nj
n0aXlKaofCwYYn3tFS/rNgKypyL5bdE/zun3QJMx6+lcefP
PWBRHJ2LzgaJGnH4XolKxUByW2XUL+AOWIfX02NeQMVt87m
iinNNdiP4zeS5iF8o0ul+BWZgXcoXJcVngDuE2BtsSnPwMv
WT67hjaFtW5N2+32opZzqOrBpXBxyLbuiI7F+IfbZPejCil
AEwxFkgYbIcI3wsTjy0v5jXMZcjFWBAGEuXUrUe97aMDdkK
+LyGQcL7xblr83PxvpukZOXKfoUD7BGs22cC9Hpd9Q9/sKA
z84L7a6rfFl8XCHoZ0Ll6Yuj+Kn8QIDAQABAoIBAEdPbFwy
9UCOmtIY8mb514xHnD/Aq7VG97ki/9AT4dAE6eG+cp8Zmfv
9R9/9NAxu/C2NyNNgB0wBCiEo+cjIxIcMPbbI92bO8u7fhJ
N/CcOOwvwLxt/IKGmOXauojZrjqvAqSZTD5nKkoFziSK5Xu
dCufor38zcr/hv4EAPJqX4DS9iPnt3Eym1KT+nVla1uuIKZ
EvPWyDz37r1T0zC8sQU1m2FROk7ojJvWcUYktknk+VIpSRV
ccLsG2cY6FnJgXD/O9M50iFKWjGp3TwGFTawaW40GOqngVI
bscX5Ly+GKmYPPjtW6ceD+YNtSEf3/i6c6MeNuV2/Q3Z0On
PEoIZECgYEA5ruhJPOqLGgzIPw8/7Ic54GXvM1EwboF4iAU
gCKQCF5UAkQaj+8Ma2035/Zf3eTPoks4D7WZyZG/Iedt+/e
0Lm+0nogoHtIU/S878zspQo5bkYwkQ4LzO7S2W4G1KZ//Cw
6+EhqUjBF/D+013AjgjsTKAZ+TiIiTbytW14nX3ScCgYEA0
VGPn0e7WNNSGtlvFBeTUlnSXLepbx6axVY4tPw0vKSaHUqz
lc67pqza9iZnOW6P/QOLOEX/B/S0n7NgBXc8T26TxbbKhwg
Hp9g9bu4qBwlhiutKkxN0UwaDN5/QNtHriE1MziWhlLUK5q
51B34qcMp2dUBK7FmPvBvTD24osScCgYBizbYTvMQCgBxk4
567X+pAuJ3hm4T18FLUoiglNqe27a3Lyp4VRKhs2Dg4fKhQ
vMqtFMjM8VcJmf/e5NuUKl5eBDe0K1oC2LNkN/XUEmF4vr0
3dmuQ/WJrDteIF+McEAeHFKkP15IE6PkgONP3hVWjzWEzkM
H8lX+M+2IUqlJlwQKBgD/A4Ma5uWU3kAVffoaXG6b0dq8Iv
ZF7t9YtCb6OJp3iYJJVY1dYjS0Z7uMUFVKXy0Fb5/Zu01uf
+7e8kZ14kKT84ANTRmJUXsiPgz6bSa+0+sGuIpujTEXRcPv
rMCbSTzPHn4IWUh2R+s0CC+EJW3HZKLVTrL5KFQ5NRz6m5b
v3AoGAMgduS1HH/Zmobgj7HTw3PLqxNmGDtq6vikc2cxbF4
Y5elQzEyGzGcwLg8BEU9MMaVHq8M4wp55DHXPwFtcH6LXGA
SqizNbGuPWluppQloIUk7HvJzEQKO8pGaadhKdr/9n+cGSp
f8VSAtwlH+xLVwnTyf87ngoTDoDzcEo=
-----END RSA PRIVATE KEY-----
END;
// 定义AliPriKey为支付宝青芒服务商私钥
define("AliPriKey",$pri_key);
function alipay_native_request(array $Params, string $Method)
{
$Params["charset"] = "utf-8";
$Params["format"] = "JSON";
$Params["method"] = $Method;
$Params["sign_type"] = "RSA2";
$Params["timestamp"] = gmdate("Y-m-d H:i:s");
$Params["version"] = "1.0";
ksort($Params); $Params = array_filter($Params);
$SignStr = urldecode(http_build_query($Params));
if(openssl_sign($SignStr, $Sign, AliPriKey, OPENSSL_ALGO_SHA256) != true) return false;
$Params["sign"] = base64_encode($Sign);
$hCurl = curl_init("https://openapi.alipay.com/gateway.do?".http_build_query($Params));
curl_setopt($hCurl, CURLOPT_RETURNTRANSFER, true);
$JsonArr = json_decode(curl_exec($hCurl), true);
curl_close($hCurl);
return $JsonArr;
}
$data=array();
$data["app_id"] = "2016112703399276";
$data['code']=$_GET['auth_code'];
$data["grant_type"] = "authorization_code";
header("Content-type:text/html;charset=gb2312");
$rst=array();
$rst=alipay_native_request($data, "alipay.system.oauth.token");
if(empty($rst['alipay_system_oauth_token_response'])){
$data=array();
$data['status']=0;
$data['msg']="fail";
echo json_encode($data);
exit;
}else{
$data=array();
$data['status']=1;
$data['user_id']=$rst['alipay_system_oauth_token_response']['user_id'];
echo json_encode($data);
exit;
}
}
?>
更多推荐
所有评论(0)