private static async Task <TRes> DecrytToResult <TRes>(WechatNotifyReceiver receiver, string apiV3Key)
            where TRes : Resp, new()
        {
            var eRes = await receiver.ToNotifyEncryptResult();

            if (!eRes.IsSuccess())
            {
                return(new TRes().WithResp(eRes));
            }

            var str = DecrytResource(eRes.resource, apiV3Key);

            return(JsonSerializer.Deserialize <TRes>(str));
        }
        /// <summary>
        ///   转化为微信通知的实体(包含验证签名
        /// </summary>
        /// <param name="receiver"></param>
        /// <returns></returns>
        public static async Task <WechatNotifyEncryptResult> ToNotifyEncryptResult(this WechatNotifyReceiver receiver)
        {
            var config = WechatPayHelper.pay_config;

            if (!receiver.header_dics.TryGetValue("Wechatpay-Nonce", out var nonce) ||
                !receiver.header_dics.TryGetValue("Wechatpay-Signature", out var signature) ||
                !receiver.header_dics.TryGetValue("Wechatpay-Timestamp", out var timestamp) ||
                !receiver.header_dics.TryGetValue("Wechatpay-Serial", out var serial))
            {
                return(new WechatNotifyEncryptResult().WithResp(RespCodes.ParaError, "微信支付通知头部参数异常!"));
            }

            var checkRes = await WechatPayHelper.Verify(config, signature, serial, nonce, timestamp.ToInt64(), receiver.body);

            // 签名正确
            if (checkRes.IsSuccess())
            {
                var wRes = JsonSerializer.Deserialize <WechatNotifyEncryptResult>(receiver.body);
                return(wRes ?? new WechatNotifyEncryptResult().WithResp(RespCodes.OperateFailed, "微信支付通知内容异常!"));
            }
            return(new WechatNotifyEncryptResult().WithResp(checkRes));
        }
 /// <summary>
 ///  解密退款结果(服务商退款结果实体
 /// </summary>
 /// <param name="receiver"></param>
 /// <param name="apiV3Key"></param>
 /// <returns></returns>
 public static Task <NotifySPRefundResult> DecrytToSPRefundResult(this WechatNotifyReceiver receiver, string apiV3Key)
 {
     return(DecrytToResult <NotifySPRefundResult>(receiver, apiV3Key));
 }
 /// <summary>
 ///  解密通知的支付结果
 /// </summary>
 /// <param name="receiver"></param>
 /// <param name="apiV3Key"></param>
 /// <returns></returns>
 public static Task <WechatNotifyPayResult> DecrytToPayResult(this WechatNotifyReceiver receiver, string apiV3Key)
 {
     return(DecrytToResult <WechatNotifyPayResult>(receiver, apiV3Key));
 }