大师请进---------------关于芝麻认证接口的问题请教

雄牛 2017-12-29 11:51:25

有个项目需要做人脸识别,接入芝麻认证,但报错了....



可是不明白那个request.BizNo是什么意思,
文档提示是一个入参,
biz_no String 是 一次认证的唯一标识,在商户调用认证初始化接口的时候获取 ZM201705173000000323200000189778

详见说明:
https://b.zmxy.com.cn/technology/openDoc.htm?relInfo=zhima.customer.certification.query@1.0@1.2&relType=API_DOC&LEFT_MENU_MODE=null#Seq_3

另外代码启动后提示错误
"Unknown object in GetInstance: Org.BouncyCastle.Asn1.DerInteger
参数名: obj"

指向如下的错误页(为芝麻sdk的DLL)
"
行 237: public static string ParseRSAPrivateKey(string privateKey)
行 238: {
行 239: RsaPrivateCrtKeyParameters privateKeyParam = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(privateKey)); //******出错行**********
行 240:
行 241: return string.Format("<RSAKeyValue><Modulus>{0}</Modulus><Exponent>{1}</Exponent><P>{2}</P><Q>{3}</Q><DP>{4}</DP><DQ>{5}</DQ><InverseQ>{6}</InverseQ><D>{7}</D></RSAKeyValue>",
"


代码如下:


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zmop.Api;
using Zmop.Api.Request;
using Zmop.Api.Response;
using Zmop.Api.Util;
namespace opensdk_dotnet4._0
{
class Program
{
//芝麻信用网关地址
private const string gatewayUrl = "https://zmopenapi.zmxy.com.cn/openapi.do";
//芝麻 RSA 公钥
private const string zhimaPublicKey = "***";//这里隐去了真实的key
//商户 RSA 私钥
private const string privateKey = "***";//这里隐去了真实的key
//数据编码格式
private const string charset = "UTF-8";
////芝麻分配给商户的 appId
private const string appId = "5010001";

public static void testZhimaCustomerCertificationQuery()
{
DefaultZmopClient client = new DefaultZmopClient(gatewayUrl, appId, privateKey, zhimaPublicKey,charset);
ZhimaCustomerCertificationQueryRequest request = new ZhimaCustomerCertificationQueryRequest();
request.SetChannel("apppc");
request.SetPlatform("zmop");
request.BizNo = "ZM201705173000000323200000189778"; //--------------必要参数-------这是什么意思---- ----
ZhimaCustomerCertificationQueryResponse response = client.Execute(request);
ZhimaCustomerCertificationQueryResponse resp = response;
}

static void Main(string[] args)
{
testZhimaCustomerCertificationQuery();
}
}
}
...全文
2180 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
雨不停雨 2018-09-05
  • 打赏
  • 举报
回复
你好,我是在芝麻分初始化授权的时候一直 check sign Fail! [sign=JiIBH/RquuNr1ORlUZIDUaP4uwZDCSOrAFdTet/BIKV7W4xT/8ytxgFuPnQanXpEnK+DQjrx5skqLNvex0xHGG6TUibqEa4j9TvfwRieHI4TG8JFkB6NkU6pbsphww38L94d9GU6HqSidsMQrWHbVRAn7kxaBEoTqkvXUJIxkpeeAibz/wGAudr47l/WJVtBvbjOTTWpCviXQnmbWnxH8m81k0bxE7GB13rhdvMVCK1ptav/u8RNKI00kgWfqFiG4c6MkgldDcHpwiNPWQGnS7Ej7+necxolUJr1IuqZQQV/oBFqjf8AHw7fDm1Ur+BSRmb5dTNsby7sMHkuMYMUfA==, signSourceData={"code":"10000","biz_no":"ZM201809053000000292900789035452","msg":"Success"}]
这是怎么回事?咱们的情况一样吗?
雄牛 2018-01-07
  • 打赏
  • 举报
回复
阿理的文档做的真的是很乱,而且腾X和阿L互相限制,导致用公众号要调用人脸识别,还要"从浏览器中打开", 然后再调起支付宝,然后再返回那个URL,最后再返回微信,用户要崩溃,最后功能是实现了,但还是只能换用腾X自己的人脸识别了.. 为了避免更多的人走弯路,把完整的公众号调用人脸的代码放出来,里面填上自己的key,如果不是APP调用的话,建议不要用...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Zmop.Api;
using Zmop.Api.Request;
using Zmop.Api.Response;
using System.Data;

namespace WeiXin_PcShare
{
    public partial class Face : System.Web.UI.Page
    {

	//以下代码仅用于微信公众号

        #region 公共定义

        //芝麻信用网关地址
        private const string gatewayUrl = "https://zmopenapi.zmxy.com.cn/openapi.do";
        //芝麻 RSA 公钥
        private const string zhimaPublicKey = "****";//填你真实的key
        //商户 RSA 私钥
        private const string privateKey = "********";//填你真实的key

        //数据编码格式
        private const string charset = "UTF-8";

        //芝麻分配给商户的 appId
        private const string appId = "3000000011";//********APPID 必须**********//填你真实的

        //产品码
        private static string bizNo = "";
        //用户码
        private static string openID = "";

        //定义取到的服务器人脸识别URL
        private static string checkFaceUrl = "";

        //取得姓名
        private static string userName = "";
        //取得身份证号
        private static string userCard = "";

        #endregion


        #region 公共芝麻信用方法

        //生成流水号
        public static string GetSerialNumber()
        {
            string SN = DateTime.Now.ToString("yyyyMMddHHmmssffff"); //18位
            return SN + "000000000001";
        }

        //取得姓名和身份证号
        public static void getNameCard()
        {
           // HttpContext.Current.Session["openid"] = "oOVYE0lbGniWsVc_Jes_u7-DO5aM";//测试代码,正式去除

            if (HttpContext.Current.Session["openid"] == null)
            {
                Pub.URL("Default.aspx");
            }

	//数据库取得用户名和身份证号
            string openids = HttpContext.Current.Session["openid"].ToString();
            if (!string.IsNullOrWhiteSpace(openids))
            {
                string sql = "Select top 1 Name,Card from  Member where  Openid='" + openids + "'";
                DataSet ds = DBHelper.GetDataSet(sql);
                if (ds != null && ds.Tables[0].Rows.Count >= 1)
                {
                    userName = ds.Tables[0].Rows[0][0].ToString();
                    userCard = ds.Tables[0].Rows[0][1].ToString();
                }
            }

        }

        //1.1发起认证初始化--取得BizNo
        public static void testZhimaCustomerCertificationInitialize()
        {
            ZhimaCustomerCertificationInitializeRequest request = new ZhimaCustomerCertificationInitializeRequest();
            //request.SetChannel("apppc");
            request.SetPlatform("zmop");
            request.TransactionId = GetSerialNumber();  //必要参数    30位长的不重复数       
            request.ProductCode = "w1010100000000002978";  //必要参数 --- 固定的产品码        
            request.BizCode = "FACE";  //必要参数             
            request.IdentityParam = "{\"identity_type\": \"CERT_INFO\", \"cert_type\": \"IDENTITY_CARD\", \"cert_name\": \"" + userName + "\", \"cert_no\":\""+userCard+"\"}";  //必要参数             
            //request.MerchantConfig = "{\"need_user_authorization\":\"false\"}";
            request.ExtBizParam = "{}";  //必要参数       

            DefaultZmopClient client = new DefaultZmopClient(gatewayUrl, appId, privateKey, zhimaPublicKey, charset);
            ZhimaCustomerCertificationInitializeResponse response = client.Execute(request);
            ZhimaCustomerCertificationInitializeResponse resp = response;
            //取得产品码
            if (response != null)
                bizNo = response.BizNo;
        }

        //2.1开始认证------取得sign签名URL
        public static void testZhimaCustomerCertificationCheck()
        {

            DefaultZmopClient client = new DefaultZmopClient(gatewayUrl, appId, privateKey, zhimaPublicKey, charset);
            ZhimaCustomerCertificationCertifyRequest request = new ZhimaCustomerCertificationCertifyRequest();
            request.SetChannel("apppc");
            request.SetPlatform("zmop");
            request.BizNo = bizNo;  //******** 必须********* 

            request.ReturnUrl = "http://www.taobao.com";  //完成后跳转地址,记得在此地址中做一个唤醒微信的schema,//填你真实的URL,支付宝验证人脸后返回的页面,可以是自己的页面       
            checkFaceUrl = client.generatePageRedirectInvokeUrl(request); //测试方法,用url生成二维码,然后用微信扫描后打开
        }

        //5.1发起认证查询,看用户是否已经做过实名,每一个实名的操作都会有一个不同的BizNo,这个要存起来.
        public static void testZhimaCustomerCertificationQuery()
        {
            DefaultZmopClient client = new DefaultZmopClient(gatewayUrl, appId, privateKey, zhimaPublicKey, charset);
            ZhimaCustomerCertificationQueryRequest request = new ZhimaCustomerCertificationQueryRequest();
            request.SetChannel("apppc");
            request.SetPlatform("zmop");
            request.BizNo = bizNo;  //必要参数             
            ZhimaCustomerCertificationQueryResponse response = client.Execute(request);
            ZhimaCustomerCertificationQueryResponse resp = response;
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            //取得姓名和身份号
            getNameCard();

            if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(userCard))
            {
                //1.1初始化并取得BizNo业务号
                testZhimaCustomerCertificationInitialize();

                //2.1取得服务器的认证URL,进入URL后,需要在浏览器中打开并调用支付宝完成人脸识别后,再唤起微信,并返回公众号个人中心
                testZhimaCustomerCertificationCheck();
                //判断URL并跳转
                if (!string.IsNullOrWhiteSpace(checkFaceUrl))
                    Response.Redirect(checkFaceUrl);
            }
            else
            {
               Pub.Msg("请完善好实名信息后,再做人脸识别!","RealNameBind.aspx");
            }
          
        }
       

    }
}
雄牛 2018-01-06
  • 打赏
  • 举报
