|
| 1 | +package cn.binarywang.wx.miniapp.api.impl; |
| 2 | + |
| 3 | +import cn.binarywang.wx.miniapp.api.WxMaService; |
| 4 | +import cn.binarywang.wx.miniapp.bean.employee.WxMaSendEmployeeMsgRequest; |
| 5 | +import cn.binarywang.wx.miniapp.bean.employee.WxMaUnbindEmployeeRequest; |
| 6 | +import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; |
| 7 | +import cn.binarywang.wx.miniapp.test.ApiTestModule; |
| 8 | +import com.google.inject.Inject; |
| 9 | +import lombok.extern.slf4j.Slf4j; |
| 10 | +import me.chanjar.weixin.common.error.WxErrorException; |
| 11 | +import org.jetbrains.annotations.NotNull; |
| 12 | +import org.testng.annotations.Guice; |
| 13 | +import org.testng.annotations.Test; |
| 14 | + |
| 15 | +import java.util.*; |
| 16 | + |
| 17 | +@Slf4j |
| 18 | +@Test |
| 19 | +@Guice(modules = ApiTestModule.class) |
| 20 | +public class WxMaEmployeeRelationServiceImplTest { |
| 21 | + |
| 22 | + @Inject |
| 23 | + protected WxMaService wxService; |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testSendEmployeeMsg() throws WxErrorException { |
| 27 | + WxMaSendEmployeeMsgRequest wxMaSendEmployeeMsgRequest = new WxMaSendEmployeeMsgRequest(); |
| 28 | + wxMaSendEmployeeMsgRequest.setPage("/pages/index/index"); |
| 29 | + wxMaSendEmployeeMsgRequest.setTouser("o0uBr12b1zdgCk1qDoBivmSYb9GA"); |
| 30 | + wxMaSendEmployeeMsgRequest.setTemplateId("nmO-O4V33TOREVLAlumwPCsHssqkt7mea_cyWNE-IFmZqT9jh_LsERhzDOsOqa-3"); |
| 31 | + |
| 32 | + // 使用 HashMap 构建数据结构 |
| 33 | + Map<String, Object> data1 = new HashMap<>(); |
| 34 | + // 内层字段 |
| 35 | + Map<String, Object> dataContent = getStringObjectMap(); |
| 36 | + |
| 37 | + data1.put("data", dataContent); |
| 38 | + wxMaSendEmployeeMsgRequest.setData(WxMaGsonBuilder.create().toJson(data1)); |
| 39 | + this.wxService.getEmployeeRelationService().sendEmployeeMsg(wxMaSendEmployeeMsgRequest); |
| 40 | + } |
| 41 | + |
| 42 | + @NotNull |
| 43 | + private static Map<String, Object> getStringObjectMap() { |
| 44 | + Map<String, String> thing1 = new HashMap<>(); |
| 45 | + Map<String, String> thing2 = new HashMap<>(); |
| 46 | + Map<String, String> time1 = new HashMap<>(); |
| 47 | + Map<String, String> character_string1 = new HashMap<>(); |
| 48 | + Map<String, String> time2 = new HashMap<>(); |
| 49 | + thing1.put("value", "高和蓝枫箱体测试"); |
| 50 | + thing2.put("value", "门口全英测试"); |
| 51 | + time1.put("value", "2026年11月23日 19:19"); |
| 52 | + character_string1.put("value", "50kg"); |
| 53 | + time2.put("value", "2026年11月23日 19:19"); |
| 54 | + |
| 55 | + // 模板消息变量,有顺序要求 |
| 56 | + Map<String, Object> dataContent = new LinkedHashMap<>(); |
| 57 | + dataContent.put("thing1", thing1); |
| 58 | + dataContent.put("thing2", thing2); |
| 59 | + dataContent.put("time1", time1); |
| 60 | + dataContent.put("character_string1", character_string1); |
| 61 | + dataContent.put("time2", time2); |
| 62 | + return dataContent; |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testUnbinduserb2cauthinfo() throws WxErrorException { |
| 68 | + WxMaUnbindEmployeeRequest wxMaUnbindEmployeeRequest = new WxMaUnbindEmployeeRequest(); |
| 69 | + wxMaUnbindEmployeeRequest.setOpenidList(List.of("o0uBr12b1zdgCk1qDoBivmSYb9GA")); |
| 70 | + this.wxService.getEmployeeRelationService().unbindEmployee(wxMaUnbindEmployeeRequest); |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments