| | |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.mock.web.MockMultipartFile; |
| | | //import org.springframework.mock.web.MockMultipartFile; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | /** |
| | | * 上传文件存储在本地的根路径 |
| | | */ |
| | | @Value("${file.path}") |
| | | @Value("${file.upload.location}") |
| | | private String localFilePath; |
| | | |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "通过code获得openid,获取用户信息",tags = {"微信小程序登录"}) |
| | | @PostMapping("/openIdByJsCode") |
| | | public AjaxResult<Map<String, Object>> openIdByJsCode(@RequestBody AppletUserEncrypteData data) { |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | /**data |
| | | * 测试用 |
| | | * @param appletUserDecodeData |
| | | * @return |
| | |
| | | public AjaxResult<Map<String, Object>> openIdByJsCode(@RequestBody AppletUserDecodeData appletUserDecodeData) { |
| | | return AjaxResult.success(appUserService.wxLogin(appletUserDecodeData, null)); |
| | | } |
| | | public static MultipartFile convertInputStreamToMultipartFile(InputStream inputStream, String fileName, String contentType) throws IOException { |
| | | return new MockMultipartFile(fileName, fileName, contentType, inputStream); |
| | | } |
| | | |
| | | // public static MultipartFile convertInputStreamToMultipartFile(InputStream inputStream, String fileName, String contentType) throws IOException { |
| | | // return new MockMultipartFile(fileName, fileName, contentType, inputStream); |
| | | // } |
| | | |
| | | @ApiOperation(value = "获取微信小程序二维码",tags = {"获取微信小程序二维码"}) |
| | | @PostMapping("/getQRCode") |
| | | public AjaxResult getQRCode() { |
| | |
| | | System.err.println(Base64.encodeBase64String(result)); |
| | | inputStream = new ByteArrayInputStream(result); |
| | | String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpeg"; |
| | | MultipartFile multipartFile = convertInputStreamToMultipartFile(inputStream, finalFileName, "image/jpeg"); |
| | | String name = FileUploadUtils.upload(localFilePath, multipartFile); |
| | | System.err.println(name); |
| | | return AjaxResult.success(name); |
| | | // MultipartFile multipartFile = convertInputStreamToMultipartFile(inputStream, finalFileName, "image/jpeg"); |
| | | // String name = FileUploadUtils.upload(localFilePath, multipartFile); |
| | | // System.err.println(name); |
| | | return AjaxResult.success(null); |
| | | } catch (Exception e) { |
| | | System.err.println("调用小程序生成微信永久小程序码URL接口异常" + e); |
| | | } finally { |