Esempio n. 1
0
        // Json 格式化处理
        private static async Task <T> JsonFormat <T>(WechatPayConfig config, HttpResponseMessage resp, bool needCheckSign)
            where T : WechatBaseResp, new()
        {
            if (!resp.IsSuccessStatusCode)
            {
                var content = await resp.Content.ReadAsStringAsync();

                return(string.IsNullOrEmpty(content)
                    ? new T().WithResp(SysRespCodes.NetError, $"微信支付接口请求异常({resp.ReasonPhrase})")
                    : JsonSerializer.Deserialize <T>(content));
            }

            var respDetail = await GetResponseDetail(resp);

            if (needCheckSign)
            {
                var verifyRes = await WechatCertificateHelper.Verify(config, respDetail.signature, respDetail.serial_no,
                                                                     respDetail.nonce, respDetail.timestamp, respDetail.body);

                if (!verifyRes.IsSuccess())
                {
                    verifyRes.request_id = respDetail.request_id;
                    return(verifyRes.ToResp <T>());
                }
            }

            return(string.IsNullOrEmpty(respDetail.body)
                ? new T()
                : JsonSerializer.Deserialize <T>(respDetail.body));
        }
Esempio n. 2
0
 /// <summary>
 /// 根据微信商户配置,验证结果签名
 /// </summary>
 /// <param name="payConfig">支付配置</param>
 /// <param name="signature">微信返回头信息中的签名</param>
 /// <param name="serialNo">微信返回头信息中的平台证书编号</param>
 /// <param name="nonce">微信返回头信息中的随机串</param>
 /// <param name="timestamp">微信返回头信息中的时间戳</param>
 /// <param name="respBody">微信返回的内容字符串</param>
 /// <returns></returns>
 public static Task <WechatBaseResp> Verify(WechatPayConfig payConfig, string signature,
                                            string serialNo, string nonce, long timestamp, string respBody)
 {
     return(WechatCertificateHelper.Verify(payConfig, signature, serialNo, nonce, timestamp, respBody));
 }