public void SendCardAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // 如果还未创建建立合作关系 则建立合作关系 if (buildPartnershipsResult is null) { BuildPartnershipsAsyncTest(); } var card_id = "pIJMr5MMiIkO_93VtPyIiEk2DZ4w";//TODO: 消费卡ID,即card_id。card_id获取方法请参见《接入前准备》配置应用中的创建消费卡。https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter5_6_2.shtml#part-6 // TODO:流水号?这样是否有效? var out_request_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6)); var requestData = new SendCardRequestData(card_id, TenPayV3Info.AppId, openId, out_request_no, new TenpayDateTime(DateTime.Now)); var marketingApis = new MarketingApis(); var result = marketingApis.SendCardAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 发放消费卡接口测试结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void SetBusifavorCouponCodesAsyncTest() { if (createBusifavorStockResult is null) { CreateBusifavorStockAsyncTest(); } var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // TODO:流水号?这样是否有效? var upload_request_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6)); string[] coupon_code_list = { "" }; //TODO: 此处需要商家已有自己的优惠券系统生成code_list var requestData = new SetBusifavorCouponCodesRequestData(createBusifavorStockResult.stock_id, coupon_code_list, upload_request_no); var marketingApis = new MarketingApis(); var result = marketingApis.SetBusifavorCouponCodesAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 上传预存code结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void DownloadStockRefundFlowAsyncTest() { // 如果还未发放代金券 则创建代金券 if (createStockResult is null) { CreateStockAsyncTest(); } var stock_id = createStockResult.stock_id; var filePath = $"{stock_id}_{SystemTime.Now.ToString("HHmmss")}-StockRefundFlow.csv"; Console.WriteLine("FilePath:" + filePath); var fs = new FileStream(filePath, FileMode.OpenOrCreate); var marketingApis = new MarketingApis(); var result = marketingApis.DownloadStockRefundFlowAsync(stock_id, fs).GetAwaiter().GetResult(); fs.Flush(); Console.WriteLine("FileStream Length:" + fs.Length); fs.Close(); Console.WriteLine("微信支付 V3 交易账单查询结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 Assert.IsTrue(File.Exists(filePath)); ////校验文件 //var fileHash = CO2NET.Helpers.FileHelper.GetFileHash(filePath, result.hash_type); //Assert.AreEqual(result.hash_value.ToUpper(), fileHash); }
public void CreateBusifavorStockAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // 商家券使用规则 即刻开始 发1小时 生效1天 满100减10 var coupon_use_rule = new CreateBusifavorStockRequestData.Coupon_Use_Rule(new(new TenpayDateTime(DateTime.Now), new TenpayDateTime(DateTime.Now.AddHours(1)), 1, null, null, null), new(100, 10), null, null, "OFF_LINE", null, null); // 商家券发放规则 var stock_send_rule = new CreateBusifavorStockRequestData.Stock_Send_Rule(10, 1, 10, true); // TODO:流水号?这样是否有效? var out_request_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6)); var requestData = new CreateBusifavorStockRequestData("Senparc微信支付V3商家券测试", TenPayV3Info.MchId, null, "微信支付V3商家券测试使用", "NORMAL", coupon_use_rule, stock_send_rule, out_request_no, null, null, "WECHATPAY_MODE", null, false); var marketingApis = new MarketingApis(); createBusifavorStockResult = marketingApis.CreateBusifavorStockRequestDataAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 创建商家券接口批次结果:" + createBusifavorStockResult.ToJson(true)); Assert.IsNotNull(createBusifavorStockResult); Assert.IsTrue(createBusifavorStockResult.ResultCode.Success); Assert.IsTrue(createBusifavorStockResult.VerifySignSuccess == true);//通过验证 }
public void PayBusifavorReceiptsAsyncTest() { 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 var transaction_id = "transaction_id"; // TODO: 填入现有订单的transaction_id var payer_merchant = "payer_merchant"; // TODO: 收款商户号 需要另一个收款的商户号 // TODO:流水号?这样是否有效? var out_subsidy_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6)); var requestData = new PayBusifavorReceiptsRequestData(createBusifavorStockResult.stock_id, coupon_code, out_subsidy_no, transaction_id, payer_merchant, 100, "Senparc营销补差付款接口单元测试", out_subsidy_no); var marketingApis = new MarketingApis(); var result = marketingApis.PayBusifavorReceiptsAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 营销补差付款接口:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void DistributeStockAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // 如果还未创建代金券批次 则创建新的代金券批次 并且激活 if (createStockResult is null) { StartStockAsyncTest(); } var out_request_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6)); var requestData = new DistributeStockRequsetData(createStockResult.stock_id, out_request_no, TenPayV3Info.AppId, TenPayV3Info.MchId); var marketingApis = new MarketingApis(); distributeStockResult = marketingApis.DistributeStockAsync(openId, requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 发放代金券批次接口结果:" + distributeStockResult.ToJson(true)); Assert.IsNotNull(distributeStockResult); Assert.IsTrue(distributeStockResult.ResultCode.Success); Assert.IsTrue(distributeStockResult.VerifySignSuccess == true);//通过验证 }
public void UseBusifavorCouponAsyncTest() { if (createBusifavorStockResult is null) { CreateBusifavorStockAsyncTest(); } var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // TODO:流水号?这样是否有效? var use_request_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6)); var coupon_code = "coupon_code";// TODO: 发券似乎还是V2接口 或者 微信支付平台流量场景发放 https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter5_2_1.shtml var requestData = new UseBusifavorCouponRequestData(coupon_code, createBusifavorStockResult.stock_id, TenPayV3Info.AppId, new TenpayDateTime(DateTime.Now), use_request_no, openId); var marketingApis = new MarketingApis(); var result = marketingApis.UseBusifavorCouponAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 核销商家券接口批次结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void QueryBusifavorNotifyUrlAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; var marketingApis = new MarketingApis(); var result = marketingApis.QueryBusifavorNotifyUrlAsync(TenPayV3Info.MchId).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 查询商家券事件通知地址接口:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void QueryBusifavorCouponAsyncTest() { 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 var marketingApis = new MarketingApis(); var result = marketingApis.QueryBusifavorCouponAsync(coupon_code, TenPayV3Info.AppId, openId).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 查询用户单张券详情接口:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void QueryBusifavorPayReceiptsAsyncTest() { if (queryBusifavorPayReceiptsReturnJson is null) { PayBusifavorReceiptsAsyncTest(); } var marketingApis = new MarketingApis(); var result = marketingApis.QueryBusifavorPayReceiptsAsync(queryBusifavorPayReceiptsReturnJson.subsidy_receipt_id).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 查询营销补差付款单详情接口:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void SetBusifavorSetNotifyUrlAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; var notify_url = "senparc.com/SetBusifavorCouponCodesAsyncTest";// TODO:这个url我随便设置的 var requestData = new SetBusifavorSetNotifyUrlRequestData(TenPayV3Info.MchId, notify_url); var marketingApis = new MarketingApis(); var result = marketingApis.SetBusifavorSetNotifyUrlAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 设置商家券事件通知地址接口:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void TerminatePartnershipsAsyncTest() { // 如果还未创建建立合作关系 则建立合作关系 if (buildPartnershipsResult is null) { BuildPartnershipsAsyncTest(); } var requestData = new TerminatePartnershipsRequestData(buildPartnershipsResult); var marketingApis = new MarketingApis(); var result = marketingApis.TerminatePartnershipsAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 终止合作关系接口结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void SetNotifyUrlAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; var marketingApis = new MarketingApis(); var notifyUrl = "https://sdk.weixin.senparc.com/TenPayRealV3/FavorNotifyCallback"; var requestData = new SetNotifyUrlRequsetData(TenPayV3Info.MchId, notifyUrl, null); var result = marketingApis.SetNotifyUrlAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 设置营销事件消息通知地址结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void QueryBusifavorCouponsAsyncTest() { if (createBusifavorStockResult is null) { CreateBusifavorStockAsyncTest(); } var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; var marketingApis = new MarketingApis(); var result = marketingApis.QueryBusifavorCouponsAsync(openId, TenPayV3Info.AppId, createBusifavorStockResult.stock_id, null, null, null, null).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 根据过滤条件查询商家券用户券接口:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void BuildPartnershipsAsyncTest() { // 如果还未创建代金券批次 则创建新的代金券批次 if (createStockResult is null) { CreateStockAsyncTest(); } //var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); //var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // TODO: 此处信息需要完善 var parner = new BuildPartnershipsRequestData.Partner("{合作方类型}", "{合作方Appid}", "{合作方商户id}"); var authorized_data = new BuildPartnershipsRequestData.Authorized_Data("FAVOR_STOCK", createStockResult.stock_id); var requestData = new BuildPartnershipsRequestData(parner, authorized_data); var marketingApis = new MarketingApis(); try { // 合作类型设置为appid 但传入 "partner.merchant_id" 的情况 buildPartnershipsResult = marketingApis.BuildPartnershipsAsync(requestData).GetAwaiter().GetResult(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(TenpayApiRequestException)); Console.WriteLine(ex.Message); Assert.IsTrue(ex.Message.Contains("为null!")); } // 修改参数 requestData.partner.merchant_id = null; buildPartnershipsResult = marketingApis.BuildPartnershipsAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 建立合作关系接口结果:" + buildPartnershipsResult.ToJson(true)); Assert.IsNotNull(buildPartnershipsResult); Assert.IsTrue(buildPartnershipsResult.ResultCode.Success); Assert.IsTrue(buildPartnershipsResult.VerifySignSuccess == true);//通过验证 }
public void RestartStockAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // 如果还未创建代金券批次 则创建新的代金券批次 激活 然后暂停发放 if (createStockResult is null) { PauseStockAsyncTest(); } var marketingApis = new MarketingApis(); var result = marketingApis.RestartStockAsync(createStockResult.stock_id, TenPayV3Info.MchId).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 重启发放代金券批次接口结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void QueryCouponAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // 如果还未发放代金券 则发放代金券 if (distributeStockResult is null) { DistributeStockAsyncTest(); } var marketingApis = new MarketingApis(); var result = marketingApis.QueryCouponAsync(distributeStockResult.coupon_id, TenPayV3Info.AppId, openId).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 查询代金券详情接口结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void QueryItemsAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // 如果还未发放代金券 则创建代金券 if (createStockResult is null) { CreateStockAsyncTest(); } var marketingApis = new MarketingApis(); var result = marketingApis.QueryItemsAsync(0, 50, TenPayV3Info.MchId, createStockResult.stock_id).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 查询代金券可用单品接口结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void ModifyBusifavorStockInformationAsyncTest() { if (createBusifavorStockResult is null) { CreateBusifavorStockAsyncTest(); } var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // TODO:流水号?这样是否有效? var out_request_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6)); var requestData = new ModifyBusifavorStockInformationRequestData(createBusifavorStockResult.stock_id, null, "Senparc微信支付V3商家券测试-修改", null, null, out_request_no, null, null, null, null); var marketingApis = new MarketingApis(); var result = marketingApis.ModifyBusifavorStockInformationAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 修改商家券基本信息接口:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
public void CreateStockAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; // 代金券批次发放使用规则 发放10张优惠券 预算1000分 每个用户限领10张 开启防刷 var stock_use_rule = new CreateStockRequsetData.Stock_Use_Rule(2, 4, null, 2, false, true); // 代金券使用规则 指明可使用本批次代金券的商户号 var coupon_use_rule = new CreateStockRequsetData.Coupon_Use_Rule(null, null, null, null, null, null, null, new string[] { TenPayV3Info.MchId /*"1610625015"*/ }); // TODO:流水号?这样是否有效? var out_request_no = string.Format("{0}{1}{2}", TenPayV3Info.MchId /*10位*/, SystemTime.Now.ToString("yyyyMMddHHmmss"), TenPayV3Util.BuildRandomStr(6)); var requestData = new CreateStockRequsetData("单元测试代金券批次", "用于单元测试", TenPayV3Info.MchId, new TenpayDateTime(DateTime.Now.AddMinutes(1)), new TenpayDateTime(DateTime.Now.AddMinutes(30)), stock_use_rule, null, coupon_use_rule, true, "NORMAL", out_request_no); /* 提示: * 使用此功能必须在后台【产品中心】开通【预充值代金券】功能! */ var marketingApis = new MarketingApis(); try { // stock_type = "NORMAL" 的情况 createStockResult = marketingApis.CreateStockAsync(requestData).GetAwaiter().GetResult(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(TenpayApiRequestException)); Console.WriteLine(ex.Message); Assert.IsTrue(ex.Message.Contains("必填")); } try { //修改参数 requestData.coupon_use_rule.fixed_normal_coupon = new CreateStockRequsetData.Coupon_Use_Rule.Fixed_Normal_Coupon(6, 1); createStockResult = marketingApis.CreateStockAsync(requestData).GetAwaiter().GetResult(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(TenpayApiRequestException)); Console.WriteLine(ex.Message); Assert.IsTrue(ex.Message.Contains("必须等于")); } try { //修改参数 requestData.coupon_use_rule.fixed_normal_coupon.coupon_amount = 2;// coupon_amount = max_coupons * max_coupons_per_user createStockResult = marketingApis.CreateStockAsync(requestData).GetAwaiter().GetResult(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(TenpayApiRequestException)); Console.WriteLine(ex.Message); Assert.IsTrue(ex.Message.Contains("必须小于等于")); } //修改参数 requestData.coupon_use_rule.fixed_normal_coupon.transaction_minimum = 2;// coupon_amount = max_coupons * max_coupons_per_user createStockResult = marketingApis.CreateStockAsync(requestData).GetAwaiter().GetResult(); Assert.IsTrue(createStockResult.ResultCode.Additional.Contains("可用商户不符合规则,请检查")); //修改参数 requestData.no_cash = false;//只有当参数为 false 时,可以使用本商户,否则只能使用其他商户 createStockResult = marketingApis.CreateStockAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 创建代金券接口批次结果:" + createStockResult.ToJson(true)); Assert.IsNotNull(createStockResult); Assert.IsTrue(createStockResult.ResultCode.Success); Assert.IsTrue(createStockResult.VerifySignSuccess == true);//通过验证 }