123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package com.fjhx.back.controller;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.fjhx.back.entity.MailboxListMessagesDto;
- import com.fjhx.back.wy163.rsa.HttpPost;
- import com.fjhx.back.wy163.rsa.RSASignatureToQiye;
- import com.fjhx.back.wy163.rsa.RSATool;
- import lombok.SneakyThrows;
- import lombok.extern.slf4j.Slf4j;
- import org.springblade.core.tool.api.R;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.net.URLEncoder;
- import java.util.Collections;
- @Slf4j
- @RestController
- @RequestMapping("/test")
- public class TestController {
- private static final String PRI_KEY =
- "30820275020100300d06092a864886f70d01010105000482025f3082025b02010002818100919453a879ad6b497f99" +
- "739c3ab66c8cfa2eaf89c963985c946529da3c968b11390155cddbe943387a5665f77e849c3f07eeb12852895b26bc29276096" +
- "03db6eb5ddd62968a7ce8e1fdfde5bce77b5262eb3aa67cb26e61426df497367b36e344be70a6404ce3d91e6a82ff5f4e13bfdb" +
- "c3ebedd827c6ccf3d1767c239087ffb02030100010281800d378838dd832f2067234969bfb2dc3c1862b0b133c58509b2b7548b" +
- "69c0c93371177bf0caac6cdbedcf76467808161f6adaf2de944fc024ce24765cc081ed2406eef1c7c87509584ca3c1926af7d26" +
- "d0f7d3c18d51368100c09fb74cef3402d23c5e223a2e4ad6ae0c82a10eef8e5dc0b8dc54c5066b54dcabba30cb9b5d1d1024100" +
- "c85b5b91e0a0e41f9c5ec2f1a038faa4409980402f5f439adeb729450ebd39841d1244031ad78e3a28cb50a7c66b65840f79bf0" +
- "5190f9235efce8aa450d8c8cf024100ba027dbe9688c63ba896f46d2b4f1aac8758659cd8435380c38d41b4e9b22d717450dd07" +
- "ceac10db63e52ec4cce2e9f7d99c16bb2ae89b6a932ea0b19f7349150240431161dbb927e2753a70f62cd00782cf4cd89577e6e3" +
- "aacbc2d5e938b6b05cfa7e88c8bf8952b2c781345df16b9833c93b2cf3e68ef7096888b7c8ed2c2b053d0240378d88ea83e0e37b" +
- "6bd571b8ad079a0acefd4a93b64f1d4046a70869b4a5ff46741bb6779f74ea2febbcc5e406e0fa498897427eb1c8f8a9b2bd6946" +
- "c33d562502400d0145f83ca2e2d2157c190d96c73a2476d8cc0bf24970d479db0dac690c74c8e60a57c13e7bf2d088234e39a9a7" +
- "e91df09ef287dc8e259296b346762fe3387d";
- /**
- * 获取邮件信息
- */
- @SneakyThrows
- @GetMapping("/mailbox/listMessages")
- public R mailboxListMessages(MailboxListMessagesDto dto) {
- String time = System.currentTimeMillis() + "";
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("fids", Collections.singletonList(dto.getFid()));
- jsonObject.put("order", "receivedDate");
- jsonObject.put("desc", true);
- jsonObject.put("start", (dto.getPageNum() - 1) * dto.getPageSize());
- jsonObject.put("limit", dto.getPageSize());
- jsonObject.put("returnTotal", true);
- String params = jsonObject.toString();
- String url = "https://apihz.qiye.163.com/qiyeservice/api/mailbox/listMessages";
- String src = "account_name=" + dto.getAccountName() + "&domain=" + dto.getDomain() + "¶ms="
- + params + "&product=" + dto.getProduct() + "&time=" + time;
- String sign = RSASignatureToQiye.generateSigature(PRI_KEY, src);
- url = url + "?" + "account_name=" + dto.getAccountName() + "&domain="
- + dto.getDomain() + "¶ms=" + URLEncoder.encode(params, "utf8") +
- "&product=" + dto.getProduct() + "&sign=" + sign + "&time=" + time;
- HttpPost hp = new HttpPost();
- String result = hp.post(url);
- return R.success(JSON.parseObject(result));
- }
- /**
- * 获取未读邮件数量
- */
- @GetMapping("/mailbox/getUnreadMsg")
- public R mailboxGetUnreadMsg(MailboxListMessagesDto dto) {
- String time = System.currentTimeMillis() + "";
- String url = "https://apihz.qiye.163.com/qiyeservice/api/mailbox/getUnreadMsg";
- String sign = "account_name=" + dto.getAccountName() + "&domain=" + dto.getDomain() + "&fid=" + dto.getFid()
- + "&product=" + dto.getProduct() + "&time=" + time;
- sign = RSASignatureToQiye.generateSigature(PRI_KEY, sign);
- url = url + "?" + "account_name=" + dto.getAccountName() + "&domain="
- + dto.getDomain() + "&fid=" + dto.getFid() + "&product="
- + dto.getProduct() + "&sign=" + sign + "&time=" + time;
- HttpPost hp = new HttpPost();
- String result = hp.post(url);
- return R.success(JSON.parseObject(result));
- }
- /**
- * 单点登录地址
- */
- @GetMapping("/mailbox/sso")
- public R detail(MailboxListMessagesDto dto) {
- String time = System.currentTimeMillis() + "";
- String src = dto.getAccountName() + dto.getDomain() + time;
- RSATool rsa = new RSATool();
- String enc = rsa.generateSHA1withRSASigature(src, PRI_KEY);
- String url = "https://entry.qiye.163.com/domain/oa/Entry?domain=" + dto.getDomain() +
- "&account_name=" + dto.getAccountName() + "&time=" + time + "&enc=" + enc + "&language=0&mid=" + dto.getMid();
- return R.success(url);
- }
- }
|