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
原文地址:https://www.cnblogs.com/maxjian/p/10790361.html