Beispiel #1
0
        public void ReturnBusifavorCouponAsyncTest()
        {
            if (createBusifavorStockResult is null)
            {
                CreateBusifavorStockAsyncTest();
            }

            var key          = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting);
            var TenPayV3Info = TenPayV3InfoCollection.Data[key];


            var coupon_code = "coupon_code";// TODO: 发券似乎还是V2接口 或者 微信支付平台流量场景发放 https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter5_2_1.shtml

            // TODO:流水号?这样是否有效?
            var return_request_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6));
            var requestData       = new ReturnBusifavorCouponRequestData(coupon_code, createBusifavorStockResult.stock_id, return_request_no);

            var marketingApis = new MarketingApis();
            var result        = marketingApis.ReturnBusifavorCouponAsync(requestData).GetAwaiter().GetResult();

            Console.WriteLine("微信支付 V3 申请退券接口:" + result.ToJson(true));

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ResultCode.Success);
            Assert.IsTrue(result.VerifySignSuccess == true);//通过验证
        }
        /// <summary>
        /// 申请退券接口
        /// <para>商户可以在退款之后调用退券api,调用了该接口后,券在用户卡包内正常展示,用户可在有效期内正常使用该优惠券。</para>
        /// <para>若券过期状态下退款,可不用调用该退券api。</para>
        /// <para>更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_13.shtml </para>
        /// </summary>
        /// <param name="data">微信支付需要POST的Data数据</param>
        /// <param name="timeOut">超时时间,单位为ms </param>
        /// <returns></returns>
        public async Task <ReturnBusifavorCouponReturnJson> ReturnBusifavorCouponAsync(ReturnBusifavorCouponRequestData data, int timeOut = Config.TIME_OUT)
        {
            var url = ReurnPayApiUrl($"https://api.mch.weixin.qq.com/{{0}}v3/marketing/busifavor/coupons/return");
            TenPayApiRequest tenPayApiRequest = new(_tenpayV3Setting);

            return(await tenPayApiRequest.RequestAsync <ReturnBusifavorCouponReturnJson>(url, data, timeOut));
        }