|
1 | 1 | package com.github.binarywang.wxpay.service.impl; |
2 | 2 |
|
3 | | -import com.github.binarywang.wxpay.bean.transfer.ReservationTransferBatchRequest; |
4 | 3 | import com.github.binarywang.wxpay.bean.transfer.ReservationTransferBatchGetResult; |
| 4 | +import com.github.binarywang.wxpay.bean.transfer.ReservationTransferBatchRequest; |
5 | 5 | import com.github.binarywang.wxpay.bean.transfer.ReservationTransferBatchResult; |
| 6 | +import com.github.binarywang.wxpay.bean.transfer.TransferBillsRequest; |
6 | 7 | import com.github.binarywang.wxpay.bean.transfer.UserAuthorizationStatusResult; |
7 | 8 | import com.github.binarywang.wxpay.exception.WxPayException; |
8 | 9 | import com.github.binarywang.wxpay.service.WxPayService; |
@@ -220,6 +221,77 @@ public void shouldCloseReservationTransferBatchWithCorrectPath() throws WxPayExc |
220 | 221 | Assert.assertEquals(handler.lastPostBody, ""); |
221 | 222 | } |
222 | 223 |
|
| 224 | + /** |
| 225 | + * 验证 TransferBillsRequest 中授权相关字段可正确序列化为 JSON(含 @SerializedName 映射)。 |
| 226 | + */ |
| 227 | + public void shouldSerializeTransferBillsRequestAuthorizationFields() { |
| 228 | + Gson gson = new Gson(); |
| 229 | + TransferBillsRequest request = TransferBillsRequest.newBuilder() |
| 230 | + .appid("wxf636efh5xxxxx") |
| 231 | + .outBillNo("OUT_BILL_001") |
| 232 | + .transferSceneId("1005") |
| 233 | + .openid("oX_7Jzr9gSZz4X_Xc9-_7HGf8XzI") |
| 234 | + .transferAmount(100) |
| 235 | + .transferRemark("测试转账") |
| 236 | + .receiptAuthorizationMode("NO_CONFIRM_RECEIPT_AUTHORIZATION") |
| 237 | + .authorizationInfo(TransferBillsRequest.AuthorizationInfo.newBuilder() |
| 238 | + .userDisplayName("张三") |
| 239 | + .outAuthorizationNo("OUT_AUTH_001") |
| 240 | + .authorizationNotifyUrl("https://example.com/auth/notify") |
| 241 | + .build()) |
| 242 | + .build(); |
| 243 | + |
| 244 | + String json = gson.toJson(request); |
| 245 | + |
| 246 | + Assert.assertTrue(json.contains("\"receipt_authorization_mode\""), |
| 247 | + "JSON 应包含 receipt_authorization_mode 字段"); |
| 248 | + Assert.assertTrue(json.contains("NO_CONFIRM_RECEIPT_AUTHORIZATION"), |
| 249 | + "JSON 应包含 receipt_authorization_mode 的值"); |
| 250 | + Assert.assertTrue(json.contains("\"authorization_info\""), |
| 251 | + "JSON 应包含 authorization_info 嵌套字段"); |
| 252 | + Assert.assertTrue(json.contains("\"user_display_name\""), |
| 253 | + "JSON 应包含 user_display_name 字段"); |
| 254 | + Assert.assertTrue(json.contains("张三"), |
| 255 | + "JSON 应包含 user_display_name 的值"); |
| 256 | + Assert.assertTrue(json.contains("\"out_authorization_no\""), |
| 257 | + "JSON 应包含 out_authorization_no 字段"); |
| 258 | + Assert.assertTrue(json.contains("OUT_AUTH_001"), |
| 259 | + "JSON 应包含 out_authorization_no 的值"); |
| 260 | + Assert.assertTrue(json.contains("\"authorization_notify_url\""), |
| 261 | + "JSON 应包含 authorization_notify_url 字段"); |
| 262 | + Assert.assertTrue(json.contains("https://example.com/auth/notify"), |
| 263 | + "JSON 应包含 authorization_notify_url 的值"); |
| 264 | + } |
| 265 | + |
| 266 | + /** |
| 267 | + * 验证通过 authorization_id 和 out_authorization_no 顶层字段发起免确认转账时序列化正确。 |
| 268 | + */ |
| 269 | + public void shouldSerializeTransferBillsRequestWithTopLevelAuthFields() { |
| 270 | + Gson gson = new Gson(); |
| 271 | + TransferBillsRequest request = TransferBillsRequest.newBuilder() |
| 272 | + .appid("wxf636efh5xxxxx") |
| 273 | + .outBillNo("OUT_BILL_002") |
| 274 | + .transferSceneId("1005") |
| 275 | + .openid("oX_7Jzr9gSZz4X_Xc9-_7HGf8XzI") |
| 276 | + .transferAmount(200) |
| 277 | + .transferRemark("免确认转账") |
| 278 | + .receiptAuthorizationMode("NO_CONFIRM_RECEIPT_AUTHORIZATION") |
| 279 | + .authorizationId("AUTH_ID_001") |
| 280 | + .outAuthorizationNo("OUT_AUTH_002") |
| 281 | + .build(); |
| 282 | + |
| 283 | + String json = gson.toJson(request); |
| 284 | + |
| 285 | + Assert.assertTrue(json.contains("\"authorization_id\""), |
| 286 | + "JSON 应包含 authorization_id 字段"); |
| 287 | + Assert.assertTrue(json.contains("AUTH_ID_001"), |
| 288 | + "JSON 应包含 authorization_id 的值"); |
| 289 | + Assert.assertTrue(json.contains("\"out_authorization_no\""), |
| 290 | + "JSON 应包含 out_authorization_no 字段"); |
| 291 | + Assert.assertTrue(json.contains("OUT_AUTH_002"), |
| 292 | + "JSON 应包含 out_authorization_no 的值"); |
| 293 | + } |
| 294 | + |
223 | 295 | /** |
224 | 296 | * 通过动态代理拦截 WxPayService 请求并记录 URL/请求体,便于断言接口路径和参数。 |
225 | 297 | */ |
|
0 commit comments