回复
不好整,微信和支付宝互相限制,只能用腾讯的了...
  • 打赏
  • 举报
回复
这个我就不清楚了,我这边只是做了向芝麻信用请求token,然后将token什么的必须信息传送给移动端,移动端调相应的芝麻接口来进行人脸识别
雄牛 2017-12-30
  • 打赏
  • 举报
回复
我连上去了,不提示密钥问题,但提示无效的调用,查了一下资料,说是biz_no的问题,那这个biz_no从哪里取,如果是芝麻给的为什么它会提示我这个问题呢? 代码如下:

 //方法1
        public static void testZhimaCustomerCertificationQuery()
        {

            DefaultZmopClient client = new DefaultZmopClient(gatewayUrl, appId, privateKey, zhimaPublicKey, charset);
            ZhimaCustomerCertificationQueryRequest request = new ZhimaCustomerCertificationQueryRequest();
            request.SetChannel("apppc");
            request.SetPlatform("zmop");
            request.BizNo = "ZM201705173000000323200000189778";  //******** 必须********* 

            ZhimaCustomerCertificationQueryResponse response = client.Execute(request);
            ZhimaCustomerCertificationQueryResponse resp = response;
            if (response.Body != null)
                response.Body.ToString();
        }
引用 1 楼 starfd 的回复:
这个是zmopsdk帮你生成出来的(获取),下面是我接入的部分helper
        private static DefaultZmopClient GetZmopClient(ZmopSettingsSection zmop = null)
        {
            if (zmop == null)
            {
                zmop = ZmopSettingsSection.GetSection();
            }
            return new DefaultZmopClient(zmop.ServerUrl, zmop.AppId, zmop.PrivateKey, zmop.ZhimaPublicKey, zmop.Charset);
        }
        /// <summary>
        /// 获取芝麻信用
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="transactionId"></param>
        /// <param name="bizNo"></param>
        /// <param name="zmScore"></param>
        public static void GetCreditScore(string openid, string transactionId, out string bizNo, out int? zmScore)
        {
            var zmop = ZmopSettingsSection.GetSection();
            ZhimaCreditScoreGetRequest request = new ZhimaCreditScoreGetRequest()
            {
                OpenId = openid,
                ProductCode = zmop.ScoreProductCode,
                TransactionId = transactionId
            };
            var response = GetZmopClient(zmop).Execute(request);
            bizNo = response.BizNo;
            zmScore = null;
            int score;
            if (int.TryParse(response.ZmScore, out score))
            {
                zmScore = score;
            }
        }
  • 打赏
  • 举报
