核心方法:
public IActionResult UserInfoCallBackAli()
{
var alipayClient = new DefaultAopClient(ConfigAli.ServerUrl,
ConfigAli.AppId,
ConfigAli.PrivateKey,
"json",
null,
"RSA2",
ConfigAli.AlipayPublicKey,
"UTF-8",
false);
var alipayRequest = new AlipaySystemOauthTokenRequest();
alipayRequest.Code = Request.Query["auth_code"];
alipayRequest.GrantType = "authorization_code";
var aliUser = new UsersAli();
try
{
var alipayResponse = alipayClient.Execute(alipayRequest);
if (!alipayResponse.IsError)
{
var requestUser = new AlipayUserInfoShareRequest();
try
{
var userinfoShareResponse = alipayClient.Execute(requestUser, alipayResponse.AccessToken);
if (!userinfoShareResponse.IsError)
{
initUserInfo(aliUser, userinfoShareResponse);
var db = DB.GetInstance();
var flag = db.Queryable<UsersAli>().Where(m => m.user_id == aliUser.user_id).Any();
if (!flag)
{
db.Insertable<UsersAli>(aliUser).ExecuteCommand();
ViewData["json"] = "入库成功";
}
ViewData["json"] = "存在记录不用入库";
db.Dispose();
}
}
catch(AopException ex)
{
System.IO.File.AppendAllText("log", ex.ErrorMsg + "\r\n");
ViewData["ex"] = "出错"+ ex.ErrorMsg;
}
}
}
catch(AopException ex)
{
System.IO.File.AppendAllText("log", ex.ErrorMsg + "\r\n");
ViewData["ex"] = "出错"+ ex.ErrorMsg;
}
return View();
}
 
其中用到的一个工具方法
private void initUserInfo(UsersAli aliUser,AlipayUserInfoShareResponse response)
{
aliUser.user_id = response.UserId;
aliUser.avatar = response.Avatar;
aliUser.nick_name = response.NickName;
aliUser.city = response.City;
aliUser.province = response.Province;
aliUser.gender = response.Gender;
aliUser.user_type = response.UserType;
aliUser.is_certified = response.IsCertified;
aliUser.is_student_certified = response.IsStudentCertified;
//aliUser.is_balance_frozen = userinfoShareResponse.isBalanceFrozen
//aliUser.address = userinfoShareResponse.address
//aliUser.area = userinfoShareResponse.area
//aliUser.business_scope = userinfoShareResponse.businessScope
//aliUser.cert_no = userinfoShareResponse.certNo
//aliUser.email = userinfoShareResponse.email
//aliUser.license_no = userinfoShareResponse.licenseNo
//aliUser.mobile = userinfoShareResponse.mobile
//aliUser.person_birthday = userinfoShareResponse.personBirthday
}
 

使用开源项目Alipay.AopSdk.Core完成支付宝网页登录的更多相关文章

  1. ASP.NET Core 使用 Alipay.AopSdk.Core 常见问题解答

    1.Alipay.AopSdk.Core.AopException:"您使用的私钥格式错误,请检查RSA私钥配置,charset = UTF-8" 出现这个问题,就是配置不正确.首 ...

  2. [最新].NET Core ORM 开源项目一览,持续更新

    截至2019-05-08共收集27个 .NET Core ORM 开源项目,38个 .NET ORM 开源项目. .NET Core ORM 开源项目收集地址:https://github.com/o ...

  3. ASP.NET Core 与支付宝开发文档

    一.目录 ASP.NET Core 2.0 使用支付宝PC网站支付 ASP.NET Core 2.0 支付宝当面付之扫码支付 常见使用问题解答 已有多个公司数个项目用本组件并上线,稳定使用. 二.项目 ...

  4. .NET平台开源项目速览(20)Newlife.Core中简单灵活的配置文件

    记得5年前开始拼命翻读X组件的源码,特别是XCode,但对Newlife.Core 的东西了解很少,最多只是会用用,而且用到的只是九牛一毛.里面好用的东西太多了. 最近一年时间,零零散散又学了很多,也 ...

  5. 积极参与开源项目,促进.NET Core生态社区发展

    今天早上在微信群里聊天聊到百度的SDK 已经支持.NET Core, 百度已经在3月份就支持了,想起当时还是我在他们的github上提的issue: https://github.com/Baidu- ...

  6. .NET Core微服务之开源项目CAP的初步使用

    Tip: 此篇已加入.NET Core微服务基础系列文章索引 一.CAP简介 下面的文字来自CAP的Wiki文档:https://github.com/dotnetcore/CAP/wiki CAP ...

  7. 【分享】Asp.net Core相关教程及开源项目

    入门 全新的ASP.NET:  https://www.cnblogs.com/Leo_wl/p/5654828.html 在IIS上部署你的ASP.NET Core项目: https://www.c ...

  8. 我发起了一个 .Net Core 平台上的 开源项目 ShadowDomain 用于 热更新

    大家好,  我发起了一个 .Net Core 平台上的 开源项目 ShadowDomain  用于 热更新 . 简单的说, 原理就是 类似 Asp.net 那样 让 当前 WebApp 运行在一个 A ...

  9. 这些 .Net and Core 相关的开源项目,你都知道吗?(持续更新中...)

    最近更新时间2017-12-28 序列化 Json.NET http://json.codeplex.com/Json.Net是一个读写Json效率比较高的.Net框架.Json.Net 使得在.Ne ...

随机推荐

  1. Egret的按钮事件处理

    首先要在exml内要设置有对应按钮的ID 2,编写TypeScript脚本: public mybutton:eui.Button; 函数内部:this.mybutton.addEventListen ...

  2. margin与padding的bug

    1.在页面布局时,值对于块元素来说,相邻的两个兄弟块元素间的margin-top与上一个兄弟的margin-bottom重合时, 解决办法:对其中一个块元素中设置    display:inline- ...

  3. vue中实现图片全屏缩放预览,支持移动端

    # 安装 npm install vue-photo-preview --save # 引入 import preview from 'vue-photo-preview' import 'vue-p ...

  4. django介绍及路由系统

    第一:Python的web框架介绍 Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引 ...

  5. Oracle报错ORA-12516 TNS:listener could not find available handler with matching protocol stack

    解决办法定位原因-- 以sysdba身份登陆PL/SQL sqlplus / as sysdba;-- 查看当前连接进程数SQL>select count(*) from v$process;- ...

  6. js原型与继承

    demofunction Fun(){}
var foo = new Fun();foo.__proto__ === Fun.prototype 摘要 1.js本身不提供类实现,es6引入了class ...

  7. 简单工厂模式demo

    1. 简单工厂模式 domain的接口 public interface Color{ public void display(); } red public Class Red implements ...

  8. HBuilder git合作-从Git Hub Clone项目

    1.Clone项目 打开”Git Respository"视图,选“Clone a Git Respository" 2.为了能正确pull项目,所有队员都必须做以下配置(其始只是 ...

  9. H5音乐自动播放ios//禁止安卓手机图片点击

    定义音乐按钮 <div id="music-btn" class="o-play" style="width: 24px; height: 24 ...

  10. Spring Cloud Eureka 使用 IP 地址进行服务注册

    默认情况下,Eureka 使用 hostname 进行服务注册,以及服务信息的显示,那如果我们使用 IP 地址的方式,该如何配置呢?答案就是eureka.instance.prefer-ip-addr ...