package com.qqflow.engine.domain.ewechat.api; import com.qqflow.engine.common.util.JsonUtil; import com.qqflow.engine.domain.ewechat.model.enterprise.rsp.*; import com.qqflow.engine.domain.ewechat.service.EnterpriseWechatService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.io.File; import static org.junit.jupiter.api.Assertions.*; @SpringBootTest class EnterpriseWechatApiTest { @Autowired private EnterpriseWechatApi enterpriseWechatApi; @Autowired private EnterpriseWechatService enterpriseWechatService; private static final String corpId = "wpU17nDAAAzci3-mra3ZS8QMAqGsB9zw"; private static final String suiteId = "dk0580416972e402b8"; @Test void getAccessToken() { EnterpriseWechatAccessTokenRsp accessToken = enterpriseWechatApi.getAccessToken(corpId,"1avQqFtd-5xHqZpoktm4IeY-r4fuH9hcccYoi8mP1Hg"); System.out.println(JsonUtil.entity2Json(accessToken)); // 61.140.242.202 } @Test void upload() { String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId); File file = new File("daoshi.png"); EnterpriseWechatUploadRsp image = enterpriseWechatApi.upload(accessToken, "image", file); System.out.println(JsonUtil.entity2Json(image)); // {"errcode":0,"errmsg":"ok","type":"image","media_id":"35FO8INS92cgjRvBPb1XfE8rL6z4y65k4tRu1asFJ-wzqMM_wuSkkTYLW9cJ93aajF3WWunaLGapBtE-CAmpUrg","created_at":"1742435297"} } @Test void addCs() { //3hr5ZiHgzWSujIzc5De7ly0kdzHrKLiXVLA3ZpwCH00ovmzHslzIRI1wLz6Q5dkuh9iolfT6fC-9Id6fkTGJt5w String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId); String mediaId = "35FO8INS92cgjRvBPb1XfE8rL6z4y65k4tRu1asFJ-wzqMM_wuSkkTYLW9cJ93aajF3WWunaLGapBtE-CAmpUrg"; EnterpriseWechatAddCsRsp addCsRsp = enterpriseWechatApi.addCs(accessToken, "换装机器人", mediaId); System.out.println(JsonUtil.entity2Json(addCsRsp)); // {"errcode":0,"errmsg":"ok","open_kfid":"wkU17nDAAAGb3xrp_kW0A6ZfB94BKH2g"} } @Test void getCsUrl() { String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId); String openKfId = "wkU17nDAAAGb3xrp_kW0A6ZfB94BKH2g"; EnterpriseWechatCsUrlRsp rsp = enterpriseWechatApi.getCsUrl(accessToken, openKfId); System.out.println(JsonUtil.entity2Json(rsp)); // {"errcode":0,"errmsg":"ok","url":"https://work.weixin.qq.com/kfid/kfcf10a952a889c4ea0?enc_scene=ENCBSKmoN2yCfdLYGVcriYG2Jv17N8DmuR92X14QmCCFSGY"} } @Test void syncMsg() { String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId); String openKfId = "wkU17nDAAAGb3xrp_kW0A6ZfB94BKH2g"; EnterpriseWechatSyncMsgRsp syncMsgRsp = enterpriseWechatApi.syncMsg(accessToken, null, null, openKfId); System.out.println(JsonUtil.entity2Json(syncMsgRsp)); // {"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} // {"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"}} } @Test void downloadMedia() { String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId); String mediaId = "35FO8INS92cgjRvBPb1XfE8rL6z4y65k4tRu1asFJ-wzqMM_wuSkkTYLW9cJ93aajF3WWunaLGapBtE-CAmpUrg"; String localFileUrl= enterpriseWechatApi.downloadMedia(accessToken, mediaId); System.out.println(localFileUrl); } @Test void getUseridByMobile() { String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId); EnterpriseWechatUseridByMobileRsp rsp = enterpriseWechatApi.getUseridByMobile(accessToken, "13450478314"); System.out.println(JsonUtil.entity2Json(rsp)); } @Test void listUserId() { String accessToken = enterpriseWechatService.getAccessToken(corpId, suiteId); EnterpriseWechatListIdRsp rsp = enterpriseWechatApi.listUserId(accessToken, null, 10); System.out.println(JsonUtil.entity2Json(rsp)); } }