1.引入阿里的SDK

2. 搬一下java 的代码

DefaultProfile profile = DefaultProfile.GetProfile(
"cn-hangzhou", //默认
"YourAccessKeyID", //您的Access Key ID
"YourAccessKeySecret");

DefaultProfile profile = DefaultProfile.GetProfile(
"cn-hangzhou", //默认
"YourAccessKeyID", //您的Access Key ID
"YourAccessKeySecret");

//IClientProfile client = DefaultProfile.GetProfile("cn-hangzhou", KeyID, KeySecret);
IAcsClient client = new DefaultAcsClient(profile);

//您在控制台上创建的、采用RPBasic认证方案的认证场景标识, 创建方法:https://help.aliyun.com/document_detail/59975.html
string biz = "YourRPBasicBiz";

//认证ID, 由使用方指定, 发起不同的认证任务需要更换不同的认证ID
string ticketId = Guid.NewGuid().ToString();

//认证token, 表达一次认证会话
string token = null;

//-1 未认证, 0 认证中, 1 认证通过, 2 认证不通过
int statusCode = -1;

//1. 服务端发起认证请求, 获取到token
//GetVerifyToken接口文档:https://help.aliyun.com/document_detail/57050.htm

GetVerifyTokenRequest getVerifyTokenRequest = new GetVerifyTokenRequest();
getVerifyTokenRequest.Biz = biz;
getVerifyTokenRequest.TicketId = ticketId;
getVerifyTokenRequest.Method = MethodType.POST;
var ss = new
{
Name= "张三",
IdentificationNumber = "330110201711110101",
IdCardFrontPic = "http://image-demo.img-cn-hangzhou.aliyuncs.com/example.jpg",
IdCardBackPic = "base64:///9j/4AAQSkZJRgABAQEASABIAAD/2..."
};
getVerifyTokenRequest.Binding = JsonConvert.SerializeObject(ss);
//通过binding参数传入业务已经采集的认证资料,其中姓名、身份证号为必要字段
//若需要binding图片资料,请控制单张图片大小在 2M 内,避免拉取超时
// getVerifyTokenRequest.setBinding("{\"Name\": \"张三\",\"IdentificationNumber\": \"330110201711110101\"}");
//友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败
// request.TemplateParamJson = "[{\"name\":\"Tom\", \"code\":\"123\"},{\"name\":\"Jack\", \"code\":\"456\"}]";

//GetEndpoints
// GetVerifyTokenResponse response = client.GetEndpoints(getVerifyTokenRequest);
// token = response.getData().getVerifyToken().getToken(); //token默认30分钟时效,每次发起认证时都必须实时获取

try
{//SetCredentialsProvider
// GetVerifyTokenResponse response = client.getAcsResponse(getVerifyTokenRequest);
GetVerifyTokenResponse response = client.GetAcsResponse(getVerifyTokenRequest);
// token = response.getData().getVerifyToken().getToken();
token = response.Data.VerifyToken.Token;//token默认30分钟时效,每次发起认证时都必须实时获取
}
catch (ServerException e)
{
Console.WriteLine(e.ErrorCode);
}

//2. 服务端将认证URL(带token)传递给H5前端
//3. H5前端跳转认证URL
//4. 用户按照认证H5流程页面的指引,提交认证资料
//5. 认证流程结束跳转指定的重定向URL(指定方法参看:https://help.aliyun.com/document_detail/58644.html?#H5Server)
//6. 服务端查询认证状态(建议以服务端调接口确认的为准)
//GetStatus接口文档:https://help.aliyun.com/document_detail/57049.html

GetStatusRequest getStatusRequest = new GetStatusRequest();

getStatusRequest.Biz = biz;
getStatusRequest.TicketId = ticketId;

try
{
GetStatusResponse response = client.GetAcsResponse(getStatusRequest);
statusCode = Convert.ToInt32(response.Data.StatusCode);
}
catch (ServerException e)
{
Console.WriteLine(e.ErrorCode);
}

//7. 服务端获取认证资料
//GetMaterials接口文档:https://help.aliyun.com/document_detail/57641.html

GetMaterialsRequest getMaterialsRequest = new GetMaterialsRequest();
getMaterialsRequest.Biz = biz;
getMaterialsRequest.TicketId = ticketId;
if (1 == statusCode || 2 == statusCode)
{
//认证通过or认证不通过
try
{
GetMaterialsResponse response = client.GetAcsResponse(getMaterialsRequest);
//后续业务处理
}
catch (ServerException e)
{
Console.WriteLine(e.ErrorCode);
}

}

3.未完待续

