获取支付宝受权用户信息

登陆 支付宝开放平台,建立应用json

进入应用api

在应用信息里设置两处,受权回调只须要到域名便可。app

接口加签方式以下图code

使用“支付宝密钥生成器”生成,以下图orm

将公钥复制到 接口加签方式 的公钥字符。htm

 

程序:blog

String auth_code = context.Request.QueryString["auth_code"];
String stateStr = String.Empty;
if (String.IsNullOrEmpty(auth_code)) //若是为空表示要获取
{
String ParkID = context.Request.QueryString["sjh"];
String DeviceID = context.Request.QueryString["deviceid"];
String PayModel = context.Request.QueryString["paymodel"];//支付方式:场内(PayInPark)、出口(PayOutPark)token

stateStr = String.Format("sjh={0}&deviceid={1}&paymodel={2}", ParkID, DeviceID, PayModel);接口

//获取auth_code
String redirect_uri = "http://www.zftong.cn/Cn.Ubingo/AlipayAuth/GetAlipayAuth.ashx";
redirect_uri = HttpUtility.UrlEncode(redirect_uri);
String accessUrl = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id={0}&scope=auth_base&redirect_uri={1}&state={2}";
String accUrl = String.Format(accessUrl, AlipayConfig.APP_ID, redirect_uri, DESEncrypt.Encrypt(stateStr));
context.Response.Redirect(accUrl, true);
context.Response.End();
return;
}ip


IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AlipayConfig.APP_ID, AlipayConfig.Pri_Key, "json", "1.0", "RSA2", AlipayConfig.Pub_Key, "GBK", false);

//获取user_id和access_token
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
request.GrantType = "authorization_code";
request.Code = auth_code;
AlipaySystemOauthTokenResponse responseAccess_token = client.Execute(request);
//获取用户信息 注:在获取auth_code时,若是是auth_base没法获取用户信息,须要auth_user //AlipayUserInfoShareRequest requestUserinfo = new AlipayUserInfoShareRequest(); //AlipayUserInfoShareResponse responseUserinfo = client.Execute(requestUserinfo, responseAccess_token.AccessToken); //String UserName = responseUserinfo.NickName;

相关文章
相关标签/搜索