.net 支付宝 应用网页验签

验证签名接口

/// 
        /// 验证网关
        /// 
        /// 
        [Route("gatewayVerify"), HttpPost, AllowAnonymous, NonUnify]
        public async Task<dynamic> gatewayVerify()
        {
            var Request = App.HttpContext.Request; //获取当前回调的请求
            var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());

            bool result = RSACheck(dict);
            if (result)
            {
                string singText = $"true";//带签名字段
                string sign = AlipaySignature.Sign(singText, app_private_key_PKCS1, "GBK", "RSA2", false);//签名
                string refSing = $"true{sign}RSA2";
                return refSing;
            }
            return null;
        }

封装SDK中的验签方法

/// 
        /// 验证签名
        /// 
        /// 
        /// 
        public static bool RSACheck(IDictionary<string, string> parameters)
        {
            string charset = "utf-8";
            string signType = "RSA2";
            if (!string.IsNullOrEmpty(parameters["charset"].ToString()))
            {
                charset = parameters["charset"].ToString();
            }
            if (!string.IsNullOrEmpty(parameters["sign_type"].ToString()))
            {
                signType= parameters["sign_type"].ToString();
            }
            if (signType== "RSA2")
            {
                return AlipaySignature.RSACertCheckV2(parameters, alipayCertPublicKey, charset, signType);
            }
            else
            {
                return AlipaySignature.RSACertCheckV1(parameters, alipayCertPublicKey, charset, signType);
            }
           
        }

注意
在这里插入图片描述
支付宝网关验签文档参考

你可能感兴趣的:(.net)