{"id":255,"date":"2025-03-24T16:10:32","date_gmt":"2025-03-24T08:10:32","guid":{"rendered":"http:\/\/danranrie.cn\/?p=255"},"modified":"2025-03-24T16:12:50","modified_gmt":"2025-03-24T08:12:50","slug":"%e7%a7%bb%e5%8a%a8%e7%ab%af%e5%9b%be%e7%89%87%e5%9f%ba%e4%ba%8e%e5%90%8e%e7%ab%af%e6%a1%86%e6%9e%b6%e7%9a%84%e5%9b%be%e7%89%87%e4%b8%8a%e4%bc%a0%e8%af%bb%e5%8f%96%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"http:\/\/danranrie.cn\/index.php\/2025\/03\/24\/%e7%a7%bb%e5%8a%a8%e7%ab%af%e5%9b%be%e7%89%87%e5%9f%ba%e4%ba%8e%e5%90%8e%e7%ab%af%e6%a1%86%e6%9e%b6%e7%9a%84%e5%9b%be%e7%89%87%e4%b8%8a%e4%bc%a0%e8%af%bb%e5%8f%96%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u79fb\u52a8\u7aef\u56fe\u7247\u57fa\u4e8e\u540e\u7aef\u6846\u67b6\u7684\u56fe\u7247\u4e0a\u4f20\u8bfb\u53d6\u529f\u80fd"},"content":{"rendered":"<blockquote><p>\n  \u6d4f\u89c8\u4e86\u5927\u90e8\u5206\u535a\u5ba2\uff0c\u4f3c\u4e4e\u5bf9\u4e8e <code>Android \u539f\u751f<\/code> + <code>Kotlin<\/code> \u6784\u9020\u7684\u79fb\u52a8\u7aef\uff0c\u5982\u4f55\u8fdb\u884c\u4e0e\u540e\u7aef\u4ea4\u4e92\u56fe\u7247\u4fe1\u606f\uff0c\u5c11\u4e14\u6b20\u7f3a\uff0c\u901a\u8fc7 Ai \u7684\u8f85\u52a9\u548c\u7f8e\u5316\uff0c\u6a21\u62df\u4e86\u4e00\u79cd\u53ef\u80fd\u662f\u5e38\u89c1\u7684\u7528\u6237\u4e2a\u4eba\u4fe1\u606f\u7684\u540e\u7aef\u64cd\u4f5c\uff0c\u4e00\u79cd\u4f2a\u7528\u6237\u4e2a\u4eba\u4fe1\u606f\u805a\u5408\u6570\u636e<\/p>\n<p>  \u5176\u5b9e\u8fd9\u4e2a\u529f\u80fd\u5012\u662f\u4e00\u4e2a\u6708\u6216\u8005\u4e00\u4e2a\u534a\u6708\u524d\u5b9e\u73b0\u7684\uff0c\u53ea\u662f\u4e00\u76f4\u61d2\u5f97\u5199<br \/>\n  \u5c31\u548c\u6211\u73b0\u5728\u7684\u535a\u5ba2 \u4e0a\u4e00\u6b21\u66f4\u65b0\u662f 2023 \u5e74\u4e00\u6837\uff0c<font color='LightSkyBlue'>\u6175\u61d2<\/font><br \/>\n  \u4ec5\u4ec5\u662f\u73b0\u5728\u4ee3\u7801\u6572\u7d2f\u4e86\uff0c\u60f3\u5fd9\u70b9\u522b\u7684\n<\/p><\/blockquote>\n<h1>\u540e\u7aef<\/h1>\n<blockquote><p>\n  \u91c7\u7528 <code>SpringBoot<\/code>\uff0c\u65e0\u8111\u642d\u5efa\u4e00\u4e2a Api \u4f9b\u7ed9\u79fb\u52a8\u7aef\u4f7f\u7528\n<\/p><\/blockquote>\n<h2>\u57fa\u7840\u6846\u67b6<\/h2>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_c8c8529c017f4d0c8e46ef9302c6c99c.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_c8c8529c017f4d0c8e46ef9302c6c99c.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_c8c8529c017f4d0c8e46ef9302c6c99c.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n<p>\u771f\u7684\u5c31\u662f\u5f88\u57fa\u7840<\/p>\n<h2>\u5b9e\u73b0\u903b\u8f91<\/h2>\n<blockquote><p>\n  \u672c\u6765\u6211\u8bbe\u60f3\u7684\u662f\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u8868\u8fdb\u884c\u64cd\u4f5c\uff0c\u7528<code>\u5b57\u8282\u6d41<\/code>\u7684\u65b9\u5f0f<br \/>\n  \u540e\u6765 Ai \u7684\u903b\u8f91\u662f\uff0c\u5bf9\u6bcf\u4e00\u4e2a\u7528\u6237\u65b0\u5efa\u4e2a\u4eba\u7528\u6237\u4fe1\u606f\u6587\u4ef6\u5939\uff0c\u7136\u540e\u6211\u5bf9\u5176\u8fdb\u884c\u7684\u903b\u8f91\u4f18\u5316\uff0c\u540e\u7aef\u7684\u6587\u4ef6\u683c\u5f0f\u90fd\u662f\u7edf\u4e00\u7684\uff0c\u4fbf\u4e8e Up Down \u548c\u7ba1\u7406\n<\/p><\/blockquote>\n<h3>\u7528\u6237\u5b9e\u4f53<\/h3>\n<pre><code class=\"language-Java line-numbers\">@TableName(value =\"user\")\n@Data\npublic class User {\n\n    @TableId(type = IdType.AUTO)\n    private Integer userid;\n    private String userphonenumber;\n    private String username;\n    private String userpassword;\n    private Integer signindays;\n    private String state;\n    \/\/  \u7701\u7565\u591a\u4f59\u4ee3\u7801\n    }\n\n<\/code><\/pre>\n<p>\u91c7\u7528\u7684\u662f <code>MybatisX<\/code> \u6846\u67b6\u8fdb\u884c\u81ea\u4e3b\u751f\u6210\u7684\u5b9e\u4f53\u5bf9\u8c61<br \/>\n\u5173\u952e\u552f\u4e00\u503c\u5b57\u6bb5\u662f <code>userphonenumber<\/code><\/p>\n<h3>\u6ce8\u518c\u903b\u8f91<\/h3>\n<pre><code class=\"language-Java line-numbers\">@PostMapping(\"\/register\")\n    String register(String userphone , String username , String password){\n        User user = userService.selectByUserphonenumber(userphone);\n        if(user == null){\n            int r = userService.insertUser(userphone,username,password);\n            System.out.println(r);\n            if (r > 0) {\n                \/\/ \u6ce8\u518c\u6210\u529f\u540e\u521b\u5efay\u7528\u6237\u6587\u4ef6\u5939\n                File userFolder = new File(UserDir, userphone);\n                if (!userFolder.exists()) {\n                    boolean isCreated = userFolder.mkdirs();\n                    if (isCreated) {\n                        System.out.println(\"Folder created for \" + username);\n                    } else {\n                        System.out.println(\"Failed to create folder for \" + username);\n                    }\n                }\n            }\n            return \"OK\" ;\n        }\n        return \"No\";\n    }\n<\/code><\/pre>\n<p>\u6ce8\u518c\u5b8c\u6210\u540e\uff0c\u6839\u636e\u552f\u4e00\u503c\u5b57\u6bb5\uff0c\u521b\u5efa\u5bf9\u5e94\u6587\u4ef6\u5939<br \/>\n\u4e0d\u8fc7\u4e2a\u4eba\u9879\u76ee\u6ca1\u6709\u4efb\u4f55\u5bc6\u7801\u6216\u8005\u662f\u4fe1\u606f\u4e0a\u7684\u52a0\u5bc6\uff0c\u5176\u5b9e\u5e38\u89c1\u5e94\u8be5\u662f\u628a\u4e2a\u4eba\u4fe1\u606f\u6570\u636e\u8fdb\u884c <code>MD5<\/code> \u52a0\u5bc6\u540e\u4e22\u8fdb <code>Sql<\/code>\uff0c\u53c8\u6216\u8005\u91c7\u7528\u522b\u7684\u65b9\u6cd5<\/p>\n<p>\u8fd9\u662f\u6211\u521b\u5efa\u7684\u4e2a\u4eba\u4fe1\u606f\u6587\u4ef6\u5939<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_296896c956849cd330d7f86ea8a333b2.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_296896c956849cd330d7f86ea8a333b2.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_296896c956849cd330d7f86ea8a333b2.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><br \/>\n\u91cc\u9762\u7684\u5934\u50cf\u9ed8\u8ba4\u91cd\u547d\u540d\u4e3a <code>headshot<\/code><br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_ae9fae976f7f3eeb06f2e916b74c6745.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_ae9fae976f7f3eeb06f2e916b74c6745.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_ae9fae976f7f3eeb06f2e916b74c6745.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><br \/>\n\u540c\u7406 \u4e2a\u4eba\u80cc\u666f\u56fe\u7684\u8bbe\u8ba1\u903b\u8f91\u5e94\u8be5\u4e5f\u662f\u53ef\u4ee5\u8fd9\u4e48\u5904\u7406<br \/>\n\u8fd9\u8fb9\u662f\u5fae\u4fe1\u7684\u903b\u8f91<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_6c44a3fb2dfec4aa48e012e5398ff186.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_6c44a3fb2dfec4aa48e012e5398ff186.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_6c44a3fb2dfec4aa48e012e5398ff186.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n<h3>\u4e0a\u4f20\u8bfb\u53d6\u903b\u8f91<\/h3>\n<p><code>Controller<\/code> \u7c7b\u4e0b\u7684 <code>\u9759\u6001\u5e38\u91cf<\/code><\/p>\n<pre><code class=\"language-Java line-numbers\">\/\/ \u56fe\u7247\u4e0a\u4f20\u8def\u5f84  \u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u7684uploads  \nprivate static final String UserDir = System.getProperty(\"user.dir\") + \"\/userInfo\";  \n\/\/ \u6269\u5c55\u540d\u767d\u540d\u5355  \nprivate static final List<String> ALLOWED_FILE_TYPES = Arrays.asList(\"image\/jpeg\", \"image\/png\");\n<\/code><\/pre>\n<h4>\u4e0a\u4f20\u903b\u8f91<\/h4>\n<pre><code class=\"language-Java line-numbers\">\/\/ MultipartFile \u6587\u4ef6\u7c7b\u578b\u5bf9\u8c61\n    @PostMapping(\"\/uploadHeadshot\")\n    public String uploadHeadshot(@RequestParam(\"image\") MultipartFile image ,@RequestParam(\"userPhoneNumber\") String userPhoneNumber) {\n        System.out.println(\"upload in\");\n        \/\/ \u68c0\u67e5\u6587\u4ef6\u662f\u5426\u4e3a\u7a7a\n        if (image.isEmpty()) {\n            return \"File Is Empty\";\n        }\n\n        \/\/ \u68c0\u67e5\u6587\u4ef6\u7c7b\u578b\n        String contentType = image.getContentType();\n        if (!ALLOWED_FILE_TYPES.contains(contentType)) {\n            return \"File Type Is Error\";\n        }\n\n        \/\/ \u83b7\u53d6\u6587\u4ef6\u7684\u6269\u5c55\u540d\n        String extension = \"\";\n        String originalFilename = image.getOriginalFilename();\n        int i = originalFilename.lastIndexOf('.');\n        if (i > 0) {\n            extension = originalFilename.substring(i);\n        }\n\n        try {\n            \/\/ \u6784\u5efa\u6587\u4ef6\u5b58\u50a8\u8def\u5f84\uff0c\u5e76\u4f7f\u7528\u65b0\u7684\u6587\u4ef6\u540d\"headshot\"\n            Path destinationDir = Paths.get(UserDir, userPhoneNumber).toAbsolutePath().normalize();\n            Path destinationFile = destinationDir.resolve(\"headshot\" + extension);\n\n            \/\/ \u786e\u4fdd\u76ee\u5f55\u5b58\u5728\n            if (!destinationDir.toFile().exists()) {\n                destinationDir.toFile().mkdirs();\n            }\n\n            \/\/ \u5220\u9664\u65e7\u7684\u5934\u50cf\u6587\u4ef6\n            Files.walk(destinationDir)\n                    .filter(path -> path.getFileName().toString().startsWith(\"headshot\"))\n                    .forEach(path -> {\n                        try {\n                            Files.deleteIfExists(path);\n                            System.out.println(\"Replace Succeed\");\n                        } catch (IOException ex) {\n                            \/\/ \u5904\u7406\u5220\u9664\u6587\u4ef6\u65f6\u53ef\u80fd\u53d1\u751f\u7684\u5f02\u5e38\n                            ex.printStackTrace();\n                        }\n                    });\n\n            \/\/ \u4fdd\u5b58\u6587\u4ef6\n            image.transferTo(destinationFile);\n            System.out.println(\"File Upload Succeed\");\n            return \"File Upload Succeed\";\n        } catch (IOException e) {\n            e.printStackTrace();\n            System.out.println(\"File Upload Failed\");\n            return \"File Upload Failed\uff1a\" + e.getMessage();\n        }\n    }\n<\/code><\/pre>\n<p>\u8fd9\u90e8\u5206 Ai \u7684\u624b\u7b14\u6bd4\u8f83\u5927<br \/>\n\u5177\u4f53\u903b\u8f91\u5c31\u662f<br \/>\n- \u5b58\u5728\u7528\u6237\u4fe1\u606f\u6839\u76ee\u5f55<br \/>\n- <font color='lime'>\u524d\u7aef\u76f4\u63a5\u4f20\u9012\u6587\u4ef6\u5b57\u8282\u6d41<\/font><br \/>\n- \u5148\u5f02\u5e38\u6355\u83b7<br \/>\n    - \u7a7a\u5224\u5b9a<br \/>\n    - \u7c7b\u578b\u5224\u5b9a<br \/>\n    - \u5176\u5b9e\u8fd9\u91cc\u6700\u597d\uff0c\u4e0d\u8bba\u524d\u7aef\u8fd8\u662f\u540e\u7aef\uff0c\u8fdb\u884c\u4e00\u4e0b <code>\u6728\u9a6c\u6ce8\u5165<\/code> \u5224\u5b9a\uff0c\u8fd9\u91cc\u6211\u6ca1\u5199\uff0c\u5426\u5219\u5e38\u89c1\u53ef\u80fd\u4f1a\u9020\u6210 <code>\u6587\u4ef6\u5305\u542b<\/code> <code>\u6587\u4ef6\u4e0a\u4f20<\/code> \uff0c\u4f1a\u88ab <font color='red'>\u4e0a\u7ebf\u8fdc\u63a7<\/font><br \/>\n- \u5982\u679c\u5b58\u5728\u5934\u50cf\uff0c\u66ff\u6362<br \/>\n- \u5b58\u50a8\u6210\u529f<\/p>\n<h4>\u8bfb\u53d6\u903b\u8f91<\/h4>\n<pre><code class=\"language-Java line-numbers\">@GetMapping(\"\/getHeadshot\/{userPhoneNumber}\")  \npublic ResponseEntity<Resource> getHeadshotImage(@PathVariable String userPhoneNumber) {  \n    try {  \n        \/\/ \u6784\u5efa\u56fe\u7247\u6587\u4ef6\u7684\u57fa\u672c\u8def\u5f84  \n        Path userDirPath = Paths.get(UserDir, userPhoneNumber);  \n\n        \/\/ \u5728\u76ee\u5f55\u4e2d\u67e5\u627e\u540d\u4e3a\"headshot\"\u7684\u6587\u4ef6  \n        Path headshotPath = Files.list(userDirPath)  \n                .filter(path -> path.getFileName().toString().startsWith(\"headshot\"))  \n                .findFirst()  \n                .orElse(null);  \n\n        \/\/ \u5982\u679c\u627e\u5230\u4e86\u6587\u4ef6\uff0c\u5219\u8fd4\u56de\u5b83  \n        if (headshotPath != null && Files.exists(headshotPath)) {  \n            Resource resource = new UrlResource(headshotPath.toUri());  \n            String contentType = Files.probeContentType(headshotPath);  \n            return ResponseEntity.ok()  \n                    .contentType(MediaType.parseMediaType(contentType))  \n                    .header(HttpHeaders.CONTENT_DISPOSITION, \"inline; filename=\\\"\" + headshotPath.getFileName() + \"\\\"\")  \n                    .body(resource);  \n        } else {  \n            \/\/ \u6587\u4ef6\u4e0d\u5b58\u5728  \n            return ResponseEntity.notFound().build();  \n        }  \n    } catch (IOException e) {  \n        e.printStackTrace();  \n        return ResponseEntity.badRequest().build();  \n    }  \n}\n<\/code><\/pre>\n<p>\u540c\u6837\uff0cAi \u6da6\u8272\u75d5\u8ff9\u5f88\u91cd<br \/>\n\u524d\u7aef\u91c7\u7528 <code>Path<\/code> \u4f20\u9012 <code>userPhoneNumber<\/code> \u7ed9 Api \uff0c\u7136\u540e\u8bfb\u53d6\u4fe1\u606f<\/p>\n<h2>\u6d4b\u8bd5\u529f\u80fd<\/h2>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_32c279c493cae197586a9a228b7722df.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_32c279c493cae197586a9a228b7722df.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_32c279c493cae197586a9a228b7722df.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n<p>\u975e\u5e38\u7684 nice \u554a\uff01<br \/>\n\u5c0f\u7965\u53ef\u7231\u634f QwQ<\/p>\n<h1>\u79fb\u52a8\u7aef<\/h1>\n<blockquote><p>\n  \u79fb\u52a8\u7aef\u91c7\u7528\u7684\u662f Android \u539f\u751f\u5f00\u53d1\n<\/p><\/blockquote>\n<h2>\u754c\u9762\u5b9e\u73b0<\/h2>\n<h3>HomeView<\/h3>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_3e47d78774464dc5f44b588177dd3ae4.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_3e47d78774464dc5f44b588177dd3ae4.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_3e47d78774464dc5f44b588177dd3ae4.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><br \/>\n\u91c7\u7528 <code>CircleImageView<\/code> \u751f\u6210\u9002\u914d\u7684\u5706\u5f62\u5934\u50cf\u754c\u9762<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_d5f36441a2db91f294e0496c005021d0.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_d5f36441a2db91f294e0496c005021d0.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_d5f36441a2db91f294e0496c005021d0.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_bdfc06d5d3bb0f57264cd03765561b34.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_bdfc06d5d3bb0f57264cd03765561b34.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_bdfc06d5d3bb0f57264cd03765561b34.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><br \/>\n\u6dfb\u52a0\u4e24\u4e2a\u63d0\u793a\u5bf9\u8bdd\u6846<\/p>\n<h3>UserSettingView<\/h3>\n<blockquote><p>\n  \u8fd9\u8fb9\u81ea\u5b9a\u4e49\u4e00\u4e2a <code>\u62bd\u5c49\u5c42<\/code> \uff0c\u6a21\u62df\u4e24\u79cd\u56fe\u7247\u83b7\u53d6\u65b9\u5f0f<br \/>\n  - \u6587\u4ef6<br \/>\n  - \u76f8\u673a<br \/>\n  <div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/4e220f72c169020d416f4a35e0bd032-486x1080.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/4e220f72c169020d416f4a35e0bd032-486x1080.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u62bd\u5c49\u5c42\u56fe\u7247png\" \/><\/div>\n<\/p><\/blockquote>\n<p>\u901a\u8fc7 <code>BottomSheetDialogFragment<\/code> \u5bf9\u8bdd\u6846\uff0c\u8c03\u7528\u56de\u8c03\u51fd\u6570\uff0c\u5b9e\u73b0\u4e0a\u4f20<\/p>\n<h2>\u5b9e\u73b0\u903b\u8f91<\/h2>\n<h3>\u56fe\u7247\u52a0\u8f7d<\/h3>\n<blockquote><p>\n  \u56fe\u7247\u52a0\u8f7d\u91c7\u7528\u4e86 <code>Glide<\/code> \u8fdb\u884c\u8bfb\u53d6 \uff0c \u76f4\u63a5\u901a\u8fc7 <font color='lime'>\u7f51\u7edc\u65b9\u5f0f<\/font> \u8bbf\u95ee\u56fe\u7247\n<\/p><\/blockquote>\n<pre><code class=\"language-Kotlin line-numbers\">    fun loadUserHeadshot(userPhone: String, headshot: ImageView): RequestBuilder<Drawable> {\n        return Glide.with(MoApplication.context)\n            .load(Repository.BASE_URL + \"\/user\/getHeadshot\/\" + userPhone)\n            .apply(RequestOptions().diskCacheStrategy(DiskCacheStrategy.NONE))\n            .apply(RequestOptions().error(R.drawable.headshot))\n            .apply(RequestOptions().dontTransform()) \/\/ \u9632\u6b62\u9519\u8bef\u65e5\u5fd7\u8f93\u51fa\n    }\n<\/code><\/pre>\n<p>\u8fd9\u8fb9\u8fdb\u884c\u4e86 <font color='LightSkyBlue'>\u4e8c\u6b21\u5c01\u88c5<\/font><br \/>\n\u4f20\u5165 <code>\u63a7\u4ef6\u5bf9\u8c61<\/code> \u548c <code>\u7528\u6237\u552f\u4e00\u6807\u8bc6\u503c<\/code><br \/>\n\u82e5\u672a\u52a0\u8f7d\u5230\u56fe\u7247 \uff0c \u52a0\u8f7d\u9ed8\u8ba4\u7684<br \/>\n\u7531\u4e8e\u591a\u4e2a\u5730\u65b9\u9700\u8981\u7528\u5230 <code>\u5934\u50cf\u52a0\u8f7d<\/code> \u903b\u8f91<br \/>\n\u6240\u4ee5\u8fdb\u884c\u5c01\u88c5<br \/>\n\u8c03\u7528\u5982\u4e0b<\/p>\n<pre><code class=\"language-Kotlin line-numbers\">Repository.loadUserHeadshot(user.phoneNumber, headshot).into(headshot)\n<\/code><\/pre>\n<h4>Path \u8bbf\u95ee \u540e\u7aef Api<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">    @GET(\"\/user\/getHeadshot\/{userPhoneNumber}\")\n    fun getUserHeadshot(@Path(\"userPhoneNumber\") userPhoneNumber:String):Call<ResponseBody>\n<\/code><\/pre>\n<h3>\u56fe\u7247\u4e0a\u4f20<\/h3>\n<h4><font color='red'>\u8c03\u7528\u56de\u8c03\u51fd\u6570  \u6587\u4ef6\u9009\u62e9\u6216\u8005\u542f\u52a8\u76f8\u673a<\/font><\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {  \n    super.onRequestPermissionsResult(requestCode, permissions, grantResults)  \n    when (requestCode) {  \n        REQUEST_CODE_PERMISSIONS_CAMERA -> {  \n            if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {  \n                if (hasStoragePermissions()) {  \n                    showChooseImageDialog()  \n                }  \n            } else {   \n                if (!shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {  \n\n                    showPermissionSettingsDialog(\"\u76f8\u673a\")  \n                } else {  \n\n\n\n                    Toast.makeText(this, \"\u76f8\u673a\u6743\u9650\u672a\u6388\u6743\", Toast.LENGTH_SHORT).show()  \n                }  \n            }  \n        }  \n        REQUEST_CODE_PERMISSIONS_STORAGE -> {  \n            if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {  \n                if (hasCameraPermissions()) {  \n                    showChooseImageDialog()  \n                }  \n            } else {  \n\n                if (!shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)) {  \n\n                    showPermissionSettingsDialog(\"\u6587\u4ef6\")  \n                } else {  \n\n                    Toast.makeText(this, \"\u6587\u4ef6\u6743\u9650\u672a\u6388\u6743\", Toast.LENGTH_SHORT).show()  \n                }  \n            }  \n        }  \n    }  \n}\n<\/code><\/pre>\n<h4>\u672a\u6388\u6743\u5904\u7406<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">private fun showPermissionSettingsDialog(mode:String) {  \n\n    AlertDialog.Builder(this)  \n        .setMessage(\"\u6b64\u5e94\u7528\u9700\u8981 $mode \u6743\u9650\u624d\u80fd\u6b63\u5e38\u5de5\u4f5c\u3002\u8bf7\u524d\u5f80\u8bbe\u7f6e\u4ee5\u6388\u6743\u6b64\u6743\u9650\u3002\")  \n        .setPositiveButton(\"\u53bb\u8bbe\u7f6e\") { _, _ ->  \n            \/\/ \u5bfc\u822a\u5230\u8bbe\u7f6e\u9875\u9762  \n            val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)  \n            val uri = Uri.fromParts(\"package\", packageName, null)  \n            intent.data = uri  \n            startActivity(intent)  \n        }  \n        .setNegativeButton(\"\u53d6\u6d88\", null)  \n        .create()  \n        .show()  \n}\n<\/code><\/pre>\n<h4><font color='red'>\u4e0a\u4f20\u56fe\u7247\u5b57\u8282\u6d41<\/font><\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">suspend fun uploadHeadshot(image: Bitmap, userphone: String): ResponseBody {  \n\n    val byteArrayOutputStream = ByteArrayOutputStream()  \n    image.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)  \n    val imageBytes = byteArrayOutputStream.toByteArray() \n    val imagePart = MultipartBody.Part.createFormData(\"image\", \"headshot.png\", imageRequestBody)  \n    return UserService.uploadHeadshot(imagePart, userPhoneNumberRequestBody).await()  \n}\n<\/code><\/pre>\n<h4>Post \u8bbf\u95ee \u540e\u7aef Api<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">@Multipart  \n@POST(\"\/user\/uploadHeadshot\")  \nfun uploadHeadshot(  \n    @Part image: MultipartBody.Part,  \n    @Part(\"userPhoneNumber\") userPhoneNumber: RequestBody  \n): Call<ResponseBody>\n<\/code><\/pre>\n<h2>\u6d4b\u8bd5\u529f\u80fd<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/01a25a40954a889cbf476a4167bcc31-1-486x1080.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/01a25a40954a889cbf476a4167bcc31-1-486x1080.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u9e21\u54e5\" \/><\/div><br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_072a513b5a08791c7dd85cd187342a96.jpg\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_072a513b5a08791c7dd85cd187342a96.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/danranrie.cn\/wp-content\/uploads\/2025\/03\/wp_editor_md_072a513b5a08791c7dd85cd187342a96.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n<h1>\u9898\u5916\u8bdd<\/h1>\n<blockquote><p>\n  \u5199\u7684\u65f6\u5019\uff0c\u79fb\u52a8\u7aef\u7684\u7f51\u7edc\u6a21\u5757\u70b8\u4e86\uff0c\u4e0d\u6e05\u695a\u662f\u4e3a\u4ec0\u4e48\uff0c\u6362\u624b\u673a\u70ed\u70b9\uff0c\u6362\u4e2aip\uff0c\u53c8\u51fa\u73b0\u4e86\u8d85\u65f6\u9519\u8bef<br \/>\n  \u7b2c\u4e8c\u5929\u4e0b\u5348\u4e09\u70b9\u4e86\uff0c\u4f9d\u65e7\u6ca1\u5904\u7406\u6210\u529f<br \/>\n  \u4f46\u662f\u5207\u6362\u624b\u673a\u8c03\u8bd5\uff0c\u4efb\u4f55\u529f\u80fd\u5c31\u8d8b\u4e8e\u6b63\u5e38\u4e86\uff0c\u4e0d\u662f\u5f88\u7406\u89e3\uff0c\u4f46\u662f\u754c\u9762\u52a8\u753b\u8fd8\u662f\u5b58\u5728\u6389\u5e27\u5361\u987f\uff0c\u53ef\u80fd\u662f\u91c7\u7528 View \u751f\u6210\u7684\u539f\u56e0\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u5353\u5f00\u53d1\u5b9e\u73b0\u7684\uff0c\u7528\u6237\u4e0a\u4f20\u5934\u50cf\u548c\u4e2a\u4eba\u7a7a\u95f4\u56fe\u7684\u529f\u80fd<\/p>\n","protected":false},"author":1,"featured_media":257,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,26,28,27],"tags":[31,30],"class_list":["post-255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-29","category-26","category-28","category-27","tag-31","tag-30"],"_links":{"self":[{"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/comments?post=255"}],"version-history":[{"count":0,"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/posts\/255\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/media\/257"}],"wp:attachment":[{"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/media?parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/categories?post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/danranrie.cn\/index.php\/wp-json\/wp\/v2\/tags?post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}