EnterpriseWechatApiTest.java 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.qqflow.engine.domain.ewechat.api;
  2. import com.qqflow.engine.common.util.JsonUtil;
  3. import com.qqflow.engine.domain.ewechat.model.enterprise.rsp.*;
  4. import com.qqflow.engine.domain.ewechat.service.EnterpriseWechatService;
  5. import org.junit.jupiter.api.Test;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.boot.test.context.SpringBootTest;
  8. import java.io.File;
  9. import static org.junit.jupiter.api.Assertions.*;
  10. @SpringBootTest
  11. class EnterpriseWechatApiTest {
  12. @Autowired
  13. private EnterpriseWechatApi enterpriseWechatApi;
  14. @Autowired
  15. private EnterpriseWechatService enterpriseWechatService;
  16. private static final String corpId = "wpU17nDAAAzci3-mra3ZS8QMAqGsB9zw";
  17. private static final String suiteId = "dk0580416972e402b8";
  18. @Test
  19. void getAccessToken() {
  20. EnterpriseWechatAccessTokenRsp accessToken = enterpriseWechatApi.getAccessToken(corpId,"1avQqFtd-5xHqZpoktm4IeY-r4fuH9hcccYoi8mP1Hg");
  21. System.out.println(JsonUtil.entity2Json(accessToken));
  22. // 61.140.242.202
  23. }
  24. @Test
  25. void upload() {
  26. String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId);
  27. File file = new File("daoshi.png");
  28. EnterpriseWechatUploadRsp image = enterpriseWechatApi.upload(accessToken, "image", file);
  29. System.out.println(JsonUtil.entity2Json(image));
  30. // {"errcode":0,"errmsg":"ok","type":"image","media_id":"35FO8INS92cgjRvBPb1XfE8rL6z4y65k4tRu1asFJ-wzqMM_wuSkkTYLW9cJ93aajF3WWunaLGapBtE-CAmpUrg","created_at":"1742435297"}
  31. }
  32. @Test
  33. void addCs() {
  34. //3hr5ZiHgzWSujIzc5De7ly0kdzHrKLiXVLA3ZpwCH00ovmzHslzIRI1wLz6Q5dkuh9iolfT6fC-9Id6fkTGJt5w
  35. String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId);
  36. String mediaId = "35FO8INS92cgjRvBPb1XfE8rL6z4y65k4tRu1asFJ-wzqMM_wuSkkTYLW9cJ93aajF3WWunaLGapBtE-CAmpUrg";
  37. EnterpriseWechatAddCsRsp addCsRsp = enterpriseWechatApi.addCs(accessToken, "换装机器人", mediaId);
  38. System.out.println(JsonUtil.entity2Json(addCsRsp));
  39. // {"errcode":0,"errmsg":"ok","open_kfid":"wkU17nDAAAGb3xrp_kW0A6ZfB94BKH2g"}
  40. }
  41. @Test
  42. void getCsUrl() {
  43. String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId);
  44. String openKfId = "wkU17nDAAAGb3xrp_kW0A6ZfB94BKH2g";
  45. EnterpriseWechatCsUrlRsp rsp = enterpriseWechatApi.getCsUrl(accessToken, openKfId);
  46. System.out.println(JsonUtil.entity2Json(rsp));
  47. // {"errcode":0,"errmsg":"ok","url":"https://work.weixin.qq.com/kfid/kfcf10a952a889c4ea0?enc_scene=ENCBSKmoN2yCfdLYGVcriYG2Jv17N8DmuR92X14QmCCFSGY"}
  48. }
  49. @Test
  50. void syncMsg() {
  51. String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId);
  52. String openKfId = "wkU17nDAAAGb3xrp_kW0A6ZfB94BKH2g";
  53. EnterpriseWechatSyncMsgRsp syncMsgRsp = enterpriseWechatApi.syncMsg(accessToken, null, null, openKfId);
  54. System.out.println(JsonUtil.entity2Json(syncMsgRsp));
  55. // {"errcode":0,"errmsg":"ok","next_cursor":"4gw7MepFLfgF2VC5np6","msg_list":[{"msgid":"4PgQZemvMsbGoLd27jX7SnDw3tPEzat4hLs236utvVTk","send_time":1742440082,"origin":4,"msgtype":"event","event":{"event_type":"enter_session","scene":"test1","open_kfid":"wkU17nDAAAGb3xrp_kW0A6ZfB94BKH2g","external_userid":"wmU17nDAAAw8PCQAHTZZ6xZOozjbKTbA","welcome_code":"ODQX6xHIeCUNz2vlBdCs-Nvfxk0gg0x71twHCHqvZYk"}}],"has_more":0}
  56. // {"msgid":"4PgQZemvMsbGoLd27jX7SnDw3tPEzat4hLs236utvVTk","send_time":1742440082,"origin":4,"msgtype":"event","event":{"event_type":"enter_session","scene":"test1","open_kfid":"wkU17nDAAAGb3xrp_kW0A6ZfB94BKH2g","external_userid":"wmU17nDAAAw8PCQAHTZZ6xZOozjbKTbA","welcome_code":"ODQX6xHIeCUNz2vlBdCs-Nvfxk0gg0x71twHCHqvZYk"}}
  57. }
  58. @Test
  59. void downloadMedia() {
  60. String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId);
  61. String mediaId = "35FO8INS92cgjRvBPb1XfE8rL6z4y65k4tRu1asFJ-wzqMM_wuSkkTYLW9cJ93aajF3WWunaLGapBtE-CAmpUrg";
  62. String localFileUrl= enterpriseWechatApi.downloadMedia(accessToken, mediaId);
  63. System.out.println(localFileUrl);
  64. }
  65. @Test
  66. void getUseridByMobile() {
  67. String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId);
  68. EnterpriseWechatUseridByMobileRsp rsp = enterpriseWechatApi.getUseridByMobile(accessToken, "13450478314");
  69. System.out.println(JsonUtil.entity2Json(rsp));
  70. }
  71. @Test
  72. void listUserId() {
  73. String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId);
  74. EnterpriseWechatListIdRsp rsp = enterpriseWechatApi.listUserId(accessToken, null, 10);
  75. System.out.println(JsonUtil.entity2Json(rsp));
  76. }
  77. }