| @@ -8,15 +8,28 @@ import io.swagger.annotations.Api; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.open.api.WxOpenMaService; | |||
| import me.chanjar.weixin.open.bean.ma.WxMaOpenCommitExtInfo; | |||
| import me.chanjar.weixin.open.bean.message.WxOpenMaSubmitAuditMessage; | |||
| import me.chanjar.weixin.open.bean.result.WxOpenMaCategoryListResult; | |||
| import me.chanjar.weixin.open.bean.result.WxOpenMaPageListResult; | |||
| import me.chanjar.weixin.open.bean.result.WxOpenMaSubmitAuditResult; | |||
| import me.chanjar.weixin.open.bean.result.WxOpenResult; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Controller; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import javax.servlet.ServletOutputStream; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.File; | |||
| import java.io.FileInputStream; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.util.Map; | |||
| /** | |||
| * Stormeye Wu | |||
| */ | |||
| @@ -41,4 +54,78 @@ public class WechatWeappCodeController { | |||
| } | |||
| return new ResultData(Result.ERROR); | |||
| } | |||
| @GetMapping("/getQrcode") | |||
| public void getQrcode(String appId, String pagePath, Map<String, String> params, HttpServletResponse response, HttpServletRequest req) { | |||
| try { | |||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||
| File file = openMaService.getTestQrcode(pagePath, params); | |||
| ServletOutputStream out = response.getOutputStream(); | |||
| response.reset(); | |||
| response.setContentType("bin"); | |||
| String agent = req.getHeader("user-agent"); | |||
| String filename = "qrcode"; | |||
| if (agent.contains("Firefox")) { | |||
| response.setHeader("Content-disposition", | |||
| "attachment; filename=" | |||
| + new String(filename.getBytes("GB2312"),"ISO-8859-1")); | |||
| } else { | |||
| response.setHeader("Content-disposition", | |||
| "attachment; filename=" | |||
| + java.net.URLEncoder.encode(filename,"UTF-8")); | |||
| } | |||
| // 循环取出流中的数据 | |||
| byte[] b = new byte[1024]; | |||
| int len; | |||
| InputStream inStream = new FileInputStream(file); | |||
| while ((len = inStream.read(b)) > 0) | |||
| response.getOutputStream().write(b, 0, len); | |||
| inStream.close(); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (IOException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| @GetMapping("/getCategory") | |||
| public ResultData getCategory(String appId) { | |||
| try { | |||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||
| WxOpenMaCategoryListResult openRet = openMaService.getCategoryList(); | |||
| logger.info(openRet.toString()); | |||
| return new ResultData(openRet); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| return new ResultData(Result.ERROR); | |||
| } | |||
| @GetMapping("/getPage") | |||
| public ResultData getPage(String appId) { | |||
| try { | |||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||
| WxOpenMaPageListResult openRet = openMaService.getPageList(); | |||
| logger.info(openRet.toString()); | |||
| return new ResultData(openRet); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| return new ResultData(Result.ERROR); | |||
| } | |||
| @PostMapping("/submitAudit") | |||
| public ResultData submitAudit(String appId, String subMesgStr) { | |||
| try { | |||
| WxOpenMaSubmitAuditMessage subMessage = JSON.parseObject(subMesgStr, WxOpenMaSubmitAuditMessage.class); | |||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||
| WxOpenMaSubmitAuditResult openRet = openMaService.submitAudit(subMessage); | |||
| logger.info(openRet.toString()); | |||
| return new ResultData(openRet); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| return new ResultData(Result.ERROR); | |||
| } | |||
| } | |||