public async Task Test() { //设置返回响应 var response = @"<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_msg><![CDATA[OK]]></return_msg> <appid><![CDATA[wx9b90e1788b39fec6]]></appid> <mch_id><![CDATA[1985518532]]></mch_id> <nonce_str><![CDATA[wrKodsjUFk34qYno]]></nonce_str> <sign><![CDATA[5F721ADF22DD2C60B4E171228F8DA36E]]></sign> <result_code><![CDATA[SUCCESS]]></result_code> <prepay_id><![CDATA[wx141217433636466fe2c3b2a10139084028]]></prepay_id> <trade_type><![CDATA[APP]]></trade_type> </xml>"; //操作 var result = new WechatpayResult(new TestConfigProvider(), response); //验证 Assert.Equal("SUCCESS", result.GetReturnCode()); Assert.Equal("OK", result.GetReturnMessage()); Assert.Equal("wx9b90e1788b39fec6", result.GetAppId()); Assert.Equal("1985518532", result.GetMerchantId()); Assert.Equal("wrKodsjUFk34qYno", result.GetNonce()); Assert.Equal("5F721ADF22DD2C60B4E171228F8DA36E", result.GetSign()); Assert.Equal("SUCCESS", result.GetResultCode()); Assert.Equal("wx141217433636466fe2c3b2a10139084028", result.GetPrepayId()); Assert.Equal("APP", result.GetTradeType()); var isValid = (await result.ValidateAsync()).IsValid; Assert.True(isValid); }
/// <summary> /// 获取结果 /// </summary> /// <param name="config">微信支付配置</param> /// <param name="builder">微信支付参数生成器</param> /// <param name="result">微信支付结果</param> /// <returns></returns> protected override string GetResult(WechatpayConfig config, WechatpayParameterBuilder builder, WechatpayResult result) { return(new WechatpayParameterBuilder(config) .Add("appId", config.AppId) .Add("timeStamp", Time.GetUnixTimestamp().SafeString()) .Add("nonceStr", Id.Guid()) .Package($"prepay_id{result.GetPrepayId()}") .Add("signType", config.SignType.Description()) .Add("paySign", result.GetSign()) .ToJson()); }