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="result">支付结果</param> protected virtual async Task <PayResult> CreateResult(WechatpayResult result) { var success = (await result.ValidateAsync()).IsValid; return(new PayResult(success, result.GetPrepayId(), result.Raw) { Parameter = result.Builder.ToString(), Message = result.GetReturnMessage(), Result = success ? GetResult(result) : null }); }
/// <summary> /// 创建退款结果 /// </summary> /// <param name="config">支付配置</param> /// <param name="builder">参数生成器</param> /// <param name="result">支付结果</param> protected virtual async Task <RefundResult> CreateResult(WechatpayConfig config, WechatpayRefundParameterBuilder builder, WechatpayResult result) { var success = (await result.ValidateAsync()).IsValid; return(new RefundResult(success, result.GetRefundId(), result.Raw) { Parameter = builder.ToString(), Message = result.GetReturnMessage(), Result = success ? GetResult(config, builder, result) : null }); }