马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

获取支付宝授权用户信息

[复制链接]
查看2333 | 回复2 | 2019-10-12 10:22:11 | 显示全部楼层 |阅读模式

登录 支付宝开放平台,创建应用

102211lhl5h25elewerk3m.png

进入应用

102212ytdtqmm8isqqqiiz.png

在应用信息里设置两处,授权回调只需要到域名即可。

接口加签方式如下图

102212tgzgx560hy5y55z5.png

利用“支付宝密钥生成器”生成,如下图

102213o4cv8xa6p0zjxbg2.png

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

程序:

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)

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;
}


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;







来源:https://www.cnblogs.com/KimhillZhang/p/11551848.html
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
mmm123 | 2019-10-17 13:25:49 | 显示全部楼层
获取支付宝授权用户信息 [复制链接]
[url=http://www.pimjz.com/m/]北京白癜风哪治的好[/url]
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则