KimhillZhang  

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

进入应用

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

接口加签方式如下图

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

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

 

程序:

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;

posted on   KimhillZhang  阅读(9647)  评论(0编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
 
点击右上角即可分享
微信分享提示