repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/ConnectionPoolUsageExampleTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/ConnectionPoolUsageExampleTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.config.WxPayConfig; import org.apache.http.impl.client.CloseableHttpClient; import org.testng.Assert; import org.testng.annotations.Test; /** * 演示连接池功能的示例测试 */ public class ConnectionPoolUsageExampleTest { @Test public void demonstrateConnectionPoolUsage() throws Exception { // 1. 创建配置并设置连接池参数 WxPayConfig config = new WxPayConfig(); config.setAppId("wx123456789"); config.setMchId("1234567890"); config.setMchKey("32位商户密钥32位商户密钥32位商户密钥"); // 设置连接池参数(可选,有默认值) config.setMaxConnTotal(50); // 最大连接数,默认20 config.setMaxConnPerRoute(20); // 每个路由最大连接数,默认10 // 2. 初始化连接池 CloseableHttpClient pooledClient = config.initHttpClient(); Assert.assertNotNull(pooledClient); // 3. 创建支付服务实例 WxPayServiceApacheHttpImpl payService = new WxPayServiceApacheHttpImpl(); payService.setConfig(config); // 4. 现在所有的HTTP请求都会使用连接池 // 对于非SSL请求,会复用同一个HttpClient实例 CloseableHttpClient client1 = payService.createHttpClient(false); CloseableHttpClient client2 = payService.createHttpClient(false); Assert.assertSame(client1, client2, "非SSL请求应该复用同一个客户端实例"); // 对于SSL请求,也会复用同一个SSL HttpClient实例(需要配置证书后) System.out.println("连接池配置成功!"); System.out.println("最大连接数:" + config.getMaxConnTotal()); System.out.println("每路由最大连接数:" + config.getMaxConnPerRoute()); } @Test public void demonstrateDefaultConfiguration() throws Exception { // 使用默认配置的示例 WxPayConfig config = new WxPayConfig(); config.setAppId("wx123456789"); config.setMchId("1234567890"); config.setMchKey("32位商户密钥32位商户密钥32位商户密钥"); // 不设置连接池参数,使用默认值 CloseableHttpClient client = config.initHttpClient(); Assert.assertNotNull(client); // 验证默认配置 Assert.assertEquals(config.getMaxConnTotal(), 20, "默认最大连接数应该是20"); Assert.assertEquals(config.getMaxConnPerRoute(), 10, "默认每路由最大连接数应该是10"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.github.binarywang.wxpay.bean.coupon.*; import com.github.binarywang.wxpay.bean.notify.*; import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.bean.request.WxPayDownloadFundFlowRequest.AccountType; import com.github.binarywang.wxpay.constant.WxPayConstants.BillType; import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.github.binarywang.wxpay.testbase.XmlWxPayConfig; import com.github.binarywang.wxpay.util.RequestUtils; import com.github.binarywang.wxpay.util.XmlConfig; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.util.RandomUtils; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Calendar; import java.util.Date; import java.util.Optional; import java.util.UUID; import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; import static org.assertj.core.api.Assertions.assertThat; import static org.testng.Assert.*; /** * 测试支付相关接口 * Created by Binary Wang on 2016/7/28. * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Slf4j @Test @Guice(modules = ApiTestModule.class) public class BaseWxPayServiceImplTest { @Inject private WxPayService payService; /** * Test method for {@link WxPayService#unifiedOrder(WxPayUnifiedOrderRequest)}. * * @throws WxPayException the wx pay exception */ @Test public void testUnifiedOrder() throws WxPayException { WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder() .body("我去") .totalFee(1) .spbillCreateIp("11.1.11.1") .notifyUrl("111111") .tradeType(TradeType.JSAPI) .openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid()) .outTradeNo("111111826") .attach("#*#{\"pn\":\"粤B87965\",\"aid\":\"wx123\"}#*#") .build(); request.setSignType(SignType.HMAC_SHA256); WxPayUnifiedOrderResult result = this.payService.unifiedOrder(request); log.info(result.toString()); log.warn(this.payService.getWxApiData().toString()); } /** * Test create order. * * @throws Exception the exception */ @Test public void testCreateOrder() throws Exception { //see other tests with method name starting with 'testCreateOrder_' } /** * Test create order jsapi. * * @throws Exception the exception */ @Test public void testCreateOrder_jsapi() throws Exception { WxPayMpOrderResult result = this.payService .createOrder(WxPayUnifiedOrderRequest.newBuilder() .body("我去") .totalFee(1) .spbillCreateIp("11.1.11.1") .notifyUrl("111111") .tradeType(TradeType.JSAPI) .openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid()) .outTradeNo("1111112") .build()); log.info(result.toString()); log.warn(this.payService.getWxApiData().toString()); } /** * Test create order app. * * @throws Exception the exception */ @Test public void testCreateOrder_app() throws Exception { WxPayAppOrderResult result = this.payService .createOrder(WxPayUnifiedOrderRequest.newBuilder() .body("我去") .totalFee(1) .spbillCreateIp("11.1.11.1") .notifyUrl("111111") .tradeType(TradeType.APP) .outTradeNo("1111112") .build()); log.info(result.toString()); log.warn(this.payService.getWxApiData().toString()); } /** * Test create order native. * * @throws Exception the exception */ @Test public void testCreateOrder_native() throws Exception { WxPayNativeOrderResult result = this.payService .createOrder(WxPayUnifiedOrderRequest.newBuilder() .body("我去") .totalFee(1) .productId("aaa") .spbillCreateIp("11.1.11.1") .notifyUrl("111111") .tradeType(TradeType.NATIVE) .outTradeNo("111111290") .build()); log.info(result.toString()); log.warn(this.payService.getWxApiData().toString()); } @Test public void testCreateOrderSpecific() throws Exception { // Won't compile // WxPayMpOrderResult result = payService.createOrder(TradeType.Specific.APP, new WxPayUnifiedOrderRequest()); payService.createOrder( TradeType.Specific.JSAPI, WxPayUnifiedOrderRequest.newBuilder() .body("我去") .totalFee(1) .productId("aaa") .spbillCreateIp("11.1.11.1") .notifyUrl("111111") .outTradeNo("111111290") .build() ) .getAppId(); } /** * Test get pay info. * * @throws Exception the exception */ @Test public void testGetPayInfo() throws Exception { //please use createOrder instead } /** * Test method for {@link WxPayService#queryOrder(String, String)} . * * @throws WxPayException the wx pay exception */ @Test public void testQueryOrder() throws WxPayException { log.info(this.payService.queryOrder("11212121", null).toString()); log.info(this.payService.queryOrder(null, "11111").toString()); } /** * Test method for {@link WxPayService#closeOrder(String)} . * * @throws WxPayException the wx pay exception */ @Test public void testCloseOrder() throws WxPayException { log.info(this.payService.closeOrder("11212121").toString()); } /** * Billing data object [ ] [ ]. * * @return the object [ ] [ ] */ @DataProvider public Object[][] billingData() { return new Object[][]{ {"20170831", BillType.ALL, TarType.GZIP, "deviceInfo"}, {"20170831", BillType.RECHARGE_REFUND, TarType.GZIP, "deviceInfo"}, {"20170831", BillType.REFUND, TarType.GZIP, "deviceInfo"}, {"20170831", BillType.SUCCESS, TarType.GZIP, "deviceInfo"}, {"20170831", BillType.ALL, null, "deviceInfo"}, {"20170831", BillType.RECHARGE_REFUND, null, "deviceInfo"}, {"20170831", BillType.REFUND, null, "deviceInfo"}, {"20170831", BillType.SUCCESS, null, "deviceInfo"} }; } /** * Test download bill. * * @param billDate the bill date * @param billType the bill type * @param tarType the tar type * @param deviceInfo the device info * @throws Exception the exception */ @Test(dataProvider = "billingData") public void testDownloadBill(String billDate, String billType, String tarType, String deviceInfo) throws Exception { WxPayBillResult billResult = this.payService.downloadBill(billDate, billType, tarType, deviceInfo); assertThat(billResult).isNotNull(); log.info(billResult.toString()); } /** * Test download bill with no params. * * @throws Exception the exception */ @Test(expectedExceptions = WxPayException.class) public void testDownloadBill_withNoParams() throws Exception { //必填字段为空时,抛出异常 this.payService.downloadBill("", "", "", null); } /** * Fund flow data object [ ] [ ]. * * @return the object [ ] [ ] */ @DataProvider public Object[][] fundFlowData() { return new Object[][]{ {"20180819", AccountType.BASIC, TarType.GZIP}, {"20180819", AccountType.OPERATION, TarType.GZIP}, {"20180819", AccountType.FEES, TarType.GZIP}, {"20180819", AccountType.BASIC, null}, {"20180819", AccountType.OPERATION, null}, {"20180819", AccountType.FEES, null} }; } /** * Test download fund flow. * * @param billDate the bill date * @param accountType the account type * @param tarType the tar type * @throws Exception the exception */ @Test(dataProvider = "fundFlowData") public void testDownloadFundFlow(String billDate, String accountType, String tarType) throws Exception { WxPayFundFlowResult fundFlowResult = this.payService.downloadFundFlow(billDate, accountType, tarType); assertThat(fundFlowResult).isNotNull(); log.info(fundFlowResult.toString()); } /** * Test download fund flow with no params. * * @throws Exception the exception */ @Test(expectedExceptions = WxPayException.class) public void testDownloadFundFlow_withNoParams() throws Exception { //必填字段为空时,抛出异常 this.payService.downloadFundFlow("", "", null); } /** * Test report. * * @throws Exception the exception */ @Test public void testReport() throws Exception { WxPayReportRequest request = new WxPayReportRequest(); request.setInterfaceUrl("hahahah"); request.setSignType(SignType.HMAC_SHA256);//貌似接口未校验此字段 request.setExecuteTime(1000); request.setReturnCode("aaa"); request.setResultCode("aaa"); request.setUserIp("8.8.8"); this.payService.report(request); } /** * Test method for {@link WxPayService#refund(WxPayRefundRequest)} . * * @throws Exception the exception */ @Test public void testRefund() throws Exception { WxPayRefundResult result = this.payService.refund( WxPayRefundRequest.newBuilder() .outRefundNo("aaa") .outTradeNo("1111") .totalFee(1222) .refundFee(111) .build()); log.info(result.toString()); } @Test public void testRefundV2() throws WxPayException { WxPayRefundResult result = this.payService.refundV2( WxPayRefundRequest.newBuilder() .outRefundNo("aaa") .outTradeNo("1111") .totalFee(1222) .refundFee(111) .build()); log.info(result.toString()); } /** * Test method for {@link WxPayService#refundQuery(String, String, String, String)} . * * @throws Exception the exception */ @Test public void testRefundQuery() throws Exception { WxPayRefundQueryResult result; result = this.payService.refundQuery("1", "", "", ""); log.info(result.toString()); result = this.payService.refundQuery("", "2", "", ""); log.info(result.toString()); result = this.payService.refundQuery("", "", "3", ""); log.info(result.toString()); result = this.payService.refundQuery("", "", "", "4"); log.info(result.toString()); //测试四个参数都填的情况,应该报异常的 result = this.payService.refundQuery("1", "2", "3", "4"); log.info(result.toString()); } @Test public void testRefundQueryV2() throws WxPayException { this.payService.refundQueryV2(WxPayRefundQueryRequest.newBuilder().outRefundNo("1").build()); } /** * Test parse refund notify result. * * @throws Exception the exception */ @Test public void testParseRefundNotifyResult() throws Exception { // 请参考com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResultTest里的单元测试 } /** * Test create scan pay qrcode mode 1. * * @throws Exception the exception */ @Test public void testCreateScanPayQrcodeMode1() throws Exception { String productId = "abc"; byte[] bytes = this.payService.createScanPayQrcodeMode1(productId, null, null); Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); Files.write(qrcodeFilePath, bytes); String qrcodeContent = QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()); log.info(qrcodeContent); assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?")); assertTrue(qrcodeContent.contains("product_id=" + productId)); } /** * Test create scan pay qrcode mode 2. * * @throws Exception the exception */ @Test public void testCreateScanPayQrcodeMode2() throws Exception { String qrcodeContent = "abc"; byte[] bytes = this.payService.createScanPayQrcodeMode2(qrcodeContent, null, null); Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); Files.write(qrcodeFilePath, bytes); assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); } /** * Test micropay. * * @throws Exception the exception */ @Test public void testMicropay() throws Exception { WxPayMicropayResult result = this.payService.micropay( WxPayMicropayRequest .newBuilder() .body("body") .outTradeNo("aaaaa") .totalFee(123) .spbillCreateIp("127.0.0.1") .authCode("aaa") .build()); log.info(result.toString()); } /** * Test get config. * * @throws Exception the exception */ @Test public void testGetConfig() throws Exception { // no need to test } /** * Test set config. * * @throws Exception the exception */ @Test public void testSetConfig() throws Exception { // no need to test } /** * Test reverse order. * * @throws Exception the exception */ @Test public void testReverseOrder() throws Exception { WxPayOrderReverseResult result = this.payService.reverseOrder( WxPayOrderReverseRequest.newBuilder() .outTradeNo("1111") .build()); assertNotNull(result); log.info(result.toString()); } /** * Test shorturl. * * @throws Exception the exception */ @Test public void testShorturl() throws Exception { String longUrl = "weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX"; String result = this.payService.shorturl(new WxPayShorturlRequest(longUrl)); assertNotNull(result); log.info(result); result = this.payService.shorturl(longUrl); assertNotNull(result); log.info(result); } /** * Test authcode 2 openid. * * @throws Exception the exception */ @Test public void testAuthcode2Openid() throws Exception { String authCode = "11111"; String result = this.payService.authcode2Openid(new WxPayAuthcode2OpenidRequest(authCode)); assertNotNull(result); log.info(result); result = this.payService.authcode2Openid(authCode); assertNotNull(result); log.info(result); } /** * Test get sandbox sign key. * * @throws Exception the exception */ @Test public void testGetSandboxSignKey() throws Exception { final String signKey = this.payService.getSandboxSignKey(); assertNotNull(signKey); log.info(signKey); } /** * Test send coupon. * * @throws Exception the exception */ @Test public void testSendCoupon() throws Exception { WxPayCouponSendResult result = this.payService.sendCoupon(WxPayCouponSendRequest.newBuilder() .couponStockId("123") .openid("122") .partnerTradeNo("1212") .openidCount(1) .build()); log.info(result.toString()); } /** * Test query coupon stock. * * @throws Exception the exception */ @Test public void testQueryCouponStock() throws Exception { WxPayCouponStockQueryResult result = this.payService.queryCouponStock( WxPayCouponStockQueryRequest.newBuilder() .couponStockId("123") .build()); log.info(result.toString()); } /** * Test query coupon info. * * @throws Exception the exception */ @Test public void testQueryCouponInfo() throws Exception { WxPayCouponInfoQueryResult result = this.payService.queryCouponInfo( WxPayCouponInfoQueryRequest.newBuilder() .openid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4") .couponId("11") .stockId("1121") .build()); log.info(result.toString()); } /** * 只支持拉取90天内的评论数据 * * @throws Exception the exception */ @Test public void testQueryComment() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -1); Date endDate = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, -88); Date beginDate = calendar.getTime(); String result = this.payService.queryComment(beginDate, endDate, 0, 1); log.info(result); } /** * Test parse order notify result. * * @throws Exception the exception * @see WxPayOrderNotifyResultTest#testFromXML() WxPayOrderNotifyResultTest#testFromXML() */ @Test public void testParseOrderNotifyResult() throws Exception { // 请参考com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResultTest 里的单元测试 String xmlString = "<xml>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <attach><![CDATA[支付测试]]></attach>\n" + " <bank_type><![CDATA[CFT]]></bank_type>\n" + " <fee_type><![CDATA[CNY]]></fee_type>\n" + " <is_subscribe><![CDATA[Y]]></is_subscribe>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <nonce_str><![CDATA[5d2b6c2a8db53831f7eda20af46e531c]]></nonce_str>\n" + " <openid><![CDATA[oUpF8uMEb4qRXf22hE3X68TekukE]]></openid>\n" + " <out_trade_no><![CDATA[1409811653]]></out_trade_no>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <sign><![CDATA[B552ED6B279343CB493C5DD0D78AB241]]></sign>\n" + " <sub_mch_id><![CDATA[10000100]]></sub_mch_id>\n" + " <time_end><![CDATA[20140903131540]]></time_end>\n" + " <total_fee>1</total_fee>\n" + " <trade_type><![CDATA[JSAPI]]></trade_type>\n" + " <transaction_id><![CDATA[1004400740201409030005092168]]></transaction_id>\n" + " <coupon_count>2</coupon_count>\n" + " <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" + " <coupon_id_0>10000</coupon_id_0>\n" + " <coupon_fee_0>100</coupon_fee_0>\n" + " <coupon_type_1><![CDATA[NO_CASH]]></coupon_type_1>\n" + " <coupon_id_1>10001</coupon_id_1>\n" + " <coupon_fee_1>200</coupon_fee_1>\n" + "</xml>"; XmlConfig.fastMode = true; WxPayOrderNotifyResult result; try { result = BaseWxPayResult.fromXML(xmlString, WxPayOrderNotifyResult.class); System.out.println(result); } finally { XmlConfig.fastMode = false; } result = this.payService.parseOrderNotifyResult(xmlString); System.out.println(result); } /** * Test parse order notify result with JSON format should give helpful error. * 测试当传入V3版本的JSON格式通知数据时,应该抛出清晰的错误提示 * * @throws Exception the exception */ @Test public void testParseOrderNotifyResultWithJsonShouldGiveHelpfulError() throws Exception { String jsonString = "{\n" + " \"id\": \"EV-2018022511223320873\",\n" + " \"create_time\": \"2015-05-20T13:29:35+08:00\",\n" + " \"resource_type\": \"encrypt-resource\",\n" + " \"event_type\": \"TRANSACTION.SUCCESS\",\n" + " \"summary\": \"支付成功\",\n" + " \"resource\": {\n" + " \"algorithm\": \"AEAD_AES_256_GCM\",\n" + " \"ciphertext\": \"test\",\n" + " \"associated_data\": \"transaction\",\n" + " \"nonce\": \"test\"\n" + " }\n" + "}"; try { this.payService.parseOrderNotifyResult(jsonString); fail("Expected WxPayException for JSON input"); } catch (WxPayException e) { // 验证错误消息包含V3版本和parseOrderNotifyV3Result方法的指导信息 String message = e.getMessage(); assertTrue(message.contains("V3版本"), "错误消息应包含'V3版本'"); assertTrue(message.contains("JSON格式"), "错误消息应包含'JSON格式'"); assertTrue(message.contains("parseOrderNotifyV3Result"), "错误消息应包含'parseOrderNotifyV3Result'方法名"); assertTrue(message.contains("SignatureHeader"), "错误消息应包含'SignatureHeader'"); log.info("JSON格式检测正常,错误提示: {}", message); } } /** * Test get wx api data. * * @throws Exception the exception */ @Test public void testGetWxApiData() throws Exception { //see test in testUnifiedOrder() } @Test public void testDownloadRawBill() { } @Test public void testTestDownloadRawBill() { } @Test public void testGetWxPayFaceAuthInfo() throws WxPayException { XmlConfig.fastMode = true; final WxPayFaceAuthInfoRequest request = new WxPayFaceAuthInfoRequest() .setStoreId("1").setRawdata("111").setNow("111").setVersion("111").setStoreName("2222").setDeviceId("111"); request.setSignType("MD5"); this.payService.getWxPayFaceAuthInfo(request); } @Test public void testFacepay() throws WxPayException { final WxPayFacepayResult result = this.payService.facepay(WxPayFacepayRequest.newBuilder().build()); } @Test public void testGetEntPayService() { // no need to test } @Test public void testGetProfitSharingService() { // no need to test } @Test public void testGetRedpackService() { // no need to test } @Test public void testSetEntPayService() { // no need to test } @Test public void testGetPayBaseUrl() { // no need to test } @Test public void testParseScanPayNotifyResult() { } @Test public void testSendMiniProgramRedpack() { } @Test public void testSendRedpack() { } @Test public void testQueryRedpack() { } @Test public void testTestQueryRedpack() { } @Test public void testGetPayScoreService() { // no need to test } @Test public void testQueryExchangeRate() throws WxPayException { final WxPayQueryExchangeRateResult result = this.payService.queryExchangeRate("USD", "20200425"); assertThat(result).isNotNull(); System.out.println(result); } private static final Gson GSON = new GsonBuilder().create(); @Test public void testUnifiedOrderV3() throws WxPayException { String outTradeNo = RandomUtils.getRandomStr(); String notifyUrl = "https://api.qq.com/"; System.out.println("outTradeNo = " + outTradeNo); WxPayUnifiedOrderV3Request request = new WxPayUnifiedOrderV3Request(); request.setOutTradeNo(outTradeNo); request.setNotifyUrl(notifyUrl); request.setDescription("test"); WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer(); payer.setOpenid("openid"); request.setPayer(payer); //构建金额信息 WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount(); //设置币种信息 amount.setCurrency(WxPayConstants.CurrencyType.CNY); //设置金额 amount.setTotal(BaseWxPayRequest.yuan2Fen(BigDecimal.ONE)); request.setAmount(amount); WxPayUnifiedOrderV3Result.JsapiResult result = this.payService.createOrderV3(TradeTypeEnum.JSAPI, request); System.out.println(GSON.toJson(result)); } @Test public void testQueryOrderV3() throws WxPayException { WxPayOrderQueryV3Request request = new WxPayOrderQueryV3Request(); request.setOutTradeNo("n1ZvYqjAg3D3LUBa"); WxPayOrderQueryV3Result result = this.payService.queryOrderV3(request); System.out.println(GSON.toJson(result)); } @Test public void testCloseOrderV3() throws WxPayException { WxPayOrderCloseV3Request request = new WxPayOrderCloseV3Request(); request.setOutTradeNo("n1ZvYqjAg3D3LUBa"); this.payService.closeOrderV3(request); } @Test public void testRefundV3() throws WxPayException { String outRefundNo = RandomUtils.getRandomStr(); String notifyUrl = "https://api.qq.com/"; System.out.println("outRefundNo = " + outRefundNo); WxPayRefundV3Request request = new WxPayRefundV3Request(); request.setOutTradeNo("n1ZvYqjAg3D3LUBa"); request.setOutRefundNo(outRefundNo); request.setNotifyUrl(notifyUrl); request.setAmount(new WxPayRefundV3Request.Amount().setRefund(100).setTotal(100).setCurrency("CNY")); WxPayRefundV3Result result = this.payService.refundV3(request); System.out.println(GSON.toJson(result)); } /** * 测试V3支付成功回调 * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_5.shtml * * @throws Exception the exception */ @Test public String testParseOrderNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception { String timestamp = request.getHeader("Wechatpay-Timestamp"); Optional.ofNullable(timestamp).orElseThrow(() -> new RuntimeException("时间戳不能为空")); String nonce = request.getHeader("Wechatpay-Nonce"); Optional.ofNullable(nonce).orElseThrow(() -> new RuntimeException("nonce不能为空")); String serialNo = request.getHeader("Wechatpay-Serial"); Optional.ofNullable(serialNo).orElseThrow(() -> new RuntimeException("serialNo不能为空")); String signature = request.getHeader("Wechatpay-Signature"); Optional.ofNullable(signature).orElseThrow(() -> new RuntimeException("signature不能为空")); log.info("请求头参数为:timestamp:{} nonce:{} serialNo:{} signature:{}", timestamp, nonce, serialNo, signature); // V2版本请参考com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResultTest里的单元测试 final WxPayNotifyV3Result wxPayOrderNotifyV3Result = this.payService.parseOrderNotifyV3Result(RequestUtils.readData(request), new SignatureHeader(timestamp, nonce, signature, serialNo)); log.info(GSON.toJson(wxPayOrderNotifyV3Result)); return WxPayNotifyV3Response.success("成功"); } /** * 测试V3退款成功回调 * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_11.shtml * * @throws Exception the exception */ @Test public String testParseRefundNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception { String timestamp = request.getHeader("Wechatpay-Timestamp"); Optional.ofNullable(timestamp).orElseThrow(() -> new RuntimeException("时间戳不能为空")); String nonce = request.getHeader("Wechatpay-Nonce"); Optional.ofNullable(nonce).orElseThrow(() -> new RuntimeException("nonce不能为空")); String serialNo = request.getHeader("Wechatpay-Serial"); Optional.ofNullable(serialNo).orElseThrow(() -> new RuntimeException("serialNo不能为空")); String signature = request.getHeader("Wechatpay-Signature"); Optional.ofNullable(signature).orElseThrow(() -> new RuntimeException("signature不能为空")); log.info("支付请求头参数为:timestamp:{} nonce:{} serialNo:{} signature:{}", timestamp, nonce, serialNo, signature); final WxPayRefundNotifyV3Result wxPayRefundNotifyV3Result = this.payService.parseRefundNotifyV3Result(RequestUtils.readData(request), new SignatureHeader(timestamp, nonce, signature, serialNo)); log.info(GSON.toJson(wxPayRefundNotifyV3Result)); // 退款金额 final WxPayRefundNotifyV3Result.DecryptNotifyResult result = wxPayRefundNotifyV3Result.getResult(); final BigDecimal total = BaseWxPayRequest.fen2Yuan(BigDecimal.valueOf(result.getAmount().getTotal())); final BigDecimal payerRefund = BaseWxPayRequest.fen2Yuan(BigDecimal.valueOf(result.getAmount().getPayerRefund())); // 处理业务逻辑 ... return WxPayNotifyV3Response.success("成功"); } /** * 商家转账批次回调通知 * https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-batch-callback-notice.html * * @return * @throws Exception */ @Test public String parseTransferBatchesNotifyV3Result() throws Exception { String body = "{\n" + " \"id\": \"1c8192d8-aba1-5898-a79c-7d3abb72eabe\",\n" + " \"create_time\": \"2023-08-16T16:43:27+08:00\",\n" + " \"resource_type\": \"encrypt-resource\",\n" + " \"event_type\": \"MCHTRANSFER.BATCH.FINISHED\",\n" + " \"summary\": \"商家转账批次完成通知\",\n" + " \"resource\": {\n" + " \"original_type\": \"mch_payment\",\n" + " \"algorithm\": \"AEAD_AES_256_GCM\",\n" + " \"ciphertext\": \"zTBf6DDPzZSoIBkoLFkC+ho97QrqnT6UU/ADM0tJP07ITaFPek4vofQjmclLUof78NqrPcJs5OIBl+gnKKJ4xCxcDmDnZZHvev5o1pk4gwtJIFIDxbq3piDr4Wq6cZpvGPPQTYC8YoVRTdVeeN+EcuklRrmaFzv8wCTSdI9wFJ9bsxtLedhq4gpkKqN5fbSguQg9JFsX3OJeT7KPfRd6SD1gu4Lpw5gwxthfOHcYsjM/eY5gaew8zzpN6mMUEJ1HqkNuQgOguHBxFnqFPiMz+Iadw7X38Yz+IgfUkOhN1iuvMhGYKbwKJ7rTiBVvGGpF6Wse1zFKgSiTLH2RnUAMkkHmxqk+JhbQKZpSWr6O8BfhHO1OKg7hpcHZtOJKNMjIF62WYDVf36w1h8h5fg==\",\n" + " \"associated_data\": \"mch_payment\",\n" + " \"nonce\": \"DdF3UJVNQaKT\"\n" + " }\n" + "}"; WxPayTransferBatchesNotifyV3Result transferBatchesNotifyV3Body = GSON.fromJson(body, WxPayTransferBatchesNotifyV3Result.class); log.info(GSON.toJson(transferBatchesNotifyV3Body)); // 处理业务逻辑 ... return WxPayNotifyV3Response.success("成功"); } // 测试 public static void main(String[] args){ String body = "{\n" + " \"id\": \"1c8192d8-aba1-5898-a79c-7d3abb72eabe\",\n" + " \"create_time\": \"2023-08-16T16:43:27+08:00\",\n" + " \"resource_type\": \"encrypt-resource\",\n" + " \"event_type\": \"MCHTRANSFER.BATCH.FINISHED\",\n" + " \"summary\": \"商家转账批次完成通知\",\n" + " \"resource\": {\n" + " \"original_type\": \"mch_payment\",\n" + " \"algorithm\": \"AEAD_AES_256_GCM\",\n" + " \"ciphertext\": \"zTBf6DDPzZSoIBkoLFkC+ho97QrqnT6UU/ADM0tJP07ITaFPek4vofQjmclLUof78NqrPcJs5OIBl+gnKKJ4xCxcDmDnZZHvev5o1pk4gwtJIFIDxbq3piDr4Wq6cZpvGPPQTYC8YoVRTdVeeN+EcuklRrmaFzv8wCTSdI9wFJ9bsxtLedhq4gpkKqN5fbSguQg9JFsX3OJeT7KPfRd6SD1gu4Lpw5gwxthfOHcYsjM/eY5gaew8zzpN6mMUEJ1HqkNuQgOguHBxFnqFPiMz+Iadw7X38Yz+IgfUkOhN1iuvMhGYKbwKJ7rTiBVvGGpF6Wse1zFKgSiTLH2RnUAMkkHmxqk+JhbQKZpSWr6O8BfhHO1OKg7hpcHZtOJKNMjIF62WYDVf36w1h8h5fg==\",\n" + " \"associated_data\": \"mch_payment\",\n" + " \"nonce\": \"DdF3UJVNQaKT\"\n" + " }\n" + "}"; OriginNotifyResponse transferBatchesNotifyV3Body = GSON.fromJson(body, OriginNotifyResponse.class); log.info(GSON.toJson(transferBatchesNotifyV3Body)); String decryptNotifyResult = "{\n" + " \"out_batch_no\": \"bfatestnotify000033\",\n" + " \"batch_id\": \"131000007026709999520922023081519403795655\",\n" + " \"batch_status\": \"FINISHED\",\n" + " \"total_num\": 2,\n" + " \"total_amount\": 200,\n" + " \"success_amount\": 100,\n" + " \"success_num\": 1,\n" + " \"fail_amount\": 100,\n" + " \"fail_num\": 1,\n" + " \"mchid\": \"2483775951\",\n" + " \"update_time\": \"2023-08-15T20:33:22+08:00\"\n" + "}"; WxPayTransferBatchesNotifyV3Result.DecryptNotifyResult notifyResult = GSON.fromJson(decryptNotifyResult, WxPayTransferBatchesNotifyV3Result.DecryptNotifyResult.class); log.info(GSON.toJson(notifyResult)); } @Test public void testWxPayNotifyV3Response() { System.out.println(WxPayNotifyV3Response.success("success")); System.out.println(WxPayNotifyV3Response.fail("fail")); } @Test public void testRefundQueryV3() throws WxPayException { WxPayRefundQueryV3Request request = new WxPayRefundQueryV3Request(); // request.setOutRefundNo("n1ZvYqjAg3D7LUBa"); request.setOutRefundNo("123456789011"); WxPayRefundQueryV3Result result = this.payService.refundQueryV3(request); System.out.println(GSON.toJson(result)); } /** * 测试包含正向代理的测试 * * @throws WxPayException */ @Test public void testQueryOrderV3WithProxy() { try { WxPayOrderQueryV3Request request = new WxPayOrderQueryV3Request(); request.setOutTradeNo("n1ZvYqjAg3D3LUBa"); WxPayConfig config = this.payService.getConfig(); config.setApiHostUrl("http://api.mch.weixin.qq.com");
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
true
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayrollServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayrollServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.marketing.payroll.*; import com.github.binarywang.wxpay.bean.marketing.transfer.PartnerTransferRequest; import com.github.binarywang.wxpay.bean.marketing.transfer.PartnerTransferResult; import com.github.binarywang.wxpay.bean.result.WxPayApplyBillV3Result; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * 微工卡(服务商) * * @author xiaoqiang * created on 2021/12/9 */ @Slf4j @Test @Guice(modules = ApiTestModule.class) public class PayrollServiceImplTest { @Inject private WxPayService wxPayService; private static final Gson GSON = new GsonBuilder().create(); @Test public void payrollCardTokens() throws WxPayException { TokensRequest request = new TokensRequest(); request.setOpenid("onqOjjmo8wmTOOtSKwXtGjg9Gb58"); request.setAppid("wxa1111111"); request.setSubMchid("1111111"); request.setSubAppid("wxa1111111"); request.setUserName("LP7bT4hQXUsOZCEvK2YrSiqFsnP0oRMfeoLN0vBg"); request.setIdCardNumber("7FzH5XksJG3a8HLLsaaUV6K54y1OnPMY5"); request.setEmploymentType("LONG_TERM_EMPLOYMENT"); TokensResult tokensResult = wxPayService.getPayrollService().payrollCardTokens(request); log.info(tokensResult.toString()); } @Test public void payrollCardRelations() throws WxPayException { RelationsRequest request = new RelationsRequest(); request.setOpenid("onqOjjmo8wmTOOtSKwXtGjg9Gb58"); request.setSubMchid("1111111"); request.setAppid("wxa1111111"); request.setSubAppid("wxa1111111"); RelationsResult relationsResult = wxPayService.getPayrollService().payrollCardRelations(request); log.info(relationsResult.toString()); } @Test public void payrollCardPreOrder() throws WxPayException { PreOrderRequest request = new PreOrderRequest(); request.setOpenid("onqOjjmo8wmTOOtSKwXtGjg9Gb58"); request.setSubMchid("1111111"); request.setAppid("wxa1111111"); request.setSubAppid("wxa1111111"); request.setAuthenticateNumber("mcdhehfgisdhfjghed39384564i83"); request.setProjectName("某项目"); request.setEmployerName("某单位名称"); PreOrderResult preOrderResult = wxPayService.getPayrollService().payrollCardPreOrder(request); log.info(preOrderResult.toString()); } @Test public void payrollCardAuthenticationsNumber() throws WxPayException { String subMchid = "1111111"; String authenticateNumber = "mcdhehfgisdhfjghed39384564i83"; AuthenticationsResult authenticationsResult = wxPayService.getPayrollService().payrollCardAuthenticationsNumber(subMchid, authenticateNumber); log.info(authenticationsResult.toString()); } @Test public void payrollCardAuthentications() throws WxPayException { AuthRecordRequest request = new AuthRecordRequest(); request.setOpenid("onqOjjmo8wmTOOtSKwXtGjg9Gb58"); request.setSubMchid("1111111"); request.setAppid("wxa1111111"); request.setSubAppid("wxa1111111"); request.setAuthenticateDate("2020-12-25"); request.setAuthenticateState("AUTHENTICATE_SUCCESS"); request.setOffset(0); request.setLimit(10); AuthRecordResult authRecordResult = wxPayService.getPayrollService().payrollCardAuthentications(request); log.info(authRecordResult.toString()); } @Test public void payrollCardPreOrderWithAuth() throws WxPayException { PreOrderWithAuthRequest request = new PreOrderWithAuthRequest(); request.setOpenid("onqOjjmo8wmTOOtSKwXtGjg9Gb58"); request.setSubMchid("1111111"); request.setAppid("wxa1111111"); request.setSubAppid("wxa1111111"); request.setAuthenticateNumber("mcdhehfgisdhfjghed39384564i83"); request.setEmployerName("某用工企业"); request.setEmploymentType("LONG_TERM_EMPLOYMENT"); request.setIdCardNumber("7FzH5XksJG3a8HLLsaaUV6K54y1OnPMY5"); request.setProjectName("某项目"); request.setUserName("LP7bT4hQXUsOZCEvK2YrSiqFsnP0oRMfeoLN0vBg"); PreOrderWithAuthResult preOrderWithAuthResult = wxPayService.getPayrollService().payrollCardPreOrderWithAuth(request); log.info(preOrderWithAuthResult.toString()); } @Test public void merchantFundWithdrawBillType() throws WxPayException { String billType = "NO_SUCC"; String billDate = "2019-08-17"; WxPayApplyBillV3Result result = wxPayService.getPayrollService().merchantFundWithdrawBillType(billType, billDate, null); log.info(result.toString()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxEntrustPapServiceTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxEntrustPapServiceTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.common.base.Joiner; import com.google.inject.Inject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * @author chenliang * created on 2021-08-02 6:45 下午 */ @Test @Guice(modules = ApiTestModule.class) public class WxEntrustPapServiceTest { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Inject private WxPayService payService; /** * 公众号纯签约 */ @Test public void testMpSign() { String contractCode = "222200002222"; String displayAccount = Joiner.on("").join("陈*", "(", "10000014", ")"); WxMpEntrustRequest wxMpEntrust = WxMpEntrustRequest.newBuilder() .planId("142323") //模板ID:跟微信申请 .contractCode(contractCode) .contractDisplayAccount(displayAccount) .notifyUrl("http://domain.com/api/wxpay/sign/callback.do") .requestSerial(6L) //.returnWeb(1) .version("1.0") .timestamp(String.valueOf(System.currentTimeMillis() / 1000)) .outerId(displayAccount) .build(); String url = null; try { url = this.payService.getWxEntrustPapService().mpSign(wxMpEntrust); } catch (WxPayException e) { e.printStackTrace(); } logger.info(url); } /** * 小程序纯签约 */ @Test public void testMaSign() { String contractCode = "222220000022222"; String displayAccount = Joiner.on("").join("陈*", "(", "10000001", ")"); WxMaEntrustRequest wxMaEntrustRequest = WxMaEntrustRequest.newBuilder() .contractCode(contractCode) .contractDisplayAccount(contractCode) .notifyUrl("http://domain.com/api/wxpay/sign/callback.do") .outerId(displayAccount) .planId("141535") .requestSerial(2L) .timestamp(String.valueOf(System.currentTimeMillis() / 1000)) .build(); try { String url = this.payService.getWxEntrustPapService().maSign(wxMaEntrustRequest); logger.info(url); } catch (WxPayException e) { e.printStackTrace(); } } /** * h5纯签约 */ @Test public void testH5Sign() { String contractCode = "222111122222"; String displayAccount = Joiner.on("").join("陈*", "(", "100000000", ")"); WxH5EntrustRequest wxH5EntrustRequest = WxH5EntrustRequest.newBuilder() .requestSerial(2L) .clientIp("127.0.0.1") .contractCode(contractCode) .contractDisplayAccount(displayAccount) .notifyUrl("http://domain.com/api/wxpay/sign/callback.do") .planId("141535") .returnAppid("1") .timestamp(String.valueOf(System.currentTimeMillis() / 1000)) .version("1.0") .outerId(displayAccount) .build(); try { WxH5EntrustResult wxH5EntrustResult = this.payService.getWxEntrustPapService().h5Sign(wxH5EntrustRequest); logger.info(wxH5EntrustResult.toString()); } catch (WxPayException e) { e.printStackTrace(); } } @Test public void testPaySign() { String contractCode = "2222211110000222"; String displayAccount = Joiner.on("").join("陈*", "(", "10000005", ")"); String outTradeNo = "11100111101"; WxPayEntrustRequest wxPayEntrustRequest = WxPayEntrustRequest.newBuilder() .attach("local") .body("产品名字") .contractAppId(this.payService.getConfig().getAppId()) .contractCode(contractCode) .contractDisplayAccount(displayAccount) .contractMchId(this.payService.getConfig().getMchId()) //签约回调 .contractNotifyUrl("http://domain.com/api/wxpay/sign/callback.do") .detail("产品是好") .deviceInfo("oneplus 7 pro") //.goodsTag() //.limitPay() //支付回调 .notifyUrl("http://domain.com/api/wxpay/pay/callback.do") .openId("oIvLdt8Q-_aKy4Vo6f4YI6gsIhMc") //openId .outTradeNo(outTradeNo) .planId("141535") //.productId() .requestSerial(3L) .spbillCreateIp("127.0.0.1") //.timeExpire() //.timeStart() .totalFee(1) .tradeType("MWEB") .contractOuterId(displayAccount) .build(); try { WxPayEntrustResult wxPayEntrustResult = this.payService.getWxEntrustPapService().paySign(wxPayEntrustRequest); logger.info(wxPayEntrustResult.toString()); } catch (WxPayException e) { e.printStackTrace(); } } @Test public void testWithhold() { String outTradeNo = "101010101"; WxWithholdRequest withholdRequest = WxWithholdRequest.newBuilder() .attach("local") .body("产品名字") .contractId("202011065409471222") // 微信返回的签约协议号 .detail("产品描述") .feeType("CNY") //.goodsTag() .notifyUrl("http://domain.com/api/wxpay/withhold/callback.do") .outTradeNo(outTradeNo) .spbillCreateIp("127.0.0.1") .totalFee(1) .tradeType("PAP") .build(); try { WxWithholdResult wxWithholdResult = this.payService.getWxEntrustPapService().withhold(withholdRequest); logger.info(wxWithholdResult.toString()); } catch (WxPayException e) { e.printStackTrace(); } } @Test public void testWithholdPartner() { String outTradeNo = "101010101"; WxWithholdRequest withholdRequest = WxWithholdRequest.newBuilder() .attach("local") .body("产品名字") .contractId("202011065409471222") // 微信返回的签约协议号 .detail("产品描述") .feeType("CNY") //.goodsTag() .notifyUrl("http://domain.com/api/wxpay/withhold/callback.do") .outTradeNo(outTradeNo) .spbillCreateIp("127.0.0.1") .totalFee(1) .tradeType("PAP") .build(); try { WxPayCommonResult wxPayCommonResult = this.payService.getWxEntrustPapService().withholdPartner(withholdRequest); logger.info(wxPayCommonResult.toString()); } catch (WxPayException e) { e.printStackTrace(); } } @Test public void testPreWithhold() { WxPreWithholdRequest.EstimateAmount estimateAmount = new WxPreWithholdRequest.EstimateAmount(); estimateAmount.setAmount(1); estimateAmount.setCurrency("CNY"); WxPreWithholdRequest wxPreWithholdRequest = WxPreWithholdRequest.newBuilder() .appId("wx73dssxxxxxx") .contractId("202010275173070001") .estimateAmount(estimateAmount) .mchId("1600010102") .build(); try { String httpResponseModel = this.payService.getWxEntrustPapService().preWithhold(wxPreWithholdRequest); logger.info(httpResponseModel); } catch (WxPayException e) { e.printStackTrace(); } } @Test public void testQuerySign() { String outTradeNo = "1212121212"; WxSignQueryRequest wxSignQueryRequest = WxSignQueryRequest.newBuilder() //.contractId("202010275173073211") .contractCode(outTradeNo) .planId(1432112) .version("1.0") .build(); try { WxSignQueryResult wxSignQueryResult = this.payService.getWxEntrustPapService().querySign(wxSignQueryRequest); logger.info(wxSignQueryResult.toString()); } catch (WxPayException e) { logger.info("异常码:" + e.getErrCode()); logger.info("异常:" + e); } } @Test public void testTerminationContract() { WxTerminatedContractRequest wxTerminatedContractRequest = WxTerminatedContractRequest.newBuilder() .contractId("202010275173070231") .contractTerminationRemark("测试解约") .version("1.0") .build(); try { WxTerminationContractResult wxTerminationContractResult = this.payService.getWxEntrustPapService().terminationContract(wxTerminatedContractRequest); logger.info(wxTerminationContractResult.toString()); } catch (WxPayException e) { logger.error(e.getMessage()); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/TransferServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/TransferServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.transfer.QueryTransferBatchesRequest; import com.github.binarywang.wxpay.bean.transfer.TransferBatchesRequest; import com.github.binarywang.wxpay.bean.transfer.TransferBillsRequest; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; /** * 获取商家转账到零钱服务类API测试 * * @author zhongjun * created on 2022/6/17 **/ @Slf4j @Test @Guice(modules = ApiTestModule.class) public class TransferServiceImplTest { @Inject private WxPayService payService; @Test public void testTransferBatches() throws WxPayException { List<TransferBatchesRequest.TransferDetail> transferDetailList = new ArrayList<>(); transferDetailList.add(TransferBatchesRequest.TransferDetail.newBuilder() .outDetailNo("1655447989156") .transferAmount(100) .transferRemark("测试转账") .openid("oX_7Jzr9gSZz4X_Xc9-_7HGf8XzI") .userName("测试用户").build()); TransferBatchesRequest batchesRequest = TransferBatchesRequest.newBuilder() .appid("wxf636efh5xxxxx") .outBatchNo("1655447999520") .batchName("测试批次") .batchRemark("测试批次备注") .totalAmount(100) .totalNum(1) .transferDetailList(transferDetailList).build(); log.info("发起商家转账:{}", this.payService.getTransferService().transferBatches(batchesRequest)); } @Test public void testTransferBatchesBatchId() throws WxPayException { log.info("微信批次单号查询批次单:{}", this.payService.getTransferService().transferBatchesBatchId(QueryTransferBatchesRequest.newBuilder() .batchId("1655448154148") .needQueryDetail(true) .build())); } @Test public void testTransferBatchesBatchIdDetail() throws WxPayException { log.info("微信明细单号查询明细单:{}", this.payService.getTransferService().transferBatchesBatchIdDetail("1030000071100999991182020050700019480001", "1040000071100999991182020050700019500100")); } @Test public void testTransferBatchesOutBatchNo() throws WxPayException { log.info("商家批次单号查询批次单:{}", this.payService.getTransferService().transferBatchesOutBatchNo(QueryTransferBatchesRequest.newBuilder() .outBatchNo("1655447999520") .needQueryDetail(true) .build())); } @Test public void testTransferBatchesOutBatchNoDetail() throws WxPayException { log.info("商家明细单号查询明细单:{}", this.payService.getTransferService().transferBatchesOutBatchNoDetail("1655447999520", "1655447989156")); } @Test public void testTransferBills() throws WxPayException { TransferBillsRequest transferBillsRequest = TransferBillsRequest.newBuilder() .appid("wxf636efh5xxxxx") .outBillNo("1655447989156") .transferSceneId("1005") .transferAmount(100) .transferRemark("测试转账") .openid("oX_7Jzr9gSZz4X_Xc9-_7HGf8XzI") .userName("测试用户").build(); log.info("发起商家转账:{}", this.payService.getTransferService().transferBills(transferBillsRequest)); } @Test public void testTransformBillsCancel() throws WxPayException { log.info("撤销商家转账:{}", this.payService.getTransferService().transformBillsCancel("123456")); } @Test public void testGetBillsByOutBillNo() throws WxPayException { log.info("商户单号查询转账单:{}", this.payService.getTransferService().getBillsByOutBillNo("123456")); } @Test public void testGetBillsByTransferBillNo() throws WxPayException { log.info("微信单号查询转账单:{}", this.payService.getTransferService().getBillsByTransferBillNo("123456")); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImplConnectionPoolTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImplConnectionPoolTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.exception.WxPayException; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.testng.Assert; import org.testng.annotations.Test; /** * 测试WxPayServiceApacheHttpImpl的连接池功能 */ public class WxPayServiceApacheHttpImplConnectionPoolTest { @Test public void testHttpClientConnectionPool() throws Exception { WxPayConfig config = new WxPayConfig(); config.setAppId("test-app-id"); config.setMchId("test-mch-id"); config.setMchKey("test-mch-key"); // 测试初始化连接池 CloseableHttpClient httpClient1 = config.initHttpClient(); Assert.assertNotNull(httpClient1, "HttpClient should not be null"); // 再次获取,应该返回同一个实例 CloseableHttpClient httpClient2 = config.getHttpClient(); Assert.assertSame(httpClient1, httpClient2, "Should return the same HttpClient instance"); // 验证连接池配置 WxPayServiceApacheHttpImpl service = new WxPayServiceApacheHttpImpl(); service.setConfig(config); // 测试不使用SSL的情况下应该使用连接池 CloseableHttpClient clientForNonSSL = service.createHttpClient(false); Assert.assertSame(httpClient1, clientForNonSSL, "Should use pooled client for non-SSL requests"); } @Test public void testSslHttpClientConnectionPool() throws Exception { WxPayConfig config = new WxPayConfig(); config.setAppId("test-app-id"); config.setMchId("test-mch-id"); config.setMchKey("test-mch-key"); // 为了测试SSL客户端,我们需要设置一些基本的SSL配置 // 注意:在实际使用中需要提供真实的证书 try { CloseableHttpClient sslClient1 = config.initSslHttpClient(); Assert.assertNotNull(sslClient1, "SSL HttpClient should not be null"); CloseableHttpClient sslClient2 = config.getSslHttpClient(); Assert.assertSame(sslClient1, sslClient2, "Should return the same SSL HttpClient instance"); WxPayServiceApacheHttpImpl service = new WxPayServiceApacheHttpImpl(); service.setConfig(config); // 测试使用SSL的情况下应该使用SSL连接池 CloseableHttpClient clientForSSL = service.createHttpClient(true); Assert.assertSame(sslClient1, clientForSSL, "Should use pooled SSL client for SSL requests"); } catch (WxPayException e) { // SSL初始化失败是预期的,因为我们没有提供真实的证书 // 这里主要是测试代码路径是否正确 Assert.assertTrue(e.getMessage().contains("证书") || e.getMessage().contains("商户号"), "Should fail with certificate or merchant ID related error"); } } @Test public void testConnectionPoolConfiguration() throws Exception { WxPayConfig config = new WxPayConfig(); config.setAppId("test-app-id"); config.setMchId("test-mch-id"); config.setMchKey("test-mch-key"); config.setMaxConnTotal(50); config.setMaxConnPerRoute(20); CloseableHttpClient httpClient = config.initHttpClient(); Assert.assertNotNull(httpClient, "HttpClient should not be null"); // 验证配置值是否正确设置 Assert.assertEquals(config.getMaxConnTotal(), 50, "Max total connections should be 50"); Assert.assertEquals(config.getMaxConnPerRoute(), 20, "Max connections per route should be 20"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BrandMerchantTransferServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BrandMerchantTransferServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.request.*; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandBatchesQueryResult; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandDetailsQueryResult; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandTransferBatchesResult; import com.github.binarywang.wxpay.bean.merchanttransfer.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * 品牌红包商家转账到零钱(直连商户) * @author moran */ @Slf4j @Test @Guice(modules = ApiTestModule.class) public class BrandMerchantTransferServiceImplTest { @Inject private WxPayService wxPayService; private static final Gson GSON = new GsonBuilder().create(); @Test public void createBrandTransfer() throws WxPayException { String requestParamStr = "{\"batch_name\":\"双十一营销用品牌红包\",\"batch_remark\":\"双十一营销用品牌红包\",\"brand_appid\":\"wxf636efh567hg4356\",\"brand_id\":1234,\"detail_list\":[{\"amount\":100,\"openid\":\"o-MYE42l80oelYMDE34nYD456Xoy\",\"out_detail_no\":\"x23zy545Bd5436\",\"remark\":\"来自XX的红包\",\"user_name\":\"757b340b45ebef5467rter35gf464344v3542sdf4t6re4tb4f54ty45t4yyry45\"}],\"out_batch_no\":\"plfk2020042013\",\"scene\":\"CUSTOM_SEND\",\"template_id\":\"123400001\",\"total_amount\":10000,\"total_num\":10}"; BrandTransferBatchesRequest request = GSON.fromJson(requestParamStr, BrandTransferBatchesRequest.class); BrandTransferBatchesResult result = wxPayService.getBrandMerchantTransferService().createBrandTransfer(request); log.info(result.toString()); } @Test public void queryBrandWxBatches() throws WxPayException { String requestParamStr = "{\"batch_no\":\"1030000071100999991182020050700019480001\",\"need_query_detail\":true,\"detail_status\":\"DETAIL_VIEW_FAIL\"}"; BrandWxBatchesQueryRequest request = GSON.fromJson(requestParamStr, BrandWxBatchesQueryRequest.class); log.info("request:{}",request); BrandBatchesQueryResult result = wxPayService.getBrandMerchantTransferService().queryBrandWxBatches(request); log.info(result.toString()); } @Test public void queryBrandWxDetails() throws WxPayException { String requestParamStr = "{\"batch_no\":\"1030000071100999991182020050700019480001\",\"detail_no\":\"1040000071100999991182020050700019500100\"}"; BrandWxDetailsQueryRequest request = GSON.fromJson(requestParamStr, BrandWxDetailsQueryRequest.class); BrandDetailsQueryResult result = wxPayService.getBrandMerchantTransferService().queryBrandWxDetails(request); log.info(result.toString()); } @Test public void queryBrandMerchantBatches() throws WxPayException { String requestParamStr = "{\"out_batch_no\":\"plfk2020042013\",\"need_query_detail\":true,\"detail_status\":\"DETAIL_VIEW_FAIL\"}"; BrandMerchantBatchesQueryRequest request = GSON.fromJson(requestParamStr, BrandMerchantBatchesQueryRequest.class); BrandBatchesQueryResult result = wxPayService.getBrandMerchantTransferService().queryBrandMerchantBatches(request); log.info(result.toString()); } @Test public void queryBrandMerchantDetails() throws WxPayException { String requestParamStr = "{\"out_batch_no\":\"plfk2020042013\",\"out_detail_no\":\"x23zy545Bd5436\"}"; BrandMerchantDetailsQueryRequest request = GSON.fromJson(requestParamStr, BrandMerchantDetailsQueryRequest.class); BrandDetailsQueryResult result = wxPayService.getBrandMerchantTransferService().queryBrandMerchantDetails(request); log.info(result.toString()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MarketingBusiFavorServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MarketingBusiFavorServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.marketing.*; import com.github.binarywang.wxpay.bean.marketing.busifavor.CouponAvailableTime; import com.github.binarywang.wxpay.bean.marketing.busifavor.CouponUseRule; import com.github.binarywang.wxpay.bean.marketing.busifavor.FixedNormalCoupon; import com.github.binarywang.wxpay.bean.marketing.busifavor.StockSendRule; import com.github.binarywang.wxpay.bean.marketing.enums.StockTypeEnum; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.assertj.core.util.Lists; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * <pre> * 营销工具代金券测试类 * </pre> * * @author thinsstar */ @Slf4j @Test @Guice(modules = ApiTestModule.class) public class MarketingBusiFavorServiceImplTest { @Inject private WxPayService wxPayService; private static final Gson GSON = new GsonBuilder().create(); private final String stockId = "1252430000000013"; private final String appId = "wxb3d189e6a9160863"; private final String openId = "o3zqj1XFQBg4ju-cMs0AOqVYG0ow"; @Test public void testCreateFavorStocksV3() throws WxPayException { BusiFavorStocksCreateRequest request = new BusiFavorStocksCreateRequest(); request.setStockName("买价值984元3大罐送价值316元2小罐"); request.setBelongMerchant(wxPayService.getConfig().getMchId()); request.setComment("买价值984元3大罐送价值316元2小罐"); request.setGoodsName("仅供安满品牌商品使用"); request.setCouponCodeMode("WECHATPAY_MODE"); request.setOutRequestNo(wxPayService.getConfig().getMchId() + "20210204" + "1234567891"); //核销规则 CouponUseRule couponUseRule = new CouponUseRule(); //线下核销 couponUseRule.setUseMethod("OFF_LINE"); //券可核销时间 CouponAvailableTime couponAvailableTime = new CouponAvailableTime(); couponAvailableTime.setAvailableBeginTime("2021-05-20T13:29:35+08:00"); couponAvailableTime.setAvailableEndTime("2021-05-21T13:29:35+08:00"); couponUseRule.setCouponAvailableTime(couponAvailableTime); //固定面额满减券 request.setStockType(StockTypeEnum.NORMAL); FixedNormalCoupon fixedNormalCoupon = new FixedNormalCoupon(); fixedNormalCoupon.setDiscountAmount(31600); fixedNormalCoupon.setTransactionMinimum(98400); couponUseRule.setFixedNormalCoupon(fixedNormalCoupon); request.setCouponUseRule(couponUseRule); //发放规则 StockSendRule stockSendRule = new StockSendRule(); stockSendRule.setMaxCoupons(100); stockSendRule.setMaxCouponsPerUser(5); request.setStockSendRule(stockSendRule); BusiFavorStocksCreateResult result = wxPayService.getMarketingBusiFavorService().createBusiFavorStocksV3(request); String stockId = result.getStockId(); log.info("stockId: [{}]", stockId); } @Test public void testGetBusiFavorStocksV3() throws WxPayException { BusiFavorStocksGetResult result = wxPayService.getMarketingBusiFavorService().getBusiFavorStocksV3("1252430000000012"); log.info("result: {}", GSON.toJson(result)); } @Test public void testVerifyBusiFavorCouponsUseV3() throws WxPayException { BusiFavorCouponsUseRequest request = new BusiFavorCouponsUseRequest(); request.setCouponCode("sxxe34343434"); request.setAppId("wx1234567889999"); request.setUseTime("2015-05-20T13:29:35+08:00"); request.setUseRequestNo("1002600620019090123143254435"); BusiFavorCouponsUseResult result = wxPayService.getMarketingBusiFavorService().verifyBusiFavorCouponsUseV3(request); log.info("result: {}", GSON.toJson(result)); } @Test public void testBuildBusiFavorCouponinfoUrl() throws WxPayException { BusiFavorCouponsUrlRequest request = new BusiFavorCouponsUrlRequest(); request.setOpenid(openId); request.setOutRequestNo("100002322019090134242"); request.setSendCouponMerchant("1466573302"); request.setStockId(stockId); String result = wxPayService.getMarketingBusiFavorService().buildBusiFavorCouponinfoUrl(request); log.info("result: {}", result); } @Test public void testQueryBusiFavorUsersCoupons() throws WxPayException { BusiFavorQueryUserCouponsRequest request = new BusiFavorQueryUserCouponsRequest(); request.setOpenid(openId); request.setAppid(appId); request.setStockId("9865000"); request.setCouponState("USED"); request.setCreatorMerchant("1466573302"); BusiFavorQueryUserCouponsResult result = wxPayService.getMarketingBusiFavorService().queryBusiFavorUsersCoupons(request); log.info("result: {}", result); } @Test public void testQueryOneBusiFavorUsersCoupons() throws WxPayException { BusiFavorQueryOneUserCouponsRequest request = new BusiFavorQueryOneUserCouponsRequest(); request.setOpenid(openId); request.setAppid(appId); request.setCouponCode("123446565767"); BusiFavorQueryOneUserCouponsResult result = wxPayService.getMarketingBusiFavorService().queryOneBusiFavorUsersCoupons(request); log.info("result: {}", result); } @Test public void testUploadBusiFavorCouponCodes() throws WxPayException { BusiFavorCouponCodeRequest request = new BusiFavorCouponCodeRequest(); request.setCouponCodeList(Lists.newArrayList("123")); request.setUploadRequestNo("upload_request_no"); BusiFavorCouponCodeResult result = wxPayService.getMarketingBusiFavorService().uploadBusiFavorCouponCodes("98065001", request); log.info("result: {}", result); } @Test public void testCreateBusiFavorCallbacks() throws WxPayException { BusiFavorCallbacksRequest request = new BusiFavorCallbacksRequest(); request.setMchid(wxPayService.getConfig().getMchId()); request.setNotifyUrl("https://ww.sd"); BusiFavorCallbacksResult result = wxPayService.getMarketingBusiFavorService().createBusiFavorCallbacks(request); log.info("result: {}", result); } @Test public void testQueryBusiFavorCallbacks() throws WxPayException { BusiFavorCallbacksRequest request = new BusiFavorCallbacksRequest(); request.setMchid(wxPayService.getConfig().getMchId()); BusiFavorCallbacksResult result = wxPayService.getMarketingBusiFavorService().queryBusiFavorCallbacks(request); log.info("result: {}", result); } @Test public void testQueryBusiFavorCouponsAssociate() throws WxPayException { BusiFavorCouponsAssociateRequest request = new BusiFavorCouponsAssociateRequest(); request.setStockId("100088"); request.setCouponCode("sxxe34343434"); request.setOutTradeNo("MCH_102233445"); request.setOutRequestNo("1002600620019090123143254435"); BusiFavorCouponsAssociateResult result = wxPayService.getMarketingBusiFavorService().queryBusiFavorCouponsAssociate(request); log.info("result: {}", result); } @Test public void testQueryBusiFavorCouponsDisassociate() throws WxPayException { BusiFavorCouponsAssociateRequest request = new BusiFavorCouponsAssociateRequest(); request.setStockId("100088"); request.setCouponCode("sxxe34343434"); request.setOutTradeNo("MCH_102233445"); request.setOutRequestNo("1002600620019090123143254435"); BusiFavorCouponsAssociateResult result = wxPayService.getMarketingBusiFavorService().queryBusiFavorCouponsDisAssociate(request); log.info("result: {}", result); } @Test public void testUpdateBusiFavorStocksBudget() throws WxPayException { BusiFavorStocksBudgetRequest request = new BusiFavorStocksBudgetRequest(); request.setTargetMaxCoupons(10); request.setCurrentMaxCoupons(4); request.setModifyBudgetRequestNo("1002600620019090123143254436"); BusiFavorStocksBudgetResult result = wxPayService.getMarketingBusiFavorService().updateBusiFavorStocksBudget("98065001", request); log.info("result: {}", result); } @Test public void testUpdateFavorStocksV3() throws WxPayException { BusiFavorStocksCreateRequest request = new BusiFavorStocksCreateRequest(); request.setStockName("买价值984元3大罐送价值316元2小罐1"); request.setComment("买价值984元3大罐送价值316元2小罐"); request.setGoodsName("仅供安满品牌商品使用"); request.setOutRequestNo(wxPayService.getConfig().getMchId() + "20210204" + "1234567890"); // //核销规则 // CouponUseRule couponUseRule = new CouponUseRule(); // //线下核销 // couponUseRule.setUseMethod("OFF_LINE"); // // //券可核销时间 // CouponAvailableTime couponAvailableTime = new CouponAvailableTime(); // couponAvailableTime.setAvailableBeginTime("2021-05-20T13:29:35+08:00"); // couponAvailableTime.setAvailableEndTime("2021-05-21T13:29:35+08:00"); // couponUseRule.setCouponAvailableTime(couponAvailableTime); // // //固定面额满减券 // request.setStockType(StockTypeEnum.NORMAL); // FixedNormalCoupon fixedNormalCoupon = new FixedNormalCoupon(); // fixedNormalCoupon.setDiscountAmount(31600); // fixedNormalCoupon.setTransactionMinimum(98400); // couponUseRule.setFixedNormalCoupon(fixedNormalCoupon); // request.setCouponUseRule(couponUseRule); // // //发放规则 // StockSendRule stockSendRule = new StockSendRule(); // stockSendRule.setMaxCoupons(100); // stockSendRule.setMaxCouponsPerUser(5); // request.setStockSendRule(stockSendRule); String result = wxPayService.getMarketingBusiFavorService().updateBusiFavorStocksV3("1252430000000012", request); log.info("result: [{}]", result); } @Test public void testReturnBusiFavorCoupons() throws WxPayException { BusiFavorCouponsReturnRequest request = new BusiFavorCouponsReturnRequest(); request.setReturnRequestNo("1002600620019090123143254436"); request.setStockId("1234567891"); request.setCouponCode("sxxe34343434"); BusiFavorCouponsReturnResult result = wxPayService.getMarketingBusiFavorService().returnBusiFavorCoupons(request); log.info("result: {}", result); } @Test public void testDeactivateBusiFavorCoupons() throws WxPayException { BusiFavorCouponsDeactivateRequest request = new BusiFavorCouponsDeactivateRequest(); request.setDeactivateRequestNo("1002600620019090123143254436"); request.setDeactivateReason("此券使用时间设置错误"); request.setStockId("1234567891"); request.setCouponCode("sxxe34343434"); BusiFavorCouponsDeactivateResult result = wxPayService.getMarketingBusiFavorService().deactiveBusiFavorCoupons(request); log.info("result: {}", result); } @Test public void testSubsidyBusiFavorPayReceipts() throws WxPayException { BusiFavorSubsidyRequest request = new BusiFavorSubsidyRequest(); request.setStockId("128888000000001"); request.setCouponCode("ABCD12345678"); request.setTransactionId("4200000913202101152566792388"); request.setPayeeMerchant("1466573302"); request.setPayerMerchant("1466573302"); request.setAmount(100); request.setDescription("20210115DESCRIPTION"); request.setOutSubsidyNo("subsidy-abcd-12345678"); BusiFavorSubsidyResult result = wxPayService.getMarketingBusiFavorService().subsidyBusiFavorPayReceipts(request); log.info("result: {}", result); } @Test public void testQueryBusiFavorSubsidyPayReceipts() throws WxPayException { BusiFavorSubsidyResult result = wxPayService.getMarketingBusiFavorService().queryBusiFavorSubsidyPayReceipts("1120200119165100000000000001"); log.info("result: {}", result); } @Test public void testNotifyBusiFavor() throws WxPayException { BusiFavorNotifyRequest request = new BusiFavorNotifyRequest(); request.setId("8b33f79f-8869-5ae5-b41b-3c0b59f957d0"); request.setCreateTime("2019-12-12T16:54:38+08:00"); request.setEventType("COUPON.SEND"); request.setResourceType("encrypt-resource"); BusiFavorNotifyResult result = wxPayService.getMarketingBusiFavorService().notifyBusiFavor("https://www.yujam.com", request); log.info("result: {}", result); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MerchantMediaServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MerchantMediaServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.media.ImageUploadResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.MerchantMediaService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.io.File; import java.io.IOException; /** * <pre> * 媒体文件上传测试类 * </pre> * * @author zhouyongshen */ @Slf4j @Test @Guice(modules = ApiTestModule.class) public class MerchantMediaServiceImplTest { @Inject private WxPayService wxPayService; @Test public void testImageUploadV3() throws WxPayException, IOException { MerchantMediaService merchantMediaService=new MerchantMediaServiceImpl(wxPayService); String filePath="你的图片文件的路径地址"; // String filePath="WxJava/images/banners/wiki.jpg"; File file=new File(filePath); ImageUploadResult imageUploadResult = merchantMediaService.imageUploadV3(file); String mediaId = imageUploadResult.getMediaId(); log.info("mediaId1:[{}]",mediaId); File file2=new File(filePath); ImageUploadResult imageUploadResult2 = merchantMediaService.imageUploadV3(file2); String mediaId2 = imageUploadResult2.getMediaId(); log.info("mediaId2:[{}]",mediaId2); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceGlobalImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceGlobalImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3GlobalRequest; import com.github.binarywang.wxpay.bean.result.enums.GlobalTradeTypeEnum; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import me.chanjar.weixin.common.util.RandomUtils; import org.testng.annotations.Test; import static org.testng.Assert.*; /** * 境外微信支付测试类 * * @author Binary Wang */ public class BaseWxPayServiceGlobalImplTest { private static final Gson GSON = new GsonBuilder().create(); @Test public void testWxPayUnifiedOrderV3GlobalRequest() { // Test that the new request class has the required fields WxPayUnifiedOrderV3GlobalRequest request = new WxPayUnifiedOrderV3GlobalRequest(); // Set basic order information String outTradeNo = RandomUtils.getRandomStr(); request.setOutTradeNo(outTradeNo); request.setDescription("Test overseas payment"); request.setNotifyUrl("https://api.example.com/notify"); // Set amount WxPayUnifiedOrderV3GlobalRequest.Amount amount = new WxPayUnifiedOrderV3GlobalRequest.Amount(); amount.setCurrency(WxPayConstants.CurrencyType.CNY); amount.setTotal(100); // 1 yuan in cents request.setAmount(amount); // Set payer WxPayUnifiedOrderV3GlobalRequest.Payer payer = new WxPayUnifiedOrderV3GlobalRequest.Payer(); payer.setOpenid("test_openid"); request.setPayer(payer); // Set the new required fields for global payments request.setTradeType("JSAPI"); request.setMerchantCategoryCode("5812"); // Example category code // Assert that all fields are properly set assertNotNull(request.getTradeType()); assertNotNull(request.getMerchantCategoryCode()); assertEquals("JSAPI", request.getTradeType()); assertEquals("5812", request.getMerchantCategoryCode()); assertEquals(outTradeNo, request.getOutTradeNo()); assertEquals("Test overseas payment", request.getDescription()); assertEquals(100, request.getAmount().getTotal()); assertEquals("test_openid", request.getPayer().getOpenid()); // Test JSON serialization contains the new fields String json = GSON.toJson(request); assertTrue(json.contains("trade_type")); assertTrue(json.contains("merchant_category_code")); assertTrue(json.contains("JSAPI")); assertTrue(json.contains("5812")); } @Test public void testGlobalTradeTypeEnum() { // Test that all trade types have the correct global endpoints assertEquals("/global/v3/transactions/app", GlobalTradeTypeEnum.APP.getUrl()); assertEquals("/global/v3/transactions/jsapi", GlobalTradeTypeEnum.JSAPI.getUrl()); assertEquals("/global/v3/transactions/native", GlobalTradeTypeEnum.NATIVE.getUrl()); assertEquals("/global/v3/transactions/h5", GlobalTradeTypeEnum.H5.getUrl()); } @Test public void testGlobalTradeTypeEnumValues() { // Test that we have all the main trade types GlobalTradeTypeEnum[] tradeTypes = GlobalTradeTypeEnum.values(); assertEquals(4, tradeTypes.length); // Test that we can convert between enum name and TradeTypeEnum for (GlobalTradeTypeEnum globalType : tradeTypes) { // This tests that the enum names match between Global and regular TradeTypeEnum String name = globalType.name(); assertNotNull(name); assertTrue(name.equals("APP") || name.equals("JSAPI") || name.equals("NATIVE") || name.equals("H5")); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/Applyment4SubServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/Applyment4SubServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.applyment.ModifySettlementRequest; import com.github.binarywang.wxpay.bean.applyment.WxPayApplyment4SubCreateRequest; import com.github.binarywang.wxpay.bean.applyment.WxPayApplymentCreateResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.Applyment4SubService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Guice; import org.testng.annotations.Test; @Slf4j @Test @Guice(modules = ApiTestModule.class) public class Applyment4SubServiceImplTest { @Inject private WxPayService wxPayService; private static final Gson GSON = new GsonBuilder().create(); @Test public void testCreateApply() throws WxPayException { Applyment4SubService applyment4SubService = new Applyment4SubServiceImpl(wxPayService); String requestParamStr = "{}"; /* {"business_code":"1596785690732","contact_info":{"contact_name":"张三","contact_id_number":"110110202001011234","mobile_phone":"13112345678","contact_email":"abc@qq.com"},"subject_info":{"subject_type":"SUBJECT_TYPE_ENTERPRISE","business_license_info":{"license_copy":"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI","license_number":"123456789012345678","merchant_name":"腾讯科技有限公司","legal_person":"张三"},"identity_info":{"id_doc_type":"IDENTIFICATION_TYPE_IDCARD","id_card_info":{"id_card_copy":"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI","id_card_national":"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI","id_card_name":"张三","id_card_number":"110110202001011234","card_period_begin":"2016-06-06","card_period_end":"2026-06-06"},"owner":false},"ubo_info":{"id_type":"IDENTIFICATION_TYPE_IDCARD","id_card_copy":"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI","id_card_national":"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI","id_doc_copy":"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI","name":"张三","id_number":"110110202001011234","id_period_begin":"2016-06-06","id_period_end":"2026-06-06"}},"business_info":{"merchant_shortname":"商户简称","service_phone":"13212345678","sales_info":{"sales_scenes_type":["SALES_SCENES_MINI_PROGRAM"],"mini_program_info":{"mini_program_appid":"wxe5f52902cf4de896"}}},"settlement_info":{"settlement_id":"716","qualification_type":"餐饮"}} */ requestParamStr = "{\"business_code\":\"1596785690732\",\"contact_info\":{\"contact_name\":\"张三\",\"contact_id_number\":\"110110202001011234\",\"mobile_phone\":\"13112345678\",\"contact_email\":\"abc@qq.com\"},\"subject_info\":{\"subject_type\":\"SUBJECT_TYPE_ENTERPRISE\",\"business_license_info\":{\"license_copy\":\"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI\",\"license_number\":\"123456789012345678\",\"merchant_name\":\"腾讯科技有限公司\",\"legal_person\":\"张三\"},\"identity_info\":{\"id_doc_type\":\"IDENTIFICATION_TYPE_IDCARD\",\"id_card_info\":{\"id_card_copy\":\"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI\",\"id_card_national\":\"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI\",\"id_card_name\":\"张三\",\"id_card_number\":\"110110202001011234\",\"card_period_begin\":\"2016-06-06\",\"card_period_end\":\"2026-06-06\"},\"owner\":false},\"ubo_info\":{\"id_type\":\"IDENTIFICATION_TYPE_IDCARD\",\"id_card_copy\":\"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI\",\"id_card_national\":\"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI\",\"id_doc_copy\":\"mxX07DyfM-bJyGJYCTyW-4wrXpJ5fq_bgYfWkIZZgjenf6Ct1gKV_FpkzgyQrf5ETVEyOWhC_0cbhOATODuLBAkxGl6Cvj31lh6OFAIHnwI\",\"name\":\"张三\",\"id_number\":\"110110202001011234\",\"id_period_begin\":\"2016-06-06\",\"id_period_end\":\"2026-06-06\"}},\"business_info\":{\"merchant_shortname\":\"商户简称\",\"service_phone\":\"13212345678\",\"sales_info\":{\"sales_scenes_type\":[\"SALES_SCENES_MINI_PROGRAM\"],\"mini_program_info\":{\"mini_program_appid\":\"wxe5f52902cf4de896\"}}},\"settlement_info\":{\"settlement_id\":\"716\",\"qualification_type\":\"餐饮\"}}"; WxPayApplyment4SubCreateRequest request = GSON.fromJson(requestParamStr, WxPayApplyment4SubCreateRequest.class); String businessCode = String.valueOf(System.currentTimeMillis()); request.setBusinessCode(businessCode); WxPayApplymentCreateResult apply = applyment4SubService.createApply(request); String applymentId = apply.getApplymentId(); log.info("businessCode:[{}],applymentId:[{}]", businessCode, applymentId); } @Test public void testQueryApplyStatusByBusinessCode() throws WxPayException { Applyment4SubService applyment4SubService = new Applyment4SubServiceImpl(wxPayService); String businessCode = "businessCode"; applyment4SubService.queryApplyStatusByBusinessCode(businessCode); } @Test public void testQueryApplyStatusByApplymentId() throws WxPayException { Applyment4SubService applyment4SubService = new Applyment4SubServiceImpl(wxPayService); String applymentId = "applymentId"; applyment4SubService.queryApplyStatusByApplymentId(applymentId); } @Test public void testQuerySettlementBySubMchid() throws WxPayException { Applyment4SubService applyment4SubService = new Applyment4SubServiceImpl(wxPayService); String subMchid = "subMchid"; applyment4SubService.querySettlementBySubMchid(subMchid); } @Test public void testModifySettlement() throws WxPayException { Applyment4SubService applyment4SubService = new Applyment4SubServiceImpl(wxPayService); String subMchid = "subMchid"; ModifySettlementRequest modifySettlementRequest = new ModifySettlementRequest(); applyment4SubService.modifySettlement(subMchid, modifySettlementRequest); } @Test public void testSettlementApplication() throws WxPayException { Applyment4SubService applyment4SubService = new Applyment4SubServiceImpl(wxPayService); String subMchid = "subMchid"; String applymentId = "applymentId"; applyment4SubService.querySettlementModifyStatusByApplicationNo(subMchid, applymentId); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreSignPlanServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreSignPlanServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanRequest; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.PartnerPayScoreSignPlanService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * @className PartnerPayScoreSignPlanServiceImplTest * @description * @author * @createTime 2023/11/6 10:30 **/ @Slf4j @Test @Guice(modules = ApiTestModule.class) public class PartnerPayScoreSignPlanServiceImplTest { @Inject private WxPayService wxPayService; private static final Gson GSON = new GsonBuilder().create(); @Test public void testcreatePlans()throws WxPayException{ PartnerPayScoreSignPlanService scoreSignPlan=new PartnerPayScoreSignPlanServiceImpl(wxPayService); WxPartnerPayScoreSignPlanRequest request=new WxPartnerPayScoreSignPlanRequest(); request.setSubMchid("子商户号"); scoreSignPlan.createPlans(request); } @Test public void testqueryPlans()throws WxPayException{ PartnerPayScoreSignPlanService scoreSignPlan=new PartnerPayScoreSignPlanServiceImpl(wxPayService); scoreSignPlan.queryPlans("merchantPlanNo","子商户号"); } @Test public void teststopPlans()throws WxPayException{ PartnerPayScoreSignPlanService scoreSignPlan=new PartnerPayScoreSignPlanServiceImpl(wxPayService); scoreSignPlan.stopPlans("merchantPlanNo","子商户号"); } @Test public void testsignPlanServiceOrder()throws WxPayException{ PartnerPayScoreSignPlanService scoreSignPlan=new PartnerPayScoreSignPlanServiceImpl(wxPayService); WxPartnerPayScoreSignPlanRequest request=new WxPartnerPayScoreSignPlanRequest(); scoreSignPlan.signPlanServiceOrder(request); } @Test public void testcreateUserSignPlans()throws WxPayException{ PartnerPayScoreSignPlanService scoreSignPlan=new PartnerPayScoreSignPlanServiceImpl(wxPayService); WxPartnerPayScoreSignPlanRequest request=new WxPartnerPayScoreSignPlanRequest(); scoreSignPlan.createUserSignPlans(request); } @Test public void testqueryUserSignPlans()throws WxPayException{ PartnerPayScoreSignPlanService scoreSignPlan=new PartnerPayScoreSignPlanServiceImpl(wxPayService); scoreSignPlan.queryUserSignPlans("merchantPlanNo","子商户号"); } @Test public void teststopUserSignPlans()throws WxPayException{ PartnerPayScoreSignPlanService scoreSignPlan=new PartnerPayScoreSignPlanServiceImpl(wxPayService); scoreSignPlan.stopUserSignPlans("merchantPlanNo","子商户号","测试取消"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/ProfitSharingServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.notify.SignatureHeader; import com.github.binarywang.wxpay.bean.profitsharing.*; import com.github.binarywang.wxpay.bean.profitsharing.request.*; import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingMerchantRatioQueryResult; import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingOrderAmountQueryResult; import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingQueryResult; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Guice; import org.testng.annotations.Test; @Test @Slf4j @Guice(modules = ApiTestModule.class) public class ProfitSharingServiceImplTest { @Inject private WxPayService payService; @Test public void testProfitSharing() throws WxPayException { ReceiverList instance = ReceiverList.getInstance(); instance.add(new Receiver(WxPayConstants.ReceiverType.PERSONAL_OPENID, "oyOUE5ql4TtzrBg5cVOwxq6tbjOs", 20, "***")); //30000002922019102310811092093 ProfitSharingRequest request = ProfitSharingRequest .newBuilder() .outOrderNo("20191023112023031060677") .transactionId("4200000431201910234736634272") .receivers(instance.toJSONString()) .build(); log.info(this.payService.getProfitSharingService().profitSharing(request).toString()); } @Test public void testMultiProfitSharing() throws WxPayException { ReceiverList instance = ReceiverList.getInstance(); instance.add(new Receiver(WxPayConstants.ReceiverType.MERCHANT_ID, "86693852", 1, "***")); ProfitSharingRequest request = ProfitSharingRequest .newBuilder() .outOrderNo("20191023154723316420060") .transactionId("4200000448201910238249687345")//order_id=30000102922019102310821824010 .receivers(instance.toJSONString()) .build(); log.info(this.payService.getProfitSharingService().multiProfitSharing(request).toString()); } @Test public void testProfitSharingFinish() throws WxPayException { ProfitSharingUnfreezeRequest request = ProfitSharingUnfreezeRequest .newBuilder() .outOrderNo("20191023103251431856285") .transactionId("4200000441201910238267278073") .description("分账完成") .build(); log.info(this.payService.getProfitSharingService().profitSharingFinish(request).toString()); } @Test public void testAddReceiver() throws WxPayException { Receiver receiver = new Receiver(WxPayConstants.ReceiverType.PERSONAL_OPENID, "oyOUE5ql4TtzrBg5cVOwxq6tbjOs", "***", "STORE_OWNER", null); ProfitSharingReceiverRequest request = ProfitSharingReceiverRequest .newBuilder() .receiver(receiver.toJSONString()) .build(); log.info(this.payService.getProfitSharingService().addReceiver(request).toString()); } @Test public void testRemoveReceiver() throws WxPayException { Receiver receiver = new Receiver(WxPayConstants.ReceiverType.PERSONAL_OPENID, "oyOUE5ql4TtzrBg5cVOwxq6tbjOs"); ProfitSharingReceiverRequest request = ProfitSharingReceiverRequest .newBuilder() .receiver(receiver.toJSONString()) .build(); log.info(this.payService.getProfitSharingService().removeReceiver(request).toString()); } @Test public void testProfitSharingQuery() throws WxPayException { ProfitSharingQueryRequest request = ProfitSharingQueryRequest .newBuilder() .outOrderNo("20191023112023031060677") .transactionId("4200000431201910234736634272") .build(); ProfitSharingQueryResult result = this.payService.getProfitSharingService().profitSharingQuery(request); log.info(result.formatReceivers().toString()); log.info(result.toString()); } @Test public void testProfitSharingMerchantRatioQuery() throws WxPayException { final String subMchId = "subMchid"; final ProfitSharingMerchantRatioQueryRequest request = new ProfitSharingMerchantRatioQueryRequest(subMchId); final ProfitSharingMerchantRatioQueryResult result = payService.getProfitSharingService().profitSharingMerchantRatioQuery(request); log.info(result.toString()); } @Test public void testProfitSharingOrderAmountQuery() throws WxPayException { final String transactionId = "4200000916202012281633853127"; final ProfitSharingOrderAmountQueryRequest request = ProfitSharingOrderAmountQueryRequest.newBuilder() .transactionId(transactionId) .build(); final ProfitSharingOrderAmountQueryResult result = payService.getProfitSharingService().profitSharingOrderAmountQuery(request); log.info(result.toString()); } @Test public void testProfitSharingReturn() throws WxPayException { ProfitSharingReturnRequest request = ProfitSharingReturnRequest .newBuilder() .outOrderNo("20191023154723316420060") .outReturnNo("R2019102315") .returnAccountType("MERCHANT_ID") .returnAccount("86693852") .returnAmount(2) .description("用户退款") .build(); log.info(this.payService.getProfitSharingService().profitSharingReturn(request).toString()); } @Test public void testProfitSharingReturnQuery() throws WxPayException { ProfitSharingReturnQueryRequest request = ProfitSharingReturnQueryRequest .newBuilder() .outOrderNo("20191023154723316420060") .outReturnNo("R2019102315") .build(); log.info(this.payService.getProfitSharingService().profitSharingReturnQuery(request).toString()); } @Test public void testProfitSharingNotifyData() throws WxPayException { SignatureHeader header = new SignatureHeader(); header.setSerial("Wechatpay-Serial"); header.setTimeStamp("Wechatpay-Timestamp"); header.setNonce("Wechatpay-Nonce"); header.setSignature("Wechatpay-Signature"); String data = "body"; log.info(this.payService.getProfitSharingService().parseProfitSharingNotifyResult(data,header).toString()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.payscore.WxPayScoreRequest; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.inject.Inject; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.net.URISyntaxException; /** * 测试代码,待补充完善. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-05-19 */ @Test @Guice(modules = ApiTestModule.class) public class PayScoreServiceImplTest { @Inject private WxPayService payService; @Test public void testCreateServiceOrder() throws WxPayException { //测试数据 /* { "out_order_no":"QLS202005201058000201", "appid":"", "service_id":"", "service_introduction":"租借服务", "time_range":{ "start_time":"OnAccept", "end_time":"20200520225840" }, "location":{ "start_location":"山", "end_location":"山" }, "risk_fund":{ "name":"DEPOSIT", "amount":200, "description":"丢失偿还费用2元/台" }, "attach":"", "notify_url":"/pay/notify/payScore", "openid":"", "need_user_confirm":true, "profit_sharing":false, "post_payments":[ { "name":"租借服务", "amount":100, "description":"服务费:1元/台", "count":1 } ], "total_amount":0 }*/ this.payService.getPayScoreService().createServiceOrder(WxPayScoreRequest.builder().build()); } @Test public void testQueryServiceOrder() throws WxPayException { //两个参数选填一个 this.payService.getPayScoreService().queryServiceOrder("11", ""); } @Test public void testCancelServiceOrder() throws WxPayException { this.payService.getPayScoreService().cancelServiceOrder("11", "测试取消"); } @Test public void testModifyServiceOrder() { } @Test public void testCompleteServiceOrder() throws WxPayException { /* { "appid":"", "service_id":"", "time_range":{ "end_time":"20200520111702" }, "need_user_confirm":false, "profit_sharing":false, "post_payments":[ { "name":"租借服务", "amount":100, "description":"服务费:1.0000元/台", "count":1 } ], "total_amount":100 } */ this.payService.getPayScoreService().completeServiceOrder(WxPayScoreRequest.builder().build()); } @Test public void testPayServiceOrder() { } @Test public void testSyncServiceOrder() { } @Test public void testDecryptNotifyData() { } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreRequestTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreRequestTest.java
package com.github.binarywang.wxpay.bean.payscore; import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; /** * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-07-11 */ public class WxPayScoreRequestTest { @Test public void testToJson() { WxPayScoreRequest request = WxPayScoreRequest.builder() .outOrderNo("QLS202005201058000201") .appid("123") .serviceId("345") .serviceIntroduction("租借服务") .timeRange(new TimeRange("20230901011023", "20230930235959","开始时间","结束时间")) .device(new Device("deviceId","deviceId","212323232")) .build(); String json = request.toJson(); System.out.println(json); String expectedJson = "{\"out_order_no\":\"QLS202005201058000201\",\"appid\":\"123\",\"service_id\":\"345\",\"service_introduction\":\"租借服务\",\"time_range\":{\"start_time\":\"20230901011023\",\"end_time\":\"20230930235959\",\"start_time_remark\":\"开始时间\",\"end_time_remark\":\"结束时间\"},\"device\":{\"start_device_id\":\"deviceId\",\"end_device_id\":\"deviceId\",\"materiel_no\":\"212323232\"}}"; assertThat(request.toJson()).isEqualTo(expectedJson); // { // "out_order_no": "QLS202005201058000201", // "appid": "123", // "service_id": "345", // "service_introduction": "租借服务", // "time_range": { // "start_time": "20230901011023", // "end_time": "20230930235959", // "start_time_remark": "开始时间", // "end_time_remark": "结束时间" // }, // "device": { // "start_device_id": "deviceId", // "end_device_id": "deviceId", // "materiel_no": "212323232" // } // } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerPayScoreRequestTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/payscore/WxPartnerPayScoreRequestTest.java
package com.github.binarywang.wxpay.bean.payscore; import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; /** * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-07-11 */ public class WxPartnerPayScoreRequestTest { @Test public void testToJson() { WxPartnerPayScoreRequest request = WxPartnerPayScoreRequest.builder() .outOrderNo("QLS202005201058000201") .appid("123") .serviceId("345") .serviceIntroduction("租借服务") .timeRange(new TimeRange("20230901011023", "20230930235959","开始时间","结束时间")) .device(new Device("deviceId","deviceId","212323232")) .build(); System.out.println(request.toJson()); String expectedJson = "{\"out_order_no\":\"QLS202005201058000201\",\"appid\":\"123\",\"service_id\":\"345\",\"service_introduction\":\"租借服务\",\"time_range\":{\"start_time\":\"20230901011023\",\"end_time\":\"20230930235959\",\"start_time_remark\":\"开始时间\",\"end_time_remark\":\"结束时间\"},\"device\":{\"start_device_id\":\"deviceId\",\"end_device_id\":\"deviceId\",\"materiel_no\":\"212323232\"}}"; assertThat(request.toJson()).isEqualTo(expectedJson); // { // "out_order_no": "QLS202005201058000201", // "appid": "123", // "service_id": "345", // "service_introduction": "租借服务", // "time_range": { // "start_time": "20230901011023", // "end_time": "20230930235959", // "start_time_remark": "开始时间", // "end_time_remark": "结束时间" // }, // "device": { // "start_device_id": "deviceId", // "end_device_id": "deviceId", // "materiel_no": "212323232" // } // } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayRedpackQueryResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayRedpackQueryResultTest.java
package com.github.binarywang.wxpay.bean.result; import com.github.binarywang.wxpay.util.XmlConfig; import org.testng.annotations.*; import static org.assertj.core.api.Assertions.assertThat; /** * <pre> * * Created by Binary Wang on 2018/1/24. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public class WxPayRedpackQueryResultTest { /** * Test from xml. */ @Test public void testFromXML() { String xmlString = "<xml>\n" + "<return_code><![CDATA[SUCCESS]]></return_code>\n" + "<return_msg><![CDATA[OK]]></return_msg>\n" + "<result_code><![CDATA[SUCCESS]]></result_code>\n" + "<err_code><![CDATA[SUCCESS]]></err_code>\n" + "<err_code_des><![CDATA[OK]]></err_code_des>\n" + "<mch_billno><![CDATA[1473919402201801230145075410]]></mch_billno>\n" + "<mch_id><![CDATA[1497236182]]></mch_id>\n" + "<detail_id><![CDATA[1000041701201801233000139830103]]></detail_id>\n" + "<status><![CDATA[RECEIVED]]></status>\n" + "<send_type><![CDATA[API]]></send_type>\n" + "<hb_type><![CDATA[NORMAL]]></hb_type>\n" + "<total_num>1</total_num>\n" + "<total_amount>100</total_amount>\n" + "<send_time><![CDATA[2018-01-23 13:45:08]]></send_time>\n" + "<hblist>\n" + "<hbinfo>\n" + "<openid><![CDATA[o3yHF0uHuckI3yE6lwWiFQBQdVDI]]></openid>\n" + "<amount>100</amount>\n" + "<rcv_time><![CDATA[2018-01-23 13:45:31]]></rcv_time>\n" + "</hbinfo>\n" + "</hblist>\n" + "</xml>"; WxPayRedpackQueryResult orderQueryResult = BaseWxPayResult.fromXML(xmlString, WxPayRedpackQueryResult.class); // System.out.println(orderQueryResult); assertThat(orderQueryResult).isNotNull(); assertThat(orderQueryResult.getRedpackList()).isNotEmpty(); assertThat(orderQueryResult.getRedpackList().get(0).getAmount()).isEqualTo(100); assertThat(orderQueryResult.getRedpackList().get(0).getOpenid()).isEqualTo("o3yHF0uHuckI3yE6lwWiFQBQdVDI"); assertThat(orderQueryResult.getRedpackList().get(0).getReceiveTime()).isEqualTo("2018-01-23 13:45:31"); } /** * Test from xml. * FastMode */ @Test public void testFromXMLFastMode() { XmlConfig.fastMode = true; String xmlString = "<xml>\n" + "<return_code><![CDATA[SUCCESS]]></return_code>\n" + "<return_msg><![CDATA[OK]]></return_msg>\n" + "<result_code><![CDATA[SUCCESS]]></result_code>\n" + "<err_code><![CDATA[SUCCESS]]></err_code>\n" + "<err_code_des><![CDATA[OK]]></err_code_des>\n" + "<mch_billno><![CDATA[1473919402201801230145075410]]></mch_billno>\n" + "<mch_id><![CDATA[1497236182]]></mch_id>\n" + "<detail_id><![CDATA[1000041701201801233000139830103]]></detail_id>\n" + "<status><![CDATA[RECEIVED]]></status>\n" + "<send_type><![CDATA[API]]></send_type>\n" + "<hb_type><![CDATA[NORMAL]]></hb_type>\n" + "<total_num>1</total_num>\n" + "<total_amount>100</total_amount>\n" + "<send_time><![CDATA[2018-01-23 13:45:08]]></send_time>\n" + "<hblist>\n" + "<hbinfo>\n" + "<openid><![CDATA[o3yHF0uHuckI3yE6lwWiFQBQdVDI]]></openid>\n" + "<amount>100</amount>\n" + "<rcv_time><![CDATA[2018-01-23 13:45:31]]></rcv_time>\n" + "</hbinfo>\n" + "</hblist>\n" + "</xml>"; try { WxPayRedpackQueryResult orderQueryResult = BaseWxPayResult.fromXML(xmlString, WxPayRedpackQueryResult.class); // System.out.println(orderQueryResult); assertThat(orderQueryResult).isNotNull(); assertThat(orderQueryResult.getRedpackList()).isNotEmpty(); assertThat(orderQueryResult.getRedpackList().get(0).getAmount()).isEqualTo(100); assertThat(orderQueryResult.getRedpackList().get(0).getOpenid()).isEqualTo("o3yHF0uHuckI3yE6lwWiFQBQdVDI"); assertThat(orderQueryResult.getRedpackList().get(0).getReceiveTime()).isEqualTo("2018-01-23 13:45:31"); } finally { XmlConfig.fastMode = false; } } @Test void benchmark() { long now = System.currentTimeMillis(); int loops = 10000; for (int i = 0; i < loops; i++) { testFromXML(); } System.out.println(" reflect mode:\t" + (System.currentTimeMillis() - now) + " (ms) "); now = System.currentTimeMillis(); for (int i = 0; i < loops; i++) { testFromXMLFastMode(); } System.out.println(" fast mode:\t" + (System.currentTimeMillis() - now) + " (ms) "); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayBillResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayBillResultTest.java
package com.github.binarywang.wxpay.bean.result; import com.github.binarywang.wxpay.constant.WxPayConstants; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; /** * @author m8cool */ public class WxPayBillResultTest { private static final String PAY_BILL_RESULT_ALL_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率,订单金额,申请退款金额,费率备注\n" + "`2019-07-25 08:35:41,`WWWW,`XXXXXXXX,`0,`,`XXXXXXXXXXXXX,`XXXXXXXXXX,`XXXXXXXXXXX,`JSAPI,`SUCCESS,`PSBC_DEBIT,`CNY,`6.00,`0.00,`0,`0,`0.00,`0.00,`,`,`XXXXXX,`XXXXXXX,`0.04000,`0.60%,`6.00,`0.00,`\n" + "总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额\n" + "`48,`5.76,`1.42,`0.00,`0.01000,`5.76,`1.42\n"; private static final String PAY_BILL_RESULT_ALL_CONTENT_1 = "交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,代金券或立减优惠金额,微信退款单号,商户退款单号,退款金额,代金券或立减优惠退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率\n" + "`2014-11-10 16:33:45,`wx2421b1c4370ec43b,`10000100,`0,`1000,`1001690740201411100005734289,`1415640626,`085e9858e3ba5186aafcbaed1,`MICROPAY,`SUCCESS,`OTHERS,`CNY,`0.01,`0.0,`0,`0,`0,`0,`,`,`被扫支付测试,`订单额外描述,`0,`0.60%\n" + "`2014-11-10 16:46:14,`wx2421b1c4370ec43b,`10000100,`0,`1000,`1002780740201411100005729794,`1415635270,`085e9858e90ca40c0b5aee463,`MICROPAY,`SUCCESS,`OTHERS,`CNY,`0.01,`0.0,`0,`0,`0,`0,`,`,`被扫支付测试,`订单额外描述,`0,`0.60%\n" + "总交易单数,总交易额,总退款金额,总代金券或立减优惠退款金额,手续费总金额\n" + "`2,`0.02,`0.0,`0.0,`0"; private static final String PAY_BILL_RESULT_SUCCESS_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,商品名称,商户数据包,手续费,费率,订单金额,费率备注\n" + "`2019-07-23 18:46:41,`XXXX,`XXX,`XXX,`,`XXX,`XXX,`XXX,`JSAPI,`SUCCESS,`CFT,`CNY,`0.01,`0.00,`XXX,`XXXX,`0.00000,`0.60%,`0.01,`\n" + "总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额\n" + "`31,`3.05,`0.00,`0.00,`0.02000,`3.05,`0.00"; private static final String PAY_BILL_RESULT_REFUND_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,退款申请时间,退款成功时间,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率,订单金额,申请退款金额,费率备注\n" + "`2019-07-23 20:53:36,`xxx,`xxx,`xxx,`,`xxx,`xxxx,`xxxxx,`JSAPI,`REFUND,`CFT,`CNY,`0.00,`0.00,`2019-07-23 20:53:36,`2019-07-23 20:53:40,`xxxx,`xxx,`0.01,`0.00,`ORIGINAL,`SUCCESS,`xxxx,`xxxx,`0.00000,`0.60%,`0.00,`0.01,`\n" + "总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额\n" + "`4,`0.00,`2.02,`0.00,`-0.02000,`0.00,`2.02"; /** * 测试微信返回类型为ALL时,解析结果是否正确 */ @Test public void testFromRawBillResultStringAll() { WxPayBillResult result = WxPayBillResult.fromRawBillResultString(PAY_BILL_RESULT_ALL_CONTENT, WxPayConstants.BillType.ALL); assertEquals(result.getTotalRecord(), "48"); assertEquals(result.getTotalFee(), "5.76"); assertEquals(result.getTotalRefundFee(), "1.42"); assertEquals(result.getTotalCouponFee(), "0.00"); assertEquals(result.getTotalPoundageFee(), "0.01000"); assertEquals(result.getTotalAmount(), "5.76"); assertEquals(result.getTotalAppliedRefundFee(), "1.42"); assertEquals(result.getBillInfoList().get(0).getTotalAmount(), "6.00"); assertEquals(result.getBillInfoList().get(0).getAppliedRefundAmount(), "0.00"); assertEquals(result.getBillInfoList().get(0).getFeeRemark(), ""); result = WxPayBillResult.fromRawBillResultString(PAY_BILL_RESULT_ALL_CONTENT_1, WxPayConstants.BillType.ALL); assertEquals(result.getTotalRecord(), "2"); assertEquals(result.getTotalFee(), "0.02"); assertEquals(result.getTotalRefundFee(), "0.0"); assertEquals(result.getTotalCouponFee(), "0.0"); assertEquals(result.getTotalPoundageFee(), "0"); assertNull(result.getTotalAmount()); assertNull(result.getTotalAppliedRefundFee()); assertNull(result.getBillInfoList().get(0).getTotalAmount()); assertNull(result.getBillInfoList().get(0).getAppliedRefundAmount()); assertNull(result.getBillInfoList().get(0).getFeeRemark()); } /** * 测试微信返回类型为SUCCESS时,解析结果是否正确 */ @Test public void testFromRawBillResultStringSuccess() { WxPayBillResult result = WxPayBillResult.fromRawBillResultString(PAY_BILL_RESULT_SUCCESS_CONTENT, WxPayConstants.BillType.SUCCESS); assertEquals(result.getTotalRecord(), "31"); assertEquals(result.getTotalFee(), "3.05"); assertEquals(result.getTotalRefundFee(), "0.00"); assertEquals(result.getTotalCouponFee(), "0.00"); assertEquals(result.getTotalPoundageFee(), "0.02000"); assertEquals(result.getTotalAmount(), "3.05"); assertEquals(result.getTotalAppliedRefundFee(), "0.00"); assertEquals(result.getBillInfoList().get(0).getTotalAmount(), "0.01"); assertEquals(result.getBillInfoList().get(0).getFeeRemark(), ""); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/BaseWxPayResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/BaseWxPayResultTest.java
package com.github.binarywang.wxpay.bean.result; import java.util.Map; import org.testng.*; import org.testng.annotations.*; /** * <pre> * Created by Binary Wang on 2017-01-04. * </pre> * * @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> */ public class BaseWxPayResultTest { /** * Test get xml value. * * @throws Exception the exception */ @Test public void testGetXmlValue() throws Exception { } /** * Test xml 2 doc. * * @throws Exception the exception */ @Test public void testXml2Doc() throws Exception { } /** * Test to map. * * @throws Exception the exception */ @Test public void testToMap() throws Exception { WxPayOrderQueryResult result = new WxPayOrderQueryResult(); result.setXmlString("<xml>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <device_info><![CDATA[1000]]></device_info>\n" + " <nonce_str><![CDATA[TN55wO9Pba5yENl8]]></nonce_str>\n" + " <sign><![CDATA[BDF0099C15FF7BC6B1585FBB110AB635]]></sign>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <openid><![CDATA[oUpF8uN95-Ptaags6E_roPHg7AG0]]></openid>\n" + " <is_subscribe><![CDATA[Y]]></is_subscribe>\n" + " <trade_type><![CDATA[MICROPAY]]></trade_type>\n" + " <bank_type><![CDATA[CCB_DEBIT]]></bank_type>\n" + " <total_fee>1</total_fee>\n" + " <fee_type><![CDATA[CNY]]></fee_type>\n" + " <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>\n" + " <out_trade_no><![CDATA[1415757673]]></out_trade_no>\n" + " <attach><![CDATA[订单额外描述]]></attach>\n" + " <time_end><![CDATA[20141111170043]]></time_end>\n" + " <trade_state><![CDATA[SUCCESS]]></trade_state>\n" + "</xml>"); Map<String, String> map = result.toMap(); System.out.println(map); Assert.assertEquals(map.get("return_code"), "SUCCESS"); Assert.assertEquals(map.get("attach"), "订单额外描述"); } /** * Test to map with empty xml string. */ @Test(expectedExceptions = {RuntimeException.class}) public void testToMap_with_empty_xmlString() { WxPayOrderQueryResult result = new WxPayOrderQueryResult(); result.setXmlString( "<?xml version=\"1.0\" ?><!DOCTYPE doc " + "[<!ENTITY win SYSTEM \"file:///C:/Users/user/Documents/testdata2.txt\">]" + "><doc>&win;</doc>"); Map<String, String> map = result.toMap(); System.out.println(map); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayRefundQueryResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayRefundQueryResultTest.java
package com.github.binarywang.wxpay.bean.result; import org.testng.*; import org.testng.annotations.*; /** * <pre> * Created by Binary Wang on 2016-12-29. * </pre> * * @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> */ public class WxPayRefundQueryResultTest { /** * Compose refund records. * * @throws Exception the exception */ @Test public void composeRefundRecords() throws Exception { /* 该xml字符串来自于官方文档示例 */ String xmlString = "<xml>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <nonce_str><![CDATA[TeqClE3i0mvn3DrK]]></nonce_str>\n" + " <out_refund_no_0><![CDATA[1415701182]]></out_refund_no_0>\n" + " <out_trade_no><![CDATA[1415757673]]></out_trade_no>\n" + " <refund_count>1</refund_count>\n" + " <refund_fee_0>1</refund_fee_0>\n" + " <refund_id_0><![CDATA[2008450740201411110000174436]]></refund_id_0>\n" + " <refund_status_0><![CDATA[PROCESSING]]></refund_status_0>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + " <sign><![CDATA[1F2841558E233C33ABA71A961D27561C]]></sign>\n" + " <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>\n" + "</xml>"; WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(xmlString, WxPayRefundQueryResult.class); result.composeRefundRecords(); Assert.assertNotNull(result.getRefundRecords()); Assert.assertEquals(result.getRefundRecords().size(), 1); Assert.assertEquals(result.getRefundRecords().get(0).getRefundId(), "2008450740201411110000174436"); Assert.assertEquals(result.getRefundRecords().get(0).getRefundFee().intValue(), 1); Assert.assertEquals(result.getRefundRecords().get(0).getOutRefundNo(), "1415701182"); Assert.assertEquals(result.getRefundRecords().get(0).getRefundStatus(), "PROCESSING"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPaySendRedpackResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPaySendRedpackResultTest.java
package com.github.binarywang.wxpay.bean.result; import com.thoughtworks.xstream.XStream; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; /** * The type Wx pay send redpack result test. */ public class WxPaySendRedpackResultTest { private XStream xstream; /** * Sets . */ @BeforeTest public void setup() { this.xstream = XStreamInitializer.getInstance(); this.xstream.processAnnotations(WxPaySendRedpackResult.class); } /** * Load success result. */ @Test public void loadSuccessResult() { final String successSample = "<xml>\n" + "<return_code><![CDATA[SUCCESS]]></return_code>\n" + "<return_msg><![CDATA[发放成功.]]></return_msg>\n" + "<result_code><![CDATA[SUCCESS]]></result_code>\n" + "<err_code><![CDATA[0]]></err_code>\n" + "<err_code_des><![CDATA[发放成功.]]></err_code_des>\n" + "<mch_billno><![CDATA[0010010404201411170000046545]]></mch_billno>\n" + "<mch_id>10010404</mch_id>\n" + "<wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid>\n" + "<re_openid><![CDATA[onqOjjmM1tad-3ROpncN-yUfa6uI]]></re_openid>\n" + "<total_amount>1</total_amount>\n" + "<send_listid>100000000020150520314766074200</send_listid>\n" + "<send_time>20150520102602</send_time>\n" + "</xml>"; WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(successSample); Assert.assertEquals("SUCCESS", wxMpRedpackResult.getReturnCode()); Assert.assertEquals("SUCCESS", wxMpRedpackResult.getResultCode()); Assert.assertEquals("20150520102602", wxMpRedpackResult.getSendTime()); } /** * Load failure result. */ @Test public void loadFailureResult() { final String failureSample = "<xml>\n" + "<return_code><![CDATA[FAIL]]></return_code>\n" + "<return_msg><![CDATA[系统繁忙,请稍后再试.]]></return_msg>\n" + "<result_code><![CDATA[FAIL]]></result_code>\n" + "<err_code><![CDATA[268458547]]></err_code>\n" + "<err_code_des><![CDATA[系统繁忙,请稍后再试.]]></err_code_des>\n" + "<mch_billno><![CDATA[0010010404201411170000046542]]></mch_billno>\n" + "<mch_id>10010404</mch_id>\n" + "<wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid>\n" + "<re_openid><![CDATA[onqOjjmM1tad-3ROpncN-yUfa6uI]]></re_openid>\n" + "<total_amount>1</total_amount>\n" + "</xml>"; WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(failureSample); Assert.assertEquals("FAIL", wxMpRedpackResult.getReturnCode()); Assert.assertEquals("FAIL", wxMpRedpackResult.getResultCode()); Assert.assertEquals("onqOjjmM1tad-3ROpncN-yUfa6uI", wxMpRedpackResult.getReOpenid()); Assert.assertEquals(1, wxMpRedpackResult.getTotalAmount().intValue()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayRefundResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayRefundResultTest.java
package com.github.binarywang.wxpay.bean.result; import com.github.binarywang.wxpay.util.XmlConfig; import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; /** * <pre> * Created by BinaryWang on 2018/4/22. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public class WxPayRefundResultTest { @Test public void testFromXML() { /* 该xml字符串来自于官方文档示例,稍加改造,加上代金卷 refund_channel 是个什么鬼,官方文档只字不提 */ String xmlString = "<xml>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <nonce_str><![CDATA[NfsMFbUFpdbEhPXP]]></nonce_str>\n" + " <sign><![CDATA[B7274EB9F8925EB93100DD2085FA56C0]]></sign>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>\n" + " <out_trade_no><![CDATA[1415757673]]></out_trade_no>\n" + " <out_refund_no><![CDATA[1415701182]]></out_refund_no>\n" + " <refund_id><![CDATA[2008450740201411110000174436]]></refund_id>\n" + " <refund_channel><![CDATA[]]></refund_channel>\n" + " <coupon_refund_fee>1</coupon_refund_fee>\n" + " <coupon_refund_count>1</coupon_refund_count>\n" + " <coupon_refund_id_0>123</coupon_refund_id_0>\n" + " <coupon_refund_fee_0>1</coupon_refund_fee_0>\n" + " <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" + " <refund_fee>2</refund_fee> \n" + "</xml>"; WxPayRefundResult result = BaseWxPayResult.fromXML(xmlString, WxPayRefundResult.class); result.composeRefundCoupons(); assertThat(result.getRefundCoupons()).isNotEmpty(); assertThat(result.getRefundCoupons().get(0).getCouponRefundId()).isEqualTo("123"); assertThat(result.getRefundCoupons().get(0).getCouponType()).isEqualTo("CASH"); assertThat(result.getRefundCoupons().get(0).getCouponRefundFee()).isEqualTo(1); } @Test public void testFromXML_danpin() { //样例来自:https://pay.weixin.qq.com/wiki/doc/api/danpin.php?chapter=9_103&index=3 String xmlString = "<xml>\n" + "<return_code><![CDATA[SUCCESS]]></return_code>\n" + "<return_msg><![CDATA[OK]]></return_msg>\n" + "<appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + "<mch_id><![CDATA[10000100]]></mch_id>\n" + "<nonce_str><![CDATA[NfsMFbUFpdbEhPXP]]></nonce_str>\n" + "<sign><![CDATA[B7274EB9F8925EB93100DD2085FA56C0]]></sign>\n" + "<result_code><![CDATA[SUCCESS]]></result_code>\n" + "<transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>\n" + "<out_trade_no><![CDATA[1415757673]]></out_trade_no>\n" + "<out_refund_no><![CDATA[1415701182]]></out_refund_no>\n" + "<refund_id><![CDATA[2008450740201411110000174436]]></refund_id>\n" + "<refund_channel><![CDATA[]]></refund_channel>\n" + "<total_fee>1</total_fee >\n" + "<refund_fee>1</refund_fee>\n" + "<cash_fee>1</cash_fee >\n" + "<cash_refund_fee>1</cash_refund_fee>\n" + "<promotion_detail>{\"promotion_detail\":[{\"promotion_id\":\"109519\",\"scope\":\"SINGLE\",\"type\":\"DISCOUNT\",\"refund_amount\":5,\"goods_detail\":[{\"goods_id\":\"a_goods1\",\"refund_quantity\":7,\"price\":1,\"refund_amount\":4},{\"goods_id\":\"a_goods2\",\"refund_quantity\":1,\"price\":2,\"refund_amount\":1}]}]}</promotion_detail>\n" + "</xml>"; WxPayRefundResult result = BaseWxPayResult.fromXML(xmlString, WxPayRefundResult.class); result.composePromotionDetails(); assertThat(result.getPromotionDetails()).isNotEmpty(); assertThat(result.getPromotionDetails().get(0).getPromotionId()).isEqualTo("109519"); assertThat(result.getPromotionDetails().get(0).getRefundAmount()).isEqualTo(5); assertThat(result.getPromotionDetails().get(0).getScope()).isEqualTo("SINGLE"); assertThat(result.getPromotionDetails().get(0).getType()).isEqualTo("DISCOUNT"); assertThat(result.getPromotionDetails().get(0).getGoodsDetails()).isNotEmpty(); assertThat(result.getPromotionDetails().get(0).getGoodsDetails().get(0).getGoodsId()).isEqualTo("a_goods1"); assertThat(result.getPromotionDetails().get(0).getGoodsDetails().get(0).getRefundQuantity()).isEqualTo(7); assertThat(result.getPromotionDetails().get(0).getGoodsDetails().get(0).getRefundAmount()).isEqualTo(4); assertThat(result.getPromotionDetails().get(0).getGoodsDetails().get(0).getPrice()).isEqualTo(1); assertThat(result.getPromotionDetails().get(0).getGoodsDetails().get(1).getGoodsId()).isEqualTo("a_goods2"); assertThat(result.getPromotionDetails().get(0).getGoodsDetails().get(1).getRefundQuantity()).isEqualTo(1); assertThat(result.getPromotionDetails().get(0).getGoodsDetails().get(1).getRefundAmount()).isEqualTo(1); assertThat(result.getPromotionDetails().get(0).getGoodsDetails().get(1).getPrice()).isEqualTo(2); } @Test public void testFromXMLFastMode() { /* 该xml字符串来自于官方文档示例,稍加改造,加上代金卷 refund_channel 是个什么鬼,官方文档只字不提 */ String xmlString = "<xml>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <nonce_str><![CDATA[NfsMFbUFpdbEhPXP]]></nonce_str>\n" + " <sign><![CDATA[B7274EB9F8925EB93100DD2085FA56C0]]></sign>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>\n" + " <out_trade_no><![CDATA[1415757673]]></out_trade_no>\n" + " <out_refund_no><![CDATA[1415701182]]></out_refund_no>\n" + " <refund_id><![CDATA[2008450740201411110000174436]]></refund_id>\n" + " <refund_channel><![CDATA[]]></refund_channel>\n" + " <coupon_refund_fee>1</coupon_refund_fee>\n" + " <coupon_refund_count>1</coupon_refund_count>\n" + " <coupon_refund_id_0>123</coupon_refund_id_0>\n" + " <coupon_refund_fee_0>1</coupon_refund_fee_0>\n" + " <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" + " <refund_fee>2</refund_fee> \n" + "</xml>"; XmlConfig.fastMode = true; try { WxPayRefundResult result = BaseWxPayResult.fromXML(xmlString, WxPayRefundResult.class); result.composeRefundCoupons(); assertThat(result.getRefundCoupons()).isNotEmpty(); assertThat(result.getRefundCoupons().get(0).getCouponRefundId()).isEqualTo("123"); assertThat(result.getRefundCoupons().get(0).getCouponType()).isEqualTo("CASH"); assertThat(result.getRefundCoupons().get(0).getCouponRefundFee()).isEqualTo(1); } finally { XmlConfig.fastMode = false; } } @Test void benchmark() { long now = System.currentTimeMillis(); int loops = 10000; for (int i = 0; i < loops; i++) { testFromXML(); } System.out.println(" reflect mode:\t" + (System.currentTimeMillis() - now) + " (ms) "); now = System.currentTimeMillis(); for (int i = 0; i < loops; i++) { testFromXMLFastMode(); } System.out.println(" fast mode:\t" + (System.currentTimeMillis() - now) + " (ms) "); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayOrderQueryResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayOrderQueryResultTest.java
package com.github.binarywang.wxpay.bean.result; import org.testng.*; import org.testng.annotations.*; /** * <pre> * Created by Binary Wang on 2017-01-04. * </pre> * * @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> */ public class WxPayOrderQueryResultTest { /** * Test compose coupons. */ @Test public void testComposeCoupons() { /* * xml样例字符串来自于官方文档,并稍加改造加入了coupon相关的数据便于测试 */ String xmlString = "<xml>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <device_info><![CDATA[1000]]></device_info>\n" + " <nonce_str><![CDATA[TN55wO9Pba5yENl8]]></nonce_str>\n" + " <sign><![CDATA[BDF0099C15FF7BC6B1585FBB110AB635]]></sign>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <openid><![CDATA[oUpF8uN95-Ptaags6E_roPHg7AG0]]></openid>\n" + " <is_subscribe><![CDATA[Y]]></is_subscribe>\n" + " <trade_type><![CDATA[MICROPAY]]></trade_type>\n" + " <bank_type><![CDATA[CCB_DEBIT]]></bank_type>\n" + " <total_fee>1</total_fee>\n" + " <fee_type><![CDATA[CNY]]></fee_type>\n" + " <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>\n" + " <out_trade_no><![CDATA[1415757673]]></out_trade_no>\n" + " <attach><![CDATA[订单额外描述]]></attach>\n" + " <time_end><![CDATA[20141111170043]]></time_end>\n" + " <trade_state><![CDATA[SUCCESS]]></trade_state>\n" + " <coupon_count>2</coupon_count>\n" + " <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" + " <coupon_id_0>10000</coupon_id_0>\n" + " <coupon_fee_0>100</coupon_fee_0>\n" + " <coupon_type_1><![CDATA[NO_CASH]]></coupon_type_1>\n" + " <coupon_id_1>10001</coupon_id_1>\n" + " <coupon_fee_1>200</coupon_fee_1>\n" + "</xml>"; WxPayOrderQueryResult orderQueryResult = WxPayOrderQueryResult.fromXML(xmlString, WxPayOrderQueryResult.class); orderQueryResult.composeCoupons(); Assert.assertEquals(orderQueryResult.getCouponCount().intValue(), 2); Assert.assertNotNull(orderQueryResult.getCoupons()); Assert.assertEquals(orderQueryResult.getCoupons().size(), 2); Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponFee().intValue(), 100); Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponFee().intValue(), 200); Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponType(), "CASH"); Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponType(), "NO_CASH"); Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponId(), "10000"); Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponId(), "10001"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java
package com.github.binarywang.wxpay.bean.result; import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; import com.github.binarywang.wxpay.v3.util.SignUtils; import org.testng.Assert; import org.testng.annotations.Test; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PrivateKey; /** * <pre> * WxPayUnifiedOrderV3Result 测试类 * 主要测试prepayId字段和静态工厂方法的解耦功能 * </pre> * * @author copilot */ public class WxPayUnifiedOrderV3ResultTest { /** * 生成测试用的RSA密钥对 */ private KeyPair generateKeyPair() throws Exception { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(2048); return keyPairGenerator.generateKeyPair(); } /** * 测试JsapiResult中的prepayId字段是否正确设置 */ @Test public void testJsapiResultWithPrepayId() throws Exception { // 准备测试数据 String testPrepayId = "wx201410272009395522657a690389285100"; String testAppId = "wx8888888888888888"; KeyPair keyPair = generateKeyPair(); PrivateKey privateKey = keyPair.getPrivate(); // 创建WxPayUnifiedOrderV3Result对象 WxPayUnifiedOrderV3Result result = new WxPayUnifiedOrderV3Result(); result.setPrepayId(testPrepayId); // 调用getPayInfo生成JsapiResult WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = result.getPayInfo(TradeTypeEnum.JSAPI, testAppId, null, privateKey); // 验证prepayId字段是否正确设置 Assert.assertNotNull(jsapiResult.getPrepayId(), "prepayId不应为null"); Assert.assertEquals(jsapiResult.getPrepayId(), testPrepayId, "prepayId应该与设置的值相同"); // 验证其他字段 Assert.assertEquals(jsapiResult.getAppId(), testAppId); Assert.assertNotNull(jsapiResult.getTimeStamp()); Assert.assertNotNull(jsapiResult.getNonceStr()); Assert.assertEquals(jsapiResult.getPackageValue(), "prepay_id=" + testPrepayId); Assert.assertEquals(jsapiResult.getSignType(), "RSA"); Assert.assertNotNull(jsapiResult.getPaySign()); } /** * 测试使用静态工厂方法生成JsapiResult(解耦场景) */ @Test public void testGetJsapiPayInfoStaticMethod() throws Exception { // 准备测试数据 String testPrepayId = "wx201410272009395522657a690389285100"; String testAppId = "wx8888888888888888"; KeyPair keyPair = generateKeyPair(); PrivateKey privateKey = keyPair.getPrivate(); // 使用静态工厂方法生成JsapiResult WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = WxPayUnifiedOrderV3Result.getJsapiPayInfo(testPrepayId, testAppId, privateKey); // 验证prepayId字段 Assert.assertNotNull(jsapiResult.getPrepayId(), "prepayId不应为null"); Assert.assertEquals(jsapiResult.getPrepayId(), testPrepayId, "prepayId应该与输入的值相同"); // 验证其他字段 Assert.assertEquals(jsapiResult.getAppId(), testAppId); Assert.assertNotNull(jsapiResult.getTimeStamp()); Assert.assertNotNull(jsapiResult.getNonceStr()); Assert.assertEquals(jsapiResult.getPackageValue(), "prepay_id=" + testPrepayId); Assert.assertEquals(jsapiResult.getSignType(), "RSA"); Assert.assertNotNull(jsapiResult.getPaySign()); } /** * 测试使用静态工厂方法生成AppResult(解耦场景) */ @Test public void testGetAppPayInfoStaticMethod() throws Exception { // 准备测试数据 String testPrepayId = "wx201410272009395522657a690389285100"; String testAppId = "wx8888888888888888"; String testMchId = "1900000109"; KeyPair keyPair = generateKeyPair(); PrivateKey privateKey = keyPair.getPrivate(); // 使用静态工厂方法生成AppResult WxPayUnifiedOrderV3Result.AppResult appResult = WxPayUnifiedOrderV3Result.getAppPayInfo(testPrepayId, testAppId, testMchId, privateKey); // 验证prepayId字段 Assert.assertNotNull(appResult.getPrepayId(), "prepayId不应为null"); Assert.assertEquals(appResult.getPrepayId(), testPrepayId, "prepayId应该与输入的值相同"); // 验证其他字段 Assert.assertEquals(appResult.getAppid(), testAppId); Assert.assertEquals(appResult.getPartnerId(), testMchId); Assert.assertNotNull(appResult.getTimestamp()); Assert.assertNotNull(appResult.getNoncestr()); Assert.assertEquals(appResult.getPackageValue(), "Sign=WXPay"); Assert.assertNotNull(appResult.getSign()); } /** * 测试解耦场景:先获取prepayId,后续再生成支付信息 */ @Test public void testDecoupledScenario() throws Exception { // 模拟场景:先创建订单获取prepayId String testPrepayId = "wx201410272009395522657a690389285100"; String testAppId = "wx8888888888888888"; KeyPair keyPair = generateKeyPair(); PrivateKey privateKey = keyPair.getPrivate(); // 步骤1:模拟从创建订单接口获取prepayId WxPayUnifiedOrderV3Result orderResult = new WxPayUnifiedOrderV3Result(); orderResult.setPrepayId(testPrepayId); // 获取prepayId用于存储 String storedPrepayId = orderResult.getPrepayId(); Assert.assertEquals(storedPrepayId, testPrepayId); // 步骤2:后续支付失败时,使用存储的prepayId重新生成支付信息 WxPayUnifiedOrderV3Result.JsapiResult newPayInfo = WxPayUnifiedOrderV3Result.getJsapiPayInfo(storedPrepayId, testAppId, privateKey); // 验证重新生成的支付信息 Assert.assertEquals(newPayInfo.getPrepayId(), storedPrepayId); Assert.assertEquals(newPayInfo.getPackageValue(), "prepay_id=" + storedPrepayId); Assert.assertNotNull(newPayInfo.getPaySign()); } /** * 测试多次生成支付信息,签名应该不同(因为timestamp和nonceStr每次都不同) */ @Test public void testMultipleGenerationsHaveDifferentSignatures() throws Exception { String testPrepayId = "wx201410272009395522657a690389285100"; String testAppId = "wx8888888888888888"; KeyPair keyPair = generateKeyPair(); PrivateKey privateKey = keyPair.getPrivate(); // 生成第一次支付信息 WxPayUnifiedOrderV3Result.JsapiResult result1 = WxPayUnifiedOrderV3Result.getJsapiPayInfo(testPrepayId, testAppId, privateKey); // 等待一秒确保timestamp不同 Thread.sleep(1000); // 生成第二次支付信息 WxPayUnifiedOrderV3Result.JsapiResult result2 = WxPayUnifiedOrderV3Result.getJsapiPayInfo(testPrepayId, testAppId, privateKey); // prepayId应该相同 Assert.assertEquals(result1.getPrepayId(), result2.getPrepayId()); // 但是timestamp、nonceStr和签名应该不同 Assert.assertNotEquals(result1.getTimeStamp(), result2.getTimeStamp(), "timestamp应该不同"); Assert.assertNotEquals(result1.getNonceStr(), result2.getNonceStr(), "nonceStr应该不同"); Assert.assertNotEquals(result1.getPaySign(), result2.getPaySign(), "签名应该不同"); } /** * 测试AppResult中的prepayId字段 */ @Test public void testAppResultWithPrepayId() throws Exception { String testPrepayId = "wx201410272009395522657a690389285100"; String testAppId = "wx8888888888888888"; String testMchId = "1900000109"; KeyPair keyPair = generateKeyPair(); PrivateKey privateKey = keyPair.getPrivate(); WxPayUnifiedOrderV3Result result = new WxPayUnifiedOrderV3Result(); result.setPrepayId(testPrepayId); // 调用getPayInfo生成AppResult WxPayUnifiedOrderV3Result.AppResult appResult = result.getPayInfo(TradeTypeEnum.APP, testAppId, testMchId, privateKey); // 验证prepayId字段 Assert.assertNotNull(appResult.getPrepayId(), "prepayId不应为null"); Assert.assertEquals(appResult.getPrepayId(), testPrepayId, "prepayId应该与设置的值相同"); } /** * 测试getJsapiPayInfo方法的空值验证 */ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "prepayId, appId 和 privateKey 不能为空") public void testGetJsapiPayInfoWithNullPrepayId() { WxPayUnifiedOrderV3Result.getJsapiPayInfo(null, "appId", null); } /** * 测试getJsapiPayInfo方法的空值验证 - appId为null */ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "prepayId, appId 和 privateKey 不能为空") public void testGetJsapiPayInfoWithNullAppId() throws Exception { KeyPair keyPair = generateKeyPair(); WxPayUnifiedOrderV3Result.getJsapiPayInfo("prepayId", null, keyPair.getPrivate()); } /** * 测试getJsapiPayInfo方法的空值验证 - privateKey为null */ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "prepayId, appId 和 privateKey 不能为空") public void testGetJsapiPayInfoWithNullPrivateKey() { WxPayUnifiedOrderV3Result.getJsapiPayInfo("prepayId", "appId", null); } /** * 测试getAppPayInfo方法的空值验证 - prepayId为null */ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "prepayId, appId, mchId 和 privateKey 不能为空") public void testGetAppPayInfoWithNullPrepayId() { WxPayUnifiedOrderV3Result.getAppPayInfo(null, "appId", "mchId", null); } /** * 测试getAppPayInfo方法的空值验证 - appId为null */ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "prepayId, appId, mchId 和 privateKey 不能为空") public void testGetAppPayInfoWithNullAppId() throws Exception { KeyPair keyPair = generateKeyPair(); WxPayUnifiedOrderV3Result.getAppPayInfo("prepayId", null, "mchId", keyPair.getPrivate()); } /** * 测试getAppPayInfo方法的空值验证 - mchId为null */ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "prepayId, appId, mchId 和 privateKey 不能为空") public void testGetAppPayInfoWithNullMchId() throws Exception { KeyPair keyPair = generateKeyPair(); WxPayUnifiedOrderV3Result.getAppPayInfo("prepayId", "appId", null, keyPair.getPrivate()); } /** * 测试getAppPayInfo方法的空值验证 - privateKey为null */ @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "prepayId, appId, mchId 和 privateKey 不能为空") public void testGetAppPayInfoWithNullPrivateKey() { WxPayUnifiedOrderV3Result.getAppPayInfo("prepayId", "appId", "mchId", null); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyUnknownFieldTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyUnknownFieldTest.java
package com.github.binarywang.wxpay.bean.notify; import com.github.binarywang.wxpay.constant.WxPayConstants; import org.apache.commons.codec.digest.DigestUtils; import org.testng.Assert; import org.testng.annotations.Test; import java.util.*; /** * 测试当微信支付回调 XML 包含未在 Java Bean 中定义的字段时,签名验证是否正常。 * <p> * 问题背景:当微信返回的 XML 包含某些未在 WxPayOrderNotifyResult 中定义的字段时, * 这些字段会被微信服务器用于签名计算。如果 toMap() 方法丢失了这些字段, * 则签名验证会失败,抛出 "参数格式校验错误!" 异常。 * </p> * <p> * 解决方案:修改 WxPayOrderNotifyResult.toMap() 方法,使用父类的 toMap() 方法 * 直接从原始 XML 解析所有字段,而不是使用 SignUtils.xmlBean2Map(this)。 * </p> * * @see <a href="https://github.com/binarywang/WxJava/issues/3750">Issue #3750</a> */ public class WxPayOrderNotifyUnknownFieldTest { private static final String MCH_KEY = "testmchkey1234567890123456789012"; private static final List<String> NO_SIGN_PARAMS = Arrays.asList("sign", "key", "xmlString", "xmlDoc", "couponList"); @Test public void testSignatureWithUnknownField() throws Exception { // 创建一个测试用的 XML,包含一个未知字段 (未在 WxPayOrderNotifyResult 中定义) Map<String, String> params = new LinkedHashMap<>(); params.put("appid", "wx58ff40508696691f"); params.put("bank_type", "ICBC_DEBIT"); params.put("cash_fee", "1"); params.put("fee_type", "CNY"); params.put("is_subscribe", "N"); params.put("mch_id", "1545462911"); params.put("nonce_str", "1761723102373"); params.put("openid", "o1gdd16CZCi6yYvkn6j9EB_1TObM"); params.put("out_trade_no", "20251029153140"); params.put("result_code", "SUCCESS"); params.put("return_code", "SUCCESS"); params.put("time_end", "20251029153852"); params.put("total_fee", "1"); params.put("trade_type", "JSAPI"); params.put("transaction_id", "4200002882220251029816273963B"); // 添加一个未知字段 params.put("unknown_field", "unknown_value"); // 计算正确的签名 (包含未知字段) String correctSign = createSign(params, WxPayConstants.SignType.MD5, MCH_KEY); params.put("sign", correctSign); // 创建 XML StringBuilder xmlBuilder = new StringBuilder("<xml>"); for (Map.Entry<String, String> entry : params.entrySet()) { xmlBuilder.append("<").append(entry.getKey()).append(">") .append(entry.getValue()) .append("</").append(entry.getKey()).append(">"); } xmlBuilder.append("</xml>"); String xml = xmlBuilder.toString(); System.out.println("测试 XML (包含未知字段 unknown_field):"); System.out.println(xml); System.out.println("正确的签名 (包含未知字段计算): " + correctSign); // 解析 XML WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xml); Map<String, String> beanMap = result.toMap(); System.out.println("\ntoMap() 结果:"); TreeMap<String, String> sortedMap = new TreeMap<>(beanMap); for (Map.Entry<String, String> entry : sortedMap.entrySet()) { System.out.println(" " + entry.getKey() + " = " + entry.getValue()); } // 检查 unknown_field 是否存在 boolean hasUnknownField = beanMap.containsKey("unknown_field"); System.out.println("\ntoMap() 是否包含 unknown_field: " + hasUnknownField); // 验证签名 String verifySign = createSign(beanMap, WxPayConstants.SignType.MD5, MCH_KEY); System.out.println("原始签名: " + result.getSign()); System.out.println("计算签名: " + verifySign); // 这个测试验证修复后 toMap() 能正确包含所有字段 Assert.assertTrue(hasUnknownField, "toMap() 应该包含 unknown_field"); Assert.assertEquals(verifySign, result.getSign(), "签名应该匹配"); } private static String createSign(Map<String, String> params, String signType, String signKey) { StringBuilder toSign = new StringBuilder(); for (String key : new TreeMap<>(params).keySet()) { String value = params.get(key); if (value != null && !value.isEmpty() && !NO_SIGN_PARAMS.contains(key)) { toSign.append(key).append("=").append(value).append("&"); } } toSign.append("key=").append(signKey); return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxScanPayNotifyResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxScanPayNotifyResultTest.java
package com.github.binarywang.wxpay.bean.notify; import com.github.binarywang.wxpay.util.XmlConfig; import org.testng.annotations.*; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; import static org.assertj.core.api.Assertions.assertThat; /** * <pre> * * Created by Binary Wang on 2018/2/2. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public class WxScanPayNotifyResultTest { /** * Test to map. */ @Test public void testToMap() { } /** * Test from xml. */ @Test public void testFromXML() { String xmlString = "<xml>\n" + " <appid><![CDATA[wx8888888888888888]]></appid>\n" + " <openid><![CDATA[o8GeHuLAsgefS_80exEr1cTqekUs]]></openid>\n" + " <mch_id><![CDATA[1900000109]]></mch_id>\n" + " <is_subscribe><![CDATA[Y]]></is_subscribe>\n" + " <nonce_str><![CDATA[5K8264ILTKCH16CQ2502SI8ZNMTM67VS]]></nonce_str>\n" + " <product_id><![CDATA[88888]]></product_id>\n" + " <sign><![CDATA[C380BEC2BFD727A4B6845133519F3AD6]]></sign>\n" + "</xml>"; WxScanPayNotifyResult result = BaseWxPayResult.fromXML(xmlString, WxScanPayNotifyResult.class); assertThat(result).isNotNull(); assertThat(result.getAppid()).isEqualTo("wx8888888888888888"); assertThat(result.getOpenid()).isEqualTo("o8GeHuLAsgefS_80exEr1cTqekUs"); assertThat(result.getMchId()).isEqualTo("1900000109"); assertThat(result.getNonceStr()).isEqualTo("5K8264ILTKCH16CQ2502SI8ZNMTM67VS"); assertThat(result.getProductId()).isEqualTo("88888"); assertThat(result.getSign()).isEqualTo("C380BEC2BFD727A4B6845133519F3AD6"); } /** * Test from xml. * fast mode. */ @Test public void testFromXMLFastMode() { String xmlString = "<xml>\n" + " <appid><![CDATA[wx8888888888888888]]></appid>\n" + " <openid><![CDATA[o8GeHuLAsgefS_80exEr1cTqekUs]]></openid>\n" + " <mch_id><![CDATA[1900000109]]></mch_id>\n" + " <is_subscribe><![CDATA[Y]]></is_subscribe>\n" + " <nonce_str><![CDATA[5K8264ILTKCH16CQ2502SI8ZNMTM67VS]]></nonce_str>\n" + " <product_id><![CDATA[88888]]></product_id>\n" + " <sign><![CDATA[C380BEC2BFD727A4B6845133519F3AD6]]></sign>\n" + "</xml>"; XmlConfig.fastMode = true; try { WxScanPayNotifyResult result = BaseWxPayResult.fromXML(xmlString, WxScanPayNotifyResult.class); assertThat(result).isNotNull(); assertThat(result.getAppid()).isEqualTo("wx8888888888888888"); assertThat(result.getOpenid()).isEqualTo("o8GeHuLAsgefS_80exEr1cTqekUs"); assertThat(result.getMchId()).isEqualTo("1900000109"); assertThat(result.getNonceStr()).isEqualTo("5K8264ILTKCH16CQ2502SI8ZNMTM67VS"); assertThat(result.getProductId()).isEqualTo("88888"); assertThat(result.getSign()).isEqualTo("C380BEC2BFD727A4B6845133519F3AD6"); } finally { XmlConfig.fastMode = false; } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponseTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponseTest.java
package com.github.binarywang.wxpay.bean.notify; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; /** * WxPayNotifyResponse 测试. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2019-06-30 */ @Slf4j public class WxPayNotifyResponseTest { /** * V2版本 */ @Test public void testSuccess() { final String result = WxPayNotifyResponse.success("OK"); assertThat(result).isEqualTo("<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>" + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml>"); } @Test public void testSuccessResp() { final String result = WxPayNotifyResponse.successResp("OK"); assertThat(result).isEqualTo("<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>" + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml>"); } @Test public void testFailResp() { final String result = WxPayNotifyResponse.failResp("500"); assertThat(result).isEqualTo("<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[500]]></return_msg>" + "</xml>"); } /** * V3版本 * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml */ @Test public void testV3Fail() { final String result = WxPayNotifyV3Response.fail("失败"); log.info(result); assertThat(result).isNotEmpty(); } @Test public void testV3Success() { final String result = WxPayNotifyV3Response.success("成功"); log.info(result); assertThat(result).isNotEmpty(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResultTest.java
package com.github.binarywang.wxpay.bean.notify; import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import javax.inject.Inject; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; import com.github.binarywang.wxpay.util.XmlConfig; import org.apache.commons.codec.binary.Base64; import org.testng.annotations.*; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.testbase.ApiTestModule; import static org.testng.Assert.*; /** * <pre> * Created by BinaryWang on 2017/8/27. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Test @Guice(modules = ApiTestModule.class) public class WxPayRefundNotifyResultTest { @Inject private WxPayConfig wxPayConfig; /** * Test from xml. * * @throws WxPayException the wx pay exception */ public void testFromXML() throws WxPayException { String xmlString = "<xml>" + "<return_code>SUCCESS</return_code>" + "<appid><![CDATA[****]]></appid>" + "<mch_id><![CDATA[****]]></mch_id>" + "<nonce_str><![CDATA[1ee38e38b04990449808688cf3a763b7]]></nonce_str>" + "<req_info><![CDATA[q1QZlV5j/4I7CsJ3voq1zDgVAuzNM/Gg5JYHcpMZCLtg9KQlB6vShzsh8tgK60dU6yG2WVa0zeSDlK4B7wJCad1lUUP8Ar0Hm18M1ZEjw5vQU17wMzypRM0M9A4CcRLBezRZYzCka9CAH90E2FZ74y6VRe4DNR87t5n3DWVtSbWTBoaFUexHtNs6pyrqX77VvbilIyLZMv5ZYQYOobbQ1U3kime5He7ShEWZ0GPI3gq+z/ZOLsnIdJ5bsT4kokhq/531hSoZ5006vxRGGXnhJt8IYiG7R+oSQxZOYqYR5SKWF+0z2/g0zzM2QQlT2ynLWvBKvdVCLlgCjFN1DF4z/7IEK5FAISFP0GGF51hYw/LofL3ftlD7h7jvjOIgH5viJ0yFGmGCEFHcLKqg0DPXmzwXIrkgQSSQPsuZ6UbHUUG0L8YTRgLnl2FwNFskJIaNx0179Il6xveR1sCXbwSDGvGN78sFuQMztbnx+gFu6VYgv7C+5pFr87wHFAeuDXGTkVM6ucAwSanP7HuxSVvf7SrSrcovKslyqj869pSqn/AB0atiQ4eoq3kWaOqx87NHOV1st9SQW1SYH7SKz4jd9uhrQyDuPb6KJSg1Z2B4sU4187NjPzL4NpzZySgiYk2yXpWKhCLIz6BdZuWX79zgqxLbGxJJnhyy3tOzRWIlMkDOppGJyh8LO0LOqhXzwyrCYzPA+h2xcr7xN5WIW1IGJSZqHdURUtlemcB+yZivuzARNH0LE2MGUfuoNgZ5j1Osn7K88IrkAyKupcIEmG3ktVnPOd1A9RQ9eWbU+C7yKrl6u5ZRZOX0eElVszKfBFy4tu3XHlT7hd/zMFK5NJt8sE89k5m7M8KCGSgJ+Y90ZnUclQvDVtoR5CFkfqsP9fSpA1L+aKYsl2ESq5+fzcqsYRL3YLEhIipBKKrvg6Gy698oNeG+9oCIyuiFexJDq8ycBZ/AWiR+pFQVbNRaFbfKPR9zCW8gHwYOGnENNY9gABuuENqxxXDx9tEYkACd0H9ezLnu9psC6AuR41ACfo6wGKUA1TnpVEHsDbdvJBWDcw60l1hkmHQN2lYFy+eMusEX]]></req_info></xml>"; WxPayRefundNotifyResult refundNotifyResult = WxPayRefundNotifyResult.fromXML(xmlString, this.wxPayConfig.getMchKey()); assertNotNull(refundNotifyResult); System.out.println(refundNotifyResult); } /** * Encode req info. * * @throws Exception the exception */ public void encodeReqInfo() throws Exception { String xml = "<root>\n" + "<out_refund_no><![CDATA[R4001312001201707262674894706_4]]></out_refund_no>\n" + "<out_trade_no><![CDATA[201707260201501501005710775]]></out_trade_no>\n" + "<refund_account><![CDATA[REFUND_SOURCE_UNSETTLED_FUNDS]]></refund_account>\n" + "<refund_fee><![CDATA[15]]></refund_fee>\n" + "<refund_id><![CDATA[50000203702017072601461713166]]></refund_id>\n" + "<refund_recv_accout><![CDATA[用户零钱]]></refund_recv_accout>\n" + "<refund_request_source><![CDATA[API]]></refund_request_source>\n" + "<refund_status><![CDATA[SUCCESS]]></refund_status>\n" + "<settlement_refund_fee><![CDATA[15]]></settlement_refund_fee>\n" + "<settlement_total_fee><![CDATA[100]]></settlement_total_fee>\n" + "<success_time><![CDATA[2017-07-26 02:45:49]]></success_time>\n" + "<total_fee><![CDATA[100]]></total_fee>\n" + "<transaction_id><![CDATA[4001312001201707262674894706]]></transaction_id>\n" + "</root>"; Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); final MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(this.wxPayConfig.getMchKey().getBytes(StandardCharsets.UTF_8)); final String keyMd5String = new BigInteger(1, md5.digest()).toString(16).toLowerCase(); SecretKeySpec key = new SecretKeySpec(keyMd5String.getBytes(StandardCharsets.UTF_8), "AES"); cipher.init(Cipher.ENCRYPT_MODE, key); System.out.println(Base64.encodeBase64String(cipher.doFinal(xml.getBytes(StandardCharsets.UTF_8)))); } /** * Test from xml. * fast mode * * @throws WxPayException the wx pay exception */ public void testFromXMLFastMode() throws WxPayException { String xmlString = "<xml>" + "<return_code>SUCCESS</return_code>" + "<appid><![CDATA[****]]></appid>" + "<mch_id><![CDATA[****]]></mch_id>" + "<nonce_str><![CDATA[1ee38e38b04990449808688cf3a763b7]]></nonce_str>" + "<req_info><![CDATA[q1QZlV5j/4I7CsJ3voq1zDgVAuzNM/Gg5JYHcpMZCLtg9KQlB6vShzsh8tgK60dU6yG2WVa0zeSDlK4B7wJCad1lUUP8Ar0Hm18M1ZEjw5vQU17wMzypRM0M9A4CcRLBezRZYzCka9CAH90E2FZ74y6VRe4DNR87t5n3DWVtSbWTBoaFUexHtNs6pyrqX77VvbilIyLZMv5ZYQYOobbQ1U3kime5He7ShEWZ0GPI3gq+z/ZOLsnIdJ5bsT4kokhq/531hSoZ5006vxRGGXnhJt8IYiG7R+oSQxZOYqYR5SKWF+0z2/g0zzM2QQlT2ynLWvBKvdVCLlgCjFN1DF4z/7IEK5FAISFP0GGF51hYw/LofL3ftlD7h7jvjOIgH5viJ0yFGmGCEFHcLKqg0DPXmzwXIrkgQSSQPsuZ6UbHUUG0L8YTRgLnl2FwNFskJIaNx0179Il6xveR1sCXbwSDGvGN78sFuQMztbnx+gFu6VYgv7C+5pFr87wHFAeuDXGTkVM6ucAwSanP7HuxSVvf7SrSrcovKslyqj869pSqn/AB0atiQ4eoq3kWaOqx87NHOV1st9SQW1SYH7SKz4jd9uhrQyDuPb6KJSg1Z2B4sU4187NjPzL4NpzZySgiYk2yXpWKhCLIz6BdZuWX79zgqxLbGxJJnhyy3tOzRWIlMkDOppGJyh8LO0LOqhXzwyrCYzPA+h2xcr7xN5WIW1IGJSZqHdURUtlemcB+yZivuzARNH0LE2MGUfuoNgZ5j1Osn7K88IrkAyKupcIEmG3ktVnPOd1A9RQ9eWbU+C7yKrl6u5ZRZOX0eElVszKfBFy4tu3XHlT7hd/zMFK5NJt8sE89k5m7M8KCGSgJ+Y90ZnUclQvDVtoR5CFkfqsP9fSpA1L+aKYsl2ESq5+fzcqsYRL3YLEhIipBKKrvg6Gy698oNeG+9oCIyuiFexJDq8ycBZ/AWiR+pFQVbNRaFbfKPR9zCW8gHwYOGnENNY9gABuuENqxxXDx9tEYkACd0H9ezLnu9psC6AuR41ACfo6wGKUA1TnpVEHsDbdvJBWDcw60l1hkmHQN2lYFy+eMusEX]]></req_info></xml>"; String xmlDecryptedReqInfo = "<root>\n" + "<out_refund_no><![CDATA[R4001312001201707262674894706_4]]></out_refund_no>\n" + "<out_trade_no><![CDATA[201707260201501501005710775]]></out_trade_no>\n" + "<refund_account><![CDATA[REFUND_SOURCE_UNSETTLED_FUNDS]]></refund_account>\n" + "<refund_fee><![CDATA[15]]></refund_fee>\n" + "<refund_id><![CDATA[50000203702017072601461713166]]></refund_id>\n" + "<refund_recv_accout><![CDATA[用户零钱]]></refund_recv_accout>\n" + "<refund_request_source><![CDATA[API]]></refund_request_source>\n" + "<refund_status><![CDATA[SUCCESS]]></refund_status>\n" + "<settlement_refund_fee><![CDATA[15]]></settlement_refund_fee>\n" + "<settlement_total_fee><![CDATA[100]]></settlement_total_fee>\n" + "<success_time><![CDATA[2017-07-26 02:45:49]]></success_time>\n" + "<total_fee><![CDATA[100]]></total_fee>\n" + "<transaction_id><![CDATA[4001312001201707262674894706]]></transaction_id>\n" + "</root>"; XmlConfig.fastMode = true; try { WxPayRefundNotifyResult refundNotifyResult = BaseWxPayResult.fromXML(xmlString, WxPayRefundNotifyResult.class); System.out.println(refundNotifyResult.getReqInfoString()); refundNotifyResult.loadReqInfo(xmlDecryptedReqInfo); assertEquals(refundNotifyResult.getReqInfo().getRefundFee().intValue(), 15); assertEquals(refundNotifyResult.getReqInfo().getRefundStatus(), "SUCCESS"); assertEquals(refundNotifyResult.getReqInfo().getRefundRecvAccount(), "用户零钱"); System.out.println(refundNotifyResult); } finally { XmlConfig.fastMode = false; } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayOrderNotifyResultTest.java
package com.github.binarywang.wxpay.bean.notify; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; import com.github.binarywang.wxpay.util.XmlConfig; import org.testng.*; import org.testng.annotations.*; /** * <pre> * Created by Binary Wang on 2017-6-15. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public class WxPayOrderNotifyResultTest { /** * Test from xml. */ @Test public void testFromXML() { String xmlString = "<xml>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <attach><![CDATA[支付测试]]></attach>\n" + " <bank_type><![CDATA[CFT]]></bank_type>\n" + " <fee_type><![CDATA[CNY]]></fee_type>\n" + " <is_subscribe><![CDATA[Y]]></is_subscribe>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <nonce_str><![CDATA[5d2b6c2a8db53831f7eda20af46e531c]]></nonce_str>\n" + " <openid><![CDATA[oUpF8uMEb4qRXf22hE3X68TekukE]]></openid>\n" + " <out_trade_no><![CDATA[1409811653]]></out_trade_no>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <sign><![CDATA[B552ED6B279343CB493C5DD0D78AB241]]></sign>\n" + " <sub_mch_id><![CDATA[10000100]]></sub_mch_id>\n" + " <time_end><![CDATA[20140903131540]]></time_end>\n" + " <total_fee>1</total_fee>\n" + " <trade_type><![CDATA[JSAPI]]></trade_type>\n" + " <transaction_id><![CDATA[1004400740201409030005092168]]></transaction_id>\n" + " <coupon_count>2</coupon_count>\n" + " <coupon_type_1><![CDATA[NO_CASH]]></coupon_type_1>\n" + " <coupon_id_1>10001</coupon_id_1>\n" + " <coupon_fee_1>200</coupon_fee_1>\n" + " <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" + " <coupon_id_0>10000</coupon_id_0>\n" + " <coupon_fee_0>100</coupon_fee_0>\n" + "</xml>"; WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlString); Assert.assertEquals(result.getCouponCount().intValue(), 2); Assert.assertNotNull(result.getCouponList()); Assert.assertEquals(result.getCouponList().size(), 2); Assert.assertEquals(result.getCouponList().get(0).getCouponFee().intValue(), 100); Assert.assertEquals(result.getCouponList().get(1).getCouponFee().intValue(), 200); Assert.assertEquals(result.getCouponList().get(0).getCouponType(), "CASH"); Assert.assertEquals(result.getCouponList().get(1).getCouponType(), "NO_CASH"); Assert.assertEquals(result.getCouponList().get(0).getCouponId(), "10000"); Assert.assertEquals(result.getCouponList().get(1).getCouponId(), "10001"); //fast mode test XmlConfig.fastMode = true; try { result = BaseWxPayResult.fromXML(xmlString, WxPayOrderNotifyResult.class); Assert.assertEquals(result.getCouponCount().intValue(), 2); Assert.assertNotNull(result.getCouponList()); Assert.assertEquals(result.getCouponList().size(), 2); Assert.assertEquals(result.getCouponList().get(0).getCouponFee().intValue(), 100); Assert.assertEquals(result.getCouponList().get(1).getCouponFee().intValue(), 200); Assert.assertEquals(result.getCouponList().get(0).getCouponType(), "CASH"); Assert.assertEquals(result.getCouponList().get(1).getCouponType(), "NO_CASH"); Assert.assertEquals(result.getCouponList().get(0).getCouponId(), "10000"); Assert.assertEquals(result.getCouponList().get(1).getCouponId(), "10001"); } finally { XmlConfig.fastMode = false; } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/marketing/FavorStocksGetResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/marketing/FavorStocksGetResultTest.java
package com.github.binarywang.wxpay.bean.marketing; import com.github.binarywang.wxpay.bean.result.BaseWxPayV3Result; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import org.testng.annotations.Test; import static org.testng.Assert.*; /** * 测试FavorStocksGetResult的原始JSON保存功能 * * @author Binary Wang */ public class FavorStocksGetResultTest { private static final Gson GSON = new GsonBuilder().create(); @Test public void testRawJsonPreservation() { // 模拟微信API返回的JSON(包含未在Result类中定义的字段) String mockJson = "{\n" + " \"stock_id\": \"9836588\",\n" + " \"stock_creator_mchid\": \"1230000109\",\n" + " \"stock_name\": \"微信支付代金券\",\n" + " \"status\": \"running\",\n" + " \"create_time\": \"2021-01-01T00:00:00.000+08:00\",\n" + " \"description\": \"微信支付营销\",\n" + " \"card_id\": \"pFS7Fjg9kqcMOBtl3bFn\",\n" + " \"extra_field\": \"这是一个新增字段\"\n" + "}"; // 模拟服务调用:反序列化JSON FavorStocksGetResult result = GSON.fromJson(mockJson, FavorStocksGetResult.class); // 模拟服务调用:设置原始JSON result.setRawJsonString(mockJson); // 验证基本字段正常解析 assertEquals(result.getStockId(), "9836588"); assertEquals(result.getStockCreatorMchId(), "1230000109"); assertEquals(result.getStockName(), "微信支付代金券"); assertEquals(result.getStatus(), "running"); // 验证原始JSON被保存 assertNotNull(result.getRawJsonString()); assertEquals(result.getRawJsonString(), mockJson); // 验证可以从原始JSON中获取未定义的字段 assertTrue(result.getRawJsonString().contains("\"card_id\": \"pFS7Fjg9kqcMOBtl3bFn\"")); assertTrue(result.getRawJsonString().contains("\"extra_field\": \"这是一个新增字段\"")); } @Test public void testBaseV3ResultInheritance() { FavorStocksGetResult result = new FavorStocksGetResult(); // 验证继承关系 assertTrue(result instanceof BaseWxPayV3Result); // 验证基类方法可用 result.setRawJsonString("test json"); assertEquals(result.getRawJsonString(), "test json"); } @Test public void testNullRawJson() { FavorStocksGetResult result = new FavorStocksGetResult(); // 验证初始状态下rawJsonString为null assertNull(result.getRawJsonString()); // 验证设置null不会出错 result.setRawJsonString(null); assertNull(result.getRawJsonString()); } @Test public void testRealWorldUsagePattern() { // 实际使用场景的示例 String realApiResponse = "{\n" + " \"stock_id\": \"9836588\",\n" + " \"stock_creator_mchid\": \"1230000109\",\n" + " \"stock_name\": \"微信支付代金券\",\n" + " \"status\": \"running\",\n" + " \"create_time\": \"2021-01-01T00:00:00.000+08:00\",\n" + " \"description\": \"微信支付营销\",\n" + " \"card_id\": \"pFS7Fjg9kqcMOBtl3bFn\",\n" + " \"future_field_1\": \"未来可能新增的字段1\",\n" + " \"future_field_2\": \"未来可能新增的字段2\"\n" + "}"; FavorStocksGetResult result = GSON.fromJson(realApiResponse, FavorStocksGetResult.class); result.setRawJsonString(realApiResponse); // 1. 正常使用已定义的字段 assertEquals(result.getStockId(), "9836588"); assertEquals(result.getStockName(), "微信支付代金券"); // 2. 安全地获取可能存在的新字段 String cardId = getStringFieldSafely(result, "card_id"); assertEquals(cardId, "pFS7Fjg9kqcMOBtl3bFn"); // 3. 获取未来可能新增的字段 String futureField1 = getStringFieldSafely(result, "future_field_1"); assertEquals(futureField1, "未来可能新增的字段1"); String nonExistentField = getStringFieldSafely(result, "non_existent"); assertNull(nonExistentField); } @Test public void testCardIdExtractionExample() { // 测试具体的card_id字段提取(这是issue中提到的用例) String apiResponseWithCardId = "{\n" + " \"stock_id\": \"9836588\",\n" + " \"stock_creator_mchid\": \"1230000109\",\n" + " \"stock_name\": \"微信支付代金券\",\n" + " \"status\": \"running\",\n" + " \"card_id\": \"pFS7Fjg9kqcMOBtl3bFn\"\n" + "}"; FavorStocksGetResult result = GSON.fromJson(apiResponseWithCardId, FavorStocksGetResult.class); result.setRawJsonString(apiResponseWithCardId); // 验证可以获取card_id字段 JsonElement jsonElement = JsonParser.parseString(result.getRawJsonString()); assertTrue(jsonElement.getAsJsonObject().has("card_id")); String cardId = jsonElement.getAsJsonObject().get("card_id").getAsString(); assertEquals(cardId, "pFS7Fjg9kqcMOBtl3bFn"); // 展示实际用法 String extractedCardId = extractCardId(result); assertEquals(extractedCardId, "pFS7Fjg9kqcMOBtl3bFn"); } /** * 提取card_id的示例方法 */ private String extractCardId(FavorStocksGetResult result) { return getStringFieldSafely(result, "card_id"); } /** * 安全地从结果中获取字符串字段的工具方法 */ private String getStringFieldSafely(BaseWxPayV3Result result, String fieldName) { String rawJson = result.getRawJsonString(); if (rawJson == null) return null; try { JsonElement jsonElement = JsonParser.parseString(rawJson); if (jsonElement.getAsJsonObject().has(fieldName)) { JsonElement fieldElement = jsonElement.getAsJsonObject().get(fieldName); return fieldElement.isJsonNull() ? null : fieldElement.getAsString(); } } catch (Exception e) { // 解析失败时返回null } return null; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequestTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequestTest.java
package com.github.binarywang.wxpay.bean.request; import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; /** * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-06-07 */ public class WxPayRefundRequestTest { @Test public void testToXML() { WxPayRefundRequest refundRequest = new WxPayRefundRequest(); refundRequest.setAppid("wx2421b1c4370ec43b"); refundRequest.setMchId("10000100"); refundRequest.setNonceStr("6cefdb308e1e2e8aabd48cf79e546a02"); refundRequest.setNotifyUrl("https://weixin.qq.com/"); refundRequest.setOutRefundNo("1415701182"); refundRequest.setOutTradeNo("1415757673"); refundRequest.setRefundFee(1); refundRequest.setTotalFee(1); refundRequest.setTransactionId(""); refundRequest.setDetail("{\"goods_detail\":[{\"goods_id\":\"商品编码\",\"wxpay_goods_id\":\"1001\",\"goods_name\":\"iPhone6s\n" + "16G\",\"refund_amount\":528800,\"refund_quantity\":1,\"price\":528800},{\"goods_id\":\"商品编码\",\"wxpay_goods_id\":\"1001\",\"goods_name\":\"iPhone6s\n" + "16G\",\"refund_amount\"\":528800,\"refund_quantity\":1,\"price\":608800}]}"); refundRequest.setSign("FE56DD4AA85C0EECA82C35595A69E153"); assertThat(refundRequest.toXML()) .isEqualTo("<xml>\n" + " <appid>wx2421b1c4370ec43b</appid>\n" + " <mch_id>10000100</mch_id>\n" + " <nonce_str>6cefdb308e1e2e8aabd48cf79e546a02</nonce_str>\n" + " <sign>FE56DD4AA85C0EECA82C35595A69E153</sign>\n" + " <transaction_id></transaction_id>\n" + " <out_trade_no>1415757673</out_trade_no>\n" + " <out_refund_no>1415701182</out_refund_no>\n" + " <total_fee>1</total_fee>\n" + " <refund_fee>1</refund_fee>\n" + " <notify_url>https://weixin.qq.com/</notify_url>\n" + " <detail><![CDATA[{\"goods_detail\":[{\"goods_id\":\"商品编码\",\"wxpay_goods_id\":\"1001\",\"goods_name\":\"iPhone6s\n" + "16G\",\"refund_amount\":528800,\"refund_quantity\":1,\"price\":528800},{\"goods_id\":\"商品编码\",\"wxpay_goods_id\":\"1001\",\"goods_name\":\"iPhone6s\n" + "16G\",\"refund_amount\"\":528800,\"refund_quantity\":1,\"price\":608800}]}]]></detail>\n" + "</xml>"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/CombineCloseRequestTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/CombineCloseRequestTest.java
package com.github.binarywang.wxpay.bean.request; import com.google.gson.Gson; import org.testng.annotations.Test; import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThat; /** * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2024-12-19 */ public class CombineCloseRequestTest { @Test public void testSerialization() { CombineCloseRequest request = new CombineCloseRequest(); request.setCombineAppid("wxd678efh567hg6787"); request.setCombineOutTradeNo("P20150806125346"); CombineCloseRequest.SubOrders subOrder = new CombineCloseRequest.SubOrders(); subOrder.setMchid("1900000109"); subOrder.setOutTradeNo("20150806125346"); subOrder.setSubMchid("1230000109"); subOrder.setSubAppid("wxd678efh567hg6999"); request.setSubOrders(Arrays.asList(subOrder)); Gson gson = new Gson(); String json = gson.toJson(request); // Verify that the JSON contains the new fields assertThat(json).contains("\"sub_mchid\":\"1230000109\""); assertThat(json).contains("\"sub_appid\":\"wxd678efh567hg6999\""); assertThat(json).contains("\"combine_appid\":\"wxd678efh567hg6787\""); assertThat(json).contains("\"mchid\":\"1900000109\""); assertThat(json).contains("\"out_trade_no\":\"20150806125346\""); // Verify deserialization works CombineCloseRequest deserializedRequest = gson.fromJson(json, CombineCloseRequest.class); assertThat(deserializedRequest.getCombineAppid()).isEqualTo("wxd678efh567hg6787"); assertThat(deserializedRequest.getSubOrders()).hasSize(1); assertThat(deserializedRequest.getSubOrders().get(0).getSubMchid()).isEqualTo("1230000109"); assertThat(deserializedRequest.getSubOrders().get(0).getSubAppid()).isEqualTo("wxd678efh567hg6999"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/applyment/WxPayApplyment4SubCreateRequestTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/applyment/WxPayApplyment4SubCreateRequestTest.java
package com.github.binarywang.wxpay.bean.applyment; import java.util.Arrays; import org.testng.annotations.Test; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; public class WxPayApplyment4SubCreateRequestTest { @Test public void testMicroBizInfoSerialization() { // 1. Test MicroStoreInfo WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroStoreInfo storeInfo = WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroStoreInfo.builder() .microName("门店名称") .microAddressCode("440305") .microAddress("详细地址") .storeEntrancePic("media_id_1") .microIndoorCopy("media_id_2") .storeLongitude("113.941046") .storeLatitude("22.546154") .build(); // 2. Test MicroMobileInfo WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroMobileInfo mobileInfo = WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroMobileInfo.builder() .microMobileName("流动经营名称") .microMobileCity("440305") .microMobileAddress("无") .microMobilePics(Arrays.asList("media_id_3", "media_id_4")) .build(); // 3. Test MicroOnlineInfo WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroOnlineInfo onlineInfo = WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroOnlineInfo.builder() .microOnlineStore("线上店铺名称") .microEcName("电商平台名称") .microQrcode("media_id_5") .microLink("https://www.example.com") .build(); WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo microBizInfo = WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.builder() .microStoreInfo(storeInfo) .microMobileInfo(mobileInfo) .microOnlineInfo(onlineInfo) .build(); Gson gson = new GsonBuilder().create(); String json = gson.toJson(microBizInfo); // Verify MicroStoreInfo serialization assertTrue(json.contains("\"micro_name\":\"门店名称\"")); assertTrue(json.contains("\"micro_address_code\":\"440305\"")); assertTrue(json.contains("\"micro_address\":\"详细地址\"")); assertTrue(json.contains("\"store_entrance_pic\":\"media_id_1\"")); assertTrue(json.contains("\"micro_indoor_copy\":\"media_id_2\"")); assertTrue(json.contains("\"store_longitude\":\"113.941046\"")); assertTrue(json.contains("\"store_latitude\":\"22.546154\"")); // Verify MicroMobileInfo serialization assertTrue(json.contains("\"micro_mobile_name\":\"流动经营名称\"")); assertTrue(json.contains("\"micro_mobile_city\":\"440305\"")); assertTrue(json.contains("\"micro_mobile_address\":\"无\"")); assertTrue(json.contains("\"micro_mobile_pics\":[\"media_id_3\",\"media_id_4\"]")); // Verify MicroOnlineInfo serialization assertTrue(json.contains("\"micro_online_store\":\"线上店铺名称\"")); assertTrue(json.contains("\"micro_ec_name\":\"电商平台名称\"")); assertTrue(json.contains("\"micro_qrcode\":\"media_id_5\"")); assertTrue(json.contains("\"micro_link\":\"https://www.example.com\"")); // Verify deserialization WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo deserialized = gson.fromJson(json, WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.class); // Verify MicroStoreInfo deserialization assertEquals(deserialized.getMicroStoreInfo().getMicroName(), "门店名称"); assertEquals(deserialized.getMicroStoreInfo().getMicroAddressCode(), "440305"); assertEquals(deserialized.getMicroStoreInfo().getMicroAddress(), "详细地址"); assertEquals(deserialized.getMicroStoreInfo().getStoreEntrancePic(), "media_id_1"); assertEquals(deserialized.getMicroStoreInfo().getMicroIndoorCopy(), "media_id_2"); assertEquals(deserialized.getMicroStoreInfo().getStoreLongitude(), "113.941046"); assertEquals(deserialized.getMicroStoreInfo().getStoreLatitude(), "22.546154"); // Verify MicroMobileInfo deserialization assertEquals(deserialized.getMicroMobileInfo().getMicroMobileName(), "流动经营名称"); assertEquals(deserialized.getMicroMobileInfo().getMicroMobileCity(), "440305"); assertEquals(deserialized.getMicroMobileInfo().getMicroMobileAddress(), "无"); assertEquals(deserialized.getMicroMobileInfo().getMicroMobilePics().size(), 2); assertEquals(deserialized.getMicroMobileInfo().getMicroMobilePics(), Arrays.asList("media_id_3", "media_id_4")); // Verify MicroOnlineInfo deserialization assertEquals(deserialized.getMicroOnlineInfo().getMicroOnlineStore(), "线上店铺名称"); assertEquals(deserialized.getMicroOnlineInfo().getMicroEcName(), "电商平台名称"); assertEquals(deserialized.getMicroOnlineInfo().getMicroQrcode(), "media_id_5"); assertEquals(deserialized.getMicroOnlineInfo().getMicroLink(), "https://www.example.com"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequestTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequestTest.java
package com.github.binarywang.wxpay.bean.entpay; import org.testng.annotations.Test; /** * . * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2019-08-18 */ public class EntPayRequestTest { @Test public void testToString() { System.out.println(EntPayRequest.newBuilder().mchId("123").build().toString()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingQueryResultTest.java
package com.github.binarywang.wxpay.bean.profitsharing; import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingQueryResult; import org.testng.annotations.Test; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; /** * 测试. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-03-22 */ @Test public class ProfitSharingQueryResultTest { @Test public void testFormatReceivers() { ProfitSharingQueryResult result = new ProfitSharingQueryResult(); result.setReceiversJson("[\n" + "{\n" + "\"type\": \"MERCHANT_ID\",\n" + "\"account\":\"190001001\",\n" + "\"amount\":100,\n" + "\"description\": \"分到商户\",\n" + "\"result\": \"SUCCESS\",\n" + "\"finish_time\": \"20180608170132\"\n" + "},\n" + "{\n" + "\"type\": \"PERSONAL_WECHATID\",\n" + "\"account\":\"86693952\",\n" + "\"amount\":888,\n" + "\"description\": \"分到个人\",\n" + "\"result\": \"SUCCESS\",\n" + "\"finish_time\": \"20180608170132\"\n" + "}\n" + "]"); List<ProfitSharingQueryResult.Receiver> receivers = result.formatReceivers(); assertThat(receivers).isNotEmpty(); assertThat(receivers.get(0)).isNotNull(); assertThat(receivers.get(0).getType()).isEqualTo("MERCHANT_ID"); assertThat(receivers.get(0).getAccount()).isEqualTo("190001001"); assertThat(receivers.get(0).getAmount()).isEqualTo(100); assertThat(receivers.get(0).getDescription()).isEqualTo("分到商户"); assertThat(receivers.get(0).getResult()).isEqualTo("SUCCESS"); assertThat(receivers.get(0).getFinishTime()).isEqualTo("20180608170132"); assertThat(receivers.get(1)).isNotNull(); assertThat(receivers.get(1).getType()).isEqualTo("PERSONAL_WECHATID"); assertThat(receivers.get(1).getAccount()).isEqualTo("86693952"); assertThat(receivers.get(1).getAmount()).isEqualTo(888); assertThat(receivers.get(1).getDescription()).isEqualTo("分到个人"); assertThat(receivers.get(1).getResult()).isEqualTo("SUCCESS"); assertThat(receivers.get(1).getFinishTime()).isEqualTo("20180608170132"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingV3ResultTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingV3ResultTest.java
package com.github.binarywang.wxpay.bean.profitsharing; import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingResult; import org.testng.annotations.Test; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; public class ProfitSharingV3ResultTest { @Test public void testGetReceiverList() { ProfitSharingResult profitSharingResult = ProfitSharingResult.fromXML("<xml>\n" + "\t<return_code>\n" + "\t\t<![CDATA[SUCCESS]]>\n" + "\t</return_code>\n" + "\t<result_code>\n" + "\t\t<![CDATA[SUCCESS]]>\n" + "\t</result_code>\n" + "\t<mch_id>\n" + "\t\t<![CDATA[aseedwq]]>\n" + "\t</mch_id>\n" + "\t<appid>\n" + "\t\t<![CDATA[qweqweq]]>\n" + "\t</appid>\n" + "\t<nonce_str>\n" + "\t\t<![CDATA[e2qedawws]]>\n" + "\t</nonce_str>\n" + "\t<sign>\n" + "\t\t<![CDATA[eqwdsqwsq\t]]>\n" + "\t</sign>\n" + "\t<transaction_id>\n" + "\t\t<![CDATA[eqwqwsq]]>\n" + "\t</transaction_id>\n" + "\t<out_order_no>\n" + "\t\t<![CDATA[wqdqwdw]]>\n" + "\t</out_order_no>\n" + "\t<order_id>\n" + "\t\t<![CDATA[dqdwedewee]]>\n" + "\t</order_id>\n" + "\t<receivers>\n" + "\t\t<![CDATA[[\n" + " {\n" + " \"account\": \"123423121\",\n" + " \"amount\": 7,\n" + " \"description\": \"解冻给分账方\",\n" + " \"detail_id\": \"360002qwq3006254484\",\n" + " \"finish_time\": \"\t360002qwq3006254484wq\",\n" + " \"result\": \"PENDING\",\n" + " \"type\": \"MERCHANT_ID\"\n" + " },\n" + " {\n" + " \"account\": \"wqwqeeqe\",\n" + " \"amount\": 3,\n" + " \"description\": \"qwwqw\",\n" + " \"detail_id\": \"3600020wqwqw06254482\",\n" + " \"finish_time\": \"q2wqewqwq\",\n" + " \"result\": \"PENDING\",\n" + " \"type\": \"MERCHANT_ID\"\n" + " }\n" + "]]]>\n" + "\t</receivers>\n" + "\t<status>\n" + "\t\t<![CDATA[PROCESSING]]>\n" + "\t</status>\n" + "</xml>", ProfitSharingResult.class); List<ProfitSharingResult.Receiver> receiverList = profitSharingResult.getReceiverList(); assertThat(receiverList).isNotEmpty(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/ApiTestModule.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/ApiTestModule.java
package com.github.binarywang.wxpay.testbase; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; /** * The type Api test module. */ public class ApiTestModule implements Module { private final Logger log = LoggerFactory.getLogger(this.getClass()); private static final String TEST_CONFIG_XML = "test-config.xml"; @Override public void configure(Binder binder) { try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { if (inputStream == null) { throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); } XmlWxPayConfig config = this.fromXml(XmlWxPayConfig.class, inputStream); config.setIfSaveApiData(true); WxPayService wxService = new WxPayServiceImpl(); wxService.setConfig(config); binder.bind(WxPayService.class).toInstance(wxService); binder.bind(WxPayConfig.class).toInstance(config); } catch (IOException e) { this.log.error(e.getMessage(), e); } } @SuppressWarnings("unchecked") private <T> T fromXml(Class<T> clazz, InputStream is) { XStream xstream = XStreamInitializer.getInstance(); xstream.alias("xml", clazz); xstream.processAnnotations(clazz); return (T) xstream.fromXML(is); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/CustomizedApiTestModule.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/CustomizedApiTestModule.java
package com.github.binarywang.wxpay.testbase; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; import java.io.*; import java.nio.charset.StandardCharsets; import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import org.apache.http.HttpRequestInterceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * The type Api test module. */ public class CustomizedApiTestModule implements Module { private final Logger log = LoggerFactory.getLogger(this.getClass()); private static final String TEST_CONFIG_XML = "test-config.xml"; @Override public void configure(Binder binder) { try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { if (inputStream == null) { throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); } XmlWxPayConfig config = this.fromXml(XmlWxPayConfig.class, inputStream); config.setIfSaveApiData(true); config.setApiV3HttpClientBuilderCustomizer((builder) -> { builder.addInterceptorLast((HttpRequestInterceptor) (r, c) -> System.out.println("--------> V3 HttpRequestInterceptor ...")); }); config.setHttpClientBuilderCustomizer((builder) -> { builder.addInterceptorLast((HttpRequestInterceptor) (r, c) -> System.out.println("--------> HttpRequestInterceptor ...")); }); try (FileInputStream fis = new FileInputStream(config.getPrivateKeyPath()); InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(isr)) { StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { stringBuilder.append(line); stringBuilder.append(System.lineSeparator()); } String fileContent = stringBuilder.toString(); config.setPrivateKeyString(fileContent); System.out.println(fileContent); } WxPayService wxService = new WxPayServiceImpl(); wxService.setConfig(config); binder.bind(WxPayService.class).toInstance(wxService); binder.bind(WxPayConfig.class).toInstance(config); } catch (IOException e) { this.log.error(e.getMessage(), e); } } @SuppressWarnings("unchecked") private <T> T fromXml(Class<T> clazz, InputStream is) { XStream xstream = XStreamInitializer.getInstance(); xstream.alias("xml", clazz); xstream.processAnnotations(clazz); return (T) xstream.fromXML(is); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/XmlWxPayConfig.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/XmlWxPayConfig.java
package com.github.binarywang.wxpay.testbase; import com.github.binarywang.wxpay.config.WxPayConfig; import com.thoughtworks.xstream.annotations.XStreamAlias; /** * The type Xml wx pay config. */ @XStreamAlias("xml") public class XmlWxPayConfig extends WxPayConfig { private String openid; /** * Gets openid. * * @return the openid */ public String getOpenid() { return openid; } /** * Sets openid. * * @param openid the openid */ public void setOpenid(String openid) { this.openid = openid; } @Override public boolean isUseSandboxEnv() { //沙箱环境不成熟,有问题无法使用,暂时屏蔽掉 //return true; return false; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/CustomizedWxPayConfigTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/CustomizedWxPayConfigTest.java
package com.github.binarywang.wxpay.config; import static org.testng.Assert.assertEquals; import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryV3Result; import com.github.binarywang.wxpay.constant.WxPayErrorCode; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.CustomizedApiTestModule; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * @author <a href="https://github.com/ifcute">dagewang</a> */ @Slf4j @Test @Guice(modules = CustomizedApiTestModule.class) public class CustomizedWxPayConfigTest { @Inject private WxPayService wxPayService; public void testCustomizerHttpClient() { try { wxPayService.queryOrder("a", null); } catch (WxPayException e) { // ignore e.printStackTrace(); } } public void testCustomizerV3HttpClient() { try { WxPayOrderQueryV3Result result = wxPayService.queryOrderV3("a", null); } catch (WxPayException e) { assertEquals(e.getErrCode(), WxPayErrorCode.RefundQuery.PARAM_ERROR); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/WxPayConfigTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/WxPayConfigTest.java
package com.github.binarywang.wxpay.config; import org.testng.annotations.Test; /** * <pre> * Created by BinaryWang on 2017/6/18. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public class WxPayConfigTest { private final WxPayConfig payConfig = new WxPayConfig(); @Test public void testInitSSLContext_classpath() throws Exception { payConfig.setMchId("123"); payConfig.setKeyPath("classpath:/dlt.p12"); payConfig.initSSLContext(); } @Test public void testInitSSLContext_http() throws Exception { payConfig.setMchId("123"); payConfig.setKeyPath("https://www.baidu.com"); payConfig.initSSLContext(); } @Test public void testInitSSLContext() throws Exception { this.testInitSSLContext_classpath(); this.testInitSSLContext_http(); } @Test @SuppressWarnings("ResultOfMethodCallIgnored") public void testHashCode() { payConfig.hashCode(); } @Test public void testInitSSLContext_base64() throws Exception { payConfig.setMchId("123"); payConfig.setKeyString("MIIKmgIBAzCCCmQGCS..."); payConfig.initSSLContext(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/WxPayConfigPrivateKeyTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/WxPayConfigPrivateKeyTest.java
package com.github.binarywang.wxpay.config; import com.github.binarywang.wxpay.exception.WxPayException; import org.testng.annotations.Test; import static org.testng.Assert.*; /** * Test cases for private key format handling in WxPayConfig */ public class WxPayConfigPrivateKeyTest { @Test public void testPrivateKeyStringFormat_PemFormat() { WxPayConfig config = new WxPayConfig(); // Set minimal required configuration config.setMchId("1234567890"); config.setApiV3Key("test-api-v3-key-32-characters-long"); config.setCertSerialNo("test-serial-number"); // Test with PEM format private key string that would previously fail String pemKey = "-----BEGIN PRIVATE KEY-----\n" + "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC2pK3buBufh8Vo\n" + "X4sfYbZ5CcPeGMnVQTGmj0b6\n" + "-----END PRIVATE KEY-----"; config.setPrivateKeyString(pemKey); // This should not throw a "无效的密钥格式" exception immediately // The actual key validation will happen during HTTP client initialization // but at least the format parsing should not fail try { // Try to initialize API V3 HTTP client - this might fail for other reasons // (like invalid key content) but should not fail due to format parsing config.initApiV3HttpClient(); // If we get here without InvalidKeySpecException, the format detection worked } catch (WxPayException e) { // Check that it's not the specific "无效的密钥格式" error from PemUtils if (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().contains("无效的密钥格式")) { fail("Private key format detection failed - PEM format was not handled correctly: " + e.getMessage()); } // Other exceptions are acceptable for this test since we're using a dummy key } catch (Exception e) { // Check for the specific InvalidKeySpecException that indicates format problems if (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().contains("无效的密钥格式")) { fail("Private key format detection failed - PEM format was not handled correctly: " + e.getMessage()); } // Other exceptions are acceptable for this test since we're using a dummy key } } @Test public void testPrivateKeyStringFormat_EmptyString() { WxPayConfig config = new WxPayConfig(); // Test with empty string - should not cause format errors config.setPrivateKeyString(""); // This should handle empty strings gracefully // No assertion needed, just ensuring no exceptions during object creation assertNotNull(config); } @Test public void testPrivateKeyStringFormat_NullString() { WxPayConfig config = new WxPayConfig(); // Test with null string - should not cause format errors config.setPrivateKeyString(null); // This should handle null strings gracefully assertNotNull(config); } @Test public void testPrivateCertStringFormat_PemFormat() { WxPayConfig config = new WxPayConfig(); // Set minimal required configuration config.setMchId("1234567890"); config.setApiV3Key("test-api-v3-key-32-characters-long"); // Test with PEM format certificate string that would previously fail String pemCert = "-----BEGIN CERTIFICATE-----\n" + "MIICdTCCAd4CAQAwDQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCQVUxEzARBgNV\n" + "BAsKClRlc3QgQ2VydCBEYXRhMRswGQYDVQQDDBJUZXN0IENlcnRpZmljYXRlQ0Ew\n" + "-----END CERTIFICATE-----"; config.setPrivateCertString(pemCert); // This should not throw a format parsing exception immediately // The actual certificate validation will happen during HTTP client initialization // but at least the format parsing should not fail try { // Try to initialize API V3 HTTP client - this might fail for other reasons // (like invalid cert content) but should not fail due to format parsing config.initApiV3HttpClient(); // If we get here without Base64 decoding issues, the format detection worked } catch (Exception e) { // Check that it's not the specific Base64 decoding error if (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().contains("Illegal base64 character")) { fail("Certificate format detection failed - PEM format was not handled correctly: " + e.getMessage()); } // Other exceptions are acceptable for this test since we're using a dummy cert } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/v3/auth/AutoUpdateCertificatesVerifierTest.java
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/v3/auth/AutoUpdateCertificatesVerifierTest.java
package com.github.binarywang.wxpay.v3.auth; import com.github.binarywang.wxpay.bean.merchanttransfer.TransferCreateRequest; import com.github.binarywang.wxpay.bean.merchanttransfer.TransferCreateRequest.TransferDetailList; import com.github.binarywang.wxpay.bean.merchanttransfer.TransferCreateResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.apache.http.util.Asserts; import org.assertj.core.util.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * 商家转账到零钱(直连商户)- 商户号配置信息错误时健壮性判断单元测试 * @author imyzt * created on 2022/10/23 */ @Slf4j @Test @Guice(modules = ApiTestModule.class) public class AutoUpdateCertificatesVerifierTest { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Inject private WxPayService payService; @Test public void testVerify() throws WxPayException { TransferDetailList transferDetailList = new TransferDetailList(); transferDetailList.setOutDetailNo("test") .setOpenid("test") .setTransferAmount(1) .setOutDetailNo("test") .setUserName("test"); TransferCreateRequest req = TransferCreateRequest.builder() .appid("wxd930ea5d5a258f4f") .batchName("test") .outBatchNo("") .totalAmount(1) .totalNum(1) .transferDetailList(Lists.newArrayList(transferDetailList)) .build(); TransferCreateResult transfer = payService.getMerchantTransferService().createTransfer(req); Asserts.notNull(transfer, "transfer"); // 商户未申请过证书。请到商户平台上申请证书授权机构颁发的证书。详情可参考:http://kf.qq.com/faq/180824JvUZ3i180824YvMNJj.html } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/RequestUtils.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/RequestUtils.java
package com.github.binarywang.wxpay.util; import javax.servlet.http.HttpServletRequest; import java.io.BufferedReader; import java.io.IOException; /** * <pre> * 请求工具类. * Created by Wang_Wong on 2023-04-14. * </pre> * * @author <a href="https://github.com/0katekate0/">Wang_Wong</a> */ public class RequestUtils { /** * 获取请求头数据,微信V3版本回调使用 * * @param request * @return 字符串 */ public static String readData(HttpServletRequest request) { BufferedReader br = null; StringBuilder result = new StringBuilder(); try { br = request.getReader(); for (String line; (line = br.readLine()) != null; ) { if (result.length() > 0) { result.append("\n"); } result.append(line); } } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } return result.toString(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/HttpProxyUtils.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/HttpProxyUtils.java
package com.github.binarywang.wxpay.util; import com.github.binarywang.wxpay.config.WxPayHttpProxy; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.HttpClientBuilder; /** * 微信支付 HTTP Proxy 工具类 * * @author Long Yu * created on 2021-12-28 15:58:03 */ public class HttpProxyUtils { /** * 配置 http 正向代理 可以实现内网服务通过代理调用接口 * 参考代码: WxPayServiceApacheHttpImpl 中的方法 createHttpClientBuilder * * @param wxPayHttpProxy 代理配置 * @param httpClientBuilder http构造参数 */ public static void initHttpProxy(HttpClientBuilder httpClientBuilder, WxPayHttpProxy wxPayHttpProxy) { if(wxPayHttpProxy == null){ return; } if (StringUtils.isNotBlank(wxPayHttpProxy.getHttpProxyHost()) && wxPayHttpProxy.getHttpProxyPort() > 0) { if (StringUtils.isEmpty(wxPayHttpProxy.getHttpProxyUsername())) { wxPayHttpProxy.setHttpProxyUsername("whatever"); } // 使用代理服务器 需要用户认证的代理服务器 CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(new AuthScope(wxPayHttpProxy.getHttpProxyHost(), wxPayHttpProxy.getHttpProxyPort()), new UsernamePasswordCredentials(wxPayHttpProxy.getHttpProxyUsername(), wxPayHttpProxy.getHttpProxyPassword())); httpClientBuilder.setDefaultCredentialsProvider(provider); httpClientBuilder.setProxy(new HttpHost(wxPayHttpProxy.getHttpProxyHost(), wxPayHttpProxy.getHttpProxyPort())); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/SignUtils.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/SignUtils.java
package com.github.binarywang.wxpay.util; import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.thoughtworks.xstream.annotations.XStreamAlias; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.*; /** * <pre> * 签名相关工具类. * Created by Binary Wang on 2017-3-23. * </pre> * * @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> */ @Slf4j public class SignUtils { /** * 签名的时候不携带的参数 */ private static final List<String> NO_SIGN_PARAMS = Lists.newArrayList("sign", "key", "xmlString", "xmlDoc", "couponList"); /** * 请参考并使用 {@link #createSign(Object, String, String, String[])}. * * @param xmlBean the xml bean * @param signKey the sign key * @return the string */ @Deprecated public static String createSign(Object xmlBean, String signKey) { return createSign(xmlBean2Map(xmlBean), signKey); } /** * 请参考并使用 {@link #createSign(Map, String, String, String[])} . * * @param params the params * @param signKey the sign key * @return the string */ @Deprecated public static String createSign(Map<String, String> params, String signKey) { return createSign(params, SignType.MD5, signKey, new String[0]); } /** * 微信支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3). * * @param xmlBean Bean里的属性如果存在XML注解,则使用其作为key,否则使用变量名 * @param signType 签名类型,如果为空,则默认为MD5 * @param signKey 签名Key * @param ignoredParams 签名时需要忽略的特殊参数 * @return 签名字符串 string */ public static String createSign(Object xmlBean, String signType, String signKey, String[] ignoredParams) { Map<String, String> map = null; if (XmlConfig.fastMode) { if (xmlBean instanceof BaseWxPayRequest) { map = ((BaseWxPayRequest) xmlBean).getSignParams(); } } if (map == null) { map = xmlBean2Map(xmlBean); } return createSign(map, signType, signKey, ignoredParams); } /** * 微信支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3). * * @param params 参数信息 * @param signType 签名类型,如果为空,则默认为MD5 * @param signKey 签名Key * @param ignoredParams 签名时需要忽略的特殊参数 * @return 签名字符串 string */ public static String createSign(Map<String, String> params, String signType, String signKey, String[] ignoredParams) { StringBuilder toSign = new StringBuilder(); for (String key : new TreeMap<>(params).keySet()) { String value = params.get(key); boolean shouldSign = false; if (StringUtils.isNotEmpty(value) && !ArrayUtils.contains(ignoredParams, key) && !NO_SIGN_PARAMS.contains(key)) { shouldSign = true; } if (shouldSign) { toSign.append(key).append("=").append(value).append("&"); } } toSign.append("key=").append(signKey); if (SignType.HMAC_SHA256.equals(signType)) { return me.chanjar.weixin.common.util.SignUtils.createHmacSha256Sign(toSign.toString(), signKey); } else { return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); } } /** * 企业微信签名 * * @param signType md5 目前接口要求使用的加密类型 */ public static String createEntSign(String actName, String mchBillNo, String mchId, String nonceStr, String reOpenid, Integer totalAmount, String wxAppId, String signKey, String signType) { Map<String, String> sortedMap = new HashMap<>(8); sortedMap.put("act_name", actName); sortedMap.put("mch_billno", mchBillNo); sortedMap.put("mch_id", mchId); sortedMap.put("nonce_str", nonceStr); sortedMap.put("re_openid", reOpenid); sortedMap.put("total_amount", totalAmount + ""); sortedMap.put("wxappid", wxAppId); return toSignBuilder(sortedMap, signKey, signType); } /** * 企业微信签名 * @param signType md5 目前接口要求使用的加密类型 */ public static String createEntSign(Integer totalAmount, String appId, String description, String mchId, String nonceStr, String openid, String partnerTradeNo, String wwMsgType, String signKey, String signType) { Map<String, String> sortedMap = new HashMap<>(8); sortedMap.put("amount", String.valueOf(totalAmount)); sortedMap.put("appid", appId); sortedMap.put("desc", description); sortedMap.put("mch_id", mchId); sortedMap.put("nonce_str", nonceStr); sortedMap.put("openid", openid); sortedMap.put("partner_trade_no", partnerTradeNo); sortedMap.put("ww_msg_type", wwMsgType); return toSignBuilder(sortedMap, signKey, signType); } private static String toSignBuilder(Map<String, String> sortedMap, String signKey, String signType) { Iterator<Map.Entry<String, String>> iterator = new TreeMap<>(sortedMap).entrySet().iterator(); StringBuilder toSign = new StringBuilder(); while (iterator.hasNext()) { Map.Entry<String, String> entry = iterator.next(); String value = entry.getValue(); boolean shouldSign = false; if (StringUtils.isNotEmpty(value)) { shouldSign = true; } if (shouldSign) { toSign.append(entry.getKey()).append("=").append(value).append("&"); } } //企业微信这里字段名不一样 toSign.append("secret=").append(signKey); if (SignType.HMAC_SHA256.equals(signType)) { return me.chanjar.weixin.common.util.SignUtils.createHmacSha256Sign(toSign.toString(), signKey); } else { return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); } } /** * 校验签名是否正确. * * @param xmlBean Bean需要标记有XML注解 * @param signType 签名类型,如果为空,则默认为MD5 * @param signKey 校验的签名Key * @return true - 签名校验成功,false - 签名校验失败 */ public static boolean checkSign(Object xmlBean, String signType, String signKey) { return checkSign(xmlBean2Map(xmlBean), signType, signKey); } /** * 校验签名是否正确. * * @param params 需要校验的参数Map * @param signType 签名类型,如果为空,则默认为MD5 * @param signKey 校验的签名Key * @return true - 签名校验成功,false - 签名校验失败 */ public static boolean checkSign(Map<String, String> params, String signType, String signKey) { String sign = createSign(params, signType, signKey, new String[0]); return sign.equals(params.get("sign")); } /** * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象. * * @param bean 包含@XStreamAlias的xml bean对象 * @return map对象 map */ public static Map<String, String> xmlBean2Map(Object bean) { Map<String, String> result = Maps.newHashMap(); List<Field> fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields())); fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); if (bean.getClass().getSuperclass().getSuperclass() == BaseWxPayRequest.class) { fields.addAll(Arrays.asList(BaseWxPayRequest.class.getDeclaredFields())); } if (bean.getClass().getSuperclass().getSuperclass() == BaseWxPayResult.class) { fields.addAll(Arrays.asList(BaseWxPayResult.class.getDeclaredFields())); } for (Field field : fields) { try { boolean isAccessible = field.isAccessible(); field.setAccessible(true); if (field.get(bean) == null) { field.setAccessible(isAccessible); continue; } if (field.isAnnotationPresent(XStreamAlias.class)) { result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString()); } else if (!Modifier.isStatic(field.getModifiers())) { //忽略掉静态成员变量 result.put(field.getName(), field.get(bean).toString()); } field.setAccessible(isAccessible); } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { log.error(e.getMessage(), e); } } return result; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/XmlConfig.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/XmlConfig.java
package com.github.binarywang.wxpay.util; public class XmlConfig { /** * 是否使用快速模式 * * 如果设置为true,将会影响下面的方法,不再使用反射的方法来进行xml转换。 * 1: BaseWxPayRequest的toXML方法 * 2: BaseWxPayResult的fromXML方法 * @see com.github.binarywang.wxpay.bean.request.BaseWxPayRequest#toXML * @see com.github.binarywang.wxpay.bean.result.BaseWxPayResult#fromXML * * 启用快速模式后,将能: * 1:性能提升约 10 ~ 15倍 * 2:可以通过 graalvm 生成native image,大大减少系统开销(CPU,RAM),加快应用启动速度(亚秒级),加快系统部署速度(脱离JRE). * * 参考测试案例: com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResultTest#benchmark * 参考网址: https://www.graalvm.org/ */ public static boolean fastMode = false; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/ResourcesUtils.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/ResourcesUtils.java
package com.github.binarywang.wxpay.util; import jodd.util.ClassUtil; import lombok.val; import java.io.IOException; import java.io.InputStream; import java.net.URL; /** * 基于jodd.util.ResourcesUtil改造实现 * * @author jodd */ public class ResourcesUtils { /** * Retrieves given resource as URL. Resource is always absolute and may * starts with a slash character. * <p> * Resource will be loaded using class loaders in the following order: * <ul> * <li>{@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()}</li> * <li>{@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()}</li> * <li>if <code>callingClass</code> is provided: {@link Class#getClassLoader() callingClass.getClassLoader()}</li> * </ul> */ public static URL getResourceUrl(String resourceName, final ClassLoader classLoader) { if (resourceName.startsWith("/")) { resourceName = resourceName.substring(1); } URL resourceUrl; // try #1 - using provided class loader if (classLoader != null) { resourceUrl = classLoader.getResource(resourceName); if (resourceUrl != null) { return resourceUrl; } } // try #2 - using thread class loader final ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader(); if ((currentThreadClassLoader != null) && (currentThreadClassLoader != classLoader)) { resourceUrl = currentThreadClassLoader.getResource(resourceName); if (resourceUrl != null) { return resourceUrl; } } // try #3 - using caller classloader, similar as Class.forName() val callerClass = ClassUtil.getCallerClass(2); val callerClassLoader = callerClass.getClassLoader(); if ((callerClassLoader != classLoader) && (callerClassLoader != currentThreadClassLoader)) { resourceUrl = callerClassLoader.getResource(resourceName); return resourceUrl; } return null; } /** * Opens a resource of the specified name for reading. * * @see #getResourceAsStream(String, ClassLoader) */ public static InputStream getResourceAsStream(final String resourceName) throws IOException { return getResourceAsStream(resourceName, null); } /** * Opens a resource of the specified name for reading. * * @see #getResourceUrl(String, ClassLoader) */ public static InputStream getResourceAsStream(final String resourceName, final ClassLoader callingClass) throws IOException { final URL url = getResourceUrl(resourceName, callingClass); if (url != null) { return url.openStream(); } return null; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/ZipUtils.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/ZipUtils.java
package com.github.binarywang.wxpay.util; import lombok.experimental.UtilityClass; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.GZIPInputStream; /** * @author Binary Wang */ @UtilityClass public class ZipUtils { /** * 解压gzip文件 */ public static File unGzip(final File file) throws IOException { File resultFile = new File(FilenameUtils.removeExtension(file.getAbsolutePath())); resultFile.createNewFile(); try (FileOutputStream fos = new FileOutputStream(resultFile); GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file))) { IOUtils.copy(gzis, fos); } return resultFile; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayErrorCode.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayErrorCode.java
package com.github.binarywang.wxpay.constant; /** * <pre> * 微信支付错误码 * Created by Binary Wang on 2018/11/18. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public class WxPayErrorCode { /** * 统一下单接口的错误码. * https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1 */ public static class UnifiedOrder { /** * <pre> * 描述:商户无此接口权限. * 原因:商户未开通此接口权限 * 解决方案:请商户前往申请此接口权限 * </pre> */ public static final String NOAUTH = "NOAUTH"; /** * <pre> * 描述:余额不足. * 原因:用户帐号余额不足 * 解决方案:用户帐号余额不足,请用户充值或更换支付卡后再支付 * </pre> */ public static final String NOTENOUGH = "NOTENOUGH"; /** * <pre> * 描述:商户订单已支付. * 原因:商户订单已支付,无需重复操作 * 解决方案:商户订单已支付,无需更多操作 * </pre> */ public static final String ORDERPAID = "ORDERPAID"; /** * <pre> * 描述:订单已关闭. * 原因:当前订单已关闭,无法支付 * 解决方案:当前订单已关闭,请重新下单 * </pre> */ public static final String ORDERCLOSED = "ORDERCLOSED"; /** * <pre> * 描述:系统错误. * 原因:系统超时 * 解决方案:系统异常,请用相同参数重新调用 * </pre> */ public static final String SYSTEMERROR = "SYSTEMERROR"; /** * <pre> * 描述:APPID不存在. * 原因:参数中缺少APPID * 解决方案:请检查APPID是否正确 * </pre> */ public static final String APPID_NOT_EXIST = "APPID_NOT_EXIST"; /** * <pre> * 描述:MCHID不存在. * 原因:参数中缺少MCHID * 解决方案:请检查MCHID是否正确 * </pre> */ public static final String MCHID_NOT_EXIST = "MCHID_NOT_EXIST"; /** * <pre> * 描述:appid和mch_id不匹配. * 原因:appid和mch_id不匹配 * 解决方案:请确认appid和mch_id是否匹配 * </pre> */ public static final String APPID_MCHID_NOT_MATCH = "APPID_MCHID_NOT_MATCH"; /** * <pre> * 描述:缺少参数. * 原因:缺少必要的请求参数 * 解决方案:请检查参数是否齐全 * </pre> */ public static final String LACK_PARAMS = "LACK_PARAMS"; /** * <pre> * 描述:商户订单号重复. * 原因:同一笔交易不能多次提交 * 解决方案:请核实商户订单号是否重复提交 * </pre> */ public static final String OUT_TRADE_NO_USED = "OUT_TRADE_NO_USED"; /** * <pre> * 描述:签名错误. * 原因:参数签名结果不正确 * 解决方案:请检查签名参数和方法是否都符合签名算法要求 * </pre> */ public static final String SIGNERROR = "SIGNERROR"; /** * <pre> * 描述:XML格式错误. * 原因:XML格式错误 * 解决方案:请检查XML参数格式是否正确 * </pre> */ public static final String XML_FORMAT_ERROR = "XML_FORMAT_ERROR"; /** * <pre> * 描述:请使用post方法. * 原因:未使用post传递参数 * 解决方案:请检查请求参数是否通过post方法提交 * </pre> */ public static final String REQUIRE_POST_METHOD = "REQUIRE_POST_METHOD"; /** * <pre> * 描述:post数据为空. * 原因:post数据不能为空 * 解决方案:请检查post数据是否为空 * </pre> */ public static final String POST_DATA_EMPTY = "POST_DATA_EMPTY"; /** * <pre> * 描述:编码格式错误. * 原因:未使用指定编码格式 * 解决方案:请使用UTF-8编码格式 * </pre> */ public static final String NOT_UTF8 = "NOT_UTF8"; } /** * 关闭订单. * https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_3&index=5 */ public static class OrderClose { /** * 订单已支付. */ public static final String ORDER_PAID = "ORDERPAID"; /** * 系统错误. */ public static final String SYSTEM_ERROR = "SYSTEMERROR"; /** * 订单不存在. */ public static final String ORDER_NOT_EXIST = "ORDERNOTEXIST"; /** * 订单已关闭. */ public static final String ORDER_CLOSED = "ORDERCLOSED"; /** * 签名错误. */ public static final String SIGN_ERROR = "SIGNERROR"; /** * 未使用POST传递参数. */ public static final String REQUIRE_POST_METHOD = "REQUIRE_POST_METHOD"; /** * XML格式错误. */ public static final String XML_FORMAT_ERROR = "XML_FORMAT_ERROR"; /** * 订单状态错误. */ public static final String TRADE_STATE_ERROR = "TRADE_STATE_ERROR"; } /** * 退款申请. * https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6 */ public static class Refund { /** * <pre> * 描述:接口返回错误. * 原因:系统超时等 * 解决方案:请不要更换商户退款单号,请使用相同参数再次调用API。 * </pre> */ public static final String SYSTEMERROR = "SYSTEMERROR"; /** * <pre> * 描述:退款业务流程错误,需要商户触发重试来解决. * 原因:并发情况下,业务被拒绝,商户重试即可解决 * 解决方案:请不要更换商户退款单号,请使用相同参数再次调用API。 * </pre> */ public static final String BIZERR_NEED_RETRY = "BIZERR_NEED_RETRY"; /** * <pre> * 描述:订单已经超过退款期限. * 原因:订单已经超过可退款的最大期限(支付后一年内可退款) * 解决方案:请选择其他方式自行退款 * </pre> */ public static final String TRADE_OVERDUE = "TRADE_OVERDUE"; /** * <pre> * 描述:业务错误. * 原因:申请退款业务发生错误 * 解决方案:该错误都会返回具体的错误原因,请根据实际返回做相应处理。 * </pre> */ public static final String ERROR = "ERROR"; /** * <pre> * 描述:退款请求失败. * 原因:用户帐号注销 * 解决方案:此状态代表退款申请失败,商户可自行处理退款。 * </pre> */ public static final String USER_ACCOUNT_ABNORMAL = "USER_ACCOUNT_ABNORMAL"; /** * <pre> * 描述:无效请求过多. * 原因:连续错误请求数过多被系统短暂屏蔽 * 解决方案:请检查业务是否正常,确认业务正常后请在1分钟后再来重试 * </pre> */ public static final String INVALID_REQ_TOO_MUCH = "INVALID_REQ_TOO_MUCH"; /** * <pre> * 描述:余额不足. * 原因:商户可用退款余额不足 * 解决方案:此状态代表退款申请失败,商户可根据具体的错误提示做相应的处理。 * </pre> */ public static final String NOTENOUGH = "NOTENOUGH"; /** * <pre> * 描述:无效transaction_id. * 原因:请求参数未按指引进行填写 * 解决方案:请求参数错误,检查原交易号是否存在或发起支付交易接口返回失败 * </pre> */ public static final String INVALID_TRANSACTIONID = "INVALID_TRANSACTIONID"; /** * <pre> * 描述:参数错误. * 原因:请求参数未按指引进行填写 * 解决方案:请求参数错误,请重新检查再调用退款申请 * </pre> */ public static final String PARAM_ERROR = "PARAM_ERROR"; /** * <pre> * 描述:APPID不存在. * 原因:参数中缺少APPID * 解决方案:请检查APPID是否正确 * </pre> */ public static final String APPID_NOT_EXIST = "APPID_NOT_EXIST"; /** * <pre> * 描述:MCHID不存在. * 原因:参数中缺少MCHID * 解决方案:请检查MCHID是否正确 * </pre> */ public static final String MCHID_NOT_EXIST = "MCHID_NOT_EXIST"; /** * <pre> * 描述:订单号不存在. * 原因:缺少有效的订单号 * 解决方案:请检查你的订单号是否正确且是否已支付,未支付的订单不能发起退款 * </pre> */ public static final String ORDERNOTEXIST = "ORDERNOTEXIST"; /** * <pre> * 描述:请使用post方法. * 原因:未使用post传递参数 * 解决方案:请检查请求参数是否通过post方法提交 * </pre> */ public static final String REQUIRE_POST_METHOD = "REQUIRE_POST_METHOD"; /** * <pre> * 描述:签名错误. * 原因:参数签名结果不正确 * 解决方案:请检查签名参数和方法是否都符合签名算法要求 * </pre> */ public static final String SIGNERROR = "SIGNERROR"; /** * <pre> * 描述:XML格式错误. * 原因:XML格式错误 * 解决方案:请检查XML参数格式是否正确 * </pre> */ public static final String XML_FORMAT_ERROR = "XML_FORMAT_ERROR"; /** * <pre> * 描述:频率限制. * 原因:2个月之前的订单申请退款有频率限制 * 解决方案:该笔退款未受理,请降低频率后重试 * </pre> */ public static final String FREQUENCY_LIMITED = "FREQUENCY_LIMITED"; } /** * 退款查询. * https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=7 */ public static class RefundQuery { /** * <pre> * 描述:接口返回错误. * 原因:系统超时 * 解决方案:请尝试再次掉调用API。 * </pre> */ public static final String SYSTEMERROR = "SYSTEMERROR"; /** * <pre> * 描述:退款订单查询失败. * 原因:订单号错误或订单状态不正确 * 解决方案:请检查订单号是否有误以及订单状态是否正确,如:未支付、已支付未退款 * </pre> */ public static final String REFUNDNOTEXIST = "REFUNDNOTEXIST"; /** * <pre> * 描述:无效transaction_id. * 原因:请求参数未按指引进行填写 * 解决方案:请求参数错误,检查原交易号是否存在或发起支付交易接口返回失败 * </pre> */ public static final String INVALID_TRANSACTIONID = "INVALID_TRANSACTIONID"; /** * <pre> * 描述:参数错误. * 原因:请求参数未按指引进行填写 * 解决方案:请求参数错误,请检查参数再调用退款申请 * </pre> */ public static final String PARAM_ERROR = "PARAM_ERROR"; /** * <pre> * 描述:APPID不存在. * 原因:参数中缺少APPID * 解决方案:请检查APPID是否正确 * </pre> */ public static final String APPID_NOT_EXIST = "APPID_NOT_EXIST"; /** * <pre> * 描述:MCHID不存在. * 原因:参数中缺少MCHID * 解决方案:请检查MCHID是否正确 * </pre> */ public static final String MCHID_NOT_EXIST = "MCHID_NOT_EXIST"; /** * <pre> * 描述:请使用post方法. * 原因:未使用post传递参数 * 解决方案:请检查请求参数是否通过post方法提交 * </pre> */ public static final String REQUIRE_POST_METHOD = "REQUIRE_POST_METHOD"; /** * <pre> * 描述:签名错误. * 原因:参数签名结果不正确 * 解决方案:请检查签名参数和方法是否都符合签名算法要求 * </pre> */ public static final String SIGNERROR = "SIGNERROR"; /** * <pre> * 描述:XML格式错误. * 原因:XML格式错误 * 解决方案:请检查XML参数格式是否正确 * </pre> */ public static final String XML_FORMAT_ERROR = "XML_FORMAT_ERROR"; } /** * 下载对账单. * https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=8 */ public static class DownloadBill { /** * <pre> * 描述:下载失败. * 原因:系统超时 * 解决方案:请尝试再次查询。 * </pre> */ public static final String SYSTEMERROR = "SYSTEMERROR"; /** * <pre> * 描述:参数错误. * 原因:请求参数未按指引进行填写 * 解决方案:参数错误,请重新检查 * </pre> */ public static final String INVALID_BILL_TYPE = "invalid bill_type"; /** * <pre> * 描述:参数错误. * 原因:请求参数未按指引进行填写 * 解决方案:参数错误,请重新检查 * </pre> */ public static final String DATA_FORMAT_ERROR = "data format error"; /** * <pre> * 描述:参数错误. * 原因:请求参数未按指引进行填写 * 解决方案:参数错误,请重新检查 * </pre> */ public static final String MISSING_PARAMETER = "missing parameter"; /** * <pre> * 描述:参数错误. * 原因:请求参数未按指引进行填写 * 解决方案:参数错误,请重新检查 * </pre> */ public static final String SIGN_ERROR = "SIGN ERROR"; /** * <pre> * 描述:账单不存在. * 原因:当前商户号没有已成交的订单,不生成对账单 * 解决方案:请检查当前商户号在指定日期内是否有成功的交易。 * 错误:微信官方文档这个错误的字符串显示是'NO Bill Exist'('o'是大写),实际返回是'No Bill Exist'('o'是小写) * </pre> */ public static final String NO_Bill_Exist = "No Bill Exist"; /** * <pre> * 描述:账单未生成. * 原因:当前商户号没有已成交的订单或对账单尚未生成 * 解决方案:请先检查当前商户号在指定日期内是否有成功的交易,如指定日期有交易则表示账单正在生成中,请在上午10点以后再下载。 * </pre> */ public static final String BILL_CREATING = "Bill Creating"; /** * <pre> * 描述:账单压缩失败. * 原因:账单压缩失败,请稍后重试 * 解决方案:账单压缩失败,请稍后重试 * </pre> */ public static final String COMPRESSG_ZIP_ERROR = "CompressGZip Error"; /** * <pre> * 描述:账单解压失败. * 原因:账单解压失败,请稍后重试 * 解决方案:账单解压失败,请稍后重试 * </pre> */ public static final String UN_COMPRESSG_ZIP_ERROR = "UnCompressGZip Error"; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayConstants.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayConstants.java
package com.github.binarywang.wxpay.constant; import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult; import com.google.common.collect.Lists; import lombok.experimental.UtilityClass; import org.apache.commons.lang3.time.FastDateFormat; import java.text.Format; import java.util.List; /** * <pre> * 微信支付常量类 * Created by Binary Wang on 2017-8-24. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public class WxPayConstants { /** * 拉取订单评价数据接口的参数中日期格式. */ public static final Format QUERY_COMMENT_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss"); /** * 币种类型. */ public static class CurrencyType { /** * 人民币. */ public static final String CNY = "CNY"; } /** * 校验用户姓名选项,企业付款时使用. */ public static class CheckNameOption { /** * 不校验真实姓名. */ public static final String NO_CHECK = "NO_CHECK"; /** * 强校验真实姓名. */ public static final String FORCE_CHECK = "FORCE_CHECK"; } /** * 压缩账单的类型. */ public static class TarType { /** * 固定值:GZIP,返回格式为.gzip的压缩包账单. */ public static final String GZIP = "GZIP"; } /** * 账单类型. */ public static class BillType { /** * 查询红包时使用:通过商户订单号获取红包信息. */ public static final String MCHT = "MCHT"; //以下为下载对账单时的账单类型 /** * 返回当日所有订单信息,默认值. */ public static final String ALL = "ALL"; /** * 返回当日成功支付的订单. */ public static final String SUCCESS = "SUCCESS"; /** * 返回当日退款订单. */ public static final String REFUND = "REFUND"; /** * 返回当日充值退款订单(相比其他对账单多一栏“返还手续费”). */ public static final String RECHARGE_REFUND = "RECHARGE_REFUND"; } /** * 交易类型. */ public static class TradeType { /** * 原生扫码支付. */ public static final String NATIVE = "NATIVE"; /** * App支付. */ public static final String APP = "APP"; /** * 公众号支付/小程序支付. */ public static final String JSAPI = "JSAPI"; /** * H5支付. */ public static final String MWEB = "MWEB"; /** * 刷卡支付. * 刷卡支付有单独的支付接口,不调用统一下单接口 */ public static final String MICROPAY = "MICROPAY"; @SuppressWarnings("unused") public abstract static class Specific<R> { public abstract String getType(); private Specific() { } public static Specific<WxPayNativeOrderResult> NATIVE = new Specific<WxPayNativeOrderResult>() { @Override public String getType() { return TradeType.NATIVE; } }; public static Specific<WxPayAppOrderResult> APP = new Specific<WxPayAppOrderResult>() { @Override public String getType() { return TradeType.APP; } }; public static Specific<WxPayMpOrderResult> JSAPI = new Specific<WxPayMpOrderResult>() { @Override public String getType() { return TradeType.JSAPI; } }; public static Specific<WxPayMwebOrderResult> MWEB = new Specific<WxPayMwebOrderResult>() { @Override public String getType() { return TradeType.MWEB; } }; public static Specific<WxPayMicropayResult> MICROPAY = new Specific<WxPayMicropayResult>() { @Override public String getType() { return TradeType.MICROPAY; } }; } } /** * 签名类型. */ public static class SignType { /** * The constant HMAC_SHA256. */ public static final String HMAC_SHA256 = "HMAC-SHA256"; /** * The constant MD5. */ public static final String MD5 = "MD5"; /** * The constant ALL_SIGN_TYPES. */ public static final List<String> ALL_SIGN_TYPES = Lists.newArrayList(HMAC_SHA256, MD5); } /** * 限定支付方式. */ public static class LimitPay { /** * no_credit--指定不能使用信用卡支付. */ public static final String NO_CREDIT = "no_credit"; } /** * 业务结果代码. */ public static class ResultCode { /** * 成功. */ public static final String SUCCESS = "SUCCESS"; /** * 失败. */ public static final String FAIL = "FAIL"; } /** * 退款资金来源. */ public static class RefundAccountSource { /** * 可用余额退款/基本账户. */ public static final String RECHARGE_FUNDS = "REFUND_SOURCE_RECHARGE_FUNDS"; /** * 未结算资金退款. */ public static final String UNSETTLED_FUNDS = "REFUND_SOURCE_UNSETTLED_FUNDS"; } /** * 退款渠道. */ public static class RefundChannel { /** * 原路退款. */ public static final String ORIGINAL = "ORIGINAL"; /** * 退回到余额. */ public static final String BALANCE = "BALANCE"; /** * 原账户异常退到其他余额账户. */ public static final String OTHER_BALANCE = "OTHER_BALANCE"; /** * 原银行卡异常退到其他银行卡. */ public static final String OTHER_BANKCARD = "OTHER_BANKCARD"; } /** * 交易状态. */ public static class WxpayTradeStatus { /** * 支付成功. */ public static final String SUCCESS = "SUCCESS"; /** * 支付失败(其他原因,如银行返回失败). */ public static final String PAY_ERROR = "PAYERROR"; /** * 用户支付中. */ public static final String USER_PAYING = "USERPAYING"; /** * 已关闭. */ public static final String CLOSED = "CLOSED"; /** * 未支付. */ public static final String NOTPAY = "NOTPAY"; /** * 转入退款. */ public static final String REFUND = "REFUND"; /** * 已撤销(刷卡支付). */ public static final String REVOKED = "REVOKED"; } /** * 退款状态. */ public static class RefundStatus { /** * 退款成功. */ public static final String SUCCESS = "SUCCESS"; /** * v2 * 退款关闭. */ public static final String REFUND_CLOSE = "REFUNDCLOSE"; /** * 退款处理中. */ public static final String PROCESSING = "PROCESSING"; /** * v2 * 退款异常. * 退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台(pay.weixin.qq.com)-交易中心,手动处理此笔退款。 */ public static final String CHANGE = "CHANGE"; /** * v3 * 退款关闭 */ public static final String CLOSED = "CLOSED"; /** * v3 * 退款异常 */ public static final String ABNORMAL = "ABNORMAL"; } public static class ReceiverType { /** * 商户id */ public static final String MERCHANT_ID = "MERCHANT_ID"; /** * 个人微信号 */ public static final String PERSONAL_WECHATID = "PERSONAL_WECHATID"; /** * 个人openid */ public static final String PERSONAL_OPENID = "PERSONAL_OPENID"; /** * 个人sub_openid */ public static final String PERSONAL_SUB_OPENID = "PERSONAL_SUB_OPENID"; } /** * 微信商户转账订单状态 */ @UtilityClass public static class TransformBillState { /** * 转账已受理 */ public static final String ACCEPTED = "ACCEPTED"; /** * 转账处理中,转账结果尚未明确,如一直处于此状态,建议检查账户余额是否足够 */ public static final String PROCESSING = "PROCESSING"; /** * 待收款用户确认,可拉起微信收款确认页面进行收款确认 */ public static final String WAIT_USER_CONFIRM = "WAIT_USER_CONFIRM"; /** * 转账结果尚未明确,可拉起微信收款确认页面再次重试确认收款 */ public static final String TRANSFERING = "TRANSFERING"; /** * 转账成功 */ public static final String SUCCESS = "SUCCESS"; /** * 转账失败 */ public static final String FAIL = "FAIL"; /** * 商户撤销请求受理成功,该笔转账正在撤销中 */ public static final String CANCELING = "CANCELING"; /** * 转账撤销完成 */ public static final String CANCELLED = "CANCELLED"; } /** * 用户授权状态 * * @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">商户查询用户授权信息</a> */ @UtilityClass public static class AuthorizationState { /** * 未授权 */ public static final String UNAUTHORIZED = "UNAUTHORIZED"; /** * 已授权 */ public static final String AUTHORIZED = "AUTHORIZED"; } /** * 预约转账批次状态 * * @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">批量预约商家转账</a> */ @UtilityClass public static class ReservationBatchState { /** * 批次已受理 */ public static final String ACCEPTED = "ACCEPTED"; /** * 批次处理中 */ public static final String PROCESSING = "PROCESSING"; /** * 批次处理完成 */ public static final String FINISHED = "FINISHED"; /** * 批次已关闭 */ public static final String CLOSED = "CLOSED"; } /** * 预约转账批次关闭原因 * * @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">预约转账批次单号查询</a> */ @UtilityClass public static class ReservationBatchCloseReason { /** * 商户主动撤销 */ public static final String MERCHANT_REVOCATION = "MERCHANT_REVOCATION"; /** * 系统超时关闭 */ public static final String OVERDUE_CLOSE = "OVERDUE_CLOSE"; } /** * 【转账场景ID】 该笔转账使用的转账场景,可前往“商户平台-产品中心-商家转账”中申请。 */ @UtilityClass public static class TransformSceneId { /** * 现金营销 */ public static final String CASH_MARKETING = "1001"; } /** * 【运营工具转账场景ID】 运营工具专用转账场景,用于商户日常运营活动 * * @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012711988">运营工具-商家转账API</a> */ @UtilityClass public static class OperationSceneId { /** * 运营工具现金营销 */ public static final String OPERATION_CASH_MARKETING = "2001"; /** * 运营工具佣金报酬 */ public static final String OPERATION_COMMISSION = "2002"; /** * 运营工具推广奖励 */ public static final String OPERATION_PROMOTION = "2003"; } /** * 用户收款感知 * * @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012711988#3.3-%E5%8F%91%E8%B5%B7%E8%BD%AC%E8%B4%A6">官方文档</a> */ @UtilityClass public static class UserRecvPerception { /** * 转账场景 现金营销 * 场景介绍 向参与营销活动的用户发放现金奖励 */ public static class CASH_MARKETING { /** * 默认展示 */ public static final String ACTIVITY = "活动奖励"; /** * 需在发起转账时,“用户收款感知”字段主动传入“现金奖励”才可展示 */ public static final String CASH = "现金奖励"; } } /** * 收款授权模式 * * @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4014399293">官方文档</a> */ @UtilityClass public static class ReceiptAuthorizationMode { /** * 需确认收款授权模式(默认值) * 用户需要手动确认才能收款 */ public static final String CONFIRM_RECEIPT_AUTHORIZATION = "CONFIRM_RECEIPT_AUTHORIZATION"; /** * 免确认收款授权模式 * 用户授权后,收款不需要确认,转账直接到账 */ public static final String NO_CONFIRM_RECEIPT_AUTHORIZATION = "NO_CONFIRM_RECEIPT_AUTHORIZATION"; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.ecommerce.*; import com.github.binarywang.wxpay.bean.ecommerce.enums.FundBillTypeEnum; import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum; import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum; import com.github.binarywang.wxpay.exception.WxPayException; import java.io.File; import java.io.IOException; import java.io.InputStream; /** * <pre> * 电商收付通相关服务类. * 接口规则:https://wechatpay-api.gitbook.io/wechatpay-api-v3 * </pre> * * @author cloudX * created on 2020 /08/17 */ public interface EcommerceService { /** * <pre> * 二级商户进件API * 接口地址: https://api.mch.weixin.qq.com/v3/ecommerce/applyments/ * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_1_8.shtml * * </pre> * * @param request 请求对象 * @return . applyments result * @throws WxPayException the wx pay exception */ ApplymentsResult createApply(ApplymentsRequest request) throws WxPayException; /** * <pre> * 查询申请状态API * 请求URL: https://api.mch.weixin.qq.com/v3/ecommerce/applyments/{applyment_id} * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_2.shtml * </pre> * * @param applymentId 申请单ID * @return . applyments status result * @throws WxPayException the wx pay exception */ ApplymentsStatusResult queryApplyStatusByApplymentId(String applymentId) throws WxPayException; /** * <pre> * 查询申请状态API * 请求URL: https://api.mch.weixin.qq.com/v3/ecommerce/applyments/out-request-no/{out_request_no} * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_2.shtml * </pre> * * @param outRequestNo 业务申请编号 * @return . applyments status result * @throws WxPayException the wx pay exception */ ApplymentsStatusResult queryApplyStatusByOutRequestNo(String outRequestNo) throws WxPayException; /** * <pre> * 合单支付API(APP支付、JSAPI支付、H5支付、NATIVE支付). * 请求URL:https://api.mch.weixin.qq.com/v3/combine-transactions/jsapi * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml * </pre> * * @param tradeType 支付方式 * @param request 请求对象 * @return 微信合单支付返回 transactions result * @throws WxPayException the wx pay exception */ TransactionsResult combine(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException; /** * <pre> * 合单支付API(APP支付、JSAPI支付、H5支付、NATIVE支付). * 请求URL:https://api.mch.weixin.qq.com/v3/combine-transactions/jsapi * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml * </pre> * * @param <T> the type parameter * @param tradeType 支付方式 * @param request 请求对象 * @return 调起支付需要的参数 t * @throws WxPayException the wx pay exception */ <T> T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException; /** * <pre> * 合单支付通知回调数据处理 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml * </pre> * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * @return 解密后通知数据 combine transactions notify result * @throws WxPayException the wx pay exception */ CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * 合单查询订单API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/combine/chapter3_3.shtml * </pre> * * @param outTradeNo 合单商户订单号 * @return 支付订单信息 * @throws WxPayException the wx pay exception */ CombineTransactionsResult queryCombineTransactions(String outTradeNo) throws WxPayException; /** * <pre> * 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付). * 请求URL:https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/transactions_sl.shtml * </pre> * * @param tradeType 支付方式 * @param request 请求对象 * @return 调起支付需要的参数 transactions result * @throws WxPayException the wx pay exception */ TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException; /** * <pre> * 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付). * 请求URL:https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/transactions_sl.shtml * </pre> * * @param <T> the type parameter * @param tradeType 支付方式 * @param request 请求对象 * @return 调起支付需要的参数 t * @throws WxPayException the wx pay exception */ <T> T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException; /** * <pre> * 普通支付通知回调数据处理 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e_transactions.shtml * </pre> * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * @return 解密后通知数据 partner transactions notify result * @throws WxPayException the wx pay exception */ PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * 普通查询订单API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/e_transactions/chapter3_5.shtml * </pre> * * @param request 商户订单信息 * @return 支付订单信息 * @throws WxPayException the wx pay exception */ PartnerTransactionsResult queryPartnerTransactions(PartnerTransactionsQueryRequest request) throws WxPayException; /** * <pre> * 关闭普通订单API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/e_transactions/chapter3_6.shtml * </pre> * * @param request 关闭普通订单请求 * @throws WxPayException the wx pay exception * @return */ String closePartnerTransactions(PartnerTransactionsCloseRequest request) throws WxPayException; /** * <pre> * 服务商账户实时余额 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml * </pre> * * @param accountType 服务商账户类型 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException; /** * <pre> * 服务商账户日终余额 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml * </pre> * * @param accountType 服务商账户类型 * @param date 查询日期 2020-09-11 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) throws WxPayException; /** * <pre> * 二级商户号账户实时余额 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml * </pre> * * @param subMchid 二级商户号 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ FundBalanceResult subNowBalance(String subMchid) throws WxPayException; /** * <pre> * 二级商户号账户实时余额 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter4_3_11.shtml * </pre> * * @param subMchid 二级商户号 * @param accountType 账户类型 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ FundBalanceResult subNowBalance(String subMchid, SpAccountTypeEnum accountType) throws WxPayException; /** * <pre> * 二级商户号账户日终余额 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml * </pre> * * @param subMchid 二级商户号 * @param date 查询日期 2020-09-11 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException; /** * <pre> * 请求分账API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_1.shtml * </pre> * * @param request 分账请求 * @return 返回数据 profit sharing result * @throws WxPayException the wx pay exception */ ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException; /** * <pre> * 查询分账结果API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_2.shtml * </pre> * * @param request 查询分账请求 * @return 返回数据 profit sharing result * @throws WxPayException the wx pay exception */ ProfitSharingResult queryProfitSharing(ProfitSharingQueryRequest request) throws WxPayException; /** * <pre> * 查询订单剩余待分金额API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_9.shtml * </pre> * * @param request 查询订单剩余待分金额请求 * @return 返回数据 profit sharing UnSplitAmount result * @throws WxPayException the wx pay exception */ ProfitSharingOrdersUnSplitAmountResult queryProfitSharingOrdersUnsplitAmount(ProfitSharingOrdersUnSplitAmountRequest request) throws WxPayException; /** * <pre> * 添加分账接收方API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_7.shtml * </pre> * * @param request 添加分账接收方 * @return 返回数据 profit sharing result * @throws WxPayException the wx pay exception */ ProfitSharingReceiverResult addReceivers(ProfitSharingReceiverRequest request) throws WxPayException; /** * <pre> * 删除分账接收方API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_8.shtml * </pre> * * @param request 删除分账接收方 * @return 返回数据 profit sharing result * @throws WxPayException the wx pay exception */ ProfitSharingReceiverResult deleteReceivers(ProfitSharingReceiverRequest request) throws WxPayException; /** * <pre> * 请求分账回退API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_3.shtml * </pre> * * @param request 分账回退请求 * @return 返回数据 return orders result * @throws WxPayException the wx pay exception */ ReturnOrdersResult returnOrders(ReturnOrdersRequest request) throws WxPayException; /** * <pre> * 查询分账回退API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_3.shtml * </pre> * * @param request 查询分账回退请求 * @return 返回数据 return orders result * @throws WxPayException the wx pay exception */ ReturnOrdersResult queryReturnOrders(ReturnOrdersQueryRequest request) throws WxPayException; /** * <pre> * 完结分账API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_5.shtml * </pre> * * @param request 完结分账请求 * @return 返回数据 return orders result * @throws WxPayException the wx pay exception */ ProfitSharingResult finishOrder(FinishOrderRequest request) throws WxPayException; /** * <pre> * 退款申请API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_1.shtml * </pre> * * @param request 退款请求 * @return 返回数据 return refunds result * @throws WxPayException the wx pay exception */ RefundsResult refunds(RefundsRequest request) throws WxPayException; /** * <pre> * 查询退款API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_2.shtml * </pre> * * @param subMchid 二级商户号 * @param refundId 微信退款单号 * @return 返回数据 return refunds result * @throws WxPayException the wx pay exception */ RefundQueryResult queryRefundByRefundId(String subMchid, String refundId) throws WxPayException; /** * <pre> * 垫付退款回补API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_4.shtml * </pre> * * @param subMchid 二级商户号 * @param refundId 微信退款单号 * @return 返回数据 return refunds result * @throws WxPayException the wx pay exception */ ReturnAdvanceResult refundsReturnAdvance(String subMchid, String refundId) throws WxPayException; /** * <pre> * 查询垫付回补结果API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_5.shtml * </pre> * * @param subMchid 二级商户号 * @param refundId 微信退款单号 * @return 返回数据 return refunds result * @throws WxPayException the wx pay exception */ ReturnAdvanceResult queryRefundsReturnAdvance(String subMchid, String refundId) throws WxPayException; /** * <pre> * 查询退款API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_2.shtml * </pre> * * @param subMchid 二级商户号 * @param outRefundNo 商户退款单号 * @return 返回数据 return refunds result * @throws WxPayException the wx pay exception */ RefundQueryResult queryRefundByOutRefundNo(String subMchid, String outRefundNo) throws WxPayException; /** * <pre> * 退款通知回调数据处理 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_3.shtml * </pre> * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * @return 解密后通知数据 partner refund notify result * @throws WxPayException the wx pay exception */ RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * 提现状态变更通知回调数据处理 * 文档地址: https://pay.weixin.qq.com/doc/v3/partner/4013049135 * </pre> * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * @return 解密后通知数据 withdraw notify result * @throws WxPayException the wx pay exception */ WithdrawNotifyResult parseWithdrawNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * 二级商户账户余额提现API * 文档地址: https://pay.weixin.qq.com/doc/v3/partner/4012476652 * </pre> * * @param request 提现请求 * @return 返回数据 return withdraw result * @throws WxPayException the wx pay exception */ SubWithdrawResult subWithdraw(SubWithdrawRequest request) throws WxPayException; /** * <pre> * 电商平台提现API * 文档地址: https://pay.weixin.qq.com/doc/v3/partner/4012476670 * </pre> * * @param request 提现请求 * @return 返回数据 return withdraw result * @throws WxPayException the wx pay exception */ SpWithdrawResult spWithdraw(SpWithdrawRequest request) throws WxPayException; /** * <pre> * 二级商户查询提现状态API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_3.shtml * </pre> * * @param subMchid 二级商户号 * @param outRequestNo 商户提现单号 * @return 返回数据 return sub withdraw status result * @throws WxPayException the wx pay exception */ SubWithdrawStatusResult querySubWithdrawByOutRequestNo(String subMchid, String outRequestNo) throws WxPayException; /** * <pre> * 电商平台查询提现状态API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_6.shtml * </pre> * * @param outRequestNo 商户提现单号 * @return 返回数据 return sp withdraw status result * @throws WxPayException the wx pay exception */ SpWithdrawStatusResult querySpWithdrawByOutRequestNo(String outRequestNo) throws WxPayException; /** * <pre> * 平台查询预约提现状态(根据微信支付预约提现单号查询) * 文档地址: https://pay.weixin.qq.com/doc/v3/partner/4012476674 * </pre> * * @param withdrawId 微信支付提现单号 * @return 返回数据 return sp withdraw status result * @throws WxPayException the wx pay exception */ SpWithdrawStatusResult querySpWithdrawByWithdrawId(String withdrawId) throws WxPayException; /** * <pre> * 二级商户按日终余额预约提现 * 文档地址: https://pay.weixin.qq.com/doc/v3/partner/4013328143 * </pre> * * @param request 提现请求 * @return 返回数据 return day-end balance withdraw result * @throws WxPayException the wx pay exception */ SubDayEndBalanceWithdrawResult subDayEndBalanceWithdraw(SubDayEndBalanceWithdrawRequest request) throws WxPayException; /** * <pre> * 查询二级商户按日终余额预约提现状态 * 文档地址: https://pay.weixin.qq.com/doc/v3/partner/4013328163 * </pre> * * @param subMchid 二级商户号 * @param outRequestNo 商户提现单号 * @return 返回数据 return day-end balance withdraw status result * @throws WxPayException the wx pay exception */ SubDayEndBalanceWithdrawStatusResult querySubDayEndBalanceWithdraw(String subMchid, String outRequestNo) throws WxPayException; /** * <pre> * 修改结算账号API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_4.shtml * </pre> * * @param subMchid 二级商户号。 * @param request 结算账号 * @throws WxPayException the wx pay exception */ void modifySettlement(String subMchid, SettlementRequest request) throws WxPayException; /** * <pre> * 查询结算账户API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_5.shtml * </pre> * * @param subMchid 二级商户号。 * @return 返回数据 return settlement result * @throws WxPayException the wx pay exception */ SettlementResult querySettlement(String subMchid) throws WxPayException; /** * <pre> * 请求账单API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/bill.shtml * </pre> * * @param request 请求信息。 * @return 返回数据 return trade bill result * @throws WxPayException the wx pay exception */ TradeBillResult applyBill(TradeBillRequest request) throws WxPayException; /** * <pre> * 申请资金账单API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/bill/chapter3_2.shtml * </pre> * * @param billType 账单类型。 * @param request 请求信息。 * @return 返回数据 return fund bill result * @throws WxPayException the wx pay exception */ FundBillResult applyFundBill(FundBillTypeEnum billType, FundBillRequest request) throws WxPayException; /** * <pre> * 下载账单API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/bill.shtml * </pre> * * @param url 微信返回的账单地址。 * @return 返回数据 return inputStream * @throws WxPayException the wx pay exception */ InputStream downloadBill(String url) throws WxPayException; /** * <pre> * 请求补差API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_1.shtml * </pre> * * @param subsidiesCreateRequest 请求补差。 * @return 返回数据 return SubsidiesCreateResult * @throws WxPayException the wx pay exception */ SubsidiesCreateResult subsidiesCreate(SubsidiesCreateRequest subsidiesCreateRequest) throws WxPayException; /** * <pre> * 请求补差回退API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_2.shtml * </pre> * * @param subsidiesReturnRequest 请求补差。 * @return 返回数据 return SubsidiesReturnResult * @throws WxPayException the wx pay exception */ SubsidiesReturnResult subsidiesReturn(SubsidiesReturnRequest subsidiesReturnRequest) throws WxPayException; /** * <pre> * 取消补差API * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_3.shtml * </pre> * * @param subsidiesCancelRequest 请求补差。 * @return 返回数据 return SubsidiesCancelResult * @throws WxPayException the wx pay exception */ SubsidiesCancelResult subsidiesCancel(SubsidiesCancelRequest subsidiesCancelRequest) throws WxPayException; /** * <pre> * 提交注销申请单 * 文档地址: https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/cancel-applications/create-cancel-application.html * </pre> * * @param accountCancelApplicationsRequest 提交注销申请单 * @return 返回数据 return AccountCancelApplicationsResult * @throws WxPayException the wx pay exception */ AccountCancelApplicationsResult createdAccountCancelApplication(AccountCancelApplicationsRequest accountCancelApplicationsRequest) throws WxPayException; /** * <pre> * 查询注销单状态 * 文档地址: https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/cancel-applications/get-cancel-application.html * </pre> * * @param outApplyNo 注销申请单号 * @return 返回数据 return AccountCancelApplicationsResult * @throws WxPayException the wx pay exception */ AccountCancelApplicationsResult getAccountCancelApplication(String outApplyNo) throws WxPayException; /** * <pre> * 注销单资料图片上传 * 文档地址: https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/media/upload-media.html * </pre> * * @param imageFile 图片 * @return 返回数据 return AccountCancelApplicationsResult * @throws WxPayException the wx pay exception */ AccountCancelApplicationsMediaResult uploadMediaAccountCancelApplication(File imageFile) throws WxPayException, IOException;; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MarketingMediaService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MarketingMediaService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.media.MarketingImageUploadResult; import com.github.binarywang.wxpay.exception.WxPayException; import java.io.File; import java.io.IOException; import java.io.InputStream; /** * <pre> * 微信支付营销专用媒体接口. * </pre> * * @author thinsstar */ public interface MarketingMediaService { /** * <pre> * 营销专用接口-图片上传API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_0_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/media/image-upload * </pre> * * @param imageFile 需要上传的图片文件 * @return ImageUploadResult 微信返回的媒体文件标识Id。示例值:6uqyGjGrCf2GtyXP8bxrbuH9-aAoTjH-rKeSl3Lf4_So6kdkQu4w8BYVP3bzLtvR38lxt4PjtCDXsQpzqge_hQEovHzOhsLleGFQVRF-U_0 * @throws WxPayException the wx pay exception */ MarketingImageUploadResult imageUploadV3(File imageFile) throws WxPayException, IOException; /** * <pre> * 营销专用接口-图片上传API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_0_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/media/image-upload * </pre> * * @param inputStream 需要上传的图片文件流 * @param fileName 需要上传的图片文件名 * @return ImageUploadResult 微信返回的媒体文件标识Id。示例值:6uqyGjGrCf2GtyXP8bxrbuH9-aAoTjH-rKeSl3Lf4_So6kdkQu4w8BYVP3bzLtvR38lxt4PjtCDXsQpzqge_hQEovHzOhsLleGFQVRF-U_0 * @throws WxPayException the wx pay exception */ MarketingImageUploadResult imageUploadV3(InputStream inputStream, String fileName) throws WxPayException, IOException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxEntrustPapService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxEntrustPapService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 微信签约代扣相关接口. * <a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter2_8.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter2_8.shtml</a> * </pre> * * @author chenliang * created on 2021 -08-02 4:50 下午 */ public interface WxEntrustPapService { /** * <pre> * 获取公众号纯签约链接, * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_1.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_1.shtml</a> * 该接口返回一个签约链接,该链接只能在微信内打开 * </pre> * * @param wxMpEntrustRequest the wx mp entrust request * @return string * @throws WxPayException the wx pay exception */ String mpSign(WxMpEntrustRequest wxMpEntrustRequest) throws WxPayException; /** * <pre> * 获取小程序纯签约参数json * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_3.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_3.shtml</a> * 返回一个json 前端用来拉起一个新的签约小程序进行签约 * </pre> * * @param wxMaEntrustRequest the wx ma entrust request * @return string * @throws WxPayException the wx pay exception */ String maSign(WxMaEntrustRequest wxMaEntrustRequest) throws WxPayException; /** * <pre> * 获取h5纯签约支付跳转链接 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_4.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_4.shtml</a> * 返回一个签约链接 在浏览器请求链接拉起微信 * </pre> * * @param wxH5EntrustRequest the wx h 5 entrust request * @return wx h 5 entrust result * @throws WxPayException the wx pay exception */ WxH5EntrustResult h5Sign(WxH5EntrustRequest wxH5EntrustRequest) throws WxPayException; /** * <pre> * 支付中签约 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_5.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_5.shtml</a> * 请求微信 若微信内请求 需要构造json返回, * 若h5请求 直接使用mweb_url 链接即可拉起微信 * </pre> * * @param wxPayEntrustRequest the wx pay entrust request * @return wx pay entrust result * @throws WxPayException the wx pay exception */ WxPayEntrustResult paySign(WxPayEntrustRequest wxPayEntrustRequest) throws WxPayException; /** * 申请扣款 * <pre> * 申请扣款 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_8.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_8.shtml</a> * 请求微信发起委托扣款,扣款额度和次数由使用的签约模板限制, * 该扣款接口是立即扣款 无延时 扣款前无消息通知。 * * • 特殊情况:周期扣费为通知后24小时扣费方式情况下,如果用户为首次签约(包含解约后重新签约), * 从用户签约成功时间开始算,商户在12小时内发起的扣款,会被立即执行,无延迟。商户超过12小时以后发起的扣款,都按24小时扣费规则执行 * </pre> * * @param wxWithholdRequest the wx withhold request * @return wx withhold result * @throws WxPayException the wx pay exception */ WxWithholdResult withhold(WxWithholdRequest wxWithholdRequest) throws WxPayException; /** * 服务商模式的申请扣款 * <pre> * 申请扣款 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter5_8.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter5_8.shtml</a> * 请求微信发起委托扣款,扣款额度和次数由使用的签约模板限制, * 该扣款接口是立即扣款 无延时 扣款前无消息通知。 * * • 特殊情况:周期扣费为通知后24小时扣费方式情况下,如果用户为首次签约(包含解约后重新签约), * 从用户签约成功时间开始算,商户在12小时内发起的扣款,会被立即执行,无延迟。商户超过12小时以后发起的扣款,都按24小时扣费规则执行 * </pre> * * @param wxWithholdRequest the wx withhold request * @return wx withhold result * @throws WxPayException the wx pay exception */ WxPayCommonResult withholdPartner(WxWithholdRequest wxWithholdRequest) throws WxPayException; /** * 预扣费通知 * <pre> * 预扣费接口 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_10.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_10.shtml</a> * 商户进行委托代扣扣费前需要在可通知时间段内调用「预扣费通知」的接口为用户发送扣费提醒, * 并设定扣费持续天数和预计扣费金额,经过扣费等待期后,在可扣费期内可发起扣费,扣款金额不能高于预计扣费金额, * 扣费失败可主动发起重试扣费(重试次数由其他规则限制),直到扣费成功,或者可扣费期结束。 * 商户只能在北京时间每天 6:00~22:00调用「预扣费通知」 * </pre> * * @param wxPreWithholdRequest the wx pre withhold request * @return string * @throws WxPayException the wx pay exception */ String preWithhold(WxPreWithholdRequest wxPreWithholdRequest) throws WxPayException; /** * 签约状态查询 * <pre> * 签约状态查询 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_7.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_7.shtml</a> * 查询签约关系接口提供单笔签约关系查询。 * </pre> * * @param wxSignQueryRequest the wx sign query request * @return wx sign query result * @throws WxPayException the wx pay exception */ WxSignQueryResult querySign(WxSignQueryRequest wxSignQueryRequest) throws WxPayException; /** * 申请解约 * <pre> * 申请解约 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_9.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_9.shtml</a> * 商户与用户的签约关系有误或者商户主动要求与用户解除之前的签约协议时可调用此接口完成解约。 * 商户可以在商户后台(pay.weixin.qq.com)设置解约回调地址,当发生解约关系的时候,微信服务器会向此地址通知解约信息,内容与签约返回一致 * </pre> * * @param wxTerminatedContractRequest the wx terminated contract request * @return wx termination contract result * @throws WxPayException the wx pay exception */ WxTerminationContractResult terminationContract(WxTerminatedContractRequest wxTerminatedContractRequest) throws WxPayException; /** * <pre> * 查询代扣订单 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter4_5.shtml">https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter4_5.shtml</a> * 该接口仅提供微信扣款服务申请扣款接口创建的订单进行查询,商户可以通过该接口主动查询微信代扣订单状态,完成下一步的业务逻辑。 * ACCEPT等待扣款:为24小时延时扣费场景下独有的,当没有达到24小时前一直是这种状态; * NOTPAY未支付:系统已经启动扣款流程,这个状态只是瞬间状态,很快会进入终态(SUCCESS、PAY_FAIL) * * </pre> * * @param wxWithholdOrderQueryRequest the wx withhold order query request * @return wx withhold order query result * @throws WxPayException the wx pay exception */ WxWithholdOrderQueryResult papOrderQuery(WxWithholdOrderQueryRequest wxWithholdOrderQueryRequest) throws WxPayException; /** * <pre> * 签约、解约结果通知解析 * 详见:<a href="https://pay.weixin.qq.com/doc/v2/merchant/4011987586">签约、解约结果通知</a> * 注意: * 1、同样的通知可能会多次发送给商户系统。商户系统必须能够正确处理重复的通知。 推荐的做法是:当商户系统收到通知进行处理时,先检查对应业务数据的状态,并判断该通知是否已经处理。如果未处理,则再进行处理;如果已处理,则直接返回结果成功。在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱。 * 2、如果在所有通知频率(0/10/10/10/30/30/30/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300/300(单位:秒))后没有收到微信侧回调,商户应调用查询订单接口确认订单状态。 * 特别提醒: * 1、商户系统对于签约、解约结果通知的内容一定要做签名验证,并校验返回的商户协议号和用户openid信息是否一致,防止数据泄露导致出现“假通知”,造成损失。 * 2、当收到通知进行处理时,首先检查对应业务数据的状态,判断该通知是否已经处理过,如果没有处理过再进行处理,如果处理过直接返回结果成功。在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱。 * </pre> * * @param xmlData the wx withhold order query request * @return wx sign result * @throws WxPayException the wx pay exception */ WxSignQueryResult parseSignNotifyResult(String xmlData) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MiPayService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MiPayService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.mipay.MedInsOrdersRequest; import com.github.binarywang.wxpay.bean.mipay.MedInsOrdersResult; import com.github.binarywang.wxpay.bean.mipay.MedInsRefundNotifyRequest; import com.github.binarywang.wxpay.bean.notify.MiPayNotifyV3Result; import com.github.binarywang.wxpay.bean.notify.SignatureHeader; import com.github.binarywang.wxpay.exception.WxPayException; /** * <a href="https://pay.weixin.qq.com/doc/v3/partner/4012503131">医保相关接口</a> * 医保相关接口 * @author xgl * @date 2025/12/20 */ public interface MiPayService { /** * <pre> * 医保自费混合收款下单 * * 从业机构调用该接口向微信医保后台下单 * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/partner/4012503131">医保自费混合收款下单</a> * </pre> * * @param request 下单参数 * @return ReservationTransferNotifyResult 下单结果 * @throws WxPayException the wx pay exception */ MedInsOrdersResult medInsOrders(MedInsOrdersRequest request) throws WxPayException; /** * <pre> * 使用医保自费混合订单号查看下单结果 * * 从业机构使用混合下单订单号,通过该接口主动查询订单状态,完成下一步的业务逻辑。 * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/partner/4012503155">使用医保自费混合订单号查看下单结果</a> * </pre> * * @param mixTradeNo 医保自费混合订单号 * @param subMchid 医疗机构的商户号 * @return MedInsOrdersResult 下单结果 * @throws WxPayException the wx pay exception */ MedInsOrdersResult getMedInsOrderByMixTradeNo(String mixTradeNo, String subMchid) throws WxPayException; /** * <pre> * 使用从业机构订单号查看下单结果 * * 从业机构使用从业机构订单号、医疗机构商户号,通过该接口主动查询订单状态,完成下一步的业务逻辑。 * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/partner/4012503286">使用从业机构订单号查看下单结果</a> * </pre> * * @param outTradeNo 从业机构订单号 * @param subMchid 医疗机构的商户号 * @return MedInsOrdersResult 下单结果 * @throws WxPayException the wx pay exception */ MedInsOrdersResult getMedInsOrderByOutTradeNo(String outTradeNo, String subMchid) throws WxPayException; /** * <pre> * 解析医保混合收款成功通知 * * 微信支付会通过POST请求向商户设置的回调URL推送医保混合收款成功通知,商户需要接收处理该消息,并返回应答。 * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/partner/4012165722">医保混合收款成功通知</a> * </pre> * * @param notifyData 通知数据字符串 * @return MiPayNotifyV3Result 医保混合收款成功通知结果 * @throws WxPayException the wx pay exception */ MiPayNotifyV3Result parseMiPayNotifyV3Result(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * 医保退款通知 * * 从业机构调用该接口向微信医保后台通知医保订单的退款成功结果 * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/partner/4012166534">医保退款通知</a> * </pre> * * @param request 医保退款通知请求参数 * @param mixTradeNo 【医保自费混合订单号】 医保自费混合订单号 * @throws WxPayException the wx pay exception */ void medInsRefundNotify(MedInsRefundNotifyRequest request, String mixTradeNo) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.WxPayApiData; import com.github.binarywang.wxpay.bean.coupon.*; import com.github.binarywang.wxpay.bean.notify.*; import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; import com.github.binarywang.wxpay.bean.result.enums.GlobalTradeTypeEnum; import com.github.binarywang.wxpay.bean.transfer.TransferBillsNotifyResult; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.exception.WxPayException; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; import java.io.File; import java.io.InputStream; import java.util.Date; import java.util.Map; /** * <pre> * 微信支付相关接口. * Created by Binary Wang on 2016/7/28. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public interface WxPayService { /** * 获取微信支付请求url前缀,沙箱环境可能不一样. * * @return the pay base url */ String getPayBaseUrl(); /** * Map里 加入新的 {@link WxPayConfig},适用于动态添加新的微信商户配置. * * @param mchId 商户id * @param appId 微信应用id * @param wxPayConfig 新的微信配置 */ void addConfig(String mchId, String appId, WxPayConfig wxPayConfig); /** * 从 Map中 移除 {@link String mchId} 和 {@link String appId} 所对应的 {@link WxPayConfig},适用于动态移除微信商户配置. * * @param mchId 对应商户的标识 * @param appId 微信应用id */ void removeConfig(String mchId, String appId); /** * 注入多个 {@link WxPayConfig} 的实现. 并为每个 {@link WxPayConfig} 赋予不同的 {@link String mchId} 值 * 随机采用一个{@link String mchId}进行Http初始化操作 * * @param wxPayConfigs WxPayConfig map */ void setMultiConfig(Map<String, WxPayConfig> wxPayConfigs); /** * 注入多个 {@link WxPayConfig} 的实现. 并为每个 {@link WxPayConfig} 赋予不同的 {@link String label} 值 * * @param wxPayConfigs WxPayConfig map * @param defaultMchId 设置一个{@link WxPayConfig} 所对应的{@link String mchId}进行Http初始化 */ void setMultiConfig(Map<String, WxPayConfig> wxPayConfigs, String defaultMchId); /** * 进行相应的商户切换. * * @param mchId 商户标识 * @param appId 微信应用id * @return 切换是否成功 boolean */ boolean switchover(String mchId, String appId); /** * 进行相应的商户切换. * * @param mchId 商户标识 * @param appId 微信应用id * @return 切换成功 ,则返回当前对象,方便链式调用,否则抛出异常 */ WxPayService switchoverTo(String mchId, String appId); /** * 发送post请求,得到响应字节数组. * * @param url 请求地址 * @param requestStr 请求信息 * @param useKey 是否使用证书 * @return 返回请求结果字节数组 byte [ ] * @throws WxPayException the wx pay exception */ byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException; /** * 发送post请求,得到响应字符串. * * @param url 请求地址 * @param requestStr 请求信息 * @param useKey 是否使用证书 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String post(String url, String requestStr, boolean useKey) throws WxPayException; /** * 发送post请求,得到响应字符串. * * @param url 请求地址 * @param requestStr 请求信息 * @param useKey 是否使用证书 * @param mimeType Content-Type请求头 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String post(String url, String requestStr, boolean useKey, String mimeType) throws WxPayException; /** * 发送post请求,得到响应字符串. * * @param url 请求地址 * @param requestStr 请求信息 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String postV3(String url, String requestStr) throws WxPayException; /** * 发送patch请求,得到响应字符串. * * @param url 请求地址 * @param requestStr 请求信息 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String patchV3(String url, String requestStr) throws WxPayException; /** * 发送post请求,得到响应字符串. * <p> * 部分字段会包含敏感信息,所以在提交前需要在请求头中会包含"Wechatpay-Serial"信息 * * @param url 请求地址 * @param requestStr 请求信息 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String postV3WithWechatpaySerial(String url, String requestStr) throws WxPayException; /** * 发送post请求,得到响应字符串. * * @param url 请求地址 * @param httpPost 请求信息 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String postV3(String url, HttpPost httpPost) throws WxPayException; /** * 发送http请求,得到响应字符串. * * @param url 请求地址 * @param httpRequest 请求信息,可以是put,post,get,delete等请求 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String requestV3(String url, HttpRequestBase httpRequest) throws WxPayException; /** * 发送get V3请求,得到响应字符串. * * @param url 请求地址 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String getV3(String url) throws WxPayException; /** * 发送get请求,得到响应字符串. * <p> * 部分字段会包含敏感信息,所以在提交前需要在请求头中会包含"Wechatpay-Serial"信息 * * @param url 请求地址 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String getV3WithWechatPaySerial(String url) throws WxPayException; /** * 发送下载 V3请求,得到响应流. * * @param url 请求地址 * @return 返回请求响应流 input stream * @throws WxPayException the wx pay exception */ InputStream downloadV3(String url) throws WxPayException; /** * 发送put V3请求,得到响应字符串. * * @param url 请求地址 * @param requestStr 请求数据 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String putV3(String url, String requestStr) throws WxPayException; /** * 发送delete V3请求,得到响应字符串. * * @param url 请求地址 * @return 返回请求结果字符串 string * @throws WxPayException the wx pay exception */ String deleteV3(String url) throws WxPayException; /** * 获取微信签约代扣服务类 * * @return entrust service */ WxEntrustPapService getWxEntrustPapService(); /** * 获取微信押金支付服务类 * * @return deposit service */ WxDepositService getWxDepositService(); /** * 获取批量转账到零钱服务类. * * @return the Batch transfer to change service */ PartnerTransferService getPartnerTransferService(); /** * 微工卡 * * @return the micro card */ PayrollService getPayrollService(); /** * 获取企业付款服务类. * * @return the ent pay service */ EntPayService getEntPayService(); /** * 获取红包接口服务类. * * @return . redpack service */ RedpackService getRedpackService(); /** * 获取分账服务类. * <p> * V3接口 {@link WxPayService#getProfitSharingService()} * </p> * * @return the ent pay service */ ProfitSharingService getProfitSharingService(); /** * 获取支付分服务类. * * @return the ent pay service */ PayScoreService getPayScoreService(); /** * 获取电商收付通服务类 * * @return the ecommerce service */ EcommerceService getEcommerceService(); /** * 获取微信支付智慧商圈服务类 * * @return the business circle service */ BusinessCircleService getBusinessCircleService(); /** * 获取微信支付通用媒体服务类 * * @return the merchant media service */ MerchantMediaService getMerchantMediaService(); /** * 获取微信支付营销媒体服务类 * * @return the marketing media service */ MarketingMediaService getMarketingMediaService(); /** * 获取微信支付营销代金券服务类 * * @return the marketing favor service */ MarketingFavorService getMarketingFavorService(); /** * 获取微信支付营销商家券服务类 * * @return the marketing favor service */ MarketingBusiFavorService getMarketingBusiFavorService(); /** * 获取商家转账到零钱服务类 * * @return the merchant transfer service */ MerchantTransferService getMerchantTransferService(); /** * 获取品牌红包商家转账到零钱服务类 * * @return the brand merchant transfer service */ BrandMerchantTransferService getBrandMerchantTransferService(); /** * 获取微信支付预约扣费服务类 (连续包月功能) * * @return the subscription billing service */ SubscriptionBillingService getSubscriptionBillingService(); /** * 设置企业付款服务类,允许开发者自定义实现类. * * @param entPayService the ent pay service */ void setEntPayService(EntPayService entPayService); /** * <pre> * 查询订单. * 详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2 * 该接口提供所有微信支付订单的查询,商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。 * 需要调用查询接口的情况: * ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知; * ◆ 调用支付接口后,返回系统错误或未知交易状态情况; * ◆ 调用被扫支付API,返回USERPAYING的状态; * ◆ 调用关单或撤销接口API之前,需确认支付状态; * 接口地址:https://api.mch.weixin.qq.com/pay/orderquery * </pre> * * @param transactionId 微信订单号 * @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。 * @return the wx pay order query result * @throws WxPayException the wx pay exception */ WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxPayException; /** * <pre> * 查询订单(适合于需要自定义子商户号和子商户appid的情形). * 详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2 * 该接口提供所有微信支付订单的查询,商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。 * 需要调用查询接口的情况: * ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知; * ◆ 调用支付接口后,返回系统错误或未知交易状态情况; * ◆ 调用被扫支付API,返回USERPAYING的状态; * ◆ 调用关单或撤销接口API之前,需确认支付状态; * 接口地址:https://api.mch.weixin.qq.com/pay/orderquery * </pre> * * @param request 查询订单请求对象 * @return the wx pay order query result * @throws WxPayException the wx pay exception */ WxPayOrderQueryResult queryOrder(WxPayOrderQueryRequest request) throws WxPayException; /** * <pre> * 查询订单 * 详见 <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml</a> * 商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。查询订单状态可通过微信支付订单号或商户订单号两种方式查询 * 注意: * 查询订单可通过微信支付订单号和商户订单号两种方式查询,两种查询方式返回结果相同 * 需要调用查询接口的情况: * ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知。 * ◆ 调用支付接口后,返回系统错误或未知交易状态情况。 * ◆ 调用付款码支付API,返回USERPAYING的状态。 * ◆ 调用关单或撤销接口API之前,需确认支付状态。 * 接口地址: * https://api.mch.weixin.qq.com/v3/pay/transactions/id/{transaction_id} * https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{out_trade_no} * </pre> * * @param transactionId 微信订单号 * @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。 * @return the wx pay order query result * @throws WxPayException the wx pay exception */ WxPayOrderQueryV3Result queryOrderV3(String transactionId, String outTradeNo) throws WxPayException; /** * <pre> * 查询订单 * 详见 <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml</a> * 商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。查询订单状态可通过微信支付订单号或商户订单号两种方式查询 * 注意: * 查询订单可通过微信支付订单号和商户订单号两种方式查询,两种查询方式返回结果相同 * 需要调用查询接口的情况: * ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知。 * ◆ 调用支付接口后,返回系统错误或未知交易状态情况。 * ◆ 调用付款码支付API,返回USERPAYING的状态。 * ◆ 调用关单或撤销接口API之前,需确认支付状态。 * 接口地址: * https://api.mch.weixin.qq.com/v3/pay/transactions/id/{transaction_id} * https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{out_trade_no} * </pre> * * @param request 查询订单请求对象 * @return the wx pay order query result * @throws WxPayException the wx pay exception */ WxPayOrderQueryV3Result queryOrderV3(WxPayOrderQueryV3Request request) throws WxPayException; /** * <pre> * 服务商模式查询订单 * 详见 <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_2.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_2.shtml</a> * 商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。查询订单状态可通过微信支付订单号或商户订单号两种方式查询 * 注意: * 查询订单可通过微信支付订单号和商户订单号两种方式查询,两种查询方式返回结果相同 * 需要调用查询接口的情况: * ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知。 * ◆ 调用支付接口后,返回系统错误或未知交易状态情况。 * ◆ 调用付款码支付API,返回USERPAYING的状态。 * ◆ 调用关单或撤销接口API之前,需确认支付状态。 * 接口地址: * https://api.mch.weixin.qq.com/v3/pay/partner/transactions/id/{transaction_id} * https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/{out_trade_no} * </pre> * * @param transactionId 微信订单号 * @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。 * @return the wx pay order query result * @throws WxPayException the wx pay exception */ WxPayPartnerOrderQueryV3Result queryPartnerOrderV3(String transactionId, String outTradeNo) throws WxPayException; /** * <pre> * 服务商模式查询订单 * 详见 <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_2.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_2.shtml</a> * 商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。查询订单状态可通过微信支付订单号或商户订单号两种方式查询 * 注意: * 查询订单可通过微信支付订单号和商户订单号两种方式查询,两种查询方式返回结果相同 * 需要调用查询接口的情况: * ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知。 * ◆ 调用支付接口后,返回系统错误或未知交易状态情况。 * ◆ 调用付款码支付API,返回USERPAYING的状态。 * ◆ 调用关单或撤销接口API之前,需确认支付状态。 * 接口地址: * https://api.mch.weixin.qq.com/v3/pay/partner/transactions/id/{transaction_id} * https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/{out_trade_no} * </pre> * * @param request 查询订单请求对象 * @return the wx pay order query result * @throws WxPayException the wx pay exception */ WxPayPartnerOrderQueryV3Result queryPartnerOrderV3(WxPayPartnerOrderQueryV3Request request) throws WxPayException; /** * <pre> * 合单查询订单API * 请求URL: https://api.mch.weixin.qq.com/v3/combine-transactions/out-trade-no/{combine_out_trade_no} * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_11.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_11.shtml</a> * </pre> * * @param combineOutTradeNo 合单商户订单号 * @return 合单支付订单信息 combine query result * @throws WxPayException the wx pay exception */ CombineQueryResult queryCombine(String combineOutTradeNo) throws WxPayException; /** * <pre> * 关闭订单. * 应用场景 * 以下情况需要调用关单接口: * 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; * 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。 * 注意:订单生成后不能马上调用关单接口,最短调用时间间隔为5分钟。 * 接口地址:https://api.mch.weixin.qq.com/pay/closeorder * 是否需要证书: 不需要。 * </pre> * * @param outTradeNo 商户系统内部的订单号 * @return the wx pay order close result * @throws WxPayException the wx pay exception */ WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException; /** * <pre> * 关闭订单(适合于需要自定义子商户号和子商户appid的情形). * 应用场景 * 以下情况需要调用关单接口: * 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; * 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。 * 注意:订单生成后不能马上调用关单接口,最短调用时间间隔为5分钟。 * 接口地址:https://api.mch.weixin.qq.com/pay/closeorder * 是否需要证书: 不需要。 * </pre> * * @param request 关闭订单请求对象 * @return the wx pay order close result * @throws WxPayException the wx pay exception */ WxPayOrderCloseResult closeOrder(WxPayOrderCloseRequest request) throws WxPayException; /** * <pre> * 关闭订单 * 应用场景 * 以下情况需要调用关单接口: * 1、商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; * 2、系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。 * 注意:关单没有时间限制,建议在订单生成后间隔几分钟(最短5分钟)再调用关单接口,避免出现订单状态同步不及时导致关单失败。 * 接口地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_3.shtml * </pre> * * @param outTradeNo 商户系统内部的订单号 * @return the wx pay order close result * @throws WxPayException the wx pay exception */ void closeOrderV3(String outTradeNo) throws WxPayException; /** * <pre> * 服务商关闭订单 * 应用场景 * 以下情况需要调用关单接口: * 1、商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; * 2、系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。 * 注意:关单没有时间限制,建议在订单生成后间隔几分钟(最短5分钟)再调用关单接口,避免出现订单状态同步不及时导致关单失败。 * 接口地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_3.shtml * </pre> * * @param outTradeNo 商户系统内部的订单号 * @return the wx pay order close result * @throws WxPayException the wx pay exception */ void closePartnerOrderV3(String outTradeNo) throws WxPayException; /** * <pre> * 关闭订单 * 应用场景 * 以下情况需要调用关单接口: * 1、商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; * 2、系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。 * 注意:关单没有时间限制,建议在订单生成后间隔几分钟(最短5分钟)再调用关单接口,避免出现订单状态同步不及时导致关单失败。 * 接口地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_3.shtml * </pre> * * @param request 关闭订单请求对象 * @return the wx pay order close result * @throws WxPayException the wx pay exception */ void closeOrderV3(WxPayOrderCloseV3Request request) throws WxPayException; /** * <pre> * 服务商关闭订单 * 应用场景 * 以下情况需要调用关单接口: * 1、商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; * 2、系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。 * 注意:关单没有时间限制,建议在订单生成后间隔几分钟(最短5分钟)再调用关单接口,避免出现订单状态同步不及时导致关单失败。 * 接口地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_3.shtml * </pre> * * @param request 关闭订单请求对象 * @return the wx pay order close result * @throws WxPayException the wx pay exception */ void closePartnerOrderV3(WxPayPartnerOrderCloseV3Request request) throws WxPayException; /** * <pre> * 合单关闭订单API * 请求URL: https://api.mch.weixin.qq.com/v3/combine-transactions/out-trade-no/{combine_out_trade_no}/close * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_12.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_12.shtml</a> * </pre> * * @param request 请求对象 * @throws WxPayException the wx pay exception */ void closeCombine(CombineCloseRequest request) throws WxPayException; /** * 调用统一下单接口,并组装生成支付所需参数对象. * * @param <T> 请使用{@link com.github.binarywang.wxpay.bean.order}包下的类 * @param request 统一下单请求参数 * @return 返回 {@link com.github.binarywang.wxpay.bean.order}包下的类对象 * @throws WxPayException the wx pay exception */ <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException; /** * 调用统一下单接口,并组装生成支付所需参数对象. * * @param <T> the type parameter * @param specificTradeType 将使用的交易方式,不能为 null * @param request 统一下单请求参数,设定的 tradeType 及配置里的 tradeType 将被忽略,转而使用 specificTradeType * @return 返回 {@link WxPayConstants.TradeType.Specific} 指定的类 * @throws WxPayException the wx pay exception * @see WxPayService#createOrder(WxPayUnifiedOrderRequest) WxPayService#createOrder(WxPayUnifiedOrderRequest)WxPayService#createOrder(WxPayUnifiedOrderRequest) */ <T> T createOrder(WxPayConstants.TradeType.Specific<T> specificTradeType, WxPayUnifiedOrderRequest request) throws WxPayException; /** * 统一下单(详见https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1) * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" * 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder * * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) * @return the wx pay unified order result * @throws WxPayException the wx pay exception */ WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxPayException; /** * 调用统一下单接口,并组装生成支付所需参数对象. * * @param <T> 请使用{@link WxPayUnifiedOrderV3Result}里的内部类或字段 * @param tradeType the trade type * @param request 统一下单请求参数 * @return 返回 {@link WxPayUnifiedOrderV3Result}里的内部类或字段 * @throws WxPayException the wx pay exception */ <T> T createOrderV3(TradeTypeEnum tradeType, WxPayUnifiedOrderV3Request request) throws WxPayException; /** * 服务商模式调用统一下单接口,并组装生成支付所需参数对象. * * @param <T> 请使用{@link WxPayUnifiedOrderV3Result}里的内部类或字段 * @param tradeType the trade type * @param request 统一下单请求参数 * @return 返回 {@link WxPayUnifiedOrderV3Result}里的内部类或字段 * @throws WxPayException the wx pay exception */ <T> T createPartnerOrderV3(TradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException; /** * 境外微信支付调用统一下单接口,并组装生成支付所需参数对象. * * @param <T> 请使用{@link WxPayUnifiedOrderV3Result}里的内部类或字段 * @param tradeType the global trade type * @param request 境外统一下单请求参数 * @return 返回 {@link WxPayUnifiedOrderV3Result}里的内部类或字段 * @throws WxPayException the wx pay exception */ <T> T createOrderV3Global(GlobalTradeTypeEnum tradeType, WxPayUnifiedOrderV3GlobalRequest request) throws WxPayException; /** * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" * * @param tradeType the trade type * @param request 请求对象,注意一些参数如spAppid、spMchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) * @return the wx pay unified order result * @throws WxPayException the wx pay exception */ WxPayUnifiedOrderV3Result unifiedPartnerOrderV3(TradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException; /** * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" * * @param tradeType the trade type * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) * @return the wx pay unified order result * @throws WxPayException the wx pay exception */ WxPayUnifiedOrderV3Result unifiedOrderV3(TradeTypeEnum tradeType, WxPayUnifiedOrderV3Request request) throws WxPayException; /** * 境外微信支付在发起支付前,需要调用统一下单接口,获取"预支付交易会话标识" * * @param tradeType the global trade type * @param request 境外请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) * @return the wx pay unified order result * @throws WxPayException the wx pay exception */ WxPayUnifiedOrderV3Result unifiedOrderV3Global(GlobalTradeTypeEnum tradeType, WxPayUnifiedOrderV3GlobalRequest request) throws WxPayException; /** * <pre> * 合单支付API(APP支付、JSAPI支付、H5支付、NATIVE支付). * 请求URL: * https://api.mch.weixin.qq.com/v3/combine-transactions/app * https://api.mch.weixin.qq.com/v3/combine-transactions/h5 * https://api.mch.weixin.qq.com/v3/combine-transactions/jsapi * https://api.mch.weixin.qq.com/v3/combine-transactions/native * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_9_3.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_9_3.shtml</a> * </pre> * * @param tradeType 支付方式 * @param request 请求对象 * @return 微信合单支付返回 combine transactions result * @throws WxPayException the wx pay exception */ CombineTransactionsResult combine(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException; /** * <pre> * 合单支付API(APP支付、JSAPI支付、H5支付、NATIVE支付). * 请求URL: * https://api.mch.weixin.qq.com/v3/combine-transactions/app * https://api.mch.weixin.qq.com/v3/combine-transactions/h5 * https://api.mch.weixin.qq.com/v3/combine-transactions/jsapi * https://api.mch.weixin.qq.com/v3/combine-transactions/native * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_9_3.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_9_3.shtml</a> * </pre> * * @param <T> the type parameter * @param tradeType 支付方式 * @param request 请求对象 * @return 调起支付需要的参数 t * @throws WxPayException the wx pay exception */ <T> T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException; /** * 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数. * 详见https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5 * * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) * @return the pay info * @throws WxPayException the wx pay exception * @deprecated 建议使用 {@link WxPayService#createOrder(WxPayUnifiedOrderRequest)} */ @Deprecated Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxPayException; /** * 获取配置. * * @return the config */ WxPayConfig getConfig(); /** * 设置配置对象. * * @param config the config */ void setConfig(WxPayConfig config); /** * <pre> * 微信支付-申请退款. * 详见 <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4">https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4</a> * 接口链接:https://api.mch.weixin.qq.com/secapi/pay/refund * </pre> * * @param request 请求对象 * @return 退款操作结果 wx pay refund result * @throws WxPayException the wx pay exception */ WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayException; /** * <pre> * 申请退款API(支持单品). * 详见 <a href="https://pay.weixin.qq.com/wiki/doc/api/danpin.php?chapter=9_103&index=3">https://pay.weixin.qq.com/wiki/doc/api/danpin.php?chapter=9_103&index=3</a> * * 应用场景 * 当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,微信支付将在收到退款请求并且验证成功之后,按照退款规则将支付款按原路退到买家帐号上。 * * 注意:
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
true
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/TransferService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/TransferService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.notify.SignatureHeader; import com.github.binarywang.wxpay.bean.transfer.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * 商家转账到零钱 * * @author zhongjun * created on 2022/6/17 **/ public interface TransferService { /** * <pre> * * 发起商家转账API * * 请求方式:POST(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_1.shtml">发起商家转账API</a> * </pre> * * @param request 转账请求参数 * @return TransferBatchesResult 转账结果 * @throws WxPayException . */ TransferBatchesResult transferBatches(TransferBatchesRequest request) throws WxPayException; /** * 解析商家转账结果 * 详见<a href="https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-batch-callback-notice.html"></a> * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * @return the wx transfer notify result * @throws WxPayException the wx pay exception */ TransferNotifyResult parseTransferNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * * 微信批次单号查询批次单API * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches/batch-id/{batch_id}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_2.shtml">微信批次单号查询批次单API</a> * </pre> * * @param request 查询请求参数 * @return TransferBatchesResult 查询结果 * @throws WxPayException . */ QueryTransferBatchesResult transferBatchesBatchId(QueryTransferBatchesRequest request) throws WxPayException; /** * <pre> * * 微信明细单号查询明细单API * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches/batch-id/{batch_id}/details/detail-id/{detail_id}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_3.shtml">微信明细单号查询明细单API</a> * </pre> * * @param batchId 微信批次单号 * @param detailId 微信明细单号 * @return TransferBatchDetailResult 查询结果 * @throws WxPayException . */ TransferBatchDetailResult transferBatchesBatchIdDetail(String batchId, String detailId) throws WxPayException; /** * <pre> * * 商家批次单号查询批次单API * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/{out_batch_no}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_5.shtml">商家批次单号查询批次单API</a> * </pre> * * @param request 查询请求参数 * @return TransferBatchesResult 查询结果 * @throws WxPayException . * @throws WxPayException . */ QueryTransferBatchesResult transferBatchesOutBatchNo(QueryTransferBatchesRequest request) throws WxPayException; /** * <pre> * * 商家明细单号查询明细单API * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/{out_batch_no}/details/out-detail-no/{out_detail_no}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_6.shtml">商家明细单号查询明细单API</a> * </pre> * * @param outBatchNo 商家明细单号 * @param outDetailNo 商家批次单号 * @return TransferBatchDetailResult 查询结果 * @throws WxPayException . */ TransferBatchDetailResult transferBatchesOutBatchNoDetail(String outBatchNo, String outDetailNo) throws WxPayException; /** * <pre> * * 2025.1.15 开始新接口 发起商家转账API * * 请求方式:POST(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716434">发起商家转账API</a> * </pre> * * @param request 转账请求参数 * @return TransferBillsResult 转账结果 * @throws WxPayException . */ TransferBillsResult transferBills(TransferBillsRequest request) throws WxPayException; /** * <pre> * * 2025.1.15 开始新接口 撤销转账API * * 请求方式:POST(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/{out_bill_no}/cancel">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716458">商户撤销转账API</a> * </pre> * * @param outBillNo 【商户单号】 商户系统内部的商家单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一 * @return TransformBillsGetResult 转账单 * @throws WxPayException . */ TransferBillsCancelResult transformBillsCancel(String outBillNo) throws WxPayException; /** * <pre> * * 2025.1.15 开始新接口 发起商家转账API * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/{out_bill_no}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716437">商户单号查询转账单API</a> * </pre> * * @param outBillNo 【商户单号】 商户系统内部的商家单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一 * @return TransformBillsGetResult 转账单 * @throws WxPayException . */ TransferBillsGetResult getBillsByOutBillNo(String outBillNo) throws WxPayException; /** * <pre> * * 2025.1.15 开始新接口 微信单号查询转账单API * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills/transfer-bill-no/{transfer_bill_no}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716437">商户单号查询转账单API</a> * </pre> * * @param transferBillNo 【微信转账单号】 微信转账单号,微信商家转账系统返回的唯一标识 * @return TransformBillsGetResult 转账单 * @throws WxPayException . */ TransferBillsGetResult getBillsByTransferBillNo(String transferBillNo) throws WxPayException; /** * 2025.1.15 开始新接口 解析商家转账结果 * 详见<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012712115"></a> * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * @return the wx transfer notify result * @throws WxPayException the wx pay exception */ TransferBillsNotifyResult parseTransferBillsNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; // ===================== 用户授权免确认模式相关接口 ===================== /** * <pre> * 商户查询用户授权信息接口 * * 商户通过此接口可查询用户是否对商户的商家转账场景进行了授权。 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/authorization/openid/{openid}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">商户查询用户授权信息</a> * </pre> * * @param openid 用户在直连商户应用下的用户标识 * @param transferSceneId 转账场景ID * @return UserAuthorizationStatusResult 用户授权信息 * @throws WxPayException . */ UserAuthorizationStatusResult getUserAuthorizationStatus(String openid, String transferSceneId) throws WxPayException; /** * <pre> * 批量预约商家转账接口 * * 商户可以通过批量预约接口一次发起批量转账请求,最多可以同时向50个用户发起转账。 * 批量预约接口适用于用户已授权免确认的场景,在转账时无需用户确认即可完成转账。 * * 请求方式:POST(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/reservation/transfer-batches">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">批量预约商家转账</a> * </pre> * * @param request 批量预约商家转账请求参数 * @return ReservationTransferBatchResult 批量预约商家转账结果 * @throws WxPayException . */ ReservationTransferBatchResult reservationTransferBatch(ReservationTransferBatchRequest request) throws WxPayException; /** * <pre> * 商户预约批次单号查询批次单接口 * * 通过商户预约批次单号查询批量预约商家转账批次单基本信息。 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/reservation/transfer-batches/out-batch-no/{out_batch_no}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">商户预约批次单号查询批次单</a> * </pre> * * @param outBatchNo 商户预约批次单号 * @param needQueryDetail 是否需要查询明细 * @param offset 分页偏移量 * @param limit 分页大小 * @param detailState 明细状态(PROCESSING/SUCCESS/FAIL) * @return ReservationTransferBatchGetResult 批量预约商家转账批次查询结果 * @throws WxPayException . */ ReservationTransferBatchGetResult getReservationTransferBatchByOutBatchNo(String outBatchNo, Boolean needQueryDetail, Integer offset, Integer limit, String detailState) throws WxPayException; /** * <pre> * 微信预约批次单号查询批次单接口 * * 通过微信预约批次单号查询批量预约商家转账批次单基本信息。 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/reservation/transfer-batches/reservation-batch-no/{reservation_batch_no}">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">微信预约批次单号查询批次单</a> * </pre> * * @param reservationBatchNo 微信预约批次单号 * @param needQueryDetail 是否需要查询明细 * @param offset 分页偏移量 * @param limit 分页大小 * @param detailState 明细状态(PROCESSING/SUCCESS/FAIL) * @return ReservationTransferBatchGetResult 批量预约商家转账批次查询结果 * @throws WxPayException . */ ReservationTransferBatchGetResult getReservationTransferBatchByReservationBatchNo(String reservationBatchNo, Boolean needQueryDetail, Integer offset, Integer limit, String detailState) throws WxPayException; /** * <pre> * 解析预约商家转账通知回调结果 * * 预约批次单中的明细单在转账成功或转账失败时,微信会把相关结果信息发送给商户。 * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">预约商家转账通知</a> * </pre> * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * @return ReservationTransferNotifyResult 预约商家转账通知结果 * @throws WxPayException the wx pay exception */ ReservationTransferNotifyResult parseReservationTransferNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * 关闭预约商家转账批次接口 * * 商户可以通过此接口关闭预约商家转账批次单。关闭后,该批次内所有未成功的转账将被取消。 * * 请求方式:POST(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/reservation/transfer-batches/out-batch-no/{out_batch_no}/close">请求地址</a> * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4015901167">关闭预约商家转账批次</a> * </pre> * * @param outBatchNo 商户预约批次单号 * @throws WxPayException . */ void closeReservationTransferBatch(String outBatchNo) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RealNameService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RealNameService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.realname.RealNameRequest; import com.github.binarywang.wxpay.bean.realname.RealNameResult; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 微信支付实名验证相关服务类. * 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public interface RealNameService { /** * <pre> * 获取用户实名认证信息API. * 用于商户查询用户的实名认证状态,如果用户未实名认证,会返回引导用户实名认证的URL * 文档详见:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 * 接口链接:https://api.mch.weixin.qq.com/userinfo/realnameauth/query * </pre> * * @param request 请求对象 * @return 实名认证查询结果 * @throws WxPayException the wx pay exception */ RealNameResult queryRealName(RealNameRequest request) throws WxPayException; /** * <pre> * 获取用户实名认证信息API(简化方法). * 用于商户查询用户的实名认证状态,如果用户未实名认证,会返回引导用户实名认证的URL * 文档详见:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 * 接口链接:https://api.mch.weixin.qq.com/userinfo/realnameauth/query * </pre> * * @param openid 用户openid * @return 实名认证查询结果 * @throws WxPayException the wx pay exception */ RealNameResult queryRealName(String openid) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MerchantTransferService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MerchantTransferService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.merchanttransfer.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * 商家转账到零钱(直联商户) * * @author glz * created on 2022-6-11 */ public interface MerchantTransferService { /** * 发起商家转账API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_1.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/batches * 请求方式:POST * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * 是否需要证书:是 * * @param request the request * @return transfer create result * @throws WxPayException the wx pay exception */ TransferCreateResult createTransfer(TransferCreateRequest request) throws WxPayException; /** * 微信批次单号查询批次单API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_2.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/batches/batch-id/{batch_id} * 请求方式:GET * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return batches query result * @throws WxPayException the wx pay exception */ BatchesQueryResult queryWxBatches(WxBatchesQueryRequest request) throws WxPayException; /** * 微信明细单号查询明细单API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_3.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/batches/batch-id/{batch_id}/details/detail-id/{detail_id} * 请求方式:GET * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return details query result * @throws WxPayException the wx pay exception */ DetailsQueryResult queryWxDetails(WxDetailsQueryRequest request) throws WxPayException; /** * 商家批次单号查询批次单API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_5.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/{out_batch_no} * 请求方式:GET * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return batches query result * @throws WxPayException the wx pay exception */ BatchesQueryResult queryMerchantBatches(MerchantBatchesQueryRequest request) throws WxPayException; /** * 商家明细单号查询明细单API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_6.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/{out_batch_no}/details/out-detail-no/{out_detail_no} * 请求方式:GET * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return details query result * @throws WxPayException the wx pay exception */ DetailsQueryResult queryMerchantDetails(MerchantDetailsQueryRequest request) throws WxPayException; /** * 转账电子回单申请受理API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_7.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt * 请求方式:POST * 接口限频: 单个商户 20QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return electronic bill result * @throws WxPayException the wx pay exception */ ElectronicBillResult applyElectronicBill(ElectronicBillApplyRequest request) throws WxPayException; /** * 查询转账电子回单API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_8.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt/{out_batch_no} * 请求方式:GET * * @param outBatchNo the out batch no * @return electronic bill result * @throws WxPayException the wx pay exception */ ElectronicBillResult queryElectronicBill(String outBatchNo) throws WxPayException; /** * 转账明细电子回单受理API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_9.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer-detail/electronic-receipts * 请求方式:POST * 接口限频: 单个商户 20QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * 前置条件:只支持受理最近30天内的转账明细单 * * @param request the request * @return detail electronic bill result * @throws WxPayException the wx pay exception */ DetailElectronicBillResult applyDetailElectronicBill(DetailElectronicBillRequest request) throws WxPayException; /** * 查询转账明细电子回单受理结果API * <p> * 适用对象:直连商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_10.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer-detail/electronic-receipts * 请求方式:GET * 前置条件:只支持查询最近90天内的转账明细单 * * @param request the request * @return detail electronic bill result * @throws WxPayException the wx pay exception */ DetailElectronicBillResult queryDetailElectronicBill(DetailElectronicBillRequest request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreSignPlanService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreSignPlanService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.bean.payscore.PartnerUserSignPlanEntity; import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanRequest; import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanResult; import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreUserSignPlanResult; import com.github.binarywang.wxpay.exception.WxPayException; import org.checkerframework.checker.nullness.qual.NonNull; /** * @author UltramanNoa * @className PartnerPayScoreSignPlanService * @description 微信支付分签约计划接口 * @createTime 2023/11/3 09:16 * * <pre> * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-pay-score-plan/create-partner-pay-score-plan.html">微信支付分签约计划</a> * <br> * 文档更新时间:2023.10.13 * <br> * 微信支付分签约计划是不同模式的支付分接口(随着国家大力推广教培行业先享后付政策,微信支付也紧跟政策于2023.07.25上线第一版签约计划接口以适用教培行业先享后付。于2023.10.13文档推至官网文档中心) * <br> * 免确认/需确认 用服务商创单接口 {@link PartnerPayScoreService} 需要用户授权 * <br> * 签约计划,用单独创单接口 {@link PartnerPayScoreSignPlanService} 不需要用户授权 * </pre> **/ public interface PartnerPayScoreSignPlanService { /** * <p>description:创建支付分计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 11:58 </p> * <p>version: v.1.0 </p> * * @param request {@link WxPartnerPayScoreSignPlanRequest} * * @return {@link WxPartnerPayScoreSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-pay-score-plan/create-partner-pay-score-plan.html">创建支付分计划</a> **/ WxPartnerPayScoreSignPlanResult createPlans(WxPartnerPayScoreSignPlanRequest request) throws WxPayException; /** * <p>description: 查询支付分计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 14:03 </p> * <p>version: v.1.0 </p> * * @param merchantPlanNo 路径参数:支付分计划商户侧单号 * @param subMchid 子商户号 * * @return {@link WxPartnerPayScoreSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-pay-score-plan/query-partner-pay-score-plan.html">查询支付分计划</a> **/ WxPartnerPayScoreSignPlanResult queryPlans(@NonNull String merchantPlanNo, @NonNull String subMchid) throws WxPayException; /** * <p>description: 停止支付分计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 14:24 </p> * <p>version: v.1.0 </p> * * @param merchantPlanNo 路径参数:支付分计划商户侧单号 * @param subMchid 子商户号 * * @return {@link WxPartnerPayScoreSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-pay-score-plan/stop-partner-pay-score-plan.html">停止支付分计划</a> **/ WxPartnerPayScoreSignPlanResult stopPlans(@NonNull String merchantPlanNo, @NonNull String subMchid) throws WxPayException; /** * <p>description: 创建用户的签约计划详情对应的服务订单 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 14:53 </p> * <p>version: v.1.0 </p> * * @param request {@link WxPartnerPayScoreSignPlanRequest} * * @return {@link WxPartnerPayScoreSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-service-order/create-partner-service-order.html">创建用户的签约计划详情对应的服务订单</a> **/ WxPartnerPayScoreSignPlanResult signPlanServiceOrder(WxPartnerPayScoreSignPlanRequest request) throws WxPayException; /** * <p>description: 创建用户的签约计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 17:48 </p> * <p>version: v.1.0 </p> * * @param request {@link WxPartnerPayScoreSignPlanRequest} * * @return {@link WxPartnerPayScoreUserSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-user-sign-plan/create-partner-user-sign-plan.html">创建用户的签约计划</a> **/ WxPartnerPayScoreUserSignPlanResult createUserSignPlans(WxPartnerPayScoreSignPlanRequest request) throws WxPayException; /** * <p>description: 查询用户的签约计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 18:01 </p> * <p>version: v.1.0 </p> * * @param merchantSignPlanNo 路径参数 商户签约计划号 * @param subMchid 子商户号 * * @return {@link PartnerUserSignPlanEntity} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-user-sign-plan/query-partner-user-sign-plan.html">查询用户的签约计划</a> **/ PartnerUserSignPlanEntity queryUserSignPlans(@NonNull String merchantSignPlanNo, @NonNull String subMchid) throws WxPayException; /** * <p>description: 取消用户的签约计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 18:01 </p> * <p>version: v.1.0 </p> * * @param merchantSignPlanNo 路径参数 商户签约计划号 subMchid – 子商户号 * @param subMchid 子商户号 * @param stopReason 停止签约计划原因 * * @return {@link PartnerUserSignPlanEntity} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-user-sign-plan/stop-partner-user-sign-plan.html">取消用户的签约计划</a> **/ PartnerUserSignPlanEntity stopUserSignPlans(@NonNull String merchantSignPlanNo, @NonNull String subMchid, @NonNull String stopReason) throws WxPayException; /** * <p>description: 回调通知校验解密 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/6 10:27 </p> * <p>version: v.1.0 </p> * @param * @param notifyData * @param header * @return {@link PartnerUserSignPlanEntity} **/ PartnerUserSignPlanEntity parseSignPlanNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BusinessOperationTransferService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BusinessOperationTransferService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.transfer.BusinessOperationTransferRequest; import com.github.binarywang.wxpay.bean.transfer.BusinessOperationTransferResult; import com.github.binarywang.wxpay.bean.transfer.BusinessOperationTransferQueryRequest; import com.github.binarywang.wxpay.bean.transfer.BusinessOperationTransferQueryResult; import com.github.binarywang.wxpay.exception.WxPayException; /** * 运营工具-商家转账API * <p> * 微信支付为商户提供的运营工具转账能力,用于商户的日常运营活动中进行转账操作 * * @author WxJava Team * @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012711988">运营工具-商家转账API</a> */ public interface BusinessOperationTransferService { /** * <pre> * 发起运营工具商家转账 * * 请求方式:POST(HTTPS) * 请求地址:https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012711988">运营工具-商家转账API</a> * </pre> * * @param request 运营工具转账请求参数 * @return BusinessOperationTransferResult 转账结果 * @throws WxPayException 微信支付异常 */ BusinessOperationTransferResult createOperationTransfer(BusinessOperationTransferRequest request) throws WxPayException; /** * <pre> * 查询运营工具转账结果 * * 请求方式:GET(HTTPS) * 请求地址:https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/{out_bill_no} * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012711988">运营工具-商家转账API</a> * </pre> * * @param request 查询请求参数 * @return BusinessOperationTransferQueryResult 查询结果 * @throws WxPayException 微信支付异常 */ BusinessOperationTransferQueryResult queryOperationTransfer(BusinessOperationTransferQueryRequest request) throws WxPayException; /** * <pre> * 通过商户单号查询运营工具转账结果 * * 请求方式:GET(HTTPS) * 请求地址:https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/{out_bill_no} * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012711988">运营工具-商家转账API</a> * </pre> * * @param outBillNo 商户单号 * @return BusinessOperationTransferQueryResult 查询结果 * @throws WxPayException 微信支付异常 */ BusinessOperationTransferQueryResult queryOperationTransferByOutBillNo(String outBillNo) throws WxPayException; /** * <pre> * 通过微信转账单号查询运营工具转账结果 * * 请求方式:GET(HTTPS) * 请求地址:https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills/transfer-bill-no/{transfer_bill_no} * * 文档地址:<a href="https://pay.weixin.qq.com/doc/v3/merchant/4012711988">运营工具-商家转账API</a> * </pre> * * @param transferBillNo 微信转账单号 * @return BusinessOperationTransferQueryResult 查询结果 * @throws WxPayException 微信支付异常 */ BusinessOperationTransferQueryResult queryOperationTransferByTransferBillNo(String transferBillNo) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayrollService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayrollService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.marketing.payroll.*; import com.github.binarywang.wxpay.bean.result.WxPayApplyBillV3Result; import com.github.binarywang.wxpay.exception.WxPayException; /** * 微工卡-对接微信api * * @author xiaoqiang * created on 2021/12/7 14:26 */ public interface PayrollService { /** * 生成授权token * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/tokens * 请求方式:POST * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ TokensResult payrollCardTokens(TokensRequest request) throws WxPayException; /** * 查询微工卡授权关系API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/relations/{openid} * 请求方式:GET * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ RelationsResult payrollCardRelations(RelationsRequest request) throws WxPayException; /** * 微工卡核身预下单API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/authentications/pre-order * 请求方式:POST * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ PreOrderResult payrollCardPreOrder(PreOrderRequest request) throws WxPayException; /** * 获取核身结果API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/authentications/{authenticate_number} * 请求方式:GET * * @param subMchid 子商户号 * @param authenticateNumber 商家核身单号 * @return 返回数据 * @throws WxPayException the wx pay exception */ AuthenticationsResult payrollCardAuthenticationsNumber(String subMchid, String authenticateNumber) throws WxPayException; /** * 查询核身记录API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/authentications * 请求方式:GET * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ AuthRecordResult payrollCardAuthentications(AuthRecordRequest request) throws WxPayException; /** * 微工卡核身预下单(流程中完成授权) * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/authentications/pre-order-with-auth * 请求方式:POST * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ PreOrderWithAuthResult payrollCardPreOrderWithAuth(PreOrderWithAuthRequest request) throws WxPayException; /** * 按日下载提现异常文件API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/merchant/fund/withdraw/bill-type/{bill_type} * 请求方式:GET * * @param billType 账单类型 * NO_SUCC:提现异常账单,包括提现失败和提现退票账单。 * 示例值:NO_SUCC * @param billDate 账单日期 表示所在日期的提现账单,格式为YYYY-MM-DD。 * 例如:2008-01-01日发起的提现,2008-01-03日银行返回提现失败,则该提现数据将出现在bill_date为2008-01-03日的账单中。 * 示例值:2019-08-17 * @return 返回数据 * @throws WxPayException the wx pay exception */ WxPayApplyBillV3Result merchantFundWithdrawBillType(String billType, String billDate, String tarType) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData; import com.github.binarywang.wxpay.bean.payscore.UserAuthorizationStatusNotifyResult; import com.github.binarywang.wxpay.bean.payscore.WxPayScoreRequest; import com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 支付分相关服务类. * 微信支付分是对个人的身份特质、支付行为、使用历史等情况的综合计算分值,旨在为用户提供更简单便捷的生活方式。 * 微信用户可以在具体应用场景中,开通微信支付分。开通后,用户可以在【微信—>钱包—>支付分】中查看分数和使用记录。 * (即需在应用场景中使用过一次,钱包才会出现支付分入口) * * Created by doger.wang on 2020/05/12. * </pre> * * @author doger.wang */ public interface PayScoreService { /** * <pre> * 支付分商户预授权API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions * </pre> * * @param request 请求对象 * @return WxPayScoreResult wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult permissions(WxPayScoreRequest request) throws WxPayException; /** * <pre> * 支付分查询与用户授权记录(授权协议号)API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions/authorization-code/{authorization_code} * </pre> * * @param authorizationCode * @return WxPayScoreResult wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult permissionsQueryByAuthorizationCode(String authorizationCode) throws WxPayException; /** * <pre> * 解除用户授权关系(授权协议号)API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_3.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions/authorization-code/{authorization_code}/terminate * </pre> * * @param authorizationCode * @param reason * @return WxPayScoreResult wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult permissionsTerminateByAuthorizationCode(String authorizationCode,String reason) throws WxPayException; /** * <pre> * 支付分查询与用户授权记录(openid)API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_4shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions/openid/{openid} * </pre> * * @param openId * @return WxPayScoreResult wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult permissionsQueryByOpenId(String openId) throws WxPayException; /** * <pre> * 解除用户授权关系(openid)API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_5.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions/openid/{openid}/terminate * </pre> * * @param openId * @param reason * @return WxPayScoreResult wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult permissionsTerminateByOpenId(String openId,String reason) throws WxPayException; /** * <pre> * 支付分创建订单API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/serviceorder * </pre> * * @param request 请求对象 * @return WxPayScoreResult wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxPayException; /** * <pre> * 支付分查询订单API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/serviceorder * </pre> * * @param outOrderNo the out order no * @param queryId the query id * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException; /** * <pre> * 支付分取消订单API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_3.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/cancel * </pre> * * @param outOrderNo the out order no * @param reason the reason * @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult cancelServiceOrder(String outOrderNo, String reason) throws WxPayException; /** * <pre> * 支付分修改订单金额API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_4.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/modify * </pre> * * @param request the request * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult modifyServiceOrder(WxPayScoreRequest request) throws WxPayException; /** * <pre> * 支付分完结订单API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_5.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/complete * </pre> * * @param request the request * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult completeServiceOrder(WxPayScoreRequest request) throws WxPayException; /** * <pre> * 支付分订单收款API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_6.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/pay * * </pre> * * @param outOrderNo the out order no * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult payServiceOrder(String outOrderNo) throws WxPayException; /** * <pre> * 支付分订单收款API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_7.shtml * 请求URL: https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/sync * </pre> * * @param request the request * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult syncServiceOrder(WxPayScoreRequest request) throws WxPayException; /** * <pre> * 授权/解除授权服务回调数据处理 * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter4_4.shtml * </pre> * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * @return 解密后通知数据 return user authorization status notify result * @throws WxPayException the wx pay exception */ UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * 支付分回调内容解析方法 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml * </pre> * * @param data the data * @return the wx pay score result */ PayScoreNotifyData parseNotifyData(String data,SignatureHeader header) throws WxPayException; /** * <pre> * 支付分回调NotifyData解密resource * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml * </pre> * * @param data the data * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPayScoreResult decryptNotifyDataResource(PayScoreNotifyData data) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerPayScoreService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData; import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreRequest; import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreResult; import com.github.binarywang.wxpay.bean.payscore.WxPartnerUserAuthorizationStatusNotifyResult; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 服务商支付分相关服务类. * 微信支付分是对个人的身份特质、支付行为、使用历史等情况的综合计算分值,旨在为用户提供更简单便捷的生活方式。 * 微信用户可以在具体应用场景中,开通微信支付分。开通后,用户可以在【微信—>钱包—>支付分】中查看分数和使用记录。 * (即需在应用场景中使用过一次,钱包才会出现支付分入口) * * @author hallkk * created on 2022/05/18 */ public interface PartnerPayScoreService { /** * 商户预授权 * @param request {@link WxPartnerPayScoreRequest} 请求对象 * * @return WxPartnerPayScoreResult wx partner payscore result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-auth/apply-partner-permissions.html">商户预授权</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/permissions */ WxPartnerPayScoreResult permissions(WxPartnerPayScoreRequest request) throws WxPayException; /** * 商户查询与用户授权记录 (authorization_code) * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-auth/get-partner-permissions-by-code.html">商户查询与用户授权记录</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/permissions/authorization-code/{authorization_code} * * @param serviceId 服务id * @param subMchid 特约子商户号 * @param authorizationCode 授权协议号 * * @return WxPayScoreResult wx partner payscore result * @throws WxPayException the wx pay exception */ WxPartnerPayScoreResult permissionsQueryByAuthorizationCode(String serviceId, String subMchid, String authorizationCode) throws WxPayException; /** * 商户解除用户授权关系(authorization_code) * * @param serviceId 服务id * @param subMchid 特约子商户号 * @param authorizationCode 授权协议号 * @param reason 撤销原因 * * @return WxPartnerPayScoreResult wx partner payscore result * @throws WxPayException the wx pay exception * @apiNote : <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-auth/terminate-partner-permissions-by-code.html">商户解除用户授权关系</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/permissions/authorization-code/{authorization_code}/terminate */ WxPartnerPayScoreResult permissionsTerminateByAuthorizationCode(String serviceId, String subMchid, String authorizationCode, String reason) throws WxPayException; /** * 商户查询与用户授权记录(OpenID) * * @param serviceId 服务id * @param subMchid 特约子商户号 * @param appId 服务商的公众号ID * @param subAppid 子商户的公众号ID * @param openId 服务商的用户标识 * @param subOpenid 子商户的用户标识 * * @return WxPayScoreResult wx partner payscore result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-auth/get-partner-permissions-by-open-id.html">商户查询与用户授权记录</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/permissions/search */ WxPartnerPayScoreResult permissionsQueryByOpenId(String serviceId, String appId, String subMchid, String subAppid, String openId, String subOpenid) throws WxPayException; /** * 商户解除用户授权关系API(OpenID) * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-auth/terminate-partner-permissions-by-open-id.html">商户解除用户授权关系API</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/permissions/terminate * * @param serviceId 服务id * @param subMchid 特约子商户号 * @param appId 服务商的公众号ID * @param subAppid 子商户的公众号ID * @param openId 服务商的用户标识 * @param subOpenid 子商户的用户标识 * @param reason 取消理由 * @return WxPayScoreResult wx partner payscore result * @throws WxPayException the wx pay exception */ WxPartnerPayScoreResult permissionsTerminateByOpenId(String serviceId, String appId, String subMchid, String subAppid, String openId, String subOpenid, String reason) throws WxPayException; /** * 支付分创建订单API. * * @param request 请求对象 * * @return WxPayScoreResult wx partner payscore result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-order/create-partner-service-order.html">创建订单</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/serviceorder */ WxPartnerPayScoreResult createServiceOrder(WxPartnerPayScoreRequest request) throws WxPayException; /** * 支付分查询订单API. * * @param serviceId 服务ID * @param subMchid 子商户商户号 * @param outOrderNo 商户订单号 * @param queryId 单据查询ID * * @return the wx pay score result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-order/get-partner-service-order.html">查询订单</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/serviceorder */ WxPartnerPayScoreResult queryServiceOrder(String serviceId, String subMchid, String outOrderNo, String queryId) throws WxPayException; /** * 支付分取消订单API. * * @param serviceId 服务ID * @param subMchid 子商户商户号 * @param outOrderNo 商户订单号 * @param reason 撤销原因 * * @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult wx pay score result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-order/cancel-partner-service-order.html">取消订单</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/serviceorder/{out_order_no}/cancel */ WxPartnerPayScoreResult cancelServiceOrder(String serviceId, String appId, String subMchid, String outOrderNo, String reason) throws WxPayException; /** * 支付分修改订单金额API. * * @param request the request * * @return the wx pay score result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-order/modify-partner-service-order.html">修改订单金额</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/serviceorder/{out_order_no}/modify */ WxPartnerPayScoreResult modifyServiceOrder(WxPartnerPayScoreRequest request) throws WxPayException; /** * 支付分完结订单API. * * @param request the request * * @return the wx pay score result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-order/complete-partner-service-order.html">完结订单</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/serviceorder/{out_order_no}/complete */ void completeServiceOrder(WxPartnerPayScoreRequest request) throws WxPayException; /** * 订单收款 * * @param serviceId 服务ID * @param subMchid 子商户商户号 * @param outOrderNo 商户订单号 * * @return the wx pay score result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-order/collect-partner-service-order.html">订单收款</a> * 请求URL:https://api.mch.weixin.qq.com/v3/payscore/partner/serviceorder/{out_order_no}/pay */ WxPartnerPayScoreResult payServiceOrder(String serviceId, String appId, String subMchid, String outOrderNo) throws WxPayException; /** * 同步订单信息 * * @param request the request * * @return the wx pay score result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/partner-service-order/sync-partner-service-order.html">同步订单信息</a> * 请求URL: https://api.mch.weixin.qq.com/v3/payscore/partner/serviceorder/{out_order_no}/sync */ WxPartnerPayScoreResult syncServiceOrder(WxPartnerPayScoreRequest request) throws WxPayException; /** * <pre> * 收付通子商户申请绑定支付分服务API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore_partner/chapter9_1.shtml * 请求URL: https://api.mch.weixin.qq.com/v3/payscore/partner/service-account-applications * </pre> * * @param request the request * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPartnerPayScoreResult applyServiceAccount(WxPartnerPayScoreRequest request) throws WxPayException; /** * <pre> * 查询收付通子商户服务绑定结果API. * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore_partner/chapter9_2.shtml * 请求URL: https://api.mch.weixin.qq.com/v3/payscore/partner/service-account-applications/{out_apply_no} * </pre> * * @param outApplyNo 商户申请绑定单号 * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPartnerPayScoreResult queryServiceAccountState(String outApplyNo) throws WxPayException; /** * 授权/解除授权服务回调通知 * * @param notifyData 通知数据 * @param header 通知头部数据,不传则表示不校验头 * * @return 解密后通知数据 return user authorization status notify result * @throws WxPayException the wx pay exception * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-weixin-pay-score/authorization-de-authorization-service-callback-notification.html">授权/解除授权服务回调通知</a> */ WxPartnerUserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * 支付分回调内容解析方法 * * @param data the data * @return the wx pay score result */ PayScoreNotifyData parseNotifyData(String data, SignatureHeader header) throws WxPayException; /** * 支付分回调NotifyData解密resource * * @param data the data * @return the wx pay score result * @throws WxPayException the wx pay exception */ WxPartnerPayScoreResult decryptNotifyDataResource(PayScoreNotifyData data) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/SubscriptionBillingService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/SubscriptionBillingService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.subscriptionbilling.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * 微信支付-预约扣费服务 (连续包月功能) * <pre> * 微信支付预约扣费功能,支持商户在用户授权的情况下, * 按照约定的时间和金额,自动从用户的支付账户中扣取费用。 * 主要用于连续包月、订阅服务等场景。 * * 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012161105 * </pre> * * @author Binary Wang * created on 2024-08-31 */ public interface SubscriptionBillingService { /** * 预约扣费 * <pre> * 商户可以通过该接口预约未来某个时间点的扣费。 * 适用于连续包月、订阅服务等场景。 * * 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012161105 * 请求URL: https://api.mch.weixin.qq.com/v3/subscription-billing/schedule * 请求方式: POST * 是否需要证书: 是 * </pre> * * @param request 预约扣费请求参数 * @return 预约扣费结果 * @throws WxPayException 微信支付异常 */ SubscriptionScheduleResult scheduleSubscription(SubscriptionScheduleRequest request) throws WxPayException; /** * 查询预约扣费 * <pre> * 商户可以通过该接口查询已预约的扣费信息。 * * 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012161105 * 请求URL: https://api.mch.weixin.qq.com/v3/subscription-billing/schedule/{subscription_id} * 请求方式: GET * </pre> * * @param subscriptionId 预约扣费ID * @return 预约扣费查询结果 * @throws WxPayException 微信支付异常 */ SubscriptionQueryResult querySubscription(String subscriptionId) throws WxPayException; /** * 取消预约扣费 * <pre> * 商户可以通过该接口取消已预约的扣费。 * * 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012161105 * 请求URL: https://api.mch.weixin.qq.com/v3/subscription-billing/schedule/{subscription_id}/cancel * 请求方式: POST * 是否需要证书: 是 * </pre> * * @param request 取消预约扣费请求参数 * @return 取消预约扣费结果 * @throws WxPayException 微信支付异常 */ SubscriptionCancelResult cancelSubscription(SubscriptionCancelRequest request) throws WxPayException; /** * 立即扣费 * <pre> * 商户可以通过该接口立即执行扣费操作。 * 通常用于补扣失败的费用或者特殊情况下的即时扣费。 * * 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012161105 * 请求URL: https://api.mch.weixin.qq.com/v3/subscription-billing/instant-billing * 请求方式: POST * 是否需要证书: 是 * </pre> * * @param request 立即扣费请求参数 * @return 立即扣费结果 * @throws WxPayException 微信支付异常 */ SubscriptionInstantBillingResult instantBilling(SubscriptionInstantBillingRequest request) throws WxPayException; /** * 查询扣费记录 * <pre> * 商户可以通过该接口查询扣费记录。 * * 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012161105 * 请求URL: https://api.mch.weixin.qq.com/v3/subscription-billing/transactions * 请求方式: GET * </pre> * * @param request 查询扣费记录请求参数 * @return 扣费记录查询结果 * @throws WxPayException 微信支付异常 */ SubscriptionTransactionQueryResult queryTransactions(SubscriptionTransactionQueryRequest request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/Apply4SubjectConfirmService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/Apply4SubjectConfirmService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.applyconfirm.ApplySubjectConfirmCreateRequest; import com.github.binarywang.wxpay.bean.applyconfirm.ApplySubjectConfirmCreateResult; import com.github.binarywang.wxpay.bean.applyconfirm.ApplySubjectConfirmMerchantStateQueryResult; import com.github.binarywang.wxpay.bean.applyconfirm.ApplySubjectConfirmStateQueryResult; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 商户开户意愿确认 * 产品文档:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter6_1_1.shtml">商户开户意愿确认流程</a> * </pre> * * @author <a href="https://github.com/wslongchen">Mr.Pan</a> */ public interface Apply4SubjectConfirmService { /** * <pre> * 提交申请单 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_1.shtml">间连商户开户意愿确认(提交申请单)</a> * </pre> * * @param request 申请请求参数 * @return 审核结果 * @throws WxPayException 异常 */ ApplySubjectConfirmCreateResult applyment(ApplySubjectConfirmCreateRequest request) throws WxPayException; /** * * <pre> * 查询申请单审核结果 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_3.shtml">查询申请单审核结果</a> * </pre> * * @param businessCode 业务申请编号 * @return 审核结果 * @throws WxPayException 异常 */ ApplySubjectConfirmStateQueryResult queryApplyStatusByBusinessCode(String businessCode) throws WxPayException; /** * * <pre> * 查询申请单审核结果 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_3.shtml">查询申请单审核结果</a> * </pre> * * @param applymentId 申请编号 * @return 审核结果 * @throws WxPayException 异常 */ ApplySubjectConfirmStateQueryResult queryApplyStatusByApplymentId(String applymentId) throws WxPayException; /** * * <pre> * 获取商户开户意愿确认状态 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_4.shtml">获取商户开户意愿确认状态API</a> * </pre> * * @param subMchId 微信支付分配的特约商户的唯一标识。 * @return 确认状态结果 * @throws WxPayException 异常 */ ApplySubjectConfirmMerchantStateQueryResult queryMerchantApplyStatusByMchId(String subMchId) throws WxPayException; /** * * <pre> * 撤销申请单 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_2.shtml">撤销申请单API</a> * </pre> * * @param businessCode 业务申请编号 * @throws WxPayException 异常 */ void cancelApplyByBusinessCode(String businessCode) throws WxPayException; /** * * <pre> * 撤销申请单 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_2.shtml">撤销申请单API</a> * </pre> * * @param applymentId 申请编号 * @throws WxPayException 异常 */ void cancelApplyByApplymentId(String applymentId) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerTransferService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerTransferService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.ecommerce.FundBalanceResult; import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum; import com.github.binarywang.wxpay.bean.marketing.transfer.*; import com.github.binarywang.wxpay.exception.WxPayException; import javax.crypto.BadPaddingException; import java.io.InputStream; /** * 微信批量转账到零钱【V3接口】服务商API * * @author xiaoqiang * created on 2021-12-06 */ public interface PartnerTransferService { /** * 发起批量转账API * 适用对象:服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter3_1.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches * 请求方式:POST * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request 请求对象 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ PartnerTransferResult batchTransfer(PartnerTransferRequest request) throws WxPayException; /** * 微信支付批次单号查询批次单API * 接口说明 * 适用对象:服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter3_2.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches/batch-id/{batch_id} * 请求方式:GET * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request 请求对象 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ BatchNumberResult queryBatchByBatchId(BatchNumberRequest request) throws WxPayException; /** * 微信支付明细单号查询明细单API * 接口说明 * 适用对象:服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter3_3.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches/batch-id/{batch_id}/details/detail-id/{detail_id} * 请求方式:GET * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param batchId 微信批次单号 * @param detailId 微信明细单号 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception * @throws BadPaddingException the wx decrypt exception */ BatchDetailsResult queryBatchDetailByWeChat(String batchId, String detailId) throws WxPayException, BadPaddingException; /** * 商家批次单号查询批次单API * 接口说明 * 适用对象:服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter3_4.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches/out-batch-no/{out_batch_no} * 请求方式:GET * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request 请求对象 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ BatchNumberResult queryBatchByOutBatchNo(MerchantBatchRequest request) throws WxPayException; /** * 商家明细单号查询明细单API * 接口说明 * 适用对象:服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter3_5.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches/out-batch-no/{out_batch_no}/details/out-detail-no/{out_detail_no} * 请求方式:GET * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param outBatchNo 商家明细单号 * @param outDetailNo 商家批次单号 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception * @throws BadPaddingException the wx decrypt exception */ BatchDetailsResult queryBatchDetailByMch(String outBatchNo, String outDetailNo) throws WxPayException, BadPaddingException; /** * 转账电子回单申请受理API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_1.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt * 请求方式:POST * * @param request 商家批次单号 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ BillReceiptResult receiptBill(ReceiptBillRequest request) throws WxPayException; /** * 查询转账电子回单API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_2.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt/{out_batch_no} * 请求方式:GET * * @param outBatchNo 商家批次单号 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ BillReceiptResult queryBillReceipt(String outBatchNo) throws WxPayException; /** * 转账明细电子回单受理API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_4.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer-detail/electronic-receipts * 请求方式:POST * 前置条件:只支持受理最近90天内的转账明细单 * * @param request 请求对象 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ ElectronicReceiptsResult transferElectronic(ElectronicReceiptsRequest request) throws WxPayException; /** * 查询转账明细电子回单受理结果API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_5.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer-detail/electronic-receipts * 请求方式:GET * 前置条件:只支持查询最近90天内的转账明细单 * * @param request 请求对象 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ ElectronicReceiptsResult queryTransferElectronicResult(ElectronicReceiptsRequest request) throws WxPayException; /** * 下载电子回单API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_3.shtml * 请求URL:通过申请账单接口获取到“download_url”,URL有效期10min * 请求方式:GET * 前置条件:调用申请账单接口并获取到“download_url” * * @param url 微信返回的电子回单地址。 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ InputStream transferDownload(String url) throws WxPayException; /** * <pre> * 查询账户实时余额API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter5_1.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/merchant/fund/balance/{account_type} * 请求方式:GET * </pre> * * @param accountType 服务商账户类型 {@link SpAccountTypeEnum} * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ FundBalanceResult fundBalance(SpAccountTypeEnum accountType) throws WxPayException; /** * <pre> * 服务商账户日终余额 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter5_2.shtml * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml * </pre> * * @param accountType 服务商账户类型 * @param date 查询日期 2020-09-11 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date); }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MarketingFavorService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MarketingFavorService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.bean.marketing.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 微信支付营销代金券接口 * </pre> * * @author thinsstar */ public interface MarketingFavorService { /** * <pre> * 代金券接口-创建代金券批次API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/coupon-stocks * </pre> * * @param request 请求对象 * @return FavorStocksResult 微信返回的批次号信息。 * @throws WxPayException the wx pay exception */ FavorStocksCreateResult createFavorStocksV3(FavorStocksCreateRequest request) throws WxPayException; /** * <pre> * 代金券接口-发放代金券API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/users/{openid}/coupons * </pre> * * @param openid 用户openid * @param request 请求对象 * @return FavorStocksResult 微信返回的发放结果信息。 * @throws WxPayException the wx pay exception */ FavorCouponsCreateResult createFavorCouponsV3(String openid, FavorCouponsCreateRequest request) throws WxPayException; /** * <pre> * 代金券接口-激活代金券批次API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_3.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/{stock_id}/start * </pre> * * @param stockId 批次号 * @param request 请求对象 * @return FavorStocksStartResult 微信返回的激活信息。 * @throws WxPayException the wx pay exception */ FavorStocksStartResult startFavorStocksV3(String stockId, FavorStocksSetRequest request) throws WxPayException; /** * <pre> * 代金券接口-条件查询代金券批次列表API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_4.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks * </pre> * * @param request 请求对象 * @return FavorStocksQueryResult 微信返回的批次列表信息。 * @throws WxPayException the wx pay exception */ FavorStocksQueryResult queryFavorStocksV3(FavorStocksQueryRequest request) throws WxPayException; /** * <pre> * 代金券接口-查询批次详情API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_5.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/{stock_id} * </pre> * * @param stockId 批次号 * @param stockCreatorMchid 创建批次的商户号 * @return FavorStocksQueryResult 微信返回的批次详情信息。 * @throws WxPayException the wx pay exception */ FavorStocksGetResult getFavorStocksV3(String stockId, String stockCreatorMchid) throws WxPayException; /** * <pre> * 代金券接口-查询代金券详情API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_6.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/users/{openid}/coupons/{coupon_id} * </pre> * * @param couponId 代金券id * @param appid 公众账号ID * @param openid 用户openid * @return FavorCouponsGetResult 微信返回的代金券详情信息。 * @throws WxPayException the wx pay exception */ FavorCouponsGetResult getFavorCouponsV3(String couponId, String appid, String openid) throws WxPayException; /** * <pre> * 代金券接口-查询代金券可用商户API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_7.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/{stock_id}/merchants * </pre> * * @param stockId 批次号 * @param stockCreatorMchid 创建批次的商户号 * @param offset 分页大小 * @param limit 创建批次的商户号 * @return FavorStocksMerchantsGetResult 微信返回的代金券可用商户信息。 * @throws WxPayException the wx pay exception */ FavorStocksMerchantsGetResult getFavorStocksMerchantsV3(String stockId, String stockCreatorMchid, Integer offset, Integer limit) throws WxPayException; /** * <pre> * 代金券接口-查询代金券可用单品API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_8.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/{stock_id}/items * </pre> * * @param stockId 批次号 * @param stockCreatorMchid 创建批次的商户号 * @param offset 分页大小 * @param limit 创建批次的商户号 * @return FavorStocksItemsGetResult 微信返回的代金券可用单品信息。 * @throws WxPayException the wx pay exception */ FavorStocksItemsGetResult getFavorStocksItemsV3(String stockId, String stockCreatorMchid, Integer offset, Integer limit) throws WxPayException; /** * <pre> * 代金券接口-根据商户号查用户的券API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_9.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/users/{openid}/coupons * </pre> * * @param request 请求对象 * @return FavorCouponsQueryResult 微信返回的用户的券信息。 * @throws WxPayException the wx pay exception */ FavorCouponsQueryResult queryFavorCouponsV3(FavorCouponsQueryRequest request) throws WxPayException; /** * <pre> * 代金券接口-下载批次核销明细API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_10.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/{stock_id}/use-flow * </pre> * * @param stockId 批次号 * @return FavorStocksFlowGetResult 微信返回的下载信息。 * @throws WxPayException the wx pay exception */ FavorStocksFlowGetResult getFavorStocksUseFlowV3(String stockId) throws WxPayException; /** * <pre> * 代金券接口-下载批次退款明细API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_11.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/{stock_id}/refund-flow * </pre> * * @param stockId 批次号 * @return FavorStocksFlowGetResult 微信返回的下载信息。 * @throws WxPayException the wx pay exception */ FavorStocksFlowGetResult getFavorStocksRefundFlowV3(String stockId) throws WxPayException; /** * <pre> * 代金券接口-设置消息通知地址API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_12.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/callbacks * </pre> * * @param request 请求对象 * @return FavorCallbacksSaveResult 微信返回的结果信息。 * @throws WxPayException the wx pay exception */ FavorCallbacksSaveResult saveFavorCallbacksV3(FavorCallbacksSaveRequest request) throws WxPayException; /** * <pre> * 代金券接口-暂停代金券批次API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_13.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/{stock_id}/pause * </pre> * * @param request 请求对象 * @return FavorStocksPauseResult 微信返回的结果信息。 * @throws WxPayException the wx pay exception */ FavorStocksPauseResult pauseFavorStocksV3(String stockId, FavorStocksSetRequest request) throws WxPayException; /** * <pre> * 代金券接口-重启代金券批次API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/marketing/convention/chapter3_14.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/{stock_id}/restart * </pre> * * @param request 请求对象 * @return FavorStocksRestartResult 微信返回的结果信息。 * @throws WxPayException the wx pay exception */ FavorStocksRestartResult restartFavorStocksV3(String stockId, FavorStocksSetRequest request) throws WxPayException; UseNotifyData parseNotifyData(String data, SignatureHeader header) throws WxPayException; FavorCouponsUseResult decryptNotifyDataResource(UseNotifyData data) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BrandMerchantTransferService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BrandMerchantTransferService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.request.*; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandBatchesQueryResult; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandDetailsQueryResult; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandTransferBatchesResult; import com.github.binarywang.wxpay.exception.WxPayException; /** * 品牌商户发放红包商家转账到零钱(直联商户) * * @author moran */ public interface BrandMerchantTransferService { /** * 品牌商户发放红包API * <p> * 适用对象:直连商户 * 文档详见: * 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/brand-redpacket/brand-merchant-batches * 请求方式:POST * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * 是否需要证书:是 * * @param request the request * @return transfer create result * @throws WxPayException the wx pay exception */ BrandTransferBatchesResult createBrandTransfer(BrandTransferBatchesRequest request) throws WxPayException; /** * 品牌红包微信批次单号查询批次单API * <p> * 适用对象:直连商户 * 文档详见: * 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/brand-redpacket/brand-merchant-batches/{batch_no} * 请求方式:GET * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return batches query result * @throws WxPayException the wx pay exception */ BrandBatchesQueryResult queryBrandWxBatches(BrandWxBatchesQueryRequest request) throws WxPayException; /** * 品牌红包微信支付明细单号查询明细单API * <p> * 适用对象:直连商户 * 文档详见: * 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/brand-redpacket/brand-merchant-batches/{batch_no}/details/{detail_no} * 请求方式:GET * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return details query result * @throws WxPayException the wx pay exception */ BrandDetailsQueryResult queryBrandWxDetails(BrandWxDetailsQueryRequest request) throws WxPayException; /** * 品牌红包商家批次单号查询批次单API * <p> * 适用对象:直连商户 * 文档详见: * 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/brand-redpacket/brand-merchant-out-batches/{out_batch_no} * 请求方式:GET * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return batches query result * @throws WxPayException the wx pay exception */ BrandBatchesQueryResult queryBrandMerchantBatches(BrandMerchantBatchesQueryRequest request) throws WxPayException; /** * 品牌红包商家明细单号查询明细单API * <p> * 适用对象:直连商户 * 文档详见: * 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/brand-redpacket/brand-merchant-out-batches/{out_batch_no}/out-details/{out_detail_no} * 请求方式:GET * 接口限频: 单个商户 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request the request * @return details query result * @throws WxPayException the wx pay exception */ BrandDetailsQueryResult queryBrandMerchantDetails(BrandMerchantDetailsQueryRequest request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ComplaintService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ComplaintService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.complaint.*; import com.github.binarywang.wxpay.bean.media.ImageUploadResult; import com.github.binarywang.wxpay.exception.WxPayException; import javax.crypto.BadPaddingException; import java.io.File; import java.io.IOException; import java.io.InputStream; /** * <pre> * 微信支付 消费者投诉2.0 API. * Created by jmdhappy on 2022/3/19. * </pre> * * @author <a href="https://gitee.com/jeequan/jeepay">jmdhappy</a> */ public interface ComplaintService { /** * <pre> * 查询投诉单列表API * 商户可通过调用此接口,查询指定时间段的所有用户投诉信息,以分页输出查询结果。 * 对于服务商、渠道商,可通过调用此接口,查询指定子商户号对应子商户的投诉信息,若不指定则查询所有子商户投诉信息。 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_11.shtml">...</a> * </pre> * * @param request {@link ComplaintRequest} 查询投诉单列表请求数据 * @return {@link ComplaintResult} 微信返回的投诉单列表 * @throws WxPayException the wx pay exception * @throws BadPaddingException . */ ComplaintResult queryComplaints(ComplaintRequest request) throws WxPayException, BadPaddingException; /** * <pre> * 查询投诉单详情API * 商户可通过调用此接口,查询指定投诉单的用户投诉详情,包含投诉内容、投诉关联订单、投诉人联系方式等信息,方便商户处理投诉。 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_13.shtml">...</a> * </pre> * * @param request {@link ComplaintDetailRequest} 投诉单详情请求数据 * @return {@link ComplaintDetailResult} 微信返回的投诉单详情 * @throws WxPayException the wx pay exception * @throws BadPaddingException . */ ComplaintDetailResult getComplaint(ComplaintDetailRequest request) throws WxPayException, BadPaddingException; /** * <pre> * 查询投诉协商历史API * 商户可通过调用此接口,查询指定投诉的用户商户协商历史,以分页输出查询结果,方便商户根据处理历史来制定后续处理方案。 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_12.shtml">...</a> * </pre> * * @param request {@link NegotiationHistoryRequest} 请求数据 * @return {@link NegotiationHistoryResult} 微信返回结果 * @throws WxPayException the wx pay exception */ NegotiationHistoryResult queryNegotiationHistorys(NegotiationHistoryRequest request) throws WxPayException; /** * <pre> * 创建投诉通知回调地址API * 商户通过调用此接口创建投诉通知回调URL,当用户产生新投诉且投诉状态已变更时,微信支付会通过回 调URL通知商户。对于服务商、渠道商,会收到所有子商户的投诉信息推送。 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_2.shtml">...</a> * </pre> * * @param request {@link ComplaintDetailRequest} 请求数据 * @return {@link ComplaintNotifyUrlResult} 微信返回结果 * @throws WxPayException the wx pay exception */ ComplaintNotifyUrlResult addComplaintNotifyUrl(ComplaintNotifyUrlRequest request) throws WxPayException; /** * <pre> * 查询投诉通知回调地址API * 商户通过调用此接口查询投诉通知的回调URL。 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_3.shtml">...</a> * </pre> * * @return {@link ComplaintNotifyUrlResult} 微信返回结果 * @throws WxPayException the wx pay exception */ ComplaintNotifyUrlResult getComplaintNotifyUrl() throws WxPayException; /** * <pre> * 更新投诉通知回调地址API * 商户通过调用此接口更新投诉通知的回调URL。 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_4.shtml">...</a> * </pre> * * @param request {@link ComplaintDetailRequest} 请求数据 * @return {@link ComplaintNotifyUrlResult} 微信返回结果 * @throws WxPayException the wx pay exception */ ComplaintNotifyUrlResult updateComplaintNotifyUrl(ComplaintNotifyUrlRequest request) throws WxPayException; /** * <pre> * 删除投诉通知回调地址API * 当商户不再需要推送通知时,可通过调用此接口删除投诉通知的回调URL,取消通知回调。 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_5.shtml">...</a> * </pre> * * @throws WxPayException the wx pay exception */ void deleteComplaintNotifyUrl() throws WxPayException; /** * <pre> * 提交回复API * 商户可通过调用此接口,提交回复内容。其中上传图片凭证需首先调用商户上传反馈图片接口,得到图片id,再将id填入请求。 * 回复可配置文字链,传入跳转链接文案和跳转链接字段,用户点击即可跳转对应页面 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_14.shtml">...</a> * </pre> * * @param request {@link ResponseRequest} 请求数据 * @throws WxPayException the wx pay exception */ void submitResponse(ResponseRequest request) throws WxPayException; /** * <pre> * 反馈处理完成API * 商户可通过调用此接口,反馈投诉单已处理完成。 * 文档详见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_15.shtml">...</a> * </pre> * * @param request {@link CompleteRequest} 请求数据 * @throws WxPayException the wx pay exception */ void complete(CompleteRequest request) throws WxPayException; /** * <pre> * 更新退款审批结果API * 针对“申请退款单”,需要商户明确返回是否可退款的审批结果。 * 若根据用户描述,核实可以退款,审批动作传入“APPROVE”,同意退款,并给出一个预计退款时间。传入“同意退款”后,需要额外调退款接口发起原路退款。退款到账后,投诉单的状态将自动扭转为“处理完成”。 * 若根据用户描述,核实不能退款,审批动作传入“REJECT”,拒绝退款,并说明拒绝退款原因。驳回退款后,投诉单的状态将自动扭转为“处理完成”。 * 文档详见: <a href="https://pay.wechatpay.cn/docs/merchant/apis/consumer-complaint/complaints/update-refund-progress.html">...</a> * </pre> * * @param request {@link UpdateRefundProgressRequest} 请求数据 * @throws WxPayException the wx pay exception */ void updateRefundProgress(UpdateRefundProgressRequest request) throws WxPayException; /** * <pre> * 商户上传反馈图片API * 文档详见: <a href="https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/images/create-images.html">...</a> * 接口链接:https://api.mch.weixin.qq.com/v3/merchant-service/images/upload * </pre> * * @param imageFile 需要上传的图片文件 * @return ImageUploadResult 微信返回的媒体文件标识Id。示例值:BB04A5DEEFEA18D4F2554C1EDD3B610B.bmp * @throws WxPayException the wx pay exception */ ImageUploadResult uploadResponseImage(File imageFile) throws WxPayException, IOException; /** * <pre> * 商户上传反馈图片API * 文档详见: <a href="https://pay.weixin.qq.com/docs/merchant/apis/consumer-complaint/images/create-images.html">...</a> * 接口链接:https://api.mch.weixin.qq.com/v3/merchant-service/images/upload * </pre> * * @param inputStream 需要上传的图片文件流 * @param fileName 需要上传的图片文件名 * @return ImageUploadResult 微信返回的媒体文件标识Id。示例值:BB04A5DEEFEA18D4F2554C1EDD3B610B.bmp * @throws WxPayException the wx pay exception */ ImageUploadResult uploadResponseImage(InputStream inputStream, String fileName) throws WxPayException, IOException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RedpackService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RedpackService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest; import com.github.binarywang.wxpay.bean.request.WxPaySendMiniProgramRedpackRequest; import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest; import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult; import com.github.binarywang.wxpay.bean.result.WxPaySendMiniProgramRedpackResult; import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult; import com.github.binarywang.wxpay.exception.WxPayException; /** * 红包相关接口. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2019-12-26 */ public interface RedpackService { /** * <pre> * 发送小程序红包. * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/tools/miniprogram_hb.php?chapter=13_9&index=2 * 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendminiprogramhb * </pre> * * @param request 请求对象 * @return the result * @throws WxPayException the exception */ WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException; /** * 发送微信红包给个人用户. * <pre> * 文档详见: * 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3 * 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack * 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4 * 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack * </pre> * * @param request 请求对象 * @return the wx pay send redpack result * @throws WxPayException the wx pay exception */ WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException; /** * <pre> * 查询红包记录. * 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。 * 请求Url:https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo * 是否需要证书:是(证书及使用说明详见商户证书) * 请求方式:POST * </pre> * * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 * @return the wx pay redpack query result * @throws WxPayException the wx pay exception */ WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException; /** * <pre> * 查询红包记录. * 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。 * 请求Url:https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo * 是否需要证书:是(证书及使用说明详见商户证书) * 请求方式:POST * </pre> * * @param request 红包查询请求 * @return the wx pay redpack query result * @throws WxPayException the wx pay exception */ WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MarketingBusiFavorService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MarketingBusiFavorService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.marketing.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 微信支付营销商家券接口 * </pre> * * @author yujam */ public interface MarketingBusiFavorService { /** * <pre> * 商家券接口-创建商家券API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks * </pre> * * @param request 请求对象 {@link BusiFavorStocksCreateRequest} * @return FavorStocksResult 微信返回的批次号信息。 * @throws WxPayException the wx pay exception */ BusiFavorStocksCreateResult createBusiFavorStocksV3(BusiFavorStocksCreateRequest request) throws WxPayException; /** * <pre> * 商家券接口-查询商家券详情API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id} * </pre> * * @param stockId 微信为每个商家券批次分配的唯一ID * @return BusiFavorStocksGetResult 微信返回的批次号信息。 {@link BusiFavorStocksGetResult} * @throws WxPayException the wx pay exception */ BusiFavorStocksGetResult getBusiFavorStocksV3(String stockId) throws WxPayException; /** * <pre> * 商家券接口-核销用户券API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_3.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/use * </pre> * * @param request 请求对象 {@link BusiFavorCouponsUseRequest} * @return BusiFavorCouponsUseResult 微信返回的信息。 * @throws WxPayException the wx pay exception */ BusiFavorCouponsUseResult verifyBusiFavorCouponsUseV3(BusiFavorCouponsUseRequest request) throws WxPayException; /** * <pre> * 商家券接口-H5发券API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_4_1.shtml * 接口链接:https://action.weixin.qq.com/busifavor/getcouponinfo * </pre> * * @param request 请求对象 {@link BusiFavorCouponsUrlRequest} * @return String H5领券地址 * @throws WxPayException the wx pay exception */ String buildBusiFavorCouponinfoUrl(BusiFavorCouponsUrlRequest request) throws WxPayException; /** * <pre> * 商家券接口-根据过滤条件查询用户券API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_4.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/{openid}/coupons * </pre> * * @param request 请求对象 {@link BusiFavorQueryUserCouponsRequest} * @return BusiFavorQueryUserCouponsResult * @throws WxPayException the wx pay exception */ BusiFavorQueryUserCouponsResult queryBusiFavorUsersCoupons(BusiFavorQueryUserCouponsRequest request) throws WxPayException; /** * <pre> * 商家券接口-查询用户单张券详情API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_5.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/{openid}/coupons/{coupon_code}/appids/{appid} * </pre> * * @param request 请求对象 {@link BusiFavorQueryOneUserCouponsResult} * @return BusiFavorQueryOneUserCouponsRequest * @throws WxPayException the wx pay exception */ BusiFavorQueryOneUserCouponsResult queryOneBusiFavorUsersCoupons(BusiFavorQueryOneUserCouponsRequest request) throws WxPayException; /** * <pre> * 商家券接口-上传预存code API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_6.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id}/couponcodes * </pre> * * @param stockId 批次号 * @param request 请求对象 {@link BusiFavorCouponCodeRequest} * @return BusiFavorCouponCodeResult * @throws WxPayException the wx pay exception */ BusiFavorCouponCodeResult uploadBusiFavorCouponCodes(String stockId, BusiFavorCouponCodeRequest request) throws WxPayException; /** * <pre> * 商家券接口-设置商家券事件通知地址 API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_7.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks * </pre> * * @param request 请求对象 {@link BusiFavorCallbacksRequest} * @return BusiFavorCallbacksResult * @throws WxPayException the wx pay exception */ BusiFavorCallbacksResult createBusiFavorCallbacks(BusiFavorCallbacksRequest request) throws WxPayException; /** * <pre> * 商家券接口-查询商家券事件通知地址 API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_8.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks * </pre> * * @param request 请求对象 {@link BusiFavorCallbacksRequest} * @return BusiFavorCallbacksResult * @throws WxPayException the wx pay exception */ BusiFavorCallbacksResult queryBusiFavorCallbacks(BusiFavorCallbacksRequest request) throws WxPayException; /** * <pre> * 商家券接口-关联订单信息 API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_9.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/associate * </pre> * * @param request 请求对象 {@link BusiFavorCouponsAssociateRequest} * @return BusiFavorCouponsAssociateResult * @throws WxPayException the wx pay exception */ BusiFavorCouponsAssociateResult queryBusiFavorCouponsAssociate(BusiFavorCouponsAssociateRequest request) throws WxPayException; /** * <pre> * 商家券接口-取消关联订单信息 API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_10.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/disassociate * </pre> * * @param request 请求对象 {@link BusiFavorCouponsAssociateRequest} * @return BusiFavorCouponsAssociateResult * @throws WxPayException the wx pay exception */ BusiFavorCouponsAssociateResult queryBusiFavorCouponsDisAssociate(BusiFavorCouponsAssociateRequest request) throws WxPayException; /** * <pre> * 商家券接口-修改批次预算 API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_11.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id}/budget * </pre> * * @param stockId 批次号 * @param request 请求对象 {@link BusiFavorStocksBudgetRequest} * @return BusiFavorStocksBudgetResult * @throws WxPayException the wx pay exception */ BusiFavorStocksBudgetResult updateBusiFavorStocksBudget(String stockId, BusiFavorStocksBudgetRequest request) throws WxPayException; /** * <pre> * 商家券接口-创建商家券API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_12.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id} * </pre> * * @param stockId 批次号 * @param request 请求对象 {@link BusiFavorStocksCreateRequest} * @return String 处理成功 应答无内容。 * @throws WxPayException the wx pay exception */ String updateBusiFavorStocksV3(String stockId, BusiFavorStocksCreateRequest request) throws WxPayException; /** * <pre> * 商家券接口-申请退款API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_13.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/return * </pre> * * @param request 请求对象 {@link BusiFavorCouponsReturnRequest} * @return BusiFavorCouponsReturnResult * @throws WxPayException the wx pay exception */ BusiFavorCouponsReturnResult returnBusiFavorCoupons(BusiFavorCouponsReturnRequest request) throws WxPayException; /** * <pre> * 商家券接口-使券失效API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_15.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/deactivate * </pre> * * @param request 请求对象 {@link BusiFavorCouponsDeactivateRequest} * @return BusiFavorCouponsDeactivateResult * @throws WxPayException the wx pay exception */ BusiFavorCouponsDeactivateResult deactiveBusiFavorCoupons(BusiFavorCouponsDeactivateRequest request) throws WxPayException; /** * <pre> * 商家券接口-营销补差付款API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_16.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts * </pre> * * @param request 请求对象 {@link BusiFavorSubsidyResult} * @return BusiFavorSubsidyRequest * @throws WxPayException the wx pay exception */ BusiFavorSubsidyResult subsidyBusiFavorPayReceipts(BusiFavorSubsidyRequest request) throws WxPayException; /** * <pre> * 商家券接口-查询营销补差付款单详情API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_17.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts/{subsidy_receipt_id} * </pre> * * @param subsidyReceiptId 补差付款唯一单号 * @return BusiFavorSubsidyRequest * @throws WxPayException the wx pay exception */ BusiFavorSubsidyResult queryBusiFavorSubsidyPayReceipts(String subsidyReceiptId) throws WxPayException; /** * <pre> * 商家券接口-领券事件回调通知API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_15.shtml * </pre> * * @param url 回调地址 * @param request 领券事件回调通知请求对象 * @return BusiFavorNotifyResult * @throws WxPayException the wx pay exception */ BusiFavorNotifyResult notifyBusiFavor(String url, BusiFavorNotifyRequest request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxDepositService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxDepositService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.request.WxDepositConsumeRequest; import com.github.binarywang.wxpay.bean.request.WxDepositOrderQueryRequest; import com.github.binarywang.wxpay.bean.request.WxDepositRefundRequest; import com.github.binarywang.wxpay.bean.request.WxDepositUnfreezeRequest; import com.github.binarywang.wxpay.bean.request.WxDepositUnifiedOrderRequest; import com.github.binarywang.wxpay.bean.result.WxDepositConsumeResult; import com.github.binarywang.wxpay.bean.result.WxDepositOrderQueryResult; import com.github.binarywang.wxpay.bean.result.WxDepositRefundResult; import com.github.binarywang.wxpay.bean.result.WxDepositUnfreezeResult; import com.github.binarywang.wxpay.bean.result.WxDepositUnifiedOrderResult; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 微信押金支付相关接口. * <a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=1">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=1</a> * </pre> * * @author Binary Wang * created on 2024-09-24 */ public interface WxDepositService { /** * <pre> * 押金下单 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=2">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=2</a> * 用于商户发起押金支付,支持JSAPI、NATIVE、APP等支付方式 * </pre> * * @param request 押金下单请求对象 * @return wx deposit unified order result * @throws WxPayException wx pay exception */ WxDepositUnifiedOrderResult unifiedOrder(WxDepositUnifiedOrderRequest request) throws WxPayException; /** * <pre> * 查询押金订单 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=3">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=3</a> * 通过商户订单号或微信订单号查询押金订单状态 * </pre> * * @param request 查询押金订单请求对象 * @return wx deposit order query result * @throws WxPayException wx pay exception */ WxDepositOrderQueryResult queryOrder(WxDepositOrderQueryRequest request) throws WxPayException; /** * <pre> * 押金消费 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=4">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=4</a> * 用于对已支付的押金进行消费扣减 * </pre> * * @param request 押金消费请求对象 * @return wx deposit consume result * @throws WxPayException wx pay exception */ WxDepositConsumeResult consume(WxDepositConsumeRequest request) throws WxPayException; /** * <pre> * 押金撤销 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=5">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=5</a> * 用于对已支付的押金进行撤销退还 * </pre> * * @param request 押金撤销请求对象 * @return wx deposit unfreeze result * @throws WxPayException wx pay exception */ WxDepositUnfreezeResult unfreeze(WxDepositUnfreezeRequest request) throws WxPayException; /** * <pre> * 押金退款 * 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=6">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=6</a> * 用于对已消费的押金进行退款 * </pre> * * @param request 押金退款请求对象 * @return wx deposit refund result * @throws WxPayException wx pay exception */ WxDepositRefundResult refund(WxDepositRefundRequest request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BusinessCircleService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BusinessCircleService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.businesscircle.BusinessCircleNotifyData; import com.github.binarywang.wxpay.bean.businesscircle.PaidResult; import com.github.binarywang.wxpay.bean.businesscircle.PointsNotifyRequest; import com.github.binarywang.wxpay.bean.businesscircle.RefundResult; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 微信支付智慧商圈API * </pre> * * @author thinsstar */ public interface BusinessCircleService { /** * <pre> * 智慧商圈接口-商圈积分同步API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/businesscircle/chapter3_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/businesscircle/points/notify * </pre> * * @param request 请求对象 * @throws WxPayException the wx pay exception */ void notifyPoints(PointsNotifyRequest request) throws WxPayException; BusinessCircleNotifyData parseNotifyData(String data, SignatureHeader header) throws WxPayException; PaidResult decryptPaidNotifyDataResource(BusinessCircleNotifyData data) throws WxPayException; RefundResult decryptRefundNotifyDataResource(BusinessCircleNotifyData data) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EntPayService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EntPayService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.entpay.*; import com.github.binarywang.wxpay.bean.entwxpay.EntWxEmpPayRequest; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 企业付款相关服务类. * Created by BinaryWang on 2017/12/19. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ public interface EntPayService { /** * <pre> * 企业付款API. * 企业付款业务是基于微信支付商户平台的资金管理能力,为了协助商户方便地实现企业向个人付款,针对部分有开发能力的商户,提供通过API完成企业付款的功能。 * 比如目前的保险行业向客户退保、给付、理赔。 * 企业付款将使用商户的可用余额,需确保可用余额充足。查看可用余额、充值、提现请登录商户平台“资金管理”https://pay.weixin.qq.com/进行操作。 * 注意:与商户微信支付收款资金并非同一账户,需要单独充值。 * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 * 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers * </pre> * * @param request 请求对象 * @return the ent pay result * @throws WxPayException the wx pay exception */ EntPayResult entPay(EntPayRequest request) throws WxPayException; /** * <pre> * 查询企业付款API. * 用于商户的企业付款操作进行结果查询,返回付款操作详细结果。 * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3 * 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo * </pre> * * @param partnerTradeNo 商户订单号 * @return the ent pay query result * @throws WxPayException the wx pay exception */ EntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException; /** * <pre> * 查询企业付款API. * 用于商户的企业付款操作进行结果查询,返回付款操作详细结果。 * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3 * 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo * </pre> * * @param request 请求对象 * @return the ent pay query result * @throws WxPayException the wx pay exception */ EntPayQueryResult queryEntPay(EntPayQueryRequest request) throws WxPayException; /** * <pre> * 获取RSA加密公钥API. * RSA算法使用说明(非对称加密算法,算法采用RSA/ECB/OAEPPadding模式) * 1、 调用获取RSA公钥API获取RSA公钥,落地成本地文件,假设为public.pem * 2、 确定public.pem文件的存放路径,同时修改代码中文件的输入路径,加载RSA公钥 * 3、 用标准的RSA加密库对敏感信息进行加密,选择RSA_PKCS1_OAEP_PADDING填充模式 * (eg:Java的填充方式要选 " RSA/ECB/OAEPWITHSHA-1ANDMGF1PADDING") * 4、 得到进行rsa加密并转base64之后的密文 * 5、 将密文传给微信侧相应字段,如付款接口(enc_bank_no/enc_true_name) * * 接口默认输出PKCS#1格式的公钥,商户需根据自己开发的语言选择公钥格式 * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_7&index=4 * 接口链接:https://fraud.mch.weixin.qq.com/risk/getpublickey * </pre> * * @return the public key * @throws WxPayException the wx pay exception */ String getPublicKey() throws WxPayException; /** * 企业付款到银行卡. * <pre> * 用于企业向微信用户银行卡付款 * 目前支持接口API的方式向指定微信用户的银行卡付款。 * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_2 * 接口链接:https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank * </pre> * * @param request 请求对象 * @return the ent pay bank result * @throws WxPayException the wx pay exception */ EntPayBankResult payBank(EntPayBankRequest request) throws WxPayException; /** * 企业付款到银行卡查询. * <pre> * 用于对商户企业付款到银行卡操作进行结果查询,返回付款操作详细结果。 * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_3 * 接口链接:https://api.mch.weixin.qq.com/mmpaysptrans/query_bank * </pre> * * @param partnerTradeNo 商户订单号 * @return the ent pay bank query result * @throws WxPayException the wx pay exception */ EntPayBankQueryResult queryPayBank(String partnerTradeNo) throws WxPayException; /** * 企业付款到银行卡查询. * <pre> * 用于对商户企业付款到银行卡操作进行结果查询,返回付款操作详细结果。 * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_3 * 接口链接:https://api.mch.weixin.qq.com/mmpaysptrans/query_bank * </pre> * * @param request 请求对象 * @return the ent pay bank query result * @throws WxPayException the wx pay exception */ EntPayBankQueryResult queryPayBank(EntPayBankQueryRequest request) throws WxPayException; /** * 企业发送微信红包给个人用户 * <pre> * 文档地址:https://work.weixin.qq.com/api/doc * 接口地址: https://api.mch.weixin.qq.com/mmpaymkttransfers/sendworkwxredpack * </pre> * @param request 请求对象 * @return the wx pay send redpack result * @throws WxPayException the wx pay exception */ EntPayRedpackResult sendEnterpriseRedpack(EntPayRedpackRequest request) throws WxPayException; /** * 企业发送微信红包查询 * <pre> * 文档地址:https://work.weixin.qq.com/api/doc * 接口地址: https://api.mch.weixin.qq.com/mmpaymkttransfers/queryworkwxredpack * </pre> * @param request 请求对象 * @return the wx pay send redpack result * @throws WxPayException the wx pay exception */ EntPayRedpackQueryResult queryEnterpriseRedpack(EntPayRedpackQueryRequest request) throws WxPayException; /** * 向员工付款 * 文档详见 https://work.weixin.qq.com/api/doc/90000/90135/90278 * 接口链接 https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/paywwsptrans2pocket * * @param request 请求对象 * @return EntPayResult the ent pay result * @throws WxPayException the wx pay exception */ EntPayResult toEmpPay(EntWxEmpPayRequest request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/Applyment4SubService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/Applyment4SubService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.applyment.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * 特约商户进件 * 产品介绍:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/applyment4sub/chapter1_1.shtml * * @author zhouyongshen */ public interface Applyment4SubService { /** * 提交申请单API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/applyment4sub/chapter3_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/ * * @param request 请求对象 * @return WxPayApplymentCreateResult 响应结果 * @throws WxPayException the wx pay exception */ WxPayApplymentCreateResult createApply(WxPayApplyment4SubCreateRequest request) throws WxPayException; /** * 通过业务申请编号查询申请状态 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/applyment4sub/chapter3_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/business_code/{business_code} * * @param businessCode 业务申请编号 * 1、只能由数字、字母或下划线组成,建议前缀为服务商商户号。 * 2、服务商自定义的唯一编号。 * 3、每个编号对应一个申请单,每个申请单审核通过后生成一个微信支付商户号。 * 4、若申请单被驳回,可填写相同的“业务申请编号”,即可覆盖修改原申请单信息。 * 示例值:1900013511_10000 * @return the applyment state query result * @throws WxPayException the wx pay exception */ ApplymentStateQueryResult queryApplyStatusByBusinessCode(String businessCode) throws WxPayException; /** * 通过申请单号查询申请状态 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/applyment4sub/chapter3_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/applyment_id/{applyment_id} * * @param applymentId 微信支付分的申请单号。示例值:2000001234567890 * @return the applyment state query result * @throws WxPayException the wx pay exception */ ApplymentStateQueryResult queryApplyStatusByApplymentId(String applymentId) throws WxPayException; /** * 根据特约子商户ID查询结算账户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_4.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/apply4sub/sub_merchants/{sub_mchid}/settlement * * @param subMchid 本服务商进件、已签约的特约商户号。 * @return the settlement info result * @throws WxPayException the wx pay exception */ SettlementInfoResult querySettlementBySubMchid(String subMchid) throws WxPayException; /** * 修改结算帐号 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_3.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/apply4sub/sub_merchants/{sub_mchid}/modify-settlement * * @param subMchid 特约商户号 * @param request 修改结算账户请求对象信息 * @throws WxPayException the wx pay exception * @return */ String modifySettlement(String subMchid, ModifySettlementRequest request) throws WxPayException; /** * 查询结算账户修改申请状态 * * @param subMchid 特约商户号 * @param applicationNo 修改结算账户申请单号 * * @return {@link SettlementModifyStateQueryResult} * @throws WxPayException * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/modify-settlement/sub-merchants/get-application.html">查询结算账户修改申请状态</a> * * <p>接口链接:https://api.mch.weixin.qq.com/v3/apply4sub/sub_merchants/{sub_mchid}/application/{applicationNo} </p> */ SettlementModifyStateQueryResult querySettlementModifyStatusByApplicationNo(String subMchid, String applicationNo) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BankService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BankService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.bank.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 微信支付-银行组件 * </pre> * * @author zhongjun **/ public interface BankService { /** * <pre> * * 获取对私银行卡号开户银行 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/search-banks-by-bank-account">https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/search-banks-by-bank-account</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_1.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_1.shtml</a> * </pre> * * @param accountNumber 银行卡号 * @return BankAccountResult 对私银行卡号开户银行信息 * @throws WxPayException . */ BankAccountResult searchBanksByBankAccount(String accountNumber) throws WxPayException; /** * <pre> * * 查询支持个人业务的银行列表 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/personal-banking">https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/personal-banking</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_2.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_2.shtml</a> * </pre> * * @param offset 本次查询偏移量 * @param limit 本次请求最大查询条数,最大值为200 * @return PersonalBankingResult 支持个人业务的银行列表信息 * @throws WxPayException . */ BankingResult personalBanking(Integer offset, Integer limit) throws WxPayException; /** * <pre> * * 支持对公业务的银行列表 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/corporate-banking">https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/corporate-banking</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_3.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_3.shtml</a> * </pre> * * @param offset 本次查询偏移量 * @param limit 本次请求最大查询条数,最大值为200 * @return BankingResult 支持对公业务的银行列表信息 * @throws WxPayException . */ BankingResult corporateBanking(Integer offset, Integer limit) throws WxPayException; /** * <pre> * * 查询省份列表API * 通过本接口获取省份列表数据(不包含中国港澳台地区),可用于省份下的城市数据查询 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/areas/provinces">https://api.mch.weixin.qq.com/v3/capital/capitallhh/areas/provinces</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_4.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_4.shtml</a> * </pre> * * @return ProvincesResult 省份列表信息 * @throws WxPayException . */ ProvincesResult areasProvinces() throws WxPayException; /** * <pre> * * 查询城市列表API * 通过本接口根据省份编码获取省份下的城市列表信息,不包含中国港澳台地区城市信息,可用于支行数据过滤查询 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/areas/provinces/{province_code}/cities">https://api.mch.weixin.qq.com/v3/capital/capitallhh/areas/provinces/{province_code}/cities</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_5.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_5.shtml</a> * </pre> * * @return CitiesResult 城市列表信息 * @throws WxPayException . */ CitiesResult areasCities(Integer provinceCode) throws WxPayException; /** * <pre> * * 查询支行列表API * 本接口可以用于根据银行别名编码(仅支持需要填写支行的银行别名编码)和城市编码过滤查询支行列表数据 * * 请求方式:GET(HTTPS) * 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/{bank_alias_code}/branches">https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/{bank_alias_code}/branches</a> * * 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_5.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_5.shtml</a> * </pre> * * @param bankAliasCode 银行别名的编码,查询支行接口仅支持需要填写支行的银行别名编码。示例值:1000006247 * @param cityCode 城市编码,唯一标识一座城市,用于结合银行别名编码查询支行列表。示例值:536 * @param offset 非负整数,表示该次请求资源的起始位置,从0开始计数。调用方选填,默认为0。offset为20,limit为100时,查询第21-120条数据 * @param limit 非0非负的整数,该次请求可返回的最大资源条数。示例值:200 * @return BankBranchesResult 城市列表信息 * @throws WxPayException . */ BankBranchesResult bankBranches(String bankAliasCode, Integer cityCode, Integer offset, Integer limit) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/CustomDeclarationService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/CustomDeclarationService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.customs.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * <pre> * 微信支付 支付报关 API. * Created by xifengzhu on 2022/05/05. * </pre> * * @author <a href="https://github.com/xifengzhu">xifengzhu</a> */ public interface CustomDeclarationService { /** * The constant DECLARATION_BASE_URL. */ String DECLARATION_BASE_URL = "https://apihk.mch.weixin.qq.com/global/v3/customs"; /** * <pre> * 报关API * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay/ch/declarecustom_ch/chapter3_1.shtml">...</a> * </pre> * * @param request the request * @return 返回数据 declaration result * @throws WxPayException the wx pay exception */ DeclarationResult declare(DeclarationRequest request) throws WxPayException; /** * <pre> * 报关查询API * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay/ch/declarecustom_ch/chapter3_3.shtml">...</a> * </pre> * * @param request the request * @return 返回数据 declaration query result * @throws WxPayException the wx pay exception */ DeclarationQueryResult query(DeclarationQueryRequest request) throws WxPayException; /** * <pre> * 身份信息校验API * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay/ch/declarecustom_ch/chapter3_2.shtml">...</a> * </pre> * * @param request the request * @return 返回数据 verify certification result * @throws WxPayException the wx pay exception */ VerifyCertificateResult verifyCertificate(VerifyCertificateRequest request) throws WxPayException; /** * <pre> * 报关信息修改API * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay/ch/declarecustom_ch/chapter3_5.shtml">...</a> * </pre> * * @param request the request * @return 返回数据 declaration result * @throws WxPayException the wx pay exception */ DeclarationResult modify(DeclarationRequest request) throws WxPayException; /** * <pre> * 报关重推API * 文档地址: <a href="https://pay.weixin.qq.com/wiki/doc/api/wxpay/ch/declarecustom_ch/chapter3_4.shtml">...</a> * </pre> * * @param request the request * @return 返回数据 redeclaration result * @throws WxPayException the wx pay exception */ RedeclareResult redeclare(RedeclareRequest request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/ProfitSharingService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.notify.SignatureHeader; import com.github.binarywang.wxpay.bean.profitsharing.notify.ProfitSharingNotifyV3Response; import com.github.binarywang.wxpay.bean.profitsharing.notify.ProfitSharingNotifyV3Result; import com.github.binarywang.wxpay.bean.profitsharing.request.*; import com.github.binarywang.wxpay.bean.profitsharing.result.*; import com.github.binarywang.wxpay.exception.WxPayException; /** * 注意:微信最高分账比例为30% * 可多次分账到同一个人,但是依然不能超过30% * * @author Wang GuangXin 2019/10/22 10:05 * @version 1.0 */ public interface ProfitSharingService { /** * <pre> * 单次分账请求按照传入的分账接收方账号和资金进行分账,同时会将订单剩余的待分账金额解冻给特约商户。故操作成功后,订单不能再进行分账,也不能进行分账完结。 * 接口频率:30QPS * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_1&index=1 * 接口链接:https://api.mch.weixin.qq.com/secapi/pay/profitsharing * </pre> * * @param request . * @return . * @throws WxPayException the wx pay exception */ ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException; /** * <pre> * 微信订单支付成功后,服务商代子商户发起分账请求,将结算后的钱分到分账接收方。多次分账请求仅会按照传入的分账接收方进行分账,不会对剩余的金额进行任何操作。故操作成功后,在待分账金额不等于零时,订单依旧能够再次进行分账。 * 多次分账,可以将本商户作为分账接收方直接传入,实现释放资金给本商户的功能 * 对同一笔订单最多能发起20次多次分账请求 * 接口频率:30QPS * </pre> * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_6&index=2 * 接口链接:https://api.mch.weixin.qq.com/secapi/pay/multiprofitsharing * * @param request . * @return . * @throws WxPayException the wx pay exception */ ProfitSharingResult multiProfitSharing(ProfitSharingRequest request) throws WxPayException; /** * <pre> * 请求分账API * * 微信订单支付成功后,商户发起分账请求,将结算后的资金分到分账接收方 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_1.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/orders * * 注意: * 对同一笔订单最多能发起20次分账请求,每次请求最多分给50个接收方 * 此接口采用异步处理模式,即在接收到商户请求后,优先受理请求再异步处理,最终的分账结果可以通过查询分账接口获取 * </pre> * * @param request {@link ProfitSharingV3Request} 针对某一笔支付订单的分账方法 * @return {@link ProfitSharingV3Result} 微信返回的分账结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_1.shtml">微信文档</a> */ ProfitSharingV3Result profitSharingV3(ProfitSharingV3Request request) throws WxPayException; /** * <pre> * 1、不需要进行分账的订单,可直接调用本接口将订单的金额全部解冻给特约商户 * 2、调用多次分账接口后,需要解冻剩余资金时,调用本接口将剩余的分账金额全部解冻给特约商户 * 3、已调用请求单次分账后,剩余待分账金额为零,不需要再调用此接口。 * 接口频率:30QPS * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_5&index=6 * 接口链接:https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish * </pre> * * @param request . * @return . * @throws WxPayException the wx pay exception */ ProfitSharingResult profitSharingFinish(ProfitSharingUnfreezeRequest request) throws WxPayException; /** * <pre> * 服务商代子商户发起添加分账接收方请求,后续可通过发起分账请求将结算后的钱分到该分账接收方。 * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_3&index=4 * 接口链接:https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver * </pre> * * @param request . * @return . * @throws WxPayException . */ ProfitSharingReceiverResult addReceiver(ProfitSharingReceiverRequest request) throws WxPayException; /** * <pre> * 服务商代子商户发起删除分账接收方请求,删除后不支持将结算后的钱分到该分账接收方。 * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_4&index=5 * 接口链接:https://api.mch.weixin.qq.com/pay/profitsharingremovereceiver * </pre> * * @param request . * @return . * @throws WxPayException . */ ProfitSharingReceiverResult removeReceiver(ProfitSharingReceiverRequest request) throws WxPayException; /** * <pre> * 添加分账接收方API * * 商户发起添加分账接收方请求,建立分账接收方列表。后续可通过发起分账请求,将分账方商户结算后的资金,分到该分账接收方 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_8.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/receivers/add * </pre> * * @param request 分账接收方实体 {@link ProfitSharingReceiverV3Request} * @return {@link ProfitSharingReceiverV3Result} 微信返回的分账接收方结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_8.shtml">微信文档</a> */ ProfitSharingReceiverV3Result addReceiverV3(ProfitSharingReceiverV3Request request) throws WxPayException; /** * <pre> * 删除分账接收方API * * 商户发起删除分账接收方请求。删除后,不支持将分账方商户结算后的资金,分到该分账接收方 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_9.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/receivers/delete * </pre> * * @param request 分账接收方实体 {@link ProfitSharingReceiverV3Request} * @return {@link ProfitSharingReceiverV3Result} 微信返回的删除的分账接收方结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_9.shtml">微信文档</a> */ ProfitSharingReceiverV3Result removeReceiverV3(ProfitSharingReceiverV3Request request) throws WxPayException; /** * TODO:微信返回签名失败 * <pre> * 发起分账请求后,可调用此接口查询分账结果;发起分账完结请求后,可调用此接口查询分账完结的执行结果。 * 接口频率:80QPS * </pre> * * @param request . * @return . * @throws WxPayException . */ ProfitSharingQueryResult profitSharingQuery(ProfitSharingQueryRequest request) throws WxPayException; /** * <pre> * 查询分账结果API(商户平台) * * 发起分账请求后,可调用此接口查询分账结果 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/profitsharing/orders/{out_order_no} * * 注意: * • 发起解冻剩余资金请求后,可调用此接口查询解冻剩余资金的结果 * </pre> * * @param outOrderNo 商户系统内部的分账单号,在商户系统内部唯一,同一分账单号多次请求等同一次。只能是数字、大小写字母_-|*@ 。 * @param transactionId 微信支付订单号 * @return {@link ProfitSharingV3Result} 微信返回的分账结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_2.shtml">微信文档</a> */ ProfitSharingV3Result profitSharingQueryV3(String outOrderNo, String transactionId) throws WxPayException; /** * <pre> * 查询分账结果API(服务商平台) * * 发起分账请求后,可调用此接口查询分账结果 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_2.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/profitsharing/orders/{out_order_no} * * 注意: * • 发起解冻剩余资金请求后,可调用此接口查询解冻剩余资金的结果 * </pre> * * @param outOrderNo 商户系统内部的分账单号,在商户系统内部唯一,同一分账单号多次请求等同一次。只能是数字、大小写字母_-|*@ 。 * @param transactionId 微信支付订单号 * @param subMchId 微信支付分配的子商户号,即分账的出资商户号。 * @return {@link ProfitSharingV3Result} 微信返回的分账结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_2.shtml">微信文档</a> */ ProfitSharingV3Result profitSharingQueryV3(String outOrderNo, String transactionId, String subMchId) throws WxPayException; /** * <pre> * 请求分账查询API * * 发起分账请求后,可调用此接口查询分账结果 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_2.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/orders/{out_order_no} * * 注意: * 发起解冻剩余资金请求后,可调用此接口查询解冻剩余资金的结果 * </pre> * * @param request {@link ProfitSharingQueryV3Request} 针对某一笔分账订单的分账方法 * @return {@link ProfitSharingV3Result} 微信返回的分账查询结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_2.shtml">微信文档</a> */ ProfitSharingV3Result profitSharingQueryV3(ProfitSharingQueryV3Request request) throws WxPayException; /** * <pre> * 服务商可通过调用此接口查询订单剩余待分金额。 * 接口频率:30QPS * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_10&index=7 * 接口链接:https://api.mch.weixin.qq.com/pay/profitsharingorderamountquery * </pre> * * @param request . * @return . * @throws WxPayException . */ ProfitSharingOrderAmountQueryResult profitSharingOrderAmountQuery(ProfitSharingOrderAmountQueryRequest request) throws WxPayException; /** * <pre> * 查询剩余待分金额API * * 可调用此接口查询订单剩余待分金额 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_6.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/transactions/{transaction_id}/amounts * </pre> * * @param transactionId 微信订单号,微信支付订单号 * @return {@link ProfitSharingOrderAmountQueryV3Result} 微信返回的订单剩余待分金额结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_6.shtml">微信文档</a> */ ProfitSharingOrderAmountQueryV3Result profitSharingUnsplitAmountQueryV3(String transactionId) throws WxPayException; /** * <pre> * 服务商可以查询子商户设置的允许服务商分账的最大比例。 * 接口频率:30QPS * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_11&index=8 * 接口链接: https://api.mch.weixin.qq.com/pay/profitsharingmerchantratioquery * </pre> * * @param request . * @return . * @throws WxPayException . */ ProfitSharingMerchantRatioQueryResult profitSharingMerchantRatioQuery(ProfitSharingMerchantRatioQueryRequest request) throws WxPayException; /** * <pre> * 查询最大分账比例 * * 可调用此接口查询特约商户设置的允许服务商分账的最大比例 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_7.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/merchant-configs/{sub_mchid} * </pre> * * @param subMchId 子商户号(微信支付分配的子商户号,即分账的出资商户号) * @return {@link ProfitSharingMerchantRatioQueryV3Result} 特约商户设置的允许服务商分账的最大比例结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_7.shtml">服务商平台>>API字典>>资金应用>>分账>>查询最大分账比例</a> * @since 4.4.0 * @date 2022-12-09 */ ProfitSharingMerchantRatioQueryV3Result profitSharingMerchantRatioQueryV3(String subMchId) throws WxPayException; /** * TODO:这个接口用真实的数据返回【参数不正确】,我对比官方文档除了缺少sub_mch_id,和sub_appid之外其他相同,当我随便填了一个商户id的时候,提示【回退方没有开通分账回退功能】 * <pre> * 仅对订单进行退款时,如果订单已经分账,可以先调用此接口将指定的金额从分账接收方(仅限商户类型的分账接收方)回退给特约商户,然后再退款。 * 回退以原分账请求为依据,可以对分给分账接收方的金额进行多次回退,只要满足累计回退不超过该请求中分给接收方的金额。 * 此接口采用同步处理模式,即在接收到商户请求后,会实时返回处理结果。 * 此功能需要接收方在商户平台-交易中心-分账-分账接收设置下,开启同意分账回退后,才能使用。 * 接口频率:30QPS * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_7&index=7 * 接口链接:https://api.mch.weixin.qq.com/secapi/pay/profitsharingreturn * </pre> * * @param returnRequest . * @return . * @throws WxPayException . */ ProfitSharingReturnResult profitSharingReturn(ProfitSharingReturnRequest returnRequest) throws WxPayException; /** * <pre> * 请求分账回退API * * 如果订单已经分账,在退款时,可以先调此接口,将已分账的资金从分账接收方的账户回退给分账方,再发起退款 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_3.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/return-orders * * 注意: * • 分账回退以原分账单为依据,支持多次回退,申请回退总金额不能超过原分账单分给该接收方的金额 * • 此接口采用同步处理模式,即在接收到商户请求后,会实时返回处理结果 * • 对同一笔分账单最多能发起20次分账回退请求 * • 退款和分账回退没有耦合,分账回退可以先于退款请求,也可以后于退款请求 * • 此功能需要接收方在商户平台-交易中心-分账-分账接收设置下,开启同意分账回退后,才能使用 * </pre> * * @param request {@link ProfitSharingReturnV3Request} 针对某一笔支付订单的分账方法 * @return {@link ProfitSharingReturnV3Result} 微信返回的分账回退结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_3.shtml">微信文档</a> */ ProfitSharingReturnV3Result profitSharingReturnV3(ProfitSharingReturnV3Request request) throws WxPayException; /** * TODO:因profitsharingReturn接口无法使用,没有办法对这里进行真实的测试,模拟数据这里返回【记录不存在】 * <pre> * 商户需要核实回退结果,可调用此接口查询回退结果。 * 如果分账回退接口返回状态为处理中,可调用此接口查询回退结果。 * 接口频率:30QPS * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_8&index=8 * 接口链接:https://api.mch.weixin.qq.com/pay/profitsharingreturnquery * </pre> * * @param queryRequest . * @return . * @throws WxPayException . */ ProfitSharingReturnResult profitSharingReturnQuery(ProfitSharingReturnQueryRequest queryRequest) throws WxPayException; /** * <pre> * 查询分账回退结果API(商户平台) * * 商户需要核实回退结果,可调用此接口查询回退结果 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_4.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/profitsharing/return-orders/{out_return_no} * * 注意: * • 如果分账回退接口返回状态为处理中,可调用此接口查询回退结果 * </pre> * * @param outOrderNo 原发起分账请求时使用的商户系统内部的分账单号 * @param outReturnNo 调用回退接口提供的商户系统内部的回退单号 * @return {@link ProfitSharingReturnV3Result} 微信返回的分账回退结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_4.shtml">微信文档</a> */ ProfitSharingReturnV3Result profitSharingReturnQueryV3(String outOrderNo, String outReturnNo) throws WxPayException; /** * <pre> * 查询分账回退结果API(服务商平台) * * 商户需要核实回退结果,可调用此接口查询回退结果 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_3.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/profitsharing/return-orders/{out_return_no} * * 注意: * • 如果分账回退接口返回状态为处理中,可调用此接口查询回退结果 * </pre> * * @param outOrderNo 原发起分账请求时使用的商户系统内部的分账单号 * @param outReturnNo 调用回退接口提供的商户系统内部的回退单号 * @param subMchId 微信支付分配的子商户号,即分账的回退方商户号。 * @return {@link ProfitSharingReturnV3Result} 微信返回的分账回退结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_3.shtml">微信文档</a> */ ProfitSharingReturnV3Result profitSharingReturnQueryV3(String outOrderNo, String outReturnNo, String subMchId) throws WxPayException; /** * <pre> * 解冻剩余资金API * * 不需要进行分账的订单,可直接调用本接口将订单的金额全部解冻给特约商户 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_5.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/orders/unfreeze * * 注意: * • 调用分账接口后,需要解冻剩余资金时,调用本接口将剩余的分账金额全部解冻给特约商户 * • 此接口采用异步处理模式,即在接收到商户请求后,优先受理请求再异步处理,最终的分账结果可以通过查询分账接口获取 * </pre> * * @param request 解冻剩余资金请求实体 {@link ProfitSharingUnfreezeV3Request} * @return {@link ProfitSharingReturnV3Result} 微信返回的解冻剩余资金结果 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_5.shtml">微信文档</a> */ ProfitSharingUnfreezeV3Result profitSharingUnfreeze(ProfitSharingUnfreezeV3Request request) throws WxPayException; /** * <pre> * 分账动账通知 * * 分账或分账回退成功后,微信会把相关变动结果发送给分账接收方(只支持商户)。 * 对后台通知交互时,如果微信收到应答不是成功或超时,微信认为通知失败,微信会通过一定的策略定期重新发起通知,尽可能提高通知的成功率,但微信不保证通知最终能成功。 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_10.shtml * </pre> * * @param notifyData 分账通知实体 * @param header 分账通知头 {@link SignatureHeader} * @return {@link ProfitSharingNotifyV3Response} 资源对象 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_10.shtml">微信文档</a> */ ProfitSharingNotifyV3Result parseProfitSharingNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; /** * <pre> * 申请分账账单 * * 微信支付按天提供分账账单文件,商户可以通过该接口获取账单文件的下载地址 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_11.shtml * 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/bills * </pre> * * @param request 申请分账账单请求实体({@link ProfitSharingBillV3Request}) * @return {@link ProfitSharingBillV3Result} 申请分账账单结果类 * @throws WxPayException the wx pay exception * @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_11.shtml">服务商平台>>API字典>>资金应用>>分账>>申请分账账单API</a> * @since 4.4.0 * @date 2022-12-09 */ ProfitSharingBillV3Result profitSharingBill(ProfitSharingBillV3Request request) throws WxPayException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MerchantMediaService.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MerchantMediaService.java
package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.media.ImageUploadResult; import com.github.binarywang.wxpay.exception.WxPayException; import java.io.File; import java.io.IOException; import java.io.InputStream; /** * <pre> * 微信支付通用媒体接口. * </pre> * * @author zhouyongshen */ public interface MerchantMediaService { /** * <pre> * 通用接口-图片上传API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/chapter3_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/merchant/media/upload * </pre> * * @param imageFile 需要上传的图片文件 * @return ImageUploadResult 微信返回的媒体文件标识Id。示例值:6uqyGjGrCf2GtyXP8bxrbuH9-aAoTjH-rKeSl3Lf4_So6kdkQu4w8BYVP3bzLtvR38lxt4PjtCDXsQpzqge_hQEovHzOhsLleGFQVRF-U_0 * @throws WxPayException the wx pay exception */ ImageUploadResult imageUploadV3(File imageFile) throws WxPayException, IOException; /** * <pre> * 通用接口-图片上传API * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/chapter3_1.shtml * 接口链接:https://api.mch.weixin.qq.com/v3/merchant/media/upload * </pre> * * @param inputStream 需要上传的图片文件流 * @param fileName 需要上传的图片文件名 * @return ImageUploadResult 微信返回的媒体文件标识Id。示例值:6uqyGjGrCf2GtyXP8bxrbuH9-aAoTjH-rKeSl3Lf4_So6kdkQu4w8BYVP3bzLtvR38lxt4PjtCDXsQpzqge_hQEovHzOhsLleGFQVRF-U_0 * @throws WxPayException the wx pay exception */ ImageUploadResult imageUploadV3(InputStream inputStream, String fileName) throws WxPayException, IOException; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/Apply4SubjectConfirmServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/Apply4SubjectConfirmServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.applyconfirm.ApplySubjectConfirmCreateRequest; import com.github.binarywang.wxpay.bean.applyconfirm.ApplySubjectConfirmCreateResult; import com.github.binarywang.wxpay.bean.applyconfirm.ApplySubjectConfirmMerchantStateQueryResult; import com.github.binarywang.wxpay.bean.applyconfirm.ApplySubjectConfirmStateQueryResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.Apply4SubjectConfirmService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; /** * <pre> * 商户开户意愿确认 * 产品文档:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter6_1_1.shtml">商户开户意愿确认流程</a> * </pre> * * @author <a href="https://github.com/wslongchen">Mr.Pan</a> */ @Slf4j @RequiredArgsConstructor public class Apply4SubjectConfirmServiceImpl implements Apply4SubjectConfirmService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; /** * <pre> * 提交申请单 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_1.shtml">间连商户开户意愿确认(提交申请单)</a> * </pre> * * @param request 申请请求参数 * @return 审核结果 * @throws WxPayException 异常 */ @Override public ApplySubjectConfirmCreateResult applyment(ApplySubjectConfirmCreateRequest request) throws WxPayException { String url = String.format("%s/v3/apply4subject/applyment", this.payService.getPayBaseUrl()); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String result = payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, ApplySubjectConfirmCreateResult.class); } /** * <pre> * 查询申请单审核结果 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_3.shtml">查询申请单审核结果</a> * </pre> * * @param businessCode 业务申请编号 * @return 审核结果 * @throws WxPayException 异常 */ @Override public ApplySubjectConfirmStateQueryResult queryApplyStatusByBusinessCode(String businessCode) throws WxPayException { String url = String.format("%s/v3/apply4subject/applyment?business_code=%s", this.payService.getPayBaseUrl(), businessCode); String result = payService.getV3(url); return GSON.fromJson(result, ApplySubjectConfirmStateQueryResult.class); } /** * <pre> * 查询申请单审核结果 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_3.shtml">查询申请单审核结果</a> * </pre> * * @param applymentId 申请编号 * @return 审核结果 * @throws WxPayException 异常 */ @Override public ApplySubjectConfirmStateQueryResult queryApplyStatusByApplymentId(String applymentId) throws WxPayException { String url = String.format("%s/v3/apply4subject/applyment?applyment_id=%s", this.payService.getPayBaseUrl(), applymentId); String result = payService.getV3(url); return GSON.fromJson(result, ApplySubjectConfirmStateQueryResult.class); } /** * <pre> * 获取商户开户意愿确认状态 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_4.shtml">获取商户开户意愿确认状态API</a> * </pre> * * @param subMchId 微信支付分配的特约商户的唯一标识。 * @return 确认状态结果 * @throws WxPayException 异常 */ @Override public ApplySubjectConfirmMerchantStateQueryResult queryMerchantApplyStatusByMchId(String subMchId) throws WxPayException { String url = String.format("%s/v3/apply4subject/applyment/merchants/%s/state", this.payService.getPayBaseUrl(), subMchId); String result = payService.getV3(url); return GSON.fromJson(result, ApplySubjectConfirmMerchantStateQueryResult.class); } /** * <pre> * 撤销申请单 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_2.shtml">撤销申请单API</a> * </pre> * * @param businessCode 业务申请编号 * @return 返回结果 * @throws WxPayException 异常 */ @Override public void cancelApplyByBusinessCode(String businessCode) throws WxPayException { String url = String.format("%s/v3/apply4subject/applyment/%s/cancel", this.payService.getPayBaseUrl(), businessCode); payService.postV3WithWechatpaySerial(url, ""); } /** * <pre> * 撤销申请单 * 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter10_1_2.shtml">撤销申请单API</a> * </pre> * * @param applymentId 申请编号 * @return 返回结果 * @throws WxPayException 异常 */ @Override public void cancelApplyByApplymentId(String applymentId) throws WxPayException { String url = String.format("%s/v3/apply4subject/applyment/%s/cancel", this.payService.getPayBaseUrl(), applymentId); payService.postV3WithWechatpaySerial(url, ""); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ComplaintServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/ComplaintServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.complaint.*; import com.github.binarywang.wxpay.bean.media.ImageUploadResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.ComplaintService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.WechatPayUploadHttpPost; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import org.apache.commons.codec.digest.DigestUtils; import javax.crypto.BadPaddingException; import java.io.*; import java.net.URI; import java.util.List; /** * <pre> * 消费者投诉2.0 实现. * Created by jmdhappy on 2022/3/19. * </pre> * * @author <a href="https://gitee.com/jeequan/jeepay">jmdhappy</a> */ @RequiredArgsConstructor public class ComplaintServiceImpl implements ComplaintService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; @Override public ComplaintResult queryComplaints(ComplaintRequest request) throws WxPayException, BadPaddingException { String url = String.format("%s/v3/merchant-service/complaints-v2?limit=%d&offset=%d&begin_date=%s&end_date=%s&complainted_mchid=%s", this.payService.getPayBaseUrl(), request.getLimit(), request.getOffset(), request.getBeginDate(), request.getEndDate(), request.getComplaintedMchid()); String response = this.payService.getV3(url); ComplaintResult complaintResult = GSON.fromJson(response, ComplaintResult.class); List<ComplaintDetailResult> data = complaintResult.getData(); for (ComplaintDetailResult complaintDetailResult : data) { // 对手机号进行解密操作 if (complaintDetailResult.getPayerPhone() != null) { String payerPhone = RsaCryptoUtil.decryptOAEP(complaintDetailResult.getPayerPhone(), this.payService.getConfig().getPrivateKey()); complaintDetailResult.setPayerPhone(payerPhone); } } return complaintResult; } @Override public ComplaintDetailResult getComplaint(ComplaintDetailRequest request) throws WxPayException, BadPaddingException { String url = String.format("%s/v3/merchant-service/complaints-v2/%s", this.payService.getPayBaseUrl(), request.getComplaintId()); String response = this.payService.getV3(url); ComplaintDetailResult result = GSON.fromJson(response, ComplaintDetailResult.class); // 对手机号进行解密操作 if (result.getPayerPhone() != null) { String payerPhone = RsaCryptoUtil.decryptOAEP(result.getPayerPhone(), this.payService.getConfig().getPrivateKey()); result.setPayerPhone(payerPhone); } return result; } @Override public NegotiationHistoryResult queryNegotiationHistorys(NegotiationHistoryRequest request) throws WxPayException { String url = String.format("%s/v3/merchant-service/complaints-v2/%s/negotiation-historys?limit=%d&offset=%d", this.payService.getPayBaseUrl(), request.getComplaintId(), request.getLimit(), request.getOffset()); String response = this.payService.getV3(url); return GSON.fromJson(response, NegotiationHistoryResult.class); } @Override public ComplaintNotifyUrlResult addComplaintNotifyUrl(ComplaintNotifyUrlRequest request) throws WxPayException { String url = String.format("%s/v3/merchant-service/complaint-notifications", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, ComplaintNotifyUrlResult.class); } @Override public ComplaintNotifyUrlResult getComplaintNotifyUrl() throws WxPayException { String url = String.format("%s/v3/merchant-service/complaint-notifications", this.payService.getPayBaseUrl()); String response = this.payService.getV3(url); return GSON.fromJson(response, ComplaintNotifyUrlResult.class); } @Override public ComplaintNotifyUrlResult updateComplaintNotifyUrl(ComplaintNotifyUrlRequest request) throws WxPayException { String url = String.format("%s/v3/merchant-service/complaint-notifications", this.payService.getPayBaseUrl()); String response = this.payService.putV3(url, GSON.toJson(request)); return GSON.fromJson(response, ComplaintNotifyUrlResult.class); } @Override public void deleteComplaintNotifyUrl() throws WxPayException { String url = String.format("%s/v3/merchant-service/complaint-notifications", this.payService.getPayBaseUrl()); this.payService.deleteV3(url); } @Override public void submitResponse(ResponseRequest request) throws WxPayException { String url = String.format("%s/v3/merchant-service/complaints-v2/%s/response", this.payService.getPayBaseUrl(), request.getComplaintId()); // 上面url已经含有complaintId,这里设置为空,避免在body中再次传递,否则微信会报错 request.setComplaintId(null); this.payService.postV3(url, GSON.toJson(request)); } @Override public void complete(CompleteRequest request) throws WxPayException { String url = String.format("%s/v3/merchant-service/complaints-v2/%s/complete", this.payService.getPayBaseUrl(), request.getComplaintId()); // 上面url已经含有complaintId,这里设置为空,避免在body中再次传递,否则微信会报错 request.setComplaintId(null); this.payService.postV3(url, GSON.toJson(request)); } @Override public void updateRefundProgress(UpdateRefundProgressRequest request) throws WxPayException { String url = String.format("%s/v3/merchant-service/complaints-v2/%s/update-refund-progress", this.payService.getPayBaseUrl(), request.getComplaintId()); // 上面url已经含有complaintId,这里设置为空,避免在body中再次传递,否则微信会报错 request.setComplaintId(null); this.payService.postV3(url, GSON.toJson(request)); } @Override public ImageUploadResult uploadResponseImage(File imageFile) throws WxPayException, IOException { String url = String.format("%s/v3/merchant-service/images/upload", this.payService.getPayBaseUrl()); try (FileInputStream s1 = new FileInputStream(imageFile)) { String sha256 = DigestUtils.sha256Hex(s1); try (InputStream s2 = new FileInputStream(imageFile)) { WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(URI.create(url)) .withImage(imageFile.getName(), sha256, s2) .build(); String result = this.payService.postV3(url, request); return ImageUploadResult.fromJson(result); } } } @Override public ImageUploadResult uploadResponseImage(InputStream inputStream, String fileName) throws WxPayException, IOException { String url = String.format("%s/v3/merchant-service/images/upload", this.payService.getPayBaseUrl()); try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { //文件大小不能超过2M byte[] buffer = new byte[2048]; int len; while ((len = inputStream.read(buffer)) > -1) { bos.write(buffer, 0, len); } bos.flush(); byte[] data = bos.toByteArray(); String sha256 = DigestUtils.sha256Hex(data); WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(URI.create(url)) .withImage(fileName, sha256, new ByteArrayInputStream(data)) .build(); String result = this.payService.postV3(url, request); return ImageUploadResult.fromJson(result); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BrandMerchantTransferServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BrandMerchantTransferServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.request.*; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandBatchesQueryResult; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandDetailsQueryResult; import com.github.binarywang.wxpay.bean.brandmerchanttransfer.result.BrandTransferBatchesResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.BrandMerchantTransferService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; /** * 品牌商户发放红包商家转账到零钱(直联商户)实现 * * @author moran */ @Slf4j @RequiredArgsConstructor public class BrandMerchantTransferServiceImpl implements BrandMerchantTransferService { private static final Gson GSON = (new GsonBuilder()).create(); private final WxPayService wxPayService; @Override public BrandTransferBatchesResult createBrandTransfer(BrandTransferBatchesRequest request) throws WxPayException { String url = String.format("%s/v3/fund-app/brand-redpacket/brand-merchant-batches", this.wxPayService.getPayBaseUrl()); RsaCryptoUtil.encryptFields(request, this.wxPayService.getConfig().getVerifier().getValidCertificate()); String response = wxPayService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(response, BrandTransferBatchesResult.class); } @Override public BrandBatchesQueryResult queryBrandWxBatches(BrandWxBatchesQueryRequest request) throws WxPayException { String url = String.format("%s/v3/fund-app/brand-redpacket/brand-merchant-batches/%s", this.wxPayService.getPayBaseUrl(), request.getBatchNo()); if (request.getNeedQueryDetail() != null) { url = String.format("%s?need_query_detail=%b", url, request.getNeedQueryDetail()); } if (request.getDetailState() != null && !request.getDetailState().isEmpty()) { url = String.format("%s&detail_state=%s", url, request.getDetailState()); } String response = wxPayService.getV3(url); return GSON.fromJson(response, BrandBatchesQueryResult.class); } @Override public BrandDetailsQueryResult queryBrandWxDetails(BrandWxDetailsQueryRequest request) throws WxPayException { String url = String.format("%s/v3/fund-app/brand-redpacket/brand-merchant-batches/%s/details/%s", this.wxPayService.getPayBaseUrl(), request.getBatchNo(), request.getDetailNo()); String response = wxPayService.getV3(url); return GSON.fromJson(response, BrandDetailsQueryResult.class); } @Override public BrandBatchesQueryResult queryBrandMerchantBatches(BrandMerchantBatchesQueryRequest request) throws WxPayException { String url = String.format("%s/v3/fund-app/brand-redpacket/brand-merchant-out-batches/%s", this.wxPayService.getPayBaseUrl(), request.getOutBatchNo()); if (request.getNeedQueryDetail() != null) { url = String.format("%s?need_query_detail=%b", url, request.getNeedQueryDetail()); } if (request.getDetailState() != null && !request.getDetailState().isEmpty()) { url = String.format("%s&detail_state=%s", url, request.getDetailState()); } String response = wxPayService.getV3(url); return GSON.fromJson(response, BrandBatchesQueryResult.class); } @Override public BrandDetailsQueryResult queryBrandMerchantDetails(BrandMerchantDetailsQueryRequest request) throws WxPayException { String url = String.format("%s/v3/fund-app/brand-redpacket/brand-merchant-out-batches/%s/out-details/%s", this.wxPayService.getPayBaseUrl(), request.getOutBatchNo(), request.getOutDetailNo()); String response = wxPayService.getV3(url); return GSON.fromJson(response, BrandDetailsQueryResult.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreSignPlanServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerPayScoreSignPlanServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.bean.payscore.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.PartnerPayScoreService; import com.github.binarywang.wxpay.service.PartnerPayScoreSignPlanService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.AesUtils; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.utils.URIBuilder; import org.checkerframework.checker.nullness.qual.NonNull; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.util.Map; import java.util.Objects; /** * @author UltramanNoa * @className PartnerPayScoreSignPlanServiceImpl * @description 微信支付分签约计划接口实现 * @createTime 2023/11/3 09:23 * * <pre> * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-pay-score-plan/create-partner-pay-score-plan.html">微信支付分签约计划</a> * <br> * 文档更新时间:2023.10.13 * <br> * 微信支付分签约计划是不同模式的支付分接口(随着国家大力推广教培行业先享后付政策,微信支付也紧跟政策于2023.07.25上线第一版签约计划接口以适用教培行业先享后付。于2023.10.13文档推至官网文档中心) * <br> * 免确认/需确认 用服务商创单接口 {@link PartnerPayScoreService} 需要用户授权 * <br> * 签约计划,用单独创单接口 {@link PartnerPayScoreSignPlanService} 不需要用户授权 * </pre> **/ @RequiredArgsConstructor public class PartnerPayScoreSignPlanServiceImpl implements PartnerPayScoreSignPlanService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService ; /** * <p>description:创建支付分计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 11:58 </p> * <p>version: v.1.0 </p> * * @param request {@link WxPartnerPayScoreSignPlanRequest} * * @return {@link WxPartnerPayScoreSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-pay-score-plan/create-partner-pay-score-plan.html">创建支付分计划</a> **/ @Override public WxPartnerPayScoreSignPlanResult createPlans(WxPartnerPayScoreSignPlanRequest request) throws WxPayException { String url = String.format("%s/v3/payscore/plan/partner/payscore-plans", payService.getPayBaseUrl()); if (StringUtils.isBlank(request.getAppid())) { request.setAppid(payService.getConfig().getAppId()); } if (StringUtils.isBlank((request.getServiceId()))) { request.setServiceId(payService.getConfig().getServiceId()); } String result = payService.postV3(url, request.toJson()); return WxPartnerPayScoreSignPlanResult.fromJson(result); } /** * <p>description: 查询支付分计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 14:03 </p> * <p>version: v.1.0 </p> * * @param merchantPlanNo 路径参数:支付分计划商户侧单号 * @param subMchid 子商户号 * * @return {@link WxPartnerPayScoreSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-pay-score-plan/query-partner-pay-score-plan.html">查询支付分计划</a> **/ @Override public WxPartnerPayScoreSignPlanResult queryPlans(@NonNull String merchantPlanNo, @NonNull String subMchid) throws WxPayException { String url = String.format("%s/v3/payscore/plan/partner/payscore-plans/merchant-plan-no/%s", payService.getPayBaseUrl(), merchantPlanNo); try { URI uri = new URIBuilder(url) .setParameter("sub_mchid", subMchid) .build(); String result = payService.getV3(uri.toString()); return WxPartnerPayScoreSignPlanResult.fromJson(result); } catch (URISyntaxException e) { throw new WxPayException("未知异常!", e); } } /** * <p>description: 停止支付分计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 14:24 </p> * <p>version: v.1.0 </p> * * @param merchantPlanNo 路径参数:支付分计划商户侧单号 * @param subMchid 子商户号 * * @return {@link WxPartnerPayScoreSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-pay-score-plan/stop-partner-pay-score-plan.html">停止支付分计划</a> **/ @Override public WxPartnerPayScoreSignPlanResult stopPlans(@NonNull String merchantPlanNo, @NonNull String subMchid) throws WxPayException { String url = String.format("%s/v3/payscore/plan/partner/payscore-plans/merchant-plan-no/%s/stop", payService.getPayBaseUrl(), merchantPlanNo); Map<String, String> params = Maps.newHashMap(); params.put("sub_mchid", subMchid); String result = payService.postV3(url, WxGsonBuilder.create().toJson(params)); return WxPartnerPayScoreSignPlanResult.fromJson(result); } /** * <p>description: 创建用户的签约计划详情对应的服务订单 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 14:53 </p> * <p>version: v.1.0 </p> * * @param request {@link WxPartnerPayScoreSignPlanRequest} * * @return {@link WxPartnerPayScoreSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-service-order/create-partner-service-order.html">创建用户的签约计划详情对应的服务订单</a> **/ @Override public WxPartnerPayScoreSignPlanResult signPlanServiceOrder(WxPartnerPayScoreSignPlanRequest request) throws WxPayException { String url = String.format("%s/v3/payscore/sign-plan/partner/serviceorder", payService.getPayBaseUrl()); if (StringUtils.isBlank(request.getAppid())) { request.setAppid(payService.getConfig().getAppId()); } if (StringUtils.isBlank((request.getServiceId()))) { request.setServiceId(payService.getConfig().getServiceId()); } String result = payService.postV3(url, request.toJson()); return WxPartnerPayScoreSignPlanResult.fromJson(result); } /** * <p>description: 创建用户的签约计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 17:48 </p> * <p>version: v.1.0 </p> * * @param request {@link WxPartnerPayScoreSignPlanRequest} * * @return {@link WxPartnerPayScoreUserSignPlanResult} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-user-sign-plan/create-partner-user-sign-plan.html">创建用户的签约计划</a> **/ @Override public WxPartnerPayScoreUserSignPlanResult createUserSignPlans(WxPartnerPayScoreSignPlanRequest request) throws WxPayException { String url = String.format("%s/v3/payscore/sign-plan/partner/user-sign-plans", payService.getPayBaseUrl()); if (StringUtils.isBlank(request.getAppid())) { request.setAppid(payService.getConfig().getAppId()); } if (StringUtils.isBlank((request.getServiceId()))) { request.setServiceId(payService.getConfig().getServiceId()); } String result = payService.postV3(url, request.toJson()); return WxPartnerPayScoreUserSignPlanResult.fromJson(result); } /** * <p>description: 查询用户的签约计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 18:01 </p> * <p>version: v.1.0 </p> * * @param merchantSignPlanNo 路径参数 商户签约计划号 * @param subMchid 子商户号 * * @return {@link PartnerUserSignPlanEntity} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-user-sign-plan/query-partner-user-sign-plan.html">查询用户的签约计划</a> **/ @Override public PartnerUserSignPlanEntity queryUserSignPlans(@NonNull String merchantSignPlanNo, @NonNull String subMchid) throws WxPayException { String url = String.format("%s/v3/payscore/sign-plan/partner/user-sign-plans/merchant-sign-plan-no/%s", payService.getPayBaseUrl(), merchantSignPlanNo); try { URI uri = new URIBuilder(url) .setParameter("sub_mchid", subMchid) .build(); String result = payService.getV3(uri.toString()); return PartnerUserSignPlanEntity.fromJson(result); } catch (URISyntaxException e) { throw new WxPayException("未知异常!", e); } } /** * <p>description: 取消用户的签约计划 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 18:01 </p> * <p>version: v.1.0 </p> * * @param merchantSignPlanNo 路径参数 商户签约计划号 subMchid – 子商户号 * @param subMchid 子商户号 * @param stopReason 停止签约计划原因 * * @return {@link PartnerUserSignPlanEntity} * @apiNote <a href="https://pay.weixin.qq.com/docs/partner/apis/partner-payscore-plan/partner-user-sign-plan/stop-partner-user-sign-plan.html">取消用户的签约计划</a> **/ @Override public PartnerUserSignPlanEntity stopUserSignPlans(@NonNull String merchantSignPlanNo, @NonNull String subMchid, @NonNull String stopReason) throws WxPayException { String url = String.format("%s/v3/payscore/sign-plan/partner/user-sign-plans/merchant-sign-plan-no/%s/stop", payService.getPayBaseUrl(), merchantSignPlanNo); Map<String, String> params = Maps.newHashMap(); params.put("sub_mchid", subMchid); params.put("stop_reason", stopReason); String result = payService.postV3(url, WxGsonBuilder.create().toJson(params)); return PartnerUserSignPlanEntity.fromJson(result); } /** * <p>description:回调通知 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 18:28 </p> * <p>version: v.1.0 </p> * * @param notifyData 回调参数 * @param header 签名 * * @return {@link PartnerUserSignPlanEntity} **/ @Override public PartnerUserSignPlanEntity parseSignPlanNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { PayScoreNotifyData response = parseNotifyData(notifyData, header); return decryptNotifyDataResource(response); } /** * <p>description: 检验并解析通知参数 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 18:30 </p> * <p>version: v.1.0 </p> * @param data * @param header * @return {@link PayScoreNotifyData} **/ public PayScoreNotifyData parseNotifyData(String data, SignatureHeader header) throws WxPayException { if (Objects.nonNull(header) && !verifyNotifySign(header, data)) { throw new WxPayException("非法请求,头部信息验证失败"); } return GSON.fromJson(data, PayScoreNotifyData.class); } /** * <p>description: 解析回调通知参数 </p> * <p>author:UltramanNoa </p> * <p>create Time: 2023/11/3 18:27 </p> * <p>version: v.1.0 </p> * * @param data {@link PayScoreNotifyData} * * @return {@link PartnerUserSignPlanEntity} **/ public PartnerUserSignPlanEntity decryptNotifyDataResource(PayScoreNotifyData data) throws WxPayException { PayScoreNotifyData.Resource resource = data.getResource(); String cipherText = resource.getCipherText(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = payService.getConfig().getApiV3Key(); try { return PartnerUserSignPlanEntity.fromJson(AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key)); } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } /** * 校验通知签名 * * @param header 通知头信息 * @param data 通知数据 * * @return true:校验通过 false:校验不通过 */ private boolean verifyNotifySign(SignatureHeader header, String data) { String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(), header.getNonce(), data); return this.payService.getConfig().getVerifier().verify( header.getSerialNo(), beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned() ); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/CustomDeclarationServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/CustomDeclarationServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.customs.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.CustomDeclarationService; import com.github.binarywang.wxpay.service.WxPayService; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.error.WxRuntimeException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; import java.util.Base64; /** * <pre> * 支付报关 实现. * Created by xifengzhu on 2022/05/05. * </pre> * * @author <a href="https://github.com/xifengzhu">xifengzhu</a> */ @RequiredArgsConstructor public class CustomDeclarationServiceImpl implements CustomDeclarationService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; @Override public DeclarationResult declare(DeclarationRequest request) throws WxPayException { String response = this.payService.postV3(DECLARATION_BASE_URL.concat("/orders"), GSON.toJson(request)); return GSON.fromJson(response, DeclarationResult.class); } @Override public DeclarationQueryResult query(DeclarationQueryRequest request) throws WxPayException { String url = String.format("%s/orders?appid=%s&mchid=%s&order_type=%s&order_no=%s&customs=%s&offset=%s&limit=%s", DECLARATION_BASE_URL, request.getAppid(), request.getMchid(), request.getOrderType(), request.getOrderNo(), request.getCustoms(), request.getOffset(), request.getLimit() ); String result = this.payService.getV3(url); return GSON.fromJson(result, DeclarationQueryResult.class); } @Override public VerifyCertificateResult verifyCertificate(VerifyCertificateRequest request) throws WxPayException { this.encryptFields(request); String response = this.payService.postV3WithWechatpaySerial(DECLARATION_BASE_URL.concat("/verify-certificate"), GSON.toJson(request)); return GSON.fromJson(response, VerifyCertificateResult.class); } @Override public DeclarationResult modify(DeclarationRequest request) throws WxPayException { String response = this.payService.patchV3(DECLARATION_BASE_URL.concat("/orders"), GSON.toJson(request)); return GSON.fromJson(response, DeclarationResult.class); } @Override public RedeclareResult redeclare(RedeclareRequest request) throws WxPayException { String response = this.payService.postV3(DECLARATION_BASE_URL.concat("/redeclare"), GSON.toJson(request)); return GSON.fromJson(response, RedeclareResult.class); } private void encryptFields(VerifyCertificateRequest request) throws WxPayException { try { request.setCertificateId(encryptOAEP(request.getCertificateId())); request.setCertificateName(encryptOAEP(request.getCertificateName())); } catch (Exception e) { throw new WxPayException("敏感信息加密失败", e); } } private X509Certificate getValidCertificate() { return this.payService.getConfig().getVerifier().getValidCertificate(); } private String encryptOAEP(String message) throws IllegalBlockSizeException { X509Certificate certificate = getValidCertificate(); try { // 身份信息校验 RSA 加密,填充方案使用 `RSAES-PKCS1-v1_5` // https://pay.weixin.qq.com/wiki/doc/api/wxpay/ch/declarecustom_ch/chapter3_2.shtml Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, certificate.getPublicKey()); byte[] data = message.getBytes(StandardCharsets.UTF_8); byte[] ciphertext = cipher.doFinal(data); return Base64.getEncoder().encodeToString(ciphertext); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { throw new WxRuntimeException("当前Java环境不支持RSA v1.5/OAEP", e); } catch (InvalidKeyException e) { throw new IllegalArgumentException("无效的证书", e); } catch (IllegalBlockSizeException | BadPaddingException e) { throw new IllegalBlockSizeException("加密原串的长度不能超过214字节"); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.WxPayApiData; import com.github.binarywang.wxpay.exception.WxPayException; import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; import jodd.http.HttpResponse; import jodd.http.ProxyInfo; import jodd.http.ProxyInfo.ProxyType; import jodd.http.net.SSLSocketHttpConnectionProvider; import jodd.http.net.SocketHttpConnectionProvider; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; import javax.net.ssl.SSLContext; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Base64; /** * 微信支付请求实现类,jodd-http实现. * Created by Binary Wang on 2016/7/28. * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Slf4j public class WxPayServiceJoddHttpImpl extends BaseWxPayServiceImpl { @Override public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException { try { HttpRequest request = this.buildHttpRequest(url, requestStr, useKey); byte[] responseBytes = request.send().bodyBytes(); final String responseString = Base64.getEncoder().encodeToString(responseBytes); log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseString); if (this.getConfig().isIfSaveApiData()) { wxApiData.set(new WxPayApiData(url, requestStr, responseString, null)); } return responseBytes; } catch (Exception e) { log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage()); wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage())); throw new WxPayException(e.getMessage(), e); } } @Override public String post(String url, String requestStr, boolean useKey) throws WxPayException { try { HttpRequest request = this.buildHttpRequest(url, requestStr, useKey); String responseString = this.getResponseString(request.send()); log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据】:{}", url, requestStr, responseString); if (this.getConfig().isIfSaveApiData()) { wxApiData.set(new WxPayApiData(url, requestStr, responseString, null)); } return responseString; } catch (Exception e) { log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage()); wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage())); throw new WxPayException(e.getMessage(), e); } } @Override public String post(String url, String requestStr, boolean useKey, String mimeType) throws WxPayException { try { HttpRequest request = this.buildHttpRequest(url, requestStr, useKey, mimeType); String responseString = this.getResponseString(request.send()); log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据】:{}", url, requestStr, responseString); if (this.getConfig().isIfSaveApiData()) { wxApiData.set(new WxPayApiData(url, requestStr, responseString, null)); } return responseString; } catch (Exception e) { log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage()); wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage())); throw new WxPayException(e.getMessage(), e); } } @Override public String postV3(String url, String requestStr) throws WxPayException { return null; } @Override public String patchV3(String url, String requestStr) throws WxPayException { return null; } @Override public String postV3WithWechatpaySerial(String url, String requestStr) throws WxPayException { return null; } @Override public String postV3(String url, HttpPost httpPost) throws WxPayException { return null; } @Override public String requestV3(String url, HttpRequestBase httpRequest) throws WxPayException { return null; } @Override public String getV3(String url) throws WxPayException { return null; } @Override public String getV3WithWechatPaySerial(String url) throws WxPayException { return null; } @Override public InputStream downloadV3(String url) throws WxPayException { return null; } @Override public String putV3(String url, String requestStr) throws WxPayException { return null; } @Override public String deleteV3(String url) throws WxPayException { return null; } private HttpRequest buildHttpRequest(String url, String requestStr, boolean useKey) throws WxPayException { HttpRequest request = HttpRequest .post(url) .timeout(this.getConfig().getHttpTimeout()) .connectionTimeout(this.getConfig().getHttpConnectionTimeout()) .bodyText(requestStr); if (useKey) { SSLContext sslContext = this.getConfig().getSslContext(); if (null == sslContext) { sslContext = this.getConfig().initSSLContext(); } final SSLSocketHttpConnectionProvider provider = new SSLSocketHttpConnectionProvider(sslContext); request.withConnectionProvider(provider); } if (StringUtils.isNotBlank(this.getConfig().getHttpProxyHost()) && this.getConfig().getHttpProxyPort() > 0) { if (StringUtils.isEmpty(this.getConfig().getHttpProxyUsername())) { this.getConfig().setHttpProxyUsername("whatever"); } ProxyInfo httpProxy = new ProxyInfo(ProxyType.HTTP, this.getConfig().getHttpProxyHost(), this.getConfig().getHttpProxyPort(), this.getConfig().getHttpProxyUsername(), this.getConfig().getHttpProxyPassword()); HttpConnectionProvider provider = request.connectionProvider(); if (null == provider) { provider = new SocketHttpConnectionProvider(); } provider.useProxy(httpProxy); request.withConnectionProvider(provider); } return request; } private HttpRequest buildHttpRequest(String url, String requestStr, boolean useKey, String mimeType) throws WxPayException { HttpRequest request = HttpRequest .post(url) .contentType(mimeType) .timeout(this.getConfig().getHttpTimeout()) .connectionTimeout(this.getConfig().getHttpConnectionTimeout()) .bodyText(requestStr); if (useKey) { SSLContext sslContext = this.getConfig().getSslContext(); if (null == sslContext) { sslContext = this.getConfig().initSSLContext(); } final SSLSocketHttpConnectionProvider provider = new SSLSocketHttpConnectionProvider(sslContext); request.withConnectionProvider(provider); } if (StringUtils.isNotBlank(this.getConfig().getHttpProxyHost()) && this.getConfig().getHttpProxyPort() > 0) { if (StringUtils.isEmpty(this.getConfig().getHttpProxyUsername())) { this.getConfig().setHttpProxyUsername("whatever"); } ProxyInfo httpProxy = new ProxyInfo(ProxyType.HTTP, this.getConfig().getHttpProxyHost(), this.getConfig().getHttpProxyPort(), this.getConfig().getHttpProxyUsername(), this.getConfig().getHttpProxyPassword()); HttpConnectionProvider provider = request.connectionProvider(); if (null == provider) { provider = new SocketHttpConnectionProvider(); } provider.useProxy(httpProxy); request.withConnectionProvider(provider); } return request; } private String getResponseString(HttpResponse response) throws WxPayException { try { log.debug("【微信服务器响应头信息】:\n{}", response.toString(false)); } catch (NullPointerException e) { log.warn("HttpResponse.toString() 居然抛出空指针异常了", e); } String responseString = response.bodyText(); if (StringUtils.isBlank(responseString)) { throw new WxPayException("响应信息为空"); } if (StringUtils.isBlank(response.charset())) { responseString = new String(responseString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); } return responseString; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.ecommerce.*; import com.github.binarywang.wxpay.bean.ecommerce.enums.FundBillTypeEnum; import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum; import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.EcommerceService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.WechatPayUploadHttpPost; import com.github.binarywang.wxpay.v3.util.AesUtils; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.common.base.CaseFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.text.DateFormat; import java.util.*; @RequiredArgsConstructor public class EcommerceServiceImpl implements EcommerceService { private static final Gson GSON = new GsonBuilder().create(); // https://stackoverflow.com/questions/6873020/gson-date-format // gson default date format not match, so custom DateFormat // detail DateFormat: FULL,LONG,SHORT,MEDIUM private static final Gson GSON_CUSTOM = new GsonBuilder().setDateFormat(DateFormat.FULL, DateFormat.FULL).create(); private final WxPayService payService; @Override public ApplymentsResult createApply(ApplymentsRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/applyments/", this.payService.getPayBaseUrl()); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, ApplymentsResult.class); } @Override public ApplymentsStatusResult queryApplyStatusByApplymentId(String applymentId) throws WxPayException { String url = String.format("%s/v3/ecommerce/applyments/%s", this.payService.getPayBaseUrl(), applymentId); String result = this.payService.getV3(url); return GSON.fromJson(result, ApplymentsStatusResult.class); } @Override public ApplymentsStatusResult queryApplyStatusByOutRequestNo(String outRequestNo) throws WxPayException { String url = String.format("%s/v3/ecommerce/applyments/out-request-no/%s", this.payService.getPayBaseUrl(), outRequestNo); String result = this.payService.getV3(url); return GSON.fromJson(result, ApplymentsStatusResult.class); } @Override public TransactionsResult combine(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException { String url = this.payService.getPayBaseUrl() + tradeType.getCombineUrl(); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, TransactionsResult.class); } @Override public <T> T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException { TransactionsResult result = this.combine(tradeType, request); return result.getPayInfo(tradeType, request.getCombineAppid(), request.getCombineMchid(), payService.getConfig().getPrivateKey()); } @Override public CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { if (Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)) { throw new WxPayException("非法请求,头部信息验证失败"); } NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class); NotifyResponse.Resource resource = response.getResource(); String cipherText = resource.getCiphertext(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key); CombineTransactionsResult transactionsResult = GSON.fromJson(result, CombineTransactionsResult.class); CombineTransactionsNotifyResult notifyResult = new CombineTransactionsNotifyResult(); notifyResult.setRawData(response); notifyResult.setResult(transactionsResult); return notifyResult; } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } @Override public CombineTransactionsResult queryCombineTransactions(String outTradeNo) throws WxPayException { String url = String.format("%s/v3/combine-transactions/out-trade-no/%s", this.payService.getPayBaseUrl(), outTradeNo); String response = this.payService.getV3(url); return GSON.fromJson(response, CombineTransactionsResult.class); } @Override public TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException { String url = this.payService.getPayBaseUrl() + tradeType.getPartnerUrl(); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, TransactionsResult.class); } @Override public <T> T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException { TransactionsResult result = this.partner(tradeType, request); String appId = request.getSubAppid() != null ? request.getSubAppid() : request.getSpAppid(); return result.getPayInfo(tradeType, appId, request.getSpMchid(), payService.getConfig().getPrivateKey()); } @Override public PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { if (Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)) { throw new WxPayException("非法请求,头部信息验证失败"); } NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class); NotifyResponse.Resource resource = response.getResource(); String cipherText = resource.getCiphertext(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key); PartnerTransactionsResult transactionsResult = GSON.fromJson(result, PartnerTransactionsResult.class); PartnerTransactionsNotifyResult notifyResult = new PartnerTransactionsNotifyResult(); notifyResult.setRawData(response); notifyResult.setResult(transactionsResult); return notifyResult; } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } @Override public PartnerTransactionsResult queryPartnerTransactions(PartnerTransactionsQueryRequest request) throws WxPayException { String url = String.format("%s/v3/pay/partner/transactions/out-trade-no/%s", this.payService.getPayBaseUrl(), request.getOutTradeNo()); if (Objects.isNull(request.getOutTradeNo())) { url = String.format("%s/v3/pay/partner/transactions/id/%s", this.payService.getPayBaseUrl(), request.getTransactionId()); } String query = String.format("?sp_mchid=%s&sub_mchid=%s", request.getSpMchid(), request.getSubMchid()); String response = this.payService.getV3(url + query); return GSON.fromJson(response, PartnerTransactionsResult.class); } @Override public String closePartnerTransactions(PartnerTransactionsCloseRequest request) throws WxPayException { String url = String.format("%s/v3/pay/partner/transactions/out-trade-no/%s/close", this.payService.getPayBaseUrl(), request.getOutTradeNo()); return this.payService.postV3(url, GSON.toJson(request)); } @Override public FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException { String url = String.format("%s/v3/merchant/fund/balance/%s", this.payService.getPayBaseUrl(), accountType); String response = this.payService.getV3(url); return GSON.fromJson(response, FundBalanceResult.class); } @Override public FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) throws WxPayException { String url = String.format("%s/v3/merchant/fund/dayendbalance/%s?date=%s", this.payService.getPayBaseUrl(), accountType, date); String response = this.payService.getV3(url); return GSON.fromJson(response, FundBalanceResult.class); } @Override public FundBalanceResult subNowBalance(String subMchid) throws WxPayException { String url = String.format("%s/v3/ecommerce/fund/balance/%s", this.payService.getPayBaseUrl(), subMchid); String response = this.payService.getV3(url); return GSON.fromJson(response, FundBalanceResult.class); } @Override public FundBalanceResult subNowBalance(String subMchid, SpAccountTypeEnum accountType) throws WxPayException { String url = String.format("%s/v3/ecommerce/fund/balance/%s", this.payService.getPayBaseUrl(), subMchid); if (Objects.nonNull(accountType)) { url += "?account_type=" + accountType.getValue(); } String response = this.payService.getV3(url); return GSON.fromJson(response, FundBalanceResult.class); } @Override public FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException { String url = String.format("%s/v3/ecommerce/fund/enddaybalance/%s?date=%s", this.payService.getPayBaseUrl(), subMchid, date); String response = this.payService.getV3(url); return GSON.fromJson(response, FundBalanceResult.class); } @Override public ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/profitsharing/orders", this.payService.getPayBaseUrl()); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String response = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(response, ProfitSharingResult.class); } @Override public ProfitSharingResult queryProfitSharing(ProfitSharingQueryRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/profitsharing/orders?sub_mchid=%s&transaction_id=%s&out_order_no=%s", this.payService.getPayBaseUrl(), request.getSubMchid(), request.getTransactionId(), request.getOutOrderNo()); String response = this.payService.getV3(url); return GSON.fromJson(response, ProfitSharingResult.class); } @Override public ProfitSharingOrdersUnSplitAmountResult queryProfitSharingOrdersUnsplitAmount(ProfitSharingOrdersUnSplitAmountRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/profitsharing/orders/%s/amounts", this.payService.getPayBaseUrl(), request.getTransactionId()); String response = this.payService.getV3(url); return GSON.fromJson(response, ProfitSharingOrdersUnSplitAmountResult.class); } @Override public ProfitSharingReceiverResult addReceivers(ProfitSharingReceiverRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/profitsharing/receivers/add", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, ProfitSharingReceiverResult.class); } @Override public ProfitSharingReceiverResult deleteReceivers(ProfitSharingReceiverRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/profitsharing/receivers/delete", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, ProfitSharingReceiverResult.class); } @Override public ReturnOrdersResult returnOrders(ReturnOrdersRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/profitsharing/returnorders", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, ReturnOrdersResult.class); } @Override public ReturnOrdersResult queryReturnOrders(ReturnOrdersQueryRequest request) throws WxPayException { String subMchid = request.getSubMchid(); String orderId = request.getOrderId(); String outOrderNo = request.getOutOrderNo(); String outReturnNo = request.getOutReturnNo(); String url = null; if (StringUtils.isBlank(orderId)) { url = String.format("%s/v3/ecommerce/profitsharing/returnorders?sub_mchid=%s&out_order_no=%s&out_return_no=%s", this.payService.getPayBaseUrl(), subMchid, outOrderNo, outReturnNo); } else { url = String.format("%s/v3/ecommerce/profitsharing/returnorders?sub_mchid=%s&order_id=%s&out_return_no=%s", this.payService.getPayBaseUrl(), subMchid, orderId, outReturnNo); } String response = this.payService.getV3(url); return GSON.fromJson(response, ReturnOrdersResult.class); } @Override public ProfitSharingResult finishOrder(FinishOrderRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/profitsharing/finish-order", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, ProfitSharingResult.class); } @Override public RefundsResult refunds(RefundsRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/refunds/apply", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, RefundsResult.class); } @Override public RefundQueryResult queryRefundByRefundId(String subMchid, String refundId) throws WxPayException { String url = String.format("%s/v3/ecommerce/refunds/id/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), refundId, subMchid); String response = this.payService.getV3(url); return GSON.fromJson(response, RefundQueryResult.class); } @Override public ReturnAdvanceResult refundsReturnAdvance(String subMchid, String refundId) throws WxPayException { String url = String.format("%s/v3/ecommerce/refunds/%s/return-advance", this.payService.getPayBaseUrl(), refundId); Map<String, String> request = new HashMap<>(); request.put("sub_mchid",subMchid); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, ReturnAdvanceResult.class); } @Override public ReturnAdvanceResult queryRefundsReturnAdvance(String subMchid, String refundId) throws WxPayException { String url = String.format("%s/v3/ecommerce/refunds/%s/return-advance?sub_mchid=%s", this.payService.getPayBaseUrl(), refundId,subMchid); String response = this.payService.getV3(url); return GSON.fromJson(response, ReturnAdvanceResult.class); } @Override public RefundQueryResult queryRefundByOutRefundNo(String subMchid, String outRefundNo) throws WxPayException { String url = String.format("%s/v3/ecommerce/refunds/out-refund-no/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), outRefundNo, subMchid); String response = this.payService.getV3(url); return GSON.fromJson(response, RefundQueryResult.class); } @Override public RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { if (Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)) { throw new WxPayException("非法请求,头部信息验证失败"); } NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class); NotifyResponse.Resource resource = response.getResource(); String cipherText = resource.getCiphertext(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key); RefundNotifyResult notifyResult = GSON.fromJson(result, RefundNotifyResult.class); notifyResult.setRawData(response); return notifyResult; } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } @Override public WithdrawNotifyResult parseWithdrawNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { if (Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)) { throw new WxPayException("非法请求,头部信息验证失败"); } NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class); NotifyResponse.Resource resource = response.getResource(); String cipherText = resource.getCiphertext(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key); WithdrawNotifyResult notifyResult = GSON.fromJson(result, WithdrawNotifyResult.class); notifyResult.setRawData(response); return notifyResult; } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } @Override public SubWithdrawResult subWithdraw(SubWithdrawRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/fund/withdraw", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, SubWithdrawResult.class); } @Override public SpWithdrawResult spWithdraw(SpWithdrawRequest request) throws WxPayException { String url = String.format("%s/v3/merchant/fund/withdraw", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, SpWithdrawResult.class); } @Override public SubWithdrawStatusResult querySubWithdrawByOutRequestNo(String subMchid, String outRequestNo) throws WxPayException { String url = String.format("%s/v3/ecommerce/fund/withdraw/out-request-no/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), outRequestNo, subMchid); String response = this.payService.getV3(url); return GSON.fromJson(response, SubWithdrawStatusResult.class); } @Override public SpWithdrawStatusResult querySpWithdrawByOutRequestNo(String outRequestNo) throws WxPayException { String url = String.format("%s/v3/merchant/fund/withdraw/out-request-no/%s", this.payService.getPayBaseUrl(), outRequestNo); String response = this.payService.getV3(url); return GSON.fromJson(response, SpWithdrawStatusResult.class); } @Override public SpWithdrawStatusResult querySpWithdrawByWithdrawId(String withdrawId) throws WxPayException { String url = String.format("%s/v3/merchant/fund/withdraw/withdraw-id/%s", this.payService.getPayBaseUrl(), withdrawId); String response = this.payService.getV3(url); return GSON.fromJson(response, SpWithdrawStatusResult.class); } @Override public SubDayEndBalanceWithdrawResult subDayEndBalanceWithdraw(SubDayEndBalanceWithdrawRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/fund/balance-withdraw", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, SubDayEndBalanceWithdrawResult.class); } @Override public SubDayEndBalanceWithdrawStatusResult querySubDayEndBalanceWithdraw(String subMchid, String outRequestNo) throws WxPayException { String url = String.format("%s/v3/ecommerce/fund/balance-withdraw/out-request-no/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), outRequestNo, subMchid); String response = this.payService.getV3(url); return GSON.fromJson(response, SubDayEndBalanceWithdrawStatusResult.class); } @Override public void modifySettlement(String subMchid, SettlementRequest request) throws WxPayException { String url = String.format("%s/v3/apply4sub/sub_merchants/%s/modify-settlement", this.payService.getPayBaseUrl(), subMchid); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); } @Override public SettlementResult querySettlement(String subMchid) throws WxPayException { String url = String.format("%s/v3/apply4sub/sub_merchants/%s/settlement", this.payService.getPayBaseUrl(), subMchid); String response = this.payService.getV3(url); return GSON.fromJson(response, SettlementResult.class); } @Override public TradeBillResult applyBill(TradeBillRequest request) throws WxPayException { String url = String.format("%s/v3/bill/tradebill?%s", this.payService.getPayBaseUrl(), this.parseURLPair(request)); String response = this.payService.getV3(url); return GSON.fromJson(response, TradeBillResult.class); } @Override public FundBillResult applyFundBill(FundBillTypeEnum billType, FundBillRequest request) throws WxPayException { String url = String.format(billType.getUrl(), this.payService.getPayBaseUrl(), this.parseURLPair(request)); String response = this.payService.getV3(url); return GSON.fromJson(response, FundBillResult.class); } @Override public InputStream downloadBill(String url) throws WxPayException { return this.payService.downloadV3(url); } @Override public SubsidiesCreateResult subsidiesCreate(SubsidiesCreateRequest subsidiesCreateRequest) throws WxPayException{ String url = String.format("%s/v3/ecommerce/subsidies/create", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(subsidiesCreateRequest)); return GSON.fromJson(response, SubsidiesCreateResult.class); } @Override public SubsidiesReturnResult subsidiesReturn(SubsidiesReturnRequest subsidiesReturnRequest) throws WxPayException{ String url = String.format("%s/v3/ecommerce/subsidies/return", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(subsidiesReturnRequest)); return GSON.fromJson(response, SubsidiesReturnResult.class); } @Override public SubsidiesCancelResult subsidiesCancel(SubsidiesCancelRequest subsidiesCancelRequest) throws WxPayException{ String url = String.format("%s/v3/ecommerce/subsidies/cancel", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(subsidiesCancelRequest)); return GSON.fromJson(response, SubsidiesCancelResult.class); } @Override public AccountCancelApplicationsResult createdAccountCancelApplication(AccountCancelApplicationsRequest accountCancelApplicationsRequest) throws WxPayException { String url = String.format("%s/v3/ecommerce/account/cancel-applications", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(accountCancelApplicationsRequest)); return GSON.fromJson(response, AccountCancelApplicationsResult.class); } @Override public AccountCancelApplicationsResult getAccountCancelApplication(String outApplyNo) throws WxPayException { String url = String.format("%s/v3/ecommerce/account/cancel-applications/out-apply-no/%s", this.payService.getPayBaseUrl(), outApplyNo); String result = this.payService.getV3(url); return GSON.fromJson(result, AccountCancelApplicationsResult.class); } @Override public AccountCancelApplicationsMediaResult uploadMediaAccountCancelApplication(File imageFile) throws WxPayException, IOException { String url = String.format("%s/v3/ecommerce/account/cancel-applications/media", this.payService.getPayBaseUrl()); try (FileInputStream s1 = new FileInputStream(imageFile)) { String sha256 = DigestUtils.sha256Hex(s1); try (InputStream s2 = new FileInputStream(imageFile)) { WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(URI.create(url)) .withImage(imageFile.getName(), sha256, s2) .buildEcommerceAccount(); String result = this.payService.postV3(url, request); return GSON.fromJson(result, AccountCancelApplicationsMediaResult.class); } } } /** * 校验通知签名 * * @param header 通知头信息 * @param data 通知数据 * @return true:校验通过 false:校验不通过 */ private boolean verifyNotifySign(SignatureHeader header, String data) { String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(), header.getNonce(), data); return payService.getConfig().getVerifier().verify(header.getSerialNo(), beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned()); } /** * 对象拼接到url * * @param o 转换对象 * @return 拼接好的string */ private String parseURLPair(Object o) { Map<Object, Object> map = getObjectToMap(o); Set<Map.Entry<Object, Object>> set = map.entrySet(); Iterator<Map.Entry<Object, Object>> it = set.iterator(); StringBuilder sb = new StringBuilder(); while (it.hasNext()) { Map.Entry<Object, Object> e = it.next(); if (!"class".equals(e.getKey()) && e.getValue() != null) { sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, String.valueOf(e.getKey()))) .append("=").append(e.getValue()).append("&"); } } return sb.deleteCharAt(sb.length() - 1).toString(); } public static Map<Object, Object> getObjectToMap(Object obj) { try { Map<Object, Object> result = new LinkedHashMap<>(); final Class<?> beanClass = obj.getClass(); final BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); if (propertyDescriptors != null) { for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (propertyDescriptor != null) { final String name = propertyDescriptor.getName(); final Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod != null) { result.put(name, readMethod.invoke(obj)); } } } } return result; } catch (IllegalAccessException | IntrospectionException | InvocationTargetException ignored) { return null; } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EntPayServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EntPayServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.entpay.*; import com.github.binarywang.wxpay.bean.entwxpay.EntWxEmpPayRequest; import com.github.binarywang.wxpay.bean.request.WxPayDefaultRequest; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.EntPayService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.util.SignUtils; import lombok.RequiredArgsConstructor; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.openssl.PEMParser; import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; import javax.crypto.Cipher; import java.io.File; import java.io.FileReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.security.PublicKey; import java.security.Security; import java.util.Base64; /** * <pre> * Created by BinaryWang on 2017/12/19. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @RequiredArgsConstructor public class EntPayServiceImpl implements EntPayService { private final WxPayService payService; @Override public EntPayResult entPay(EntPayRequest request) throws WxPayException { request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/promotion/transfers"; String responseContent = this.payService.post(url, request.toXML(), true); EntPayResult result = BaseWxPayResult.fromXML(responseContent, EntPayResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public EntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException { EntPayQueryRequest request = new EntPayQueryRequest(); request.setPartnerTradeNo(partnerTradeNo); request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/gettransferinfo"; String responseContent = this.payService.post(url, request.toXML(), true); EntPayQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayQueryResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public EntPayQueryResult queryEntPay(EntPayQueryRequest request) throws WxPayException { request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/gettransferinfo"; String responseContent = this.payService.post(url, request.toXML(), true); EntPayQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayQueryResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public String getPublicKey() throws WxPayException { WxPayDefaultRequest request = new WxPayDefaultRequest(); request.setMchId(this.payService.getConfig().getMchId()); request.setNonceStr(String.valueOf(System.currentTimeMillis())); request.checkAndSign(this.payService.getConfig()); String url = "https://fraud.mch.weixin.qq.com/risk/getpublickey"; String responseContent = this.payService.post(url, request.toXML(), true); GetPublicKeyResult result = BaseWxPayResult.fromXML(responseContent, GetPublicKeyResult.class); result.checkResult(this.payService, request.getSignType(), true); return result.getPubKey(); } @Override public EntPayBankResult payBank(EntPayBankRequest request) throws WxPayException { File publicKeyFile = this.buildPublicKeyFile(); request.setEncBankNo(this.encryptRSA(publicKeyFile, request.getEncBankNo())); request.setEncTrueName(this.encryptRSA(publicKeyFile, request.getEncTrueName())); publicKeyFile.deleteOnExit(); request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaysptrans/pay_bank"; String responseContent = this.payService.post(url, request.toXML(), true); EntPayBankResult result = BaseWxPayResult.fromXML(responseContent, EntPayBankResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public EntPayBankQueryResult queryPayBank(String partnerTradeNo) throws WxPayException { EntPayBankQueryRequest request = new EntPayBankQueryRequest(); request.setPartnerTradeNo(partnerTradeNo); request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaysptrans/query_bank"; String responseContent = this.payService.post(url, request.toXML(), true); EntPayBankQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayBankQueryResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public EntPayBankQueryResult queryPayBank(EntPayBankQueryRequest request) throws WxPayException { request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaysptrans/query_bank"; String responseContent = this.payService.post(url, request.toXML(), true); EntPayBankQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayBankQueryResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public EntPayRedpackResult sendEnterpriseRedpack(EntPayRedpackRequest request) throws WxPayException { //企业微信签名,需要在请求签名之前 request.setNonceStr(String.valueOf(System.currentTimeMillis())); request.setWorkWxSign(SignUtils.createEntSign(request.getActName(), request.getMchBillNo(), request.getMchId(), request.getNonceStr(), request.getReOpenid(), request.getTotalAmount(), request.getWxAppId(), payService.getConfig().getEntPayKey(), WxPayConstants.SignType.MD5)); request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendworkwxredpack"; String responseContent = this.payService.post(url, request.toXML(), true); final EntPayRedpackResult result = BaseWxPayResult.fromXML(responseContent, EntPayRedpackResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public EntPayRedpackQueryResult queryEnterpriseRedpack(EntPayRedpackQueryRequest request) throws WxPayException { request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/queryworkwxredpack"; String responseContent = this.payService.post(url, request.toXML(), true); final EntPayRedpackQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayRedpackQueryResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public EntPayResult toEmpPay(EntWxEmpPayRequest request) throws WxPayException { //企业微信签名,需要在请求签名之前 request.setNonceStr(String.valueOf(System.currentTimeMillis())); request.setWorkWxSign(SignUtils.createEntSign(request.getAmount(), request.getAppid(), request.getDescription(), request.getMchId(), request.getNonceStr(), request.getOpenid(), request.getPartnerTradeNo(), request.getWwMsgType(), payService.getConfig().getEntPayKey(), WxPayConstants.SignType.MD5)); request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/promotion/paywwsptrans2pocket"; String responseContent = this.payService.post(url, request.toXML(), true); final EntPayResult result = BaseWxPayResult.fromXML(responseContent, EntPayResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } private String encryptRSA(File publicKeyFile, String srcString) throws WxPayException { try { Security.addProvider(new BouncyCastleProvider()); Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA1AndMGF1Padding"); try (PEMParser reader = new PEMParser(new FileReader(publicKeyFile))) { final PublicKey publicKey = new JcaPEMKeyConverter().setProvider("BC") .getPublicKey((SubjectPublicKeyInfo) reader.readObject()); cipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] encrypt = cipher.doFinal(srcString.getBytes(StandardCharsets.UTF_8)); return Base64.getEncoder().encodeToString(encrypt); } } catch (Exception e) { throw new WxPayException("加密出错", e); } } private File buildPublicKeyFile() throws WxPayException { try { String publicKeyStr = this.getPublicKey(); Path tmpFile = Files.createTempFile("payToBank", ".pem"); Files.write(tmpFile, publicKeyStr.getBytes(StandardCharsets.UTF_8)); return tmpFile.toFile(); } catch (Exception e) { throw new WxPayException("生成加密公钥文件时发生异常", e); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MarketingFavorServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MarketingFavorServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.bean.marketing.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.MarketingFavorService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.AesUtils; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.util.Objects; /** * 微信支付-营销代金券接口 * * @author thinsstar */ @Slf4j @RequiredArgsConstructor public class MarketingFavorServiceImpl implements MarketingFavorService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; @Override public FavorStocksCreateResult createFavorStocksV3(FavorStocksCreateRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/favor/coupon-stocks", this.payService.getPayBaseUrl()); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); FavorStocksCreateResult favorStocksCreateResult = GSON.fromJson(result, FavorStocksCreateResult.class); favorStocksCreateResult.setRawJsonString(result); return favorStocksCreateResult; } @Override public FavorCouponsCreateResult createFavorCouponsV3(String openid, FavorCouponsCreateRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/favor/users/%s/coupons", this.payService.getPayBaseUrl(), openid); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, FavorCouponsCreateResult.class); } @Override public FavorStocksStartResult startFavorStocksV3(String stockId, FavorStocksSetRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks/%s/start", this.payService.getPayBaseUrl(), stockId); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, FavorStocksStartResult.class); } @Override public FavorStocksQueryResult queryFavorStocksV3(FavorStocksQueryRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks", this.payService.getPayBaseUrl()); String query = String.format("?offset=%s&limit=%s&stock_creator_mchid=%s", request.getOffset(), request.getLimit(), request.getStockCreatorMchid()); if (StringUtils.isNotBlank(request.getCreateStartTime())) { query += "&create_start_time=" + request.getCreateStartTime(); } if (StringUtils.isNotBlank(request.getCreateEndTime())) { query += "&create_end_time=" + request.getCreateEndTime(); } if (StringUtils.isNotBlank(request.getStatus())) { query += "&status=" + request.getStatus(); } String result = this.payService.getV3(url + query); return GSON.fromJson(result, FavorStocksQueryResult.class); } @Override public FavorStocksGetResult getFavorStocksV3(String stockId, String stockCreatorMchid) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks/%s", this.payService.getPayBaseUrl(), stockId); String query = String.format("?stock_creator_mchid=%s", stockCreatorMchid); String result = this.payService.getV3(url + query); FavorStocksGetResult favorStocksGetResult = GSON.fromJson(result, FavorStocksGetResult.class); favorStocksGetResult.setRawJsonString(result); return favorStocksGetResult; } @Override public FavorCouponsGetResult getFavorCouponsV3(String couponId, String appid, String openid) throws WxPayException { String url = String.format("%s/v3/marketing/favor/users/%s/coupons/%s", this.payService.getPayBaseUrl(), openid, couponId); String query = String.format("?appid=%s", appid); String result = this.payService.getV3(url + query); FavorCouponsGetResult favorCouponsGetResult = GSON.fromJson(result, FavorCouponsGetResult.class); favorCouponsGetResult.setRawJsonString(result); return favorCouponsGetResult; } @Override public FavorStocksMerchantsGetResult getFavorStocksMerchantsV3(String stockId, String stockCreatorMchid, Integer offset, Integer limit) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks/%s/merchants", this.payService.getPayBaseUrl(), stockId); String query = String.format("?stock_creator_mchid=%s&offset=%s&limit=%s", stockCreatorMchid, offset, limit); String result = this.payService.getV3(url + query); return GSON.fromJson(result, FavorStocksMerchantsGetResult.class); } @Override public FavorStocksItemsGetResult getFavorStocksItemsV3(String stockId, String stockCreatorMchid, Integer offset, Integer limit) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks/%s/items", this.payService.getPayBaseUrl(), stockId); String query = String.format("?stock_creator_mchid=%s&offset=%s&limit=%s", stockCreatorMchid, offset, limit); String result = this.payService.getV3(url + query); return GSON.fromJson(result, FavorStocksItemsGetResult.class); } @Override public FavorCouponsQueryResult queryFavorCouponsV3(FavorCouponsQueryRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/favor/users/%s/coupons", this.payService.getPayBaseUrl(), request.getOpenid()); String query = String.format("?appid=%s", request.getAppid()); if (StringUtils.isNotBlank(request.getStockId())) { query += "&stock_id=" + request.getStockId(); } if (StringUtils.isNotBlank(request.getStatus())) { query += "&status=" + request.getStatus(); } if (StringUtils.isNotBlank(request.getCreatorMchid())) { query += "&creator_mchid=" + request.getCreatorMchid(); } if (StringUtils.isNotBlank(request.getSenderMchid())) { query += "&sender_mchid=" + request.getSenderMchid(); } if (StringUtils.isNotBlank(request.getAvailableMchid())) { query += "&available_mchid=" + request.getAvailableMchid(); } if (request.getOffset() != null) { query += "&offset=" + request.getOffset(); } if (request.getLimit() != null) { query += "&limit=" + request.getLimit(); } String result = this.payService.getV3(url + query); return GSON.fromJson(result, FavorCouponsQueryResult.class); } @Override public FavorStocksFlowGetResult getFavorStocksUseFlowV3(String stockId) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks/%s/use-flow", this.payService.getPayBaseUrl(), stockId); String result = this.payService.getV3(url); return GSON.fromJson(result, FavorStocksFlowGetResult.class); } @Override public FavorStocksFlowGetResult getFavorStocksRefundFlowV3(String stockId) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks/%s/refund-flow", this.payService.getPayBaseUrl(), stockId); String result = this.payService.getV3(url); return GSON.fromJson(result, FavorStocksFlowGetResult.class); } @Override public FavorCallbacksSaveResult saveFavorCallbacksV3(FavorCallbacksSaveRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/favor/callbacks", this.payService.getPayBaseUrl()); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, FavorCallbacksSaveResult.class); } @Override public FavorStocksPauseResult pauseFavorStocksV3(String stockId, FavorStocksSetRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks/%s/pause", this.payService.getPayBaseUrl(), stockId); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, FavorStocksPauseResult.class); } @Override public FavorStocksRestartResult restartFavorStocksV3(String stockId, FavorStocksSetRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/favor/stocks/%s/restart", this.payService.getPayBaseUrl(), stockId); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, FavorStocksRestartResult.class); } /** * 校验通知签名 * * @param header 通知头信息 * @param data 通知数据 * @return true:校验通过 false:校验不通过 */ private boolean verifyNotifySign(SignatureHeader header, String data) { String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(), header.getNonce(), data); return payService.getConfig().getVerifier().verify(header.getSerialNo(), beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned()); } @Override public UseNotifyData parseNotifyData(String data, SignatureHeader header) throws WxPayException { if (Objects.nonNull(header) && !this.verifyNotifySign(header, data)) { throw new WxPayException("非法请求,头部信息验证失败"); } return GSON.fromJson(data, UseNotifyData.class); } @Override public FavorCouponsUseResult decryptNotifyDataResource(UseNotifyData data) throws WxPayException { UseNotifyData.Resource resource = data.getResource(); String cipherText = resource.getCipherText(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { return GSON.fromJson(AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key), FavorCouponsUseResult.class); } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MarketingMediaServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MarketingMediaServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.media.MarketingImageUploadResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.MarketingMediaService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.WechatPayUploadHttpPost; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import java.io.*; import java.net.URI; /** * 微信支付-营销专用媒体文件上传service * * @author thinsstar */ @Slf4j @RequiredArgsConstructor public class MarketingMediaServiceImpl implements MarketingMediaService { private final WxPayService payService; @Override public MarketingImageUploadResult imageUploadV3(File imageFile) throws WxPayException, IOException { String url = String.format("%s/v3/marketing/favor/media/image-upload", this.payService.getPayBaseUrl()); try (FileInputStream s1 = new FileInputStream(imageFile)) { String sha256 = DigestUtils.sha256Hex(s1); try (InputStream s2 = new FileInputStream(imageFile)) { WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(URI.create(url)) .withImage(imageFile.getName(), sha256, s2) .build(); String result = this.payService.postV3(url, request); return MarketingImageUploadResult.fromJson(result); } } } @Override public MarketingImageUploadResult imageUploadV3(InputStream inputStream, String fileName) throws WxPayException, IOException { String url = String.format("%s/v3/marketing/favor/media/image-upload", this.payService.getPayBaseUrl()); try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { byte[] buffer = new byte[2048]; int len; while ((len = inputStream.read(buffer)) > -1) { bos.write(buffer, 0, len); } bos.flush(); byte[] data = bos.toByteArray(); String sha256 = DigestUtils.sha256Hex(data); WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(URI.create(url)) .withImage(fileName, sha256, new ByteArrayInputStream(data)) .build(); String result = this.payService.postV3(url, request); return MarketingImageUploadResult.fromJson(result); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MarketingBusiFavorServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MarketingBusiFavorServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.marketing.*; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.MarketingBusiFavorService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.util.SignUtils; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.Map; /** * 微信支付-营销商家券接口 * * @author yujam */ @Slf4j @RequiredArgsConstructor public class MarketingBusiFavorServiceImpl implements MarketingBusiFavorService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; @Override public BusiFavorStocksCreateResult createBusiFavorStocksV3(BusiFavorStocksCreateRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/stocks", this.payService.getPayBaseUrl()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorStocksCreateResult.class); } @Override public BusiFavorStocksGetResult getBusiFavorStocksV3(String stockId) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/stocks/%s", this.payService.getPayBaseUrl(), stockId); String result = this.payService.getV3(url); return GSON.fromJson(result, BusiFavorStocksGetResult.class); } @Override public BusiFavorCouponsUseResult verifyBusiFavorCouponsUseV3(BusiFavorCouponsUseRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/coupons/use", this.payService.getPayBaseUrl()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorCouponsUseResult.class); } @Override public String buildBusiFavorCouponinfoUrl(BusiFavorCouponsUrlRequest request) throws WxPayException { Map<String, String> signMap = new HashMap<>(8); signMap.put("out_request_no", request.getOutRequestNo()); signMap.put("stock_id", request.getStockId()); signMap.put("send_coupon_merchant", request.getSendCouponMerchant()); signMap.put("open_id", request.getOpenid()); String sign = SignUtils.createSign(signMap, WxPayConstants.SignType.HMAC_SHA256, this.payService.getConfig().getMchKey(), null); String actionBaseUrl = "https://action.weixin.qq.com"; return String.format("%s/busifavor/getcouponinfo?stock_id=%s&out_request_no=%s&sign=%s&send_coupon_merchant=%s&open_id=%s#wechat_redirect", actionBaseUrl, request.getStockId(), request.getOutRequestNo(), sign, request.getSendCouponMerchant(), request.getOpenid()); } @Override public BusiFavorQueryUserCouponsResult queryBusiFavorUsersCoupons(BusiFavorQueryUserCouponsRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/users/%s/coupons", this.payService.getPayBaseUrl(), request.getOpenid()); if (request.getOffset() == null) { request.setOffset(0); } if (request.getLimit() == null || request.getLimit() <= 0) { request.setLimit(20); } String query = String.format("?appid=%s&offset=%s&limit=%s", request.getAppid(), request.getOffset(), request.getLimit()); if (StringUtils.isNotBlank(request.getStockId())) { query += "&stock_id=" + request.getStockId(); } if (StringUtils.isNotBlank(request.getCouponState())) { query += "&coupon_state=" + request.getCouponState(); } if (StringUtils.isNotBlank(request.getCreatorMerchant())) { query += "&creator_merchant=" + request.getCreatorMerchant(); } if (StringUtils.isNotBlank(request.getBelongMerchant())) { query += "&belong_merchant=" + request.getBelongMerchant(); } if (StringUtils.isNotBlank(request.getSenderMerchant())) { query += "&sender_merchant=" + request.getSenderMerchant(); } String result = this.payService.getV3(url + query); return GSON.fromJson(result, BusiFavorQueryUserCouponsResult.class); } @Override public BusiFavorQueryOneUserCouponsResult queryOneBusiFavorUsersCoupons(BusiFavorQueryOneUserCouponsRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/users/%s/coupons/%s/appids/%s", this.payService.getPayBaseUrl(), request.getOpenid(), request.getCouponCode(), request.getAppid()); String result = this.payService.getV3(url); return GSON.fromJson(result, BusiFavorQueryOneUserCouponsResult.class); } @Override public BusiFavorCouponCodeResult uploadBusiFavorCouponCodes(String stockId, BusiFavorCouponCodeRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/stocks/%s/couponcodes", this.payService.getPayBaseUrl(), stockId); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorCouponCodeResult.class); } @Override public BusiFavorCallbacksResult createBusiFavorCallbacks(BusiFavorCallbacksRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/callbacks", this.payService.getPayBaseUrl()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorCallbacksResult.class); } @Override public BusiFavorCallbacksResult queryBusiFavorCallbacks(BusiFavorCallbacksRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/callbacks", this.payService.getPayBaseUrl()); if (StringUtils.isNotBlank(request.getMchid())) { url += "?mchid=" + request.getMchid(); } String result = this.payService.getV3(url); return GSON.fromJson(result, BusiFavorCallbacksResult.class); } @Override public BusiFavorCouponsAssociateResult queryBusiFavorCouponsAssociate(BusiFavorCouponsAssociateRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/coupons/associate", this.payService.getPayBaseUrl()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorCouponsAssociateResult.class); } @Override public BusiFavorCouponsAssociateResult queryBusiFavorCouponsDisAssociate(BusiFavorCouponsAssociateRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/coupons/disassociate", this.payService.getPayBaseUrl()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorCouponsAssociateResult.class); } @Override public BusiFavorStocksBudgetResult updateBusiFavorStocksBudget(String stockId, BusiFavorStocksBudgetRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/stocks/%s/budget", this.payService.getPayBaseUrl(), stockId); String result = payService.patchV3(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorStocksBudgetResult.class); } @Override public String updateBusiFavorStocksV3(String stockId, BusiFavorStocksCreateRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/stocks/%s", this.payService.getPayBaseUrl(), stockId); return this.payService.patchV3(url, GSON.toJson(request)); } @Override public BusiFavorCouponsReturnResult returnBusiFavorCoupons(BusiFavorCouponsReturnRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/coupons/return", this.payService.getPayBaseUrl()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorCouponsReturnResult.class); } @Override public BusiFavorCouponsDeactivateResult deactiveBusiFavorCoupons(BusiFavorCouponsDeactivateRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/coupons/deactivate", this.payService.getPayBaseUrl()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorCouponsDeactivateResult.class); } @Override public BusiFavorSubsidyResult subsidyBusiFavorPayReceipts(BusiFavorSubsidyRequest request) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/subsidy/pay-receipts", this.payService.getPayBaseUrl()); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorSubsidyResult.class); } @Override public BusiFavorSubsidyResult queryBusiFavorSubsidyPayReceipts(String subsidyReceiptId) throws WxPayException { String url = String.format("%s/v3/marketing/busifavor/subsidy/pay-receipts/%s", this.payService.getPayBaseUrl(), subsidyReceiptId); String result = this.payService.getV3(url); return GSON.fromJson(result, BusiFavorSubsidyResult.class); } @Override public BusiFavorNotifyResult notifyBusiFavor(String url, BusiFavorNotifyRequest request) throws WxPayException { String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, BusiFavorNotifyResult.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/RedpackServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/RedpackServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest; import com.github.binarywang.wxpay.bean.request.WxPaySendMiniProgramRedpackRequest; import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult; import com.github.binarywang.wxpay.bean.result.WxPaySendMiniProgramRedpackResult; import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.RedpackService; import com.github.binarywang.wxpay.service.WxPayService; import lombok.RequiredArgsConstructor; /** * 老板加点注释吧. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2019-12-26 */ @RequiredArgsConstructor public class RedpackServiceImpl implements RedpackService { private final WxPayService payService; @Override public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException { request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendminiprogramhb"; String responseContent = this.payService.post(url, request.toXML(), true); WxPaySendMiniProgramRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendMiniProgramRedpackResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException { request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack"; if (request.getAmtType() != null) { //裂变红包 url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/sendgroupredpack"; } String responseContent = this.payService.post(url, request.toXML(), true); final WxPaySendRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendRedpackResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } @Override public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException { WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); request.setMchBillNo(mchBillNo); return this.queryRedpack(request); } @Override public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException { request.setBillType(WxPayConstants.BillType.MCHT); request.checkAndSign(this.payService.getConfig()); String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo"; String responseContent = this.payService.post(url, request.toXML(), true); WxPayRedpackQueryResult result = BaseWxPayResult.fromXML(responseContent, WxPayRedpackQueryResult.class); result.checkResult(this.payService, request.getSignType(), true); return result; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxDepositServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxDepositServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxDepositService; import com.github.binarywang.wxpay.service.WxPayService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; /** * <pre> * 微信押金支付服务实现 * </pre> * * @author Binary Wang * created on 2024-09-24 */ @Slf4j @RequiredArgsConstructor public class WxDepositServiceImpl implements WxDepositService { private final WxPayService payService; @Override public WxDepositUnifiedOrderResult unifiedOrder(WxDepositUnifiedOrderRequest request) throws WxPayException { request.checkAndSign(payService.getConfig()); String url = payService.getPayBaseUrl() + "/pay/depositpay"; String responseContent = payService.post(url, request.toXML(), false); WxDepositUnifiedOrderResult result = BaseWxPayResult.fromXML(responseContent, WxDepositUnifiedOrderResult.class); result.checkResult(payService, request.getSignType(), true); return result; } @Override public WxDepositOrderQueryResult queryOrder(WxDepositOrderQueryRequest request) throws WxPayException { request.checkAndSign(payService.getConfig()); String url = payService.getPayBaseUrl() + "/pay/depositorderquery"; String responseContent = payService.post(url, request.toXML(), false); WxDepositOrderQueryResult result = BaseWxPayResult.fromXML(responseContent, WxDepositOrderQueryResult.class); result.checkResult(payService, request.getSignType(), true); return result; } @Override public WxDepositConsumeResult consume(WxDepositConsumeRequest request) throws WxPayException { request.checkAndSign(payService.getConfig()); String url = payService.getPayBaseUrl() + "/pay/depositconsume"; String responseContent = payService.post(url, request.toXML(), false); WxDepositConsumeResult result = BaseWxPayResult.fromXML(responseContent, WxDepositConsumeResult.class); result.checkResult(payService, request.getSignType(), true); return result; } @Override public WxDepositUnfreezeResult unfreeze(WxDepositUnfreezeRequest request) throws WxPayException { request.checkAndSign(payService.getConfig()); String url = payService.getPayBaseUrl() + "/pay/depositreverse"; String responseContent = payService.post(url, request.toXML(), false); WxDepositUnfreezeResult result = BaseWxPayResult.fromXML(responseContent, WxDepositUnfreezeResult.class); result.checkResult(payService, request.getSignType(), true); return result; } @Override public WxDepositRefundResult refund(WxDepositRefundRequest request) throws WxPayException { request.checkAndSign(payService.getConfig()); String url = payService.getPayBaseUrl() + "/pay/depositrefund"; String responseContent = payService.post(url, request.toXML(), true); WxDepositRefundResult result = BaseWxPayResult.fromXML(responseContent, WxDepositRefundResult.class); result.checkResult(payService, request.getSignType(), true); return result; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MiPayServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MiPayServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.mipay.MedInsOrdersRequest; import com.github.binarywang.wxpay.bean.mipay.MedInsOrdersResult; import com.github.binarywang.wxpay.bean.mipay.MedInsRefundNotifyRequest; import com.github.binarywang.wxpay.bean.notify.MiPayNotifyV3Result; import com.github.binarywang.wxpay.bean.notify.SignatureHeader; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.MiPayService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.security.cert.X509Certificate; import lombok.RequiredArgsConstructor; /** * <a href="https://pay.weixin.qq.com/doc/v3/partner/4012503131">医保相关接口</a> * 医保相关接口 * @author xgl * @date 2025/12/20 */ @RequiredArgsConstructor public class MiPayServiceImpl implements MiPayService { private final WxPayService payService; private static final Gson GSON = new GsonBuilder().create(); @Override public MedInsOrdersResult medInsOrders(MedInsOrdersRequest request) throws WxPayException { String url = String.format("%s/v3/med-ins/orders", this.payService.getPayBaseUrl()); X509Certificate validCertificate = this.payService.getConfig().getVerifier().getValidCertificate(); RsaCryptoUtil.encryptFields(request, validCertificate); String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, MedInsOrdersResult.class); } @Override public MedInsOrdersResult getMedInsOrderByMixTradeNo(String mixTradeNo, String subMchid) throws WxPayException { String url = String.format("%s/v3/med-ins/orders/mix-trade-no/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), mixTradeNo, subMchid); String result = this.payService.getV3(url); return GSON.fromJson(result, MedInsOrdersResult.class); } @Override public MedInsOrdersResult getMedInsOrderByOutTradeNo(String outTradeNo, String subMchid) throws WxPayException { String url = String.format("%s/v3/med-ins/orders/out-trade-no/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), outTradeNo, subMchid); String result = this.payService.getV3(url); return GSON.fromJson(result, MedInsOrdersResult.class); } @Override public MiPayNotifyV3Result parseMiPayNotifyV3Result(String notifyData, SignatureHeader header) throws WxPayException { return this.payService.baseParseOrderNotifyV3Result(notifyData, header, MiPayNotifyV3Result.class, MiPayNotifyV3Result.DecryptNotifyResult.class); } @Override public void medInsRefundNotify(MedInsRefundNotifyRequest request, String mixTradeNo) throws WxPayException { String url = String.format("%s/v3/med-ins/refunds/notify?mix_trade_no=%s", this.payService.getPayBaseUrl(), mixTradeNo); this.payService.postV3(url, GSON.toJson(request)); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BankServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BankServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.bank.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.BankService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import java.net.URLEncoder; /** * 微信支付-银行组件 * * @author zhongjun **/ @RequiredArgsConstructor public class BankServiceImpl implements BankService { private final WxPayService payService; private static final Gson GSON = new GsonBuilder().create(); @Override public BankAccountResult searchBanksByBankAccount(String accountNumber) throws WxPayException { try { String encryptAccountNumber = RsaCryptoUtil.encryptOAEP(accountNumber, this.payService.getConfig().getVerifier().getValidCertificate()); accountNumber = URLEncoder.encode(encryptAccountNumber, "UTF-8"); } catch (Exception e) { throw new RuntimeException("银行卡号加密异常!", e); } String url = String.format("%s/v3/capital/capitallhh/banks/search-banks-by-bank-account?account_number=%s", this.payService.getPayBaseUrl(), accountNumber); String response = payService.getV3WithWechatPaySerial(url); return GSON.fromJson(response, BankAccountResult.class); } @Override public BankingResult personalBanking(Integer offset, Integer limit) throws WxPayException { offset = offset == null ? 0 : offset; limit = limit == null ? 200 : limit; String url = String.format("%s/v3/capital/capitallhh/banks/personal-banking?offset=%s&limit=%s", this.payService.getPayBaseUrl(), offset, limit); String response = payService.getV3(url); return GSON.fromJson(response, BankingResult.class); } @Override public BankingResult corporateBanking(Integer offset, Integer limit) throws WxPayException { offset = offset == null ? 0 : offset; limit = limit == null ? 200 : limit; String url = String.format("%s/v3/capital/capitallhh/banks/corporate-banking?offset=%s&limit=%s", this.payService.getPayBaseUrl(), offset, limit); String response = payService.getV3(url); return GSON.fromJson(response, BankingResult.class); } @Override public ProvincesResult areasProvinces() throws WxPayException { String url = String.format("%s/v3/capital/capitallhh/areas/provinces", this.payService.getPayBaseUrl()); String response = payService.getV3WithWechatPaySerial(url); return GSON.fromJson(response, ProvincesResult.class); } @Override public CitiesResult areasCities(Integer provinceCode) throws WxPayException { String url = String.format("%s/v3/capital/capitallhh/areas/provinces/%s/cities", this.payService.getPayBaseUrl(), provinceCode); String response = payService.getV3WithWechatPaySerial(url); return GSON.fromJson(response, CitiesResult.class); } @Override public BankBranchesResult bankBranches(String bankAliasCode, Integer cityCode, Integer offset, Integer limit) throws WxPayException { offset = offset == null ? 0 : offset; limit = limit == null ? 200 : limit; String url = String.format("%s/v3/capital/capitallhh/banks/%s/branches?city_code=%s&offset=%s&limit=%s", this.payService.getPayBaseUrl(), bankAliasCode, cityCode, offset, limit); String response = payService.getV3(url); return GSON.fromJson(response, BankBranchesResult.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayrollServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayrollServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.marketing.payroll.*; import com.github.binarywang.wxpay.bean.result.WxPayApplyBillV3Result; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.PayrollService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import javax.crypto.IllegalBlockSizeException; /** * 微信支付-微工卡 * * @author xiaoqiang * created on 2021/12/2 */ @Slf4j @RequiredArgsConstructor public class PayrollServiceImpl implements PayrollService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; /** * 生成授权token * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/tokens * 请求方式:POST * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ @Override public TokensResult payrollCardTokens(TokensRequest request) throws WxPayException { String url = String.format("%s/v3/payroll-card/tokens", payService.getPayBaseUrl()); try { String userName = RsaCryptoUtil.encryptOAEP(request.getUserName(), payService.getConfig().getVerifier().getValidCertificate()); request.setUserName(userName); String idCardNumber = RsaCryptoUtil.encryptOAEP(request.getIdCardNumber(), payService.getConfig().getVerifier().getValidCertificate()); request.setIdCardNumber(idCardNumber); } catch (IllegalBlockSizeException e) { throw new RuntimeException("加密异常!", e); } String response = payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, TokensResult.class); } /** * 查询微工卡授权关系API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/relations/{openid} * 请求方式:GET * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ @Override public RelationsResult payrollCardRelations(RelationsRequest request) throws WxPayException { String url = String.format("%s/v3/payroll-card/relations/%s", payService.getPayBaseUrl(), request.getOpenid()); String query = String.format("?sub_mchid=%s", request.getSubMchid()); if (StringUtils.isNotEmpty(request.getAppid())) { query += "&appid=" + request.getAppid(); } if (StringUtils.isNotEmpty(request.getSubAppid())) { query += "&sub_appid=" + request.getSubAppid(); } String response = payService.getV3(url + query); return GSON.fromJson(response, RelationsResult.class); } /** * 微工卡核身预下单API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/authentications/pre-order * 请求方式:POST * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ @Override public PreOrderResult payrollCardPreOrder(PreOrderRequest request) throws WxPayException { String url = String.format("%s/v3/payroll-card/authentications/pre-order", payService.getPayBaseUrl()); String response = payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, PreOrderResult.class); } /** * 获取核身结果API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/authentications/{authenticate_number} * 请求方式:GET * * @param subMchid 子商户号 * @param authenticateNumber 商家核身单号 * @return 返回数据 * @throws WxPayException the wx pay exception */ @Override public AuthenticationsResult payrollCardAuthenticationsNumber(String subMchid, String authenticateNumber) throws WxPayException { String url = String.format("%s/v3/payroll-card/authentications/%s", payService.getPayBaseUrl(), authenticateNumber); String query = String.format("?sub_mchid=%s", subMchid); String response = payService.getV3(url + query); return GSON.fromJson(response, AuthenticationsResult.class); } /** * 查询核身记录API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/authentications * 请求方式:GET * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ @Override public AuthRecordResult payrollCardAuthentications(AuthRecordRequest request) throws WxPayException { String url = String.format("%s/v3/payroll-card/authentications", payService.getPayBaseUrl()); String query = String.format("?openid=%s&sub_mchid=%s&authenticate_date=%s", request.getOpenid(), request.getAppid(), request.getSubMchid(), request.getAuthenticateDate()); if (StringUtils.isNotEmpty(request.getAppid())) { query += "&appid=" + request.getAppid(); } if (StringUtils.isNotEmpty(request.getAppid())) { query += "&sub_appid=" + request.getSubAppid(); } if (StringUtils.isNotEmpty(request.getAuthenticateState())) { query += "&authenticate_state=" + request.getAuthenticateState(); } String response = payService.getV3(url + query); return GSON.fromJson(response, AuthRecordResult.class); } /** * 微工卡核身预下单(流程中完成授权) * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/payroll-card/authentications/pre-order-with-auth * 请求方式:POST * * @param request 请求参数 * @return 返回数据 * @throws WxPayException the wx pay exception */ @Override public PreOrderWithAuthResult payrollCardPreOrderWithAuth(PreOrderWithAuthRequest request) throws WxPayException { String url = String.format("%s/v3/payroll-card/authentications/pre-order-with-auth", payService.getPayBaseUrl()); try { String userName = RsaCryptoUtil.encryptOAEP(request.getUserName(), payService.getConfig().getVerifier().getValidCertificate()); request.setUserName(userName); String idCardNumber = RsaCryptoUtil.encryptOAEP(request.getIdCardNumber(), payService.getConfig().getVerifier().getValidCertificate()); request.setIdCardNumber(idCardNumber); } catch (IllegalBlockSizeException e) { throw new RuntimeException("敏感信息加密异常!", e); } String response = payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, PreOrderWithAuthResult.class); } /** * 按日下载提现异常文件API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/merchant/fund/withdraw/bill-type/{bill_type} * 请求方式:GET * * @param billType 账单类型 * NO_SUCC:提现异常账单,包括提现失败和提现退票账单。 * 示例值:NO_SUCC * @param billDate 账单日期 表示所在日期的提现账单,格式为YYYY-MM-DD。 * 例如:2008-01-01日发起的提现,2008-01-03日银行返回提现失败,则该提现数据将出现在bill_date为2008-01-03日的账单中。 * 示例值:2019-08-17 * @return 返回数据 * @throws WxPayException the wx pay exception */ @Override public WxPayApplyBillV3Result merchantFundWithdrawBillType(String billType, String billDate, String tarType) throws WxPayException { String url = String.format("%s/v3/merchant/fund/withdraw/bill-type/%s", payService.getPayBaseUrl(), billType); String query = String.format("?bill_date=%s", billDate); if (StringUtils.isNotBlank(tarType)) { query += String.format("&tar_type=%s", tarType); } String response = payService.getV3(url + query); return GSON.fromJson(response, WxPayApplyBillV3Result.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/TransferServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/TransferServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.notify.SignatureHeader; import com.github.binarywang.wxpay.bean.transfer.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.TransferService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import java.security.cert.X509Certificate; import java.util.List; /** * 商家转账到零钱 * * @author zhongjun * created on 2022/6/17 **/ @RequiredArgsConstructor public class TransferServiceImpl implements TransferService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; @Override public TransferBatchesResult transferBatches(TransferBatchesRequest request) throws WxPayException { String url = String.format("%s/v3/transfer/batches", this.payService.getPayBaseUrl()); List<TransferBatchesRequest.TransferDetail> transferDetailList = request.getTransferDetailList(); X509Certificate validCertificate = this.payService.getConfig().getVerifier().getValidCertificate(); for (TransferBatchesRequest.TransferDetail detail : transferDetailList) { RsaCryptoUtil.encryptFields(detail, validCertificate); } String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, TransferBatchesResult.class); } @Override public TransferNotifyResult parseTransferNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { return this.payService.baseParseOrderNotifyV3Result(notifyData, header, TransferNotifyResult.class, TransferNotifyResult.DecryptNotifyResult.class); } @Override public QueryTransferBatchesResult transferBatchesBatchId(QueryTransferBatchesRequest request) throws WxPayException { String url; if (request.getNeedQueryDetail()) { url = String.format("%s/v3/transfer/batches/batch-id/%s?need_query_detail=true&offset=%s&limit=%s&detail_status=%s", this.payService.getPayBaseUrl(), request.getBatchId(), request.getOffset(), request.getLimit(), request.getDetailStatus()); } else { url = String.format("%s/v3/transfer/batches/batch-id/%s?need_query_detail=false", this.payService.getPayBaseUrl(), request.getBatchId()); } String result = this.payService.getV3(url); return GSON.fromJson(result, QueryTransferBatchesResult.class); } @Override public TransferBatchDetailResult transferBatchesBatchIdDetail(String batchId, String detailId) throws WxPayException { String url = String.format("%s/v3/transfer/batches/batch-id/%s/details/detail-id/%s", this.payService.getPayBaseUrl(), batchId, detailId); String result = this.payService.getV3(url); return GSON.fromJson(result, TransferBatchDetailResult.class); } @Override public QueryTransferBatchesResult transferBatchesOutBatchNo(QueryTransferBatchesRequest request) throws WxPayException { String url; if (request.getNeedQueryDetail()) { url = String.format("%s/v3/transfer/batches/out-batch-no/%s?need_query_detail=true&offset=%s&limit=%s&detail_status=%s", this.payService.getPayBaseUrl(), request.getOutBatchNo(), request.getOffset(), request.getLimit(), request.getDetailStatus()); } else { url = String.format("%s/v3/transfer/batches/out-batch-no/%s?need_query_detail=false", this.payService.getPayBaseUrl(), request.getOutBatchNo()); } String result = this.payService.getV3(url); return GSON.fromJson(result, QueryTransferBatchesResult.class); } @Override public TransferBatchDetailResult transferBatchesOutBatchNoDetail(String outBatchNo, String outDetailNo) throws WxPayException { String url = String.format("%s/v3/transfer/batches/out-batch-no/%s/details/out-detail-no/%s", this.payService.getPayBaseUrl(), outBatchNo, outDetailNo); String result = this.payService.getV3(url); return GSON.fromJson(result, TransferBatchDetailResult.class); } @Override public TransferBillsResult transferBills(TransferBillsRequest request) throws WxPayException { String url = String.format("%s/v3/fund-app/mch-transfer/transfer-bills", this.payService.getPayBaseUrl()); if (request.getUserName() != null && !request.getUserName().isEmpty()) { X509Certificate validCertificate = this.payService.getConfig().getVerifier().getValidCertificate(); RsaCryptoUtil.encryptFields(request, validCertificate); } String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, TransferBillsResult.class); } @Override public TransferBillsCancelResult transformBillsCancel(String outBillNo) throws WxPayException { String url = String.format("%s/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/%s/cancel", this.payService.getPayBaseUrl(), outBillNo); String result = this.payService.postV3(url, ""); return GSON.fromJson(result, TransferBillsCancelResult.class); } @Override public TransferBillsGetResult getBillsByOutBillNo(String outBillNo) throws WxPayException { String url = String.format("%s/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/%s", this.payService.getPayBaseUrl(), outBillNo); String result = this.payService.getV3(url); return GSON.fromJson(result, TransferBillsGetResult.class); } @Override public TransferBillsGetResult getBillsByTransferBillNo(String transferBillNo) throws WxPayException { String url = String.format("%s/v3/fund-app/mch-transfer/transfer-bills/transfer-bill-no/%s", this.payService.getPayBaseUrl(), transferBillNo); String result = this.payService.getV3(url); return GSON.fromJson(result, TransferBillsGetResult.class); } @Override public TransferBillsNotifyResult parseTransferBillsNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { return this.payService.baseParseOrderNotifyV3Result(notifyData, header, TransferBillsNotifyResult.class, TransferBillsNotifyResult.DecryptNotifyResult.class); } // ===================== 用户授权免确认模式相关接口实现 ===================== @Override public UserAuthorizationStatusResult getUserAuthorizationStatus(String openid, String transferSceneId) throws WxPayException { String url = String.format("%s/v3/fund-app/mch-transfer/authorization/openid/%s?transfer_scene_id=%s", this.payService.getPayBaseUrl(), openid, transferSceneId); String result = this.payService.getV3(url); return GSON.fromJson(result, UserAuthorizationStatusResult.class); } @Override public ReservationTransferBatchResult reservationTransferBatch(ReservationTransferBatchRequest request) throws WxPayException { String url = String.format("%s/v3/fund-app/mch-transfer/reservation/transfer-batches", this.payService.getPayBaseUrl()); List<ReservationTransferBatchRequest.TransferDetail> transferDetailList = request.getTransferDetailList(); if (transferDetailList != null && !transferDetailList.isEmpty()) { X509Certificate validCertificate = this.payService.getConfig().getVerifier().getValidCertificate(); for (ReservationTransferBatchRequest.TransferDetail detail : transferDetailList) { if (detail.getUserName() != null && !detail.getUserName().isEmpty()) { RsaCryptoUtil.encryptFields(detail, validCertificate); } } } String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(result, ReservationTransferBatchResult.class); } @Override public ReservationTransferBatchGetResult getReservationTransferBatchByOutBatchNo(String outBatchNo, Boolean needQueryDetail, Integer offset, Integer limit, String detailState) throws WxPayException { String url = buildReservationBatchQueryUrl("out-batch-no", outBatchNo, needQueryDetail, offset, limit, detailState); String result = this.payService.getV3(url); return GSON.fromJson(result, ReservationTransferBatchGetResult.class); } @Override public ReservationTransferBatchGetResult getReservationTransferBatchByReservationBatchNo(String reservationBatchNo, Boolean needQueryDetail, Integer offset, Integer limit, String detailState) throws WxPayException { String url = buildReservationBatchQueryUrl("reservation-batch-no", reservationBatchNo, needQueryDetail, offset, limit, detailState); String result = this.payService.getV3(url); return GSON.fromJson(result, ReservationTransferBatchGetResult.class); } private String buildReservationBatchQueryUrl(String batchNoType, String batchNo, Boolean needQueryDetail, Integer offset, Integer limit, String detailState) { StringBuilder url = new StringBuilder(); url.append(this.payService.getPayBaseUrl()) .append("/v3/fund-app/mch-transfer/reservation/transfer-batches/") .append(batchNoType).append("/").append(batchNo); boolean hasParams = false; if (needQueryDetail != null) { url.append("?need_query_detail=").append(needQueryDetail); hasParams = true; } if (offset != null) { url.append(hasParams ? "&" : "?").append("offset=").append(offset); hasParams = true; } if (limit != null) { url.append(hasParams ? "&" : "?").append("limit=").append(limit); hasParams = true; } if (detailState != null && !detailState.isEmpty()) { url.append(hasParams ? "&" : "?").append("detail_state=").append(detailState); } return url.toString(); } @Override public ReservationTransferNotifyResult parseReservationTransferNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { return this.payService.baseParseOrderNotifyV3Result(notifyData, header, ReservationTransferNotifyResult.class, ReservationTransferNotifyResult.DecryptNotifyResult.class); } @Override public void closeReservationTransferBatch(String outBatchNo) throws WxPayException { String url = String.format("%s/v3/fund-app/mch-transfer/reservation/transfer-batches/out-batch-no/%s/close", this.payService.getPayBaseUrl(), outBatchNo); this.payService.postV3(url, ""); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BusinessCircleServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BusinessCircleServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.businesscircle.BusinessCircleNotifyData; import com.github.binarywang.wxpay.bean.businesscircle.PaidResult; import com.github.binarywang.wxpay.bean.businesscircle.PointsNotifyRequest; import com.github.binarywang.wxpay.bean.businesscircle.RefundResult; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.BusinessCircleService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.AesUtils; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.util.Objects; /** * 微信支付-微信支付智慧商圈service * * @author thinsstar */ @Slf4j @RequiredArgsConstructor public class BusinessCircleServiceImpl implements BusinessCircleService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; @Override public void notifyPoints(PointsNotifyRequest request) throws WxPayException { String url = String.format("%s/v3/businesscircle/points/notify", this.payService.getPayBaseUrl()); RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); } /** * 校验通知签名 * * @param header 通知头信息 * @param data 通知数据 * @return true:校验通过 false:校验不通过 */ private boolean verifyNotifySign(SignatureHeader header, String data) { String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(), header.getNonce(), data); return payService.getConfig().getVerifier().verify(header.getSerialNo(), beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned()); } @Override public BusinessCircleNotifyData parseNotifyData(String data, SignatureHeader header) throws WxPayException { if (Objects.nonNull(header) && !this.verifyNotifySign(header, data)) { throw new WxPayException("非法请求,头部信息验证失败"); } return GSON.fromJson(data, BusinessCircleNotifyData.class); } @Override public PaidResult decryptPaidNotifyDataResource(BusinessCircleNotifyData data) throws WxPayException { BusinessCircleNotifyData.Resource resource = data.getResource(); String cipherText = resource.getCipherText(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { return GSON.fromJson(AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key), PaidResult.class); } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } @Override public RefundResult decryptRefundNotifyDataResource(BusinessCircleNotifyData data) throws WxPayException { BusinessCircleNotifyData.Resource resource = data.getResource(); String cipherText = resource.getCipherText(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { return GSON.fromJson(AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key), RefundResult.class); } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData; import com.github.binarywang.wxpay.bean.payscore.UserAuthorizationStatusNotifyResult; import com.github.binarywang.wxpay.bean.payscore.WxPayScoreRequest; import com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.exception.WxSignTestException; import com.github.binarywang.wxpay.service.PayScoreService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.AesUtils; import com.google.common.base.Strings; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.utils.URIBuilder; import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.util.HashMap; import java.util.Map; import java.util.Objects; /** * @author doger.wang * created on 2020/5/14 9:43 */ @RequiredArgsConstructor public class PayScoreServiceImpl implements PayScoreService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; @Override public WxPayScoreResult permissions(WxPayScoreRequest request) throws WxPayException { WxPayConfig config = this.payService.getConfig(); String url = this.payService.getPayBaseUrl() + "/v3/payscore/permissions"; if(Strings.isNullOrEmpty(request.getAppid())){ request.setAppid(config.getAppId()); } if(Strings.isNullOrEmpty(request.getServiceId())){ request.setServiceId(config.getServiceId()); } if(Strings.isNullOrEmpty(request.getNotifyUrl())){ String permissionNotifyUrl = config.getPayScorePermissionNotifyUrl(); if (StringUtils.isBlank(permissionNotifyUrl)) { throw new WxPayException("授权回调地址未配置"); } request.setNotifyUrl(permissionNotifyUrl); } String authorizationCode = request.getAuthorizationCode(); if (StringUtils.isBlank(authorizationCode)) { throw new WxPayException("authorizationCode不允许为空"); } String result = this.payService.postV3(url, request.toJson()); return WxPayScoreResult.fromJson(result); } @Override public WxPayScoreResult permissionsQueryByAuthorizationCode(String authorizationCode) throws WxPayException { WxPayConfig config = this.payService.getConfig(); if (StringUtils.isBlank(authorizationCode)) { throw new WxPayException("authorizationCode不允许为空"); } String url = String.format("%s/v3/payscore/permissions/authorization-code/%s", this.payService.getPayBaseUrl(), authorizationCode); URIBuilder uriBuilder; try { uriBuilder = new URIBuilder(url); } catch (URISyntaxException e) { throw new WxPayException("未知异常!", e); } uriBuilder.setParameter("service_id", config.getServiceId()); try { String result = payService.getV3(uriBuilder.build().toString()); return WxPayScoreResult.fromJson(result); } catch (URISyntaxException e) { throw new WxPayException("未知异常!", e); } } @Override public WxPayScoreResult permissionsTerminateByAuthorizationCode(String authorizationCode, String reason) throws WxPayException { WxPayConfig config = this.payService.getConfig(); if (StringUtils.isBlank(authorizationCode)) { throw new WxPayException("authorizationCode不允许为空"); } String url = String.format("%s/v3/payscore/permissions/authorization-code/%s/terminate", this.payService.getPayBaseUrl(), authorizationCode); Map<String, Object> map = new HashMap<>(4); map.put("service_id", config.getServiceId()); map.put("reason", reason); String result = payService.postV3(url, WxGsonBuilder.create().toJson(map)); return WxPayScoreResult.fromJson(result); } @Override public WxPayScoreResult permissionsQueryByOpenId(String openId) throws WxPayException { WxPayConfig config = this.payService.getConfig(); if (StringUtils.isBlank(openId)) { throw new WxPayException("openId不允许为空"); } String url = String.format("%s/v3/payscore/permissions/openid/%s", this.payService.getPayBaseUrl(), openId); URIBuilder uriBuilder; try { uriBuilder = new URIBuilder(url); } catch (URISyntaxException e) { throw new WxPayException("未知异常!", e); } uriBuilder.setParameter("appid", config.getAppId()); uriBuilder.setParameter("service_id", config.getServiceId()); try { String result = payService.getV3(uriBuilder.build().toString()); return WxPayScoreResult.fromJson(result); } catch (URISyntaxException e) { throw new WxPayException("未知异常!", e); } } @Override public WxPayScoreResult permissionsTerminateByOpenId(String openId, String reason) throws WxPayException { WxPayConfig config = this.payService.getConfig(); if (StringUtils.isBlank(openId)) { throw new WxPayException("openId不允许为空"); } String url = String.format("%s/v3/payscore/permissions/openid/%s/terminate", this.payService.getPayBaseUrl(), openId); Map<String, Object> map = new HashMap<>(4); map.put("service_id", config.getServiceId()); map.put("appid", config.getAppId()); map.put("reason", reason); String result = payService.postV3(url, WxGsonBuilder.create().toJson(map)); return WxPayScoreResult.fromJson(result); } @Override public WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxPayException { boolean needUserConfirm = request.getNeedUserConfirm(); WxPayConfig config = this.payService.getConfig(); String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder"; if(Strings.isNullOrEmpty(request.getAppid())){ request.setAppid(config.getAppId()); } if(Strings.isNullOrEmpty(request.getServiceId())){ request.setServiceId(config.getServiceId()); } if(Strings.isNullOrEmpty(request.getNotifyUrl())){ request.setNotifyUrl(config.getPayScoreNotifyUrl()); } String result = this.payService.postV3(url, request.toJson()); WxPayScoreResult wxPayScoreCreateResult = WxPayScoreResult.fromJson(result); //补充算一下签名给小程序跳转用 String currentTimeMillis = System.currentTimeMillis() + ""; Map<String, String> signMap = new HashMap<>(8); signMap.put("mch_id", config.getMchId()); if (needUserConfirm) { signMap.put("package", wxPayScoreCreateResult.getPackageX()); } else { signMap.put("service_id", config.getServiceId()); signMap.put("out_order_no", request.getOutOrderNo()); } signMap.put("timestamp", currentTimeMillis); signMap.put("nonce_str", currentTimeMillis); signMap.put("sign_type", "HMAC-SHA256"); String sign = AesUtils.createSign(signMap, config.getMchKey()); signMap.put("sign", sign); wxPayScoreCreateResult.setPayScoreSignInfo(signMap); return wxPayScoreCreateResult; } @Override public WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException { WxPayConfig config = this.payService.getConfig(); String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder"; URIBuilder uriBuilder; try { uriBuilder = new URIBuilder(url); } catch (URISyntaxException e) { throw new WxPayException("未知异常!", e); } if (StringUtils.isAllEmpty(outOrderNo, queryId) || !StringUtils.isAnyEmpty(outOrderNo, queryId)) { throw new WxPayException("out_order_no,query_id不允许都填写或都不填写"); } if (StringUtils.isNotEmpty(outOrderNo)) { uriBuilder.setParameter("out_order_no", outOrderNo); } if (StringUtils.isNotEmpty(queryId)) { uriBuilder.setParameter("query_id", queryId); } uriBuilder.setParameter("service_id", config.getServiceId()); uriBuilder.setParameter("appid", config.getAppId()); try { String result = payService.getV3(uriBuilder.build().toString()); return WxPayScoreResult.fromJson(result); } catch (URISyntaxException e) { throw new WxPayException("未知异常!", e); } } @Override public WxPayScoreResult cancelServiceOrder(String outOrderNo, String reason) throws WxPayException { WxPayConfig config = this.payService.getConfig(); String url = String.format("%s/v3/payscore/serviceorder/%s/cancel", this.payService.getPayBaseUrl(), outOrderNo); Map<String, Object> map = new HashMap<>(4); map.put("appid", config.getAppId()); map.put("service_id", config.getServiceId()); map.put("reason", reason); String result = payService.postV3(url, WxGsonBuilder.create().toJson(map)); return WxPayScoreResult.fromJson(result); } @Override public WxPayScoreResult modifyServiceOrder(WxPayScoreRequest request) throws WxPayException { WxPayConfig config = this.payService.getConfig(); String outOrderNo = request.getOutOrderNo(); String url = String.format("%s/v3/payscore/serviceorder/%s/modify", this.payService.getPayBaseUrl(), outOrderNo); if(Strings.isNullOrEmpty(request.getAppid())){ request.setAppid(config.getAppId()); } if(Strings.isNullOrEmpty(request.getServiceId())){ request.setServiceId(config.getServiceId()); } request.setOutOrderNo(null); String result = payService.postV3(url, request.toJson()); return WxPayScoreResult.fromJson(result); } @Override public WxPayScoreResult completeServiceOrder(WxPayScoreRequest request) throws WxPayException { WxPayConfig config = this.payService.getConfig(); String outOrderNo = request.getOutOrderNo(); String url = String.format("%s/v3/payscore/serviceorder/%s/complete", this.payService.getPayBaseUrl(), outOrderNo); if(Strings.isNullOrEmpty(request.getAppid())){ request.setAppid(config.getAppId()); } if(Strings.isNullOrEmpty(request.getServiceId())){ request.setServiceId(config.getServiceId()); } request.setOutOrderNo(null); String result = payService.postV3(url, request.toJson()); return WxPayScoreResult.fromJson(result); } @Override public WxPayScoreResult payServiceOrder(String outOrderNo) throws WxPayException { WxPayConfig config = this.payService.getConfig(); String url = String.format("%s/v3/payscore/serviceorder/%s/pay", this.payService.getPayBaseUrl(), outOrderNo); Map<String, Object> map = new HashMap<>(2); map.put("appid", config.getAppId()); map.put("service_id", config.getServiceId()); String result = payService.postV3(url, WxGsonBuilder.create().toJson(map)); return WxPayScoreResult.fromJson(result); } @Override public WxPayScoreResult syncServiceOrder(WxPayScoreRequest request) throws WxPayException { WxPayConfig config = this.payService.getConfig(); String outOrderNo = request.getOutOrderNo(); String url = String.format("%s/v3/payscore/serviceorder/%s/sync", this.payService.getPayBaseUrl(), outOrderNo); if(Strings.isNullOrEmpty(request.getAppid())){ request.setAppid(config.getAppId()); } if(Strings.isNullOrEmpty(request.getServiceId())){ request.setServiceId(config.getServiceId()); } request.setOutOrderNo(null); String result = payService.postV3(url, request.toJson()); return WxPayScoreResult.fromJson(result); } @Override public UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { PayScoreNotifyData response = parseNotifyData(notifyData, header); PayScoreNotifyData.Resource resource = response.getResource(); String cipherText = resource.getCipherText(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key); UserAuthorizationStatusNotifyResult notifyResult = GSON.fromJson(result, UserAuthorizationStatusNotifyResult.class); notifyResult.setRawData(response); return notifyResult; } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } @Override public PayScoreNotifyData parseNotifyData(String data, SignatureHeader header) throws WxPayException { if (Objects.nonNull(header) && !this.verifyNotifySign(header, data)) { throw new WxPayException("非法请求,头部信息验证失败"); } return GSON.fromJson(data, PayScoreNotifyData.class); } @Override public WxPayScoreResult decryptNotifyDataResource(PayScoreNotifyData data) throws WxPayException { PayScoreNotifyData.Resource resource = data.getResource(); String cipherText = resource.getCipherText(); String associatedData = resource.getAssociatedData(); String nonce = resource.getNonce(); String apiV3Key = this.payService.getConfig().getApiV3Key(); try { return WxPayScoreResult.fromJson(AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key)); } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } /** * 校验通知签名 * * @param header 通知头信息 * @param data 通知数据 * @return true:校验通过 false:校验不通过 */ private boolean verifyNotifySign(SignatureHeader header, String data) throws WxSignTestException { String wxPaySign = header.getSigned(); if(wxPaySign.startsWith("WECHATPAY/SIGNTEST/")){ throw new WxSignTestException("微信支付签名探测流量"); } String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(), header.getNonce(), data); return payService.getConfig().getVerifier().verify(header.getSerialNo(), beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerTransferServiceImpl.java
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerTransferServiceImpl.java
package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.ecommerce.FundBalanceResult; import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum; import com.github.binarywang.wxpay.bean.marketing.transfer.*; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.PartnerTransferService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import jodd.util.StringUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import java.io.InputStream; /** * 批量转账到零钱(服务商) * * @author xiaoqiang * created on 2021-12-06 */ @Slf4j @RequiredArgsConstructor public class PartnerTransferServiceImpl implements PartnerTransferService { private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; /** * 发起批量转账API * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches * 请求方式:POST * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request 请求对象 * @return 返回数据 {@link PartnerTransferResult} * @throws WxPayException the wx pay exception */ @Override public PartnerTransferResult batchTransfer(PartnerTransferRequest request) throws WxPayException { request.getTransferDetailList().forEach(p -> { try { String userName = RsaCryptoUtil.encryptOAEP(p.getUserName(), this.payService.getConfig().getVerifier().getValidCertificate()); p.setUserName(userName); if (StringUtil.isNotBlank(p.getUserIdCard())) { String userIdCard = RsaCryptoUtil.encryptOAEP(p.getUserIdCard(), this.payService.getConfig().getVerifier().getValidCertificate()); p.setUserIdCard(userIdCard); } } catch (IllegalBlockSizeException e) { throw new RuntimeException("姓名或身份证转换异常!", e); } }); String url = String.format("%s/v3/partner-transfer/batches", this.payService.getPayBaseUrl()); String response = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); return GSON.fromJson(response, PartnerTransferResult.class); } /** * 微信支付批次单号查询批次单API * 接口说明 * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches/batch-id/{batch_id} * https://api.mch.weixin.qq.com/v3/partner-transfer/batches/batch-id/1030000071100999991182020050700019480001 * ?need_query_detail=true&offset=1 * 请求方式:GET * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request 请求对象 * @return 返回数据 {@link BatchNumberResult} * @throws WxPayException the wx pay exception */ @Override public BatchNumberResult queryBatchByBatchId(BatchNumberRequest request) throws WxPayException { String url = String.format("%s/v3/partner-transfer/batches/batch-id/%s", this.payService.getPayBaseUrl(), request.getBatchId()); if (request.getOffset() == null) { request.setOffset(0); } if (request.getLimit() == null || request.getLimit() <= 0) { request.setLimit(20); } String detailStatus = StringUtil.isNotBlank(request.getDetailStatus()) ? request.getDetailStatus() : "ALL"; String query = String.format("?need_query_detail=%s&detail_status=%s&offset=%s&limit=%s", request.getNeedQueryDetail(), detailStatus, request.getOffset(), request.getLimit()); String response = this.payService.getV3(url + query); return GSON.fromJson(response, BatchNumberResult.class); } /** * 商家批次单号查询批次单API * 接口说明 * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches/out-batch-no/{out_batch_no} * 请求方式:GET * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param request 请求对象 * @return 返回数据 {@link BatchNumberResult} * @throws WxPayException the wx pay exception */ @Override public BatchNumberResult queryBatchByOutBatchNo(MerchantBatchRequest request) throws WxPayException { String url = String.format("%s/v3/partner-transfer/batches/out-batch-no/%s", this.payService.getPayBaseUrl(), request.getOutBatchNo()); if (request.getOffset() == null) { request.setOffset(0); } if (request.getLimit() == null || request.getLimit() <= 0) { request.setLimit(20); } String query = String.format("?need_query_detail=%s&offset=%s&limit=%s", request.getNeedQueryDetail(), request.getOffset(), request.getLimit()); if (StringUtil.isNotBlank(request.getDetailStatus())) { query += "&detail_status=" + request.getDetailStatus(); } String response = this.payService.getV3(url + query); return GSON.fromJson(response, BatchNumberResult.class); } /** * 微信支付明细单号查询明细单API * 接口说明 * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches/batch-id/{batch_id}/details/detail-id/{detail_id} * 请求方式:GET * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param batchId 微信批次单号 * @param detailId 微信明细单号 * @return 返回数据 {@link BatchDetailsResult} * @throws WxPayException the wx pay exception * @throws BadPaddingException the wx decrypt exception */ @Override public BatchDetailsResult queryBatchDetailByWeChat(String batchId, String detailId) throws WxPayException, BadPaddingException { String url = String.format("%s/v3/partner-transfer/batches/batch-id/%s/details/detail-id/%s", this.payService.getPayBaseUrl(), batchId, detailId); String response = this.payService.getV3(url); BatchDetailsResult batchDetailsResult = GSON.fromJson(response, BatchDetailsResult.class); String userName = RsaCryptoUtil.decryptOAEP(batchDetailsResult.getUserName(), this.payService.getConfig().getPrivateKey()); batchDetailsResult.setUserName(userName); return batchDetailsResult; } /** * 商家明细单号查询明细单API * 接口说明 * 适用对象:服务商 * 请求URL:https://api.mch.weixin.qq.com/v3/partner-transfer/batches/out-batch-no/{out_batch_no}/details/out-detail * -no/{out_detail_no} * 请求方式:GET * 接口限频:单个服务商 50QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。 * * @param outBatchNo 商家明细单号 * @param outDetailNo 商家批次单号 * @return 返回数据 {@link BatchDetailsResult} * @throws WxPayException the wx pay exception * @throws BadPaddingException the wx decrypt exception */ @Override public BatchDetailsResult queryBatchDetailByMch(String outBatchNo, String outDetailNo) throws WxPayException, BadPaddingException { String url = String.format("%s/v3/partner-transfer/batches/out-batch-no/%s/details/out-detail-no/%s", this.payService.getPayBaseUrl(), outBatchNo, outDetailNo); String response = this.payService.getV3(url); BatchDetailsResult batchDetailsResult = GSON.fromJson(response, BatchDetailsResult.class); String userName = RsaCryptoUtil.decryptOAEP(batchDetailsResult.getUserName(), this.payService.getConfig().getPrivateKey()); batchDetailsResult.setUserName(userName); return batchDetailsResult; } /** * 转账电子回单申请受理API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_1.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt * 请求方式:POST * * @param request 商家批次单号 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ @Override public BillReceiptResult receiptBill(ReceiptBillRequest request) throws WxPayException { String url = String.format("%s/v3/transfer/bill-receipt", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, BillReceiptResult.class); } /** * 查询转账电子回单API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_2.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt/{out_batch_no} * 请求方式:GET * * @param outBatchNo 商家批次单号 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ @Override public BillReceiptResult queryBillReceipt(String outBatchNo) throws WxPayException { String url = String.format("%s/v3/transfer/bill-receipt/%s", this.payService.getPayBaseUrl(), outBatchNo); String response = this.payService.getV3(url); return GSON.fromJson(response, BillReceiptResult.class); } /** * 转账明细电子回单受理API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_4.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer-detail/electronic-receipts * 请求方式:POST * 前置条件:只支持受理最近90天内的转账明细单 * * @param request 请求对象 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ @Override public ElectronicReceiptsResult transferElectronic(ElectronicReceiptsRequest request) throws WxPayException { String url = String.format("%s/v3/transfer-detail/electronic-receipts", this.payService.getPayBaseUrl()); String response = this.payService.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, ElectronicReceiptsResult.class); } /** * 查询转账明细电子回单受理结果API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_5.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/transfer-detail/electronic-receipts * 请求方式:GET * 前置条件:只支持查询最近90天内的转账明细单 * * @param request 请求对象 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ @Override public ElectronicReceiptsResult queryTransferElectronicResult(ElectronicReceiptsRequest request) throws WxPayException { String url = String.format("%s/v3/transfer-detail/electronic-receipts", this.payService.getPayBaseUrl()); String query = String.format("?accept_type=%s&out_batch_no=%s&out_detail_no=%s", request.getAcceptType(), request.getOutBatchNo(), request.getOutDetailNo()); String response = this.payService.getV3(url + query); return GSON.fromJson(response, ElectronicReceiptsResult.class); } /** * 下载电子回单API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_3.shtml * 请求URL:通过申请账单接口获取到“download_url”,URL有效期10min * 请求方式:GET * 前置条件:调用申请账单接口并获取到“download_url” * * @param url 微信返回的电子回单地址。 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ @Override public InputStream transferDownload(String url) throws WxPayException { InputStream response = this.payService.downloadV3(url); return response; } /** * <pre> * 查询账户实时余额API * 接口说明 * 适用对象:直连商户 服务商 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter5_1.shtml * 请求URL:https://api.mch.weixin.qq.com/v3/merchant/fund/balance/{account_type} * 请求方式:GET * </pre> * * @param accountType 服务商账户类型 {@link SpAccountTypeEnum} * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ @Override public FundBalanceResult fundBalance(SpAccountTypeEnum accountType) throws WxPayException { String url = String.format("%s/v3/merchant/fund/balance/%s", this.payService.getPayBaseUrl(), accountType); String response = this.payService.getV3(url); return GSON.fromJson(response, FundBalanceResult.class); } /** * <pre> * 服务商账户日终余额 * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter5_2.shtml * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml * </pre> * * @param accountType 服务商账户类型 * @param date 查询日期 2020-09-11 * @return 返回数据 fund balance result * @throws WxPayException the wx pay exception */ @Override public FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) { try { return this.payService.getEcommerceService().spDayEndBalance(accountType, date); } catch (Exception e) { e.printStackTrace(); } return null; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false