feat: 添加微信小程序环境版本配置及相关功能实现

This commit is contained in:
2026-07-23 17:23:10 +08:00
parent ba9f32fd02
commit 05d68d106c
7 changed files with 586 additions and 18 deletions

View File

@@ -44,7 +44,22 @@ class AppOutdoorFairControllerTest
AjaxResult result = controller.checkIn(attendee(12L));
assertEquals(500, result.get(AjaxResult.CODE_TAG));
assertEquals("招聘会尚未开始,暂不能签到", result.get(AjaxResult.MSG_TAG));
assertEquals("招聘会还没有开始,暂不能签到", result.get(AjaxResult.MSG_TAG));
verify(attendeeService, never()).save(any(OutdoorFairAttendee.class));
}
@Test
void fairWithoutStartTimeUsesNotStartedMessage() throws Exception
{
IOutdoorFairService fairService = mock(IOutdoorFairService.class);
IOutdoorFairAttendeeService attendeeService = mock(IOutdoorFairAttendeeService.class);
when(fairService.getById(12L)).thenReturn(fairAt(null));
AppOutdoorFairController controller = controllerWith(fairService, attendeeService);
AjaxResult result = controller.checkIn(attendee(12L));
assertEquals(500, result.get(AjaxResult.CODE_TAG));
assertEquals("招聘会还没有开始,暂不能签到", result.get(AjaxResult.MSG_TAG));
verify(attendeeService, never()).save(any(OutdoorFairAttendee.class));
}

View File

@@ -26,7 +26,7 @@ class WeChatMiniProgramQrCodeServiceTest
when(client.getAccessToken("app-id", "app-secret"))
.thenReturn(new WeChatMiniProgramApiClient.AccessTokenResult("token-1", 7200));
when(client.getUnlimitedQrCode("token-1", "fairId=12",
WeChatMiniProgramQrCodeService.OUTDOOR_FAIR_PAGE))
WeChatMiniProgramQrCodeService.OUTDOOR_FAIR_PAGE, "trial"))
.thenReturn(new WeChatMiniProgramApiClient.QrCodeImage(
"image-content".getBytes(StandardCharsets.UTF_8), "image/png"));
@@ -38,13 +38,14 @@ class WeChatMiniProgramQrCodeServiceTest
assertEquals(12L, first.get("fairId"));
assertEquals("fairId=12", first.get("scene"));
assertEquals("packageA/pages/outdoorFair/detail", first.get("page"));
assertEquals("trial", first.get("envVersion"));
assertTrue((Boolean) first.get("permanent"));
assertFalse((Boolean) first.get("rotationRequired"));
assertTrue(String.valueOf(first.get("imageData")).startsWith("data:image/png;base64,"));
assertEquals(first.get("imageData"), second.get("imageData"));
verify(client, times(1)).getAccessToken("app-id", "app-secret");
verify(client, times(1)).getUnlimitedQrCode(
"token-1", "fairId=12", WeChatMiniProgramQrCodeService.OUTDOOR_FAIR_PAGE);
"token-1", "fairId=12", WeChatMiniProgramQrCodeService.OUTDOOR_FAIR_PAGE, "trial");
}
@Test
@@ -55,7 +56,7 @@ class WeChatMiniProgramQrCodeServiceTest
when(client.getAccessToken("app-id", "app-secret"))
.thenReturn(new WeChatMiniProgramApiClient.AccessTokenResult("token-1", 7200))
.thenReturn(new WeChatMiniProgramApiClient.AccessTokenResult("token-2", 7200));
when(client.getUnlimitedQrCode(anyString(), anyString(), anyString()))
when(client.getUnlimitedQrCode(anyString(), anyString(), anyString(), anyString()))
.thenReturn(new WeChatMiniProgramApiClient.QrCodeImage(new byte[]{1, 2, 3}, "image/png"));
WeChatMiniProgramQrCodeService service = new WeChatMiniProgramQrCodeService(
@@ -66,9 +67,9 @@ class WeChatMiniProgramQrCodeServiceTest
verify(client, times(2)).getAccessToken("app-id", "app-secret");
verify(client).getUnlimitedQrCode(
"token-1", "fairId=1", WeChatMiniProgramQrCodeService.OUTDOOR_FAIR_PAGE);
"token-1", "fairId=1", WeChatMiniProgramQrCodeService.OUTDOOR_FAIR_PAGE, "trial");
verify(client).getUnlimitedQrCode(
"token-2", "fairId=2", WeChatMiniProgramQrCodeService.OUTDOOR_FAIR_PAGE);
"token-2", "fairId=2", WeChatMiniProgramQrCodeService.OUTDOOR_FAIR_PAGE, "trial");
}
@Test
@@ -83,4 +84,17 @@ class WeChatMiniProgramQrCodeServiceTest
assertEquals("微信小程序配置不完整,请联系管理员", exception.getMessage());
}
@Test
void rejectsUnsupportedEnvironmentVersion()
{
WeChatMiniProgramApiClient client = mock(WeChatMiniProgramApiClient.class);
ServiceException exception = assertThrows(ServiceException.class,
() -> new WeChatMiniProgramQrCodeService(
client, "app-id", "app-secret", "unknown", () -> 1_000L));
assertEquals("微信小程序版本配置不正确,仅支持 trial、release 或 develop",
exception.getMessage());
}
}