- 无法获取到类目模板的id
文档:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html 获取模板ID:https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN 入参不支持传类目模板编号 获取模板列表:https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=ACCESS_TOKEN 获取不到类目模板
2023-01-10 - 为什么uploadFile好像传不了文件到后台?
前端调用代码 [代码]selectImg: [代码][代码]function[代码][代码](e){[代码][代码] [代码][代码]var[代码] [代码]that=[代码][代码]this[代码][代码] [代码][代码]wx.chooseImage({[代码][代码] [代码][代码]count: 3,[代码][代码] [代码][代码]sizeType: [[代码][代码]'original'[代码][代码], [代码][代码]'compressed'[代码][代码]],[代码][代码] [代码][代码]sourceType: [[代码][代码]'album'[代码][代码], [代码][代码]'camera'[代码][代码]],[代码][代码] [代码][代码]success(res) {[代码][代码] [代码][代码]const tempFilePaths = res.tempFilePaths[代码][代码] [代码][代码]console.log(tempFilePaths)[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]imgUrl: tempFilePaths[代码][代码] [代码][代码]})[代码][代码] [代码][代码]wx.uploadFile({[代码][代码] [代码][代码]url: app.serverUrl+[代码][代码]"/upload/XZImg?openid="[代码][代码]+app.openID, [代码][代码]//仅为示例,非真实的接口地址[代码][代码] [代码][代码]filePath: tempFilePaths[0],[代码][代码] [代码][代码]name: [代码][代码]'files'[代码][代码],[代码][代码] [代码][代码]success(res) {[代码][代码] [代码][代码]const data = res.data[代码][代码] [代码][代码]//do something[代码][代码] [代码][代码]console.log(data)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]})[代码][代码] [代码] [代码] [代码][代码]}[代码][代码] [代码][代码]})[代码]后端代码 [代码]@RestController[代码][代码]@RequestMapping[代码][代码]([代码][代码]"/upload"[代码][代码])[代码][代码]public[代码] [代码]class[代码] [代码]uploadImage {[代码] [代码] [代码][代码]@PostMapping[代码][代码]([代码][代码]"/XZImg"[代码][代码])[代码][代码] [代码][代码]public[代码] [代码]void[代码] [代码]uploadFace(String openid, [代码][代码]@RequestParam[代码][代码]([代码][代码]"files"[代码][代码]) MultipartFile[] files ) [代码][代码]throws[代码] [代码]Exception {[代码][代码] [代码][代码]System.out.println(openid);[代码] [代码] [代码][代码]if[代码] [代码](StringUtils.isNotBlank(openid)) {[代码][代码] [代码][代码]// 文件保存的命名空间[代码][代码] [代码][代码]String fileSpace = [代码][代码]"C:/Users/Administrator/ssm_images"[代码][代码];[代码][代码] [代码][代码]// 保存到数据库中的相对路径[代码][代码] [代码][代码]String uploadPathDB = [代码][代码]"/"[代码] [代码]+ openid;[代码][代码] [代码][代码]System.out.println(uploadPathDB);[代码][代码] [代码][代码]FileOutputStream fileOutputStream = [代码][代码]null[代码][代码];[代码][代码] [代码][代码]InputStream inputStream = [代码][代码]null[代码][代码];[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]if[代码] [代码](files != [代码][代码]null[代码] [代码]&&files.length>[代码][代码]0[代码][代码]) {[代码][代码] [代码][代码]System.out.println(files);[代码][代码] [代码][代码]String fileName = files[[代码][代码]0[代码][代码]].getOriginalFilename();[代码][代码] [代码][代码]if[代码] [代码](StringUtils.isNotBlank(fileName)) {[代码][代码] [代码][代码]// 文件上传的最终保存路径[代码][代码] [代码][代码]String finalFacePath = fileSpace + uploadPathDB + [代码][代码]"/"[代码] [代码]+ fileName;[代码][代码] [代码][代码]// 设置数据库保存的路径[代码][代码] [代码][代码]uploadPathDB += ([代码][代码]"/"[代码] [代码]+ fileName);[代码] [代码] [代码][代码]File outFile = [代码][代码]new[代码] [代码]File(finalFacePath);[代码][代码] [代码][代码]if[代码] [代码](outFile.getParentFile() != [代码][代码]null[代码] [代码]|| !outFile.getParentFile().isDirectory()) {[代码][代码] [代码][代码]// 创建父文件夹[代码][代码] [代码][代码]outFile.getParentFile().mkdirs();[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]fileOutputStream = [代码][代码]new[代码] [代码]FileOutputStream(outFile);[代码][代码] [代码][代码]inputStream = files[[代码][代码]0[代码][代码]].getInputStream();[代码][代码] [代码][代码]IOUtils.copy(inputStream, fileOutputStream);[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]}[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](Exception e) {[代码][代码] [代码][代码]e.printStackTrace();[代码][代码] [代码][代码]} [代码][代码]finally[代码] [代码]{[代码][代码] [代码][代码]if[代码] [代码](fileOutputStream != [代码][代码]null[代码][代码]) {[代码][代码] [代码][代码]fileOutputStream.flush();[代码][代码] [代码][代码]fileOutputStream.close();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]}[代码][代码]}[代码]一直进不去啊,用HttpServltRequest看请求体参数files是null。是哪里出问题了呢?好像文件根本就没传过去,都是null
2019-08-09