2.阿里实人认证 .net 准备工作2 转换demo的更多相关文章

  1. 阿里实人认证 .net 准备工作

    1.H5+服务端接入 认证方案 https://help.aliyun.com/document_detail/61362.html?spm=a2c4g.11186623.2.37.35247556k ...

  2. Asp.Net Core基于JWT认证的数据接口网关Demo

    近日,应一位朋友的邀请写了个Asp.Net Core基于JWT认证的数据接口网关Demo.朋友自己开了个公司,接到的一个升级项目,客户要求用Aps.Net Core做数据网关服务且基于JWT认证实现对 ...

  3. java 双因素认证(2FA)TOTP demo

    TOTP 的全称是"基于时间的一次性密码"(Time-based One-time Password).它是公认的可靠解决方案,已经写入国际标准 RFC6238. 很早就知道有这个 ...

  4. Cognos第三方用户认证(CustomJavaProvider)

    关于Cognos第三方用户认证(CustomJavaProvider)的demo网上的例子很多,当然最权威的你可以从Cognos安装的SDK中去探索,本文不详细的说明代码,主要说一下认证的处理过程,以 ...

  5. 新浪微博API Oauth2.0 认证

    原文链接: http://rsj217.diandian.com/post/2013-04-17/40050093587 本意是在注销账号前保留之前的一些数据.决定用python 爬取收藏.可是未登录 ...

  6. drf 认证、权限、限流、过滤、排序、分页器

    认证Authentication 准备工作:(需要结合权限用) 1. 需要使用到登陆功能,所以我们使用django内置admin站点并创建一个管理员. python manage.py creates ...

  7. CA认证_demo

    CA认证,即电子认证服务 [1]  ,是指为电子签名相关各方提供真实性.可靠性验证的活动. 证书颁发机构(CA, Certificate Authority)即颁发数字证书的机构.是负责发放和管理数字 ...

  8. DRF之三大认证

    一.用户认证Authorticatons 1.源码解析 第一步. 找入口 def dispatch(self, request, *args, **kwargs): # 1.首先我们进入的是APIVi ...

  9. drf三大组件之认证组件与权限组件

    复习 """ 视图家族 1.视图类:APIView.GenericAPIView APIView:作为drf的基础view:as_view()禁用csrf:dispatc ...

随机推荐

  1. char a[] = "hello world1"和char *p = "hello world2";的区别(转)

    转自:jianchi88 http://blog.csdn.net/jianchi88/article/details/6876405 #include<stdio.h> int main ...

  2. js调试工具Console命令详解——转

    一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...

  3. 【转】java中定义二维数组的几种写法

    原文链接 注:以下的 type[][] var 也可以这样申明 type var[][] type为数组的类型,var为变量名 写法一:行列固定的数组 //定义二维数组写法1 class Test { ...

  4. arch+win7 双系统启动引导

    笔者的电脑之前已经安装了win7,安装完arch后电脑中存在两个系统,因此需要引导连个系统. 1. 在安装arch时,一般都会安装grub.如果没有安装,则参考arch wiki中 grub2一节安装 ...

  5. freemarker基本入门教程

    copy自http://demojava.iteye.com/blog/800204 以下内容全部是网上收集: FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主 ...

  6. oracle数据库中修改已存在数据的字段

    在oracle中,如果已经存在的数据的某些列,假如要更换类型的话,有的时候是比较麻烦的, 会出现:ORA-01439: column to be modified must be empty to c ...

  7. 简单总结:以设计模式的角度总结Java基本IO流

    在总结 Java Basic IO 时,发现 java.io 包的相关类真心不少--.看到一堆"排山倒海"般的类,我想,唯有英雄联盟中小炮的台词才能表现此刻我的心情: 跌倒了没?崩 ...

  8. 微信开发之c#下获取jssdk的access_token

    获取access_token是调用微信JS接口的基础,只有得到了它才能得到我们需要的jsapi_ticket并生成签名,然后注入配置信息config. 微信官方文档我就不多做介绍,反正我是踩了不少坑. ...

  9. C#设置图片透明度

    逐个像素进行Alpha值的设置,网上其他的代码不能处理有透明背景的图片,因此要对Alpha.R.G.B均为0的透明色进行特殊处理,不做转换. private Bitmap SetImageOpacit ...

  10. Thinkpad R400无线网络一个都不见了!

    今天,我的Thinkpad R400无线网络一个都不见了,用手机测试,家里的无线网络正常.反复开关无线网络控制硬件开关,还是不好使,无线网络那个图标里面,并没有无线网络.上网搜索一下,发现小黑居然还有 ...