Пример #1
0
        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);
        }
Пример #2
0
 /// <summary>
 /// 获取结果
 /// </summary>
 /// <param name="result">支付结果</param>
 protected override string GetResult(WechatpayResult result)
 {
     return(new WechatpayParameterBuilder(result.Config)
            .Add("appId", result.Config.AppId)
            .Add("timeStamp", Time.GetUnixTimestamp().SafeString())
            .Add("nonceStr", Id.Guid())
            .Package($"prepay_id={result.GetPrepayId()}")
            .Add("signType", result.Config.SignType.Description())
            .ToJson());
 }
Пример #3
0
        /// <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
            });
        }
Пример #4
0
 /// <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)
            .AppId(config.AppId)
            .PartnerId(config.MerchantId)
            .Add("prepayid", result.GetPrepayId())
            .Add("noncestr", Id.Guid())
            .Timestamp()
            .Package()
            .ToJson());
 }
Пример #5
0
 /// <summary>
 /// 获取结果
 /// </summary>
 /// <param name="result">支付结果</param>
 protected virtual string GetResult(WechatpayResult result)
 {
     return(result.GetPrepayId());
 }
Пример #6
0
 /// <summary>
 /// 获取结果
 /// </summary>
 /// <param name="config">微信支付配置</param>
 /// <param name="builder">微信支付参数生成器</param>
 /// <param name="result">微信支付结果</param>
 /// <returns></returns>
 protected virtual string GetResult(WechatpayConfig config, WechatpayParameterBuilder builder,
                                    WechatpayResult result)
 {
     return(result.GetPrepayId());
 }