123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package com.hz.employmentsite.controller;
- import com.google.zxing.WriterException;
- import com.hz.employmentsite.filter.exception.BaseResponse;
- import com.hz.employmentsite.filter.exception.RespGenerstor;
- import com.hz.employmentsite.services.service.WechatService;
- import com.hz.employmentsite.util.QrCodeUtils;
- import lombok.extern.slf4j.Slf4j;
- import me.chanjar.weixin.common.error.WxErrorException;
- import org.apache.tomcat.util.buf.UDecoder;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.UnsupportedEncodingException;
- import java.net.URLDecoder;
- import java.util.Base64;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.UUID;
- @RestController
- @RequestMapping("/api/wx")
- @Slf4j
- public class WxController {
- /*@Autowired
- private RemoteHelper remoteHelper;
- @GetMapping("/getWxToken")
- public String getWxToken() {
- Map<String, String> params = new HashMap<>();
- params.put("grant_type","client_credential");
- params.put("appid","wx765e6ec59e26c288");
- params.put("secret","a44d8034671866e957484f5ed4e1df48");
- remoteHelper.getJson(params, "https://api.weixin.qq.com/cgi-bin/token",null);
- return "";
- }*/
- @Autowired
- private WechatService wechatService;
- @Autowired
- private QrCodeUtils qrCodeUtils;
- @GetMapping("getOAuthUrl")
- public BaseResponse<String> getOAuthUrl(String redirectUrl) throws UnsupportedEncodingException {
- String url = wechatService.getOAuthUrl(URLDecoder.decode(redirectUrl, "UTF-8"));
- log.info("getOAuthUrl:" + url);
- return RespGenerstor.success(url);
- }
- @GetMapping("getOpenId")
- public BaseResponse<String> getOpenId(String code) throws WxErrorException {
- return RespGenerstor.success(wechatService.getOpenId(code));
- }
- @PostMapping("/sentMsg")
- public BaseResponse<String> sentMsg() throws Exception {
- Map<String, String> data = new HashMap<>();
- data.put("thing28", "张三");
- data.put("phone_number34", "134556456456");
- data.put("thing10", "开发");
- return RespGenerstor.success(wechatService.sendMsg("ow5Mm61JAlqqNhZzcV9lLqTDnBCs", UUID.randomUUID().toString(), "http://www.bowintek.com/hzyz/mobile/index.html/#/jobUserInfo/index?userId=60ea0d5b-a75c-11ed-a6c5-7085c2a9999e",
- "-R2xeAeey7rOKN5VAuUr8cFMsJFlFp7ksN7m6H5_5VU", data));
- }
- @GetMapping("/getQRCodeUrlToBase64")
- public BaseResponse<String> getQRCodeUrlToBase64(@RequestParam("url") String url, @RequestParam("userId") String userId, @RequestParam(required = false) Integer margin) throws IOException, WriterException {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- String fullUrl = wechatService.getQrcodeUrl(URLDecoder.decode(url, "UTF-8"), userId);
- qrCodeUtils.getQrCode(bos, fullUrl, margin);
- byte[] bytes = bos.toByteArray();
- Base64.Encoder encoder = Base64.getEncoder();
- String base64String = encoder.encodeToString(bytes);
- bos.close();
- return RespGenerstor.success(base64String);
- }
- @GetMapping("qrcodeVerify")
- public BaseResponse<Boolean> qrcodeVerify(@RequestParam("qrCodeId") String qrCodeId, @RequestParam(required = false) String openId) {
- return RespGenerstor.success(wechatService.qrcodeVerify(qrCodeId, openId));
- }
- }
|