回复
这个是zmopsdk帮你生成出来的(获取),下面是我接入的部分helper
        private static DefaultZmopClient GetZmopClient(ZmopSettingsSection zmop = null)
        {
            if (zmop == null)
            {
                zmop = ZmopSettingsSection.GetSection();
            }
            return new DefaultZmopClient(zmop.ServerUrl, zmop.AppId, zmop.PrivateKey, zmop.ZhimaPublicKey, zmop.Charset);
        }
        /// <summary>
        /// 获取芝麻信用
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="transactionId"></param>
        /// <param name="bizNo"></param>
        /// <param name="zmScore"></param>
        public static void GetCreditScore(string openid, string transactionId, out string bizNo, out int? zmScore)
        {
            var zmop = ZmopSettingsSection.GetSection();
            ZhimaCreditScoreGetRequest request = new ZhimaCreditScoreGetRequest()
            {
                OpenId = openid,
                ProductCode = zmop.ScoreProductCode,
                TransactionId = transactionId
            };
            var response = GetZmopClient(zmop).Execute(request);
            bizNo = response.BizNo;
            zmScore = null;
            int score;
            if (int.TryParse(response.ZmScore, out score))
            {
                zmScore = score;
            }
        }
  • 打赏
  • 举报
回复
    public static class ZmopHelper
    {
        /// <summary>
        /// 查询用户是否已经授权查询芝麻信用,返回空代表未授权
        /// </summary>
        /// <param name="certNo"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string AuthQuery(string certNo, string name)
        {
            ZhimaAuthInfoAuthqueryRequest request = new ZhimaAuthInfoAuthqueryRequest()
            {
                IdentityType = "2",
                IdentityParam = $"{{\"certNo\":\"{certNo}\",\"certType\":\"IDENTITY_CARD\",\"name\":\"{name}\"}}"
            };
            var response = GetZmopClient().Execute(request);
            return response.Authorized ? response.OpenId : null;
        }
        private static DefaultZmopClient GetZmopClient(ZmopSettingsSection zmop = null)
        {
            if (zmop == null)
            {
                zmop = ZmopSettingsSection.GetSection();
            }
            return new DefaultZmopClient(zmop.ServerUrl, zmop.AppId, zmop.PrivateKey, zmop.ZhimaPublicKey, zmop.Charset);
        }
        /// <summary>
        /// 获取芝麻认证令牌
        /// </summary>
        /// <param name="certNo"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string GetToken(string certNo, string name, string transactionId,
            string bizParams = null, string sourceType = "sdk", string schemaUrl = null, string pageUrl = null)
        {
            var zmop = ZmopSettingsSection.GetSection();
            ZhimaCustomerCertifyInitialRequest request = new ZhimaCustomerCertifyInitialRequest()
            {
                ContractFlag = zmop.ContractFlag,
                ProductCode = zmop.ProductCode,
                State = JsonConvert.SerializeObject(new Dictionary<string, string> { [certNo] = certNo, [name] = name }),
                IdentityType = "BY_CERTNO_AND_NAME",
                IdentityParam = $"{{\"certNo\":\"{certNo}\",\"certType\":\"IDENTITY_CARD\",\"name\":\"{name}\"}}",
                TransactionId = transactionId,
                SourceType = sourceType,
                BizParams = bizParams,
                SchemaUrl = schemaUrl,
                PageUrl = pageUrl
            };
            var response = GetZmopClient(zmop).Execute(request);
            return response.Token;
        }
        /// <summary>
        /// 获取移动端签名所需参数
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public static IDictionary<string, string> GetCertifyParams(string token)
        {
            ZhimaCustomerCertifyApplyRequest request = new ZhimaCustomerCertifyApplyRequest()
            {
                Token = token
            };
            var url = GetZmopClient().generatePageRedirectInvokeUrl(request);
            return GetParamsFromUrl(url);
        }
        private static IDictionary<string,string> GetParamsFromUrl(string url)
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            string[] temp = url.Split('?');
            string[] paramsString = temp[1].Split('&');
            foreach (var attr in paramsString)
            {
                string[] keyAndValue = attr.Split('=');
                if (("params||app_id||sign").IndexOf(keyAndValue[0]) > -1)
                {
                    dic.Add(keyAndValue[0], keyAndValue[1]);
                }
            }
            return dic;
        }
        /// <summary>
        /// 获取芝麻信用
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="transactionId"></param>
        /// <param name="bizNo"></param>
        /// <param name="zmScore"></param>
        public static void GetCreditScore(string openid, string transactionId, out string bizNo, out int? zmScore)
        {
            var zmop = ZmopSettingsSection.GetSection();
            ZhimaCreditScoreGetRequest request = new ZhimaCreditScoreGetRequest()
            {
                OpenId = openid,
                ProductCode = zmop.ScoreProductCode,
                TransactionId = transactionId
            };
            var response = GetZmopClient(zmop).Execute(request);
            bizNo = response.BizNo;
            zmScore = null;
            int score;
            if (int.TryParse(response.ZmScore, out score))
            {
                zmScore = score;
            }
        }
    }

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