{"id":24116,"date":"2024-11-21T11:06:28","date_gmt":"2024-11-21T03:06:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24116\/"},"modified":"2024-11-21T11:06:28","modified_gmt":"2024-11-21T03:06:28","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8webman%e6%a1%86%e6%9e%b6%e5%ae%9e%e7%8e%b0%e5%9c%a8%e7%ba%bf%e9%a2%84%e8%ae%a2%e5%92%8c%e6%94%af%e4%bb%98%e5%8a%9f%e8%83%bd%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24116\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u5728\u7ebf\u9884\u8ba2\u548c\u652f\u4ed8\u529f\u80fd\uff1f"},"content":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528webman\u6846\u67b6\u5b9e\u73b0\u5728\u7ebf\u9884\u8ba2\u548c\u652f\u4ed8\u529f\u80fd\uff1f<\/p>\n<p>\u5f15\u8a00\uff1a<br \/>Webman\u662f\u4e00\u4e2a\u57fa\u4e8eJava\u7684\u5feb\u901f\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u5957\u5f00\u53d1\u5de5\u5177\u548c\u4fbf\u6377\u7684API\uff0c\u4f7f\u5f97\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u548c\u9ad8\u6548\u3002\u672c\u6587\u5c06\u4ee5\u5728\u7ebf\u9884\u8ba2\u548c\u652f\u4ed8\u529f\u80fd\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u642d\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u9884\u8ba2\u7cfb\u7edf\uff0c\u5e76\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\u3002<\/p>\n<ol>\n<li>\u51c6\u5907\u5de5\u4f5c<br \/>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u597d\u4e86Java JDK\u548cMaven\u3002\u7136\u540e\uff0c\u5728Maven\u7684pom.xml\u6587\u4ef6\u4e2d\u6dfb\u52a0Webman\u7684\u4f9d\u8d56\u9879\uff1a<\/li>\n<\/ol>\n<pre>&lt;dependency&gt;&lt;groupid&gt;org.webmanframework&lt;\/groupid&gt;&lt;artifactid&gt;webman-core&lt;\/artifactid&gt;&lt;version&gt;0.1.0&lt;\/version&gt;&lt;\/dependency&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u521b\u5efa\u9879\u76ee\u7ed3\u6784<br \/>\u5728\u547d\u4ee4\u884c\u6216IDE\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2aMaven\u9879\u76ee\uff0c\u5e76\u6309\u7167\u4ee5\u4e0b\u7ed3\u6784\u7ec4\u7ec7\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>src\n\u2514\u2500main\n    \u251c\u2500java\n    \u2502  \u2514\u2500com\n    \u2502      \u2514\u2500example\n    \u2502          \u2514\u2500booking\n    \u2502              \u251c\u2500controller\n    \u2502              \u2502  \u2514\u2500BookingController.java\n    \u2502              \u251c\u2500model\n    \u2502              \u2502  \u2514\u2500Booking.java\n    \u2502              \u2514\u2500service\n    \u2502                  \u2514\u2500BookingService.java\n    \u2514\u2500resources\n        \u2514\u2500application.properties<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u7f16\u5199\u4ee3\u7801<br \/>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u9884\u8ba2\u6570\u636e\u6a21\u578b\uff0c\u521b\u5efaBooking.java\u6587\u4ef6\uff1a<\/li>\n<\/ol>\n<pre>package com.example.booking.model;\n\npublic class Booking {\n  private String id;\n  private String name;\n  private String date;\n  private double amount;\n  \n  \/\/ getter and setter methods\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u9884\u8ba2\u670d\u52a1\u7c7b\uff0c\u7528\u4e8e\u5904\u7406\u9884\u8ba2\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u521b\u5efaBookingService.java\u6587\u4ef6\uff1a<\/p>\n<pre>package com.example.booking.service;\n\nimport com.example.booking.model.Booking;\n\npublic class BookingService {\n  public void createBooking(Booking booking) {\n    \/\/ \u5904\u7406\u9884\u8ba2\u903b\u8f91\n  }\n  \n  public Booking getBookingById(String id) {\n    \/\/ \u6839\u636eID\u83b7\u53d6\u9884\u8ba2\u4fe1\u606f\n    return null;\n  }\n  \n  \/\/ \u5176\u4ed6\u4e1a\u52a1\u65b9\u6cd5\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u9884\u8ba2\u63a7\u5236\u5668\u7c7b\uff0c\u7528\u4e8e\u5904\u7406\u6765\u81eaWeb\u9875\u9762\u7684\u8bf7\u6c42\u548c\u54cd\u5e94\uff0c\u521b\u5efaBookingController.java\u6587\u4ef6\uff1a<\/p>\n<pre>package com.example.booking.controller;\n\nimport com.example.booking.model.Booking;\nimport com.example.booking.service.BookingService;\n\nimport org.webmanframework.annotation.Controller;\nimport org.webmanframework.annotation.Post;\nimport org.webmanframework.annotation.RequestBody;\nimport org.webmanframework.annotation.RequestMapping;\nimport org.webmanframework.annotation.RequestParam;\nimport org.webmanframework.http.HttpResponse;\n\n@Controller\npublic class BookingController {\n  private BookingService bookingService; \/\/ \u9884\u8ba2\u670d\u52a1\u7c7b\u7684\u5b9e\u4f8b\n  \n  @RequestMapping(\"\/booking\/create\")\n  @Post\n  public HttpResponse createBooking(@RequestBody Booking booking) {\n    bookingService.createBooking(booking); \/\/ \u8c03\u7528\u9884\u8ba2\u670d\u52a1\u7c7b\u7684\u521b\u5efa\u65b9\u6cd5\n    return HttpResponse.ok();\n  }\n  \n  @RequestMapping(\"\/booking\/get\")\n  public HttpResponse getBookingById(@RequestParam(\"id\") String id) {\n    Booking booking = bookingService.getBookingById(id); \/\/ \u8c03\u7528\u9884\u8ba2\u670d\u52a1\u7c7b\u7684\u67e5\u8be2\u65b9\u6cd5\n    return HttpResponse.ok(booking);\n  }\n  \n  \/\/ \u5176\u4ed6\u5904\u7406\u65b9\u6cd5\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6700\u540e\uff0c\u5728application.properties\u6587\u4ef6\u4e2d\u914d\u7f6eWebman\u7684\u57fa\u672c\u5c5e\u6027\uff1a<\/p>\n<pre>webman.server.port=8080\nwebman.controller.scanPackage=com.example.booking.controller<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f<br \/>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u5207\u6362\u5230\u9879\u76ee\u6839\u76ee\u5f55\uff0c\u5e76\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8Webman\u670d\u52a1\u5668\uff1a<\/li>\n<\/ol>\n<pre>mvn clean package\njava -jar target\/booking-1.0.0.jar<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95eehttp:\/\/localhost:8080\/booking\/get?id=1\u6765\u83b7\u53d6ID\u4e3a1\u7684\u9884\u8ba2\u4fe1\u606f\u3002<\/p>\n<ol>\n<li>\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd<br \/>\u4e3a\u4e86\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u652f\u4ed8\u63a5\u53e3\u548c\u76f8\u5173\u7684\u5e93\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4e3e\u4f8b\u8bf4\u660e\u5982\u4f55\u4f7f\u7528Alipay SDK\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\u3002<\/li>\n<\/ol>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728pom.xml\u6587\u4ef6\u4e2d\u6dfb\u52a0Alipay SDK\u7684\u4f9d\u8d56\uff1a<\/p>\n<pre>&lt;dependency&gt;&lt;groupid&gt;com.alipay.sdk&lt;\/groupid&gt;&lt;artifactid&gt;alipay-sdk-java&lt;\/artifactid&gt;&lt;version&gt;3.4.49.ALL&lt;\/version&gt;&lt;\/dependency&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7136\u540e\uff0c\u5728BookingController.java\u6587\u4ef6\u4e2d\u6dfb\u52a0\u652f\u4ed8\u5904\u7406\u65b9\u6cd5\uff1a<\/p>\n<pre>import com.alipay.api.AlipayApiException;\nimport com.alipay.api.AlipayClient;\nimport com.alipay.api.DefaultAlipayClient;\nimport com.alipay.api.request.AlipayTradePagePayRequest;\nimport com.alipay.api.response.AlipayTradePagePayResponse;\n\n@Controller\npublic class BookingController {\n  \/\/ ...\n\n  @RequestMapping(\"\/booking\/pay\")\n  public HttpResponse pay(@RequestParam(\"orderId\") String orderId, \n                          @RequestParam(\"totalAmount\") String totalAmount) {\n    String alipayAppId = \"YOUR_APP_ID\";\n    String alipayPrivateKey = \"YOUR_PRIVATE_KEY\";\n    String alipayPublicKey = \"YOUR_PUBLIC_KEY\";\n    String alipayGateway = \"https:\/\/openapi.alipay.com\/gateway.do\";\n    String returnUrl = \"http:\/\/localhost:8080\/booking\/pay\/callback\";\n    \n    AlipayClient alipayClient = new DefaultAlipayClient(alipayGateway, alipayAppId, alipayPrivateKey, \"json\", \"UTF-8\", alipayPublicKey, \"RSA2\");\n    AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();\n    alipayRequest.setReturnUrl(returnUrl);\n    alipayRequest.setNotifyUrl(returnUrl);\n    alipayRequest.setBizContent(\"{\"out_trade_no\":\"\" + orderId + \"\",\"total_amount\":\"\" + totalAmount + \"\",\"subject\":\"\" + orderId + \"\",\"body\":\"\" + orderId + \"\",\"timeout_express\":\"5m\",\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}\");\n    \n    try {\n      AlipayTradePagePayResponse alipayResponse = alipayClient.pageExecute(alipayRequest);\n      \/\/ \u4e0b\u5355\u6210\u529f\uff0c\u8fd4\u56de\u652f\u4ed8URL\n      return HttpResponse.ok(alipayResponse.getBody());\n    } catch (AlipayApiException e) {\n      e.printStackTrace();\n      \/\/ \u4e0b\u5355\u5931\u8d25\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\n      return HttpResponse.error(500, \"\u652f\u4ed8\u5931\u8d25\");\n    }\n  }\n  \n  @RequestMapping(\"\/booking\/pay\/callback\")\n  public HttpResponse payCallback(@RequestParam(\"\") String param) {\n    \/\/ \u5904\u7406\u652f\u4ed8\u56de\u8c03\u903b\u8f91\n    return HttpResponse.ok();\n  }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u9996\u5148\u9700\u8981\u8bbe\u7f6e\u652f\u4ed8\u76f8\u5173\u7684\u914d\u7f6e\uff0c\u5305\u62ecAlipay\u7684App ID\u3001\u79c1\u94a5\u548c\u516c\u94a5\u7b49\u4fe1\u606f\u3002\u7136\u540e\uff0c\u521b\u5efaAlipayClient\u5b9e\u4f8b\uff0c\u5e76\u6784\u5efa\u4e00\u4e2a\u652f\u4ed8\u8bf7\u6c42\u5bf9\u8c61\uff0c\u8bbe\u7f6e\u51fa\u53c2\u548c\u56de\u8c03\u5730\u5740\u3002\u6700\u540e\uff0c\u4f7f\u7528AlipayClient\u5bf9\u8c61\u6267\u884c\u652f\u4ed8\u8bf7\u6c42\uff0c\u83b7\u53d6\u8fd4\u56de\u7ed3\u679c\u5e76\u5904\u7406\u3002<\/p>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u5728\u7ebf\u9884\u8ba2\u548c\u652f\u4ed8\u529f\u80fd\u7684\u5f00\u53d1\u3002<\/p>\n<p>\u7ed3\u8bba\uff1a<br \/>Webman\u6846\u67b6\u63d0\u4f9b\u4e86\u4e00\u5957\u7b80\u6d01\u6613\u7528\u7684API\u548c\u5de5\u5177\uff0c\u4f7f\u5f97\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u53d8\u5f97\u66f4\u52a0\u9ad8\u6548\u3002\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u642d\u5efa\u4e00\u4e2a\u9884\u8ba2\u7cfb\u7edf\uff0c\u5e76\u5b9e\u73b0\u4e86\u652f\u4ed8\u529f\u80fd\u3002<\/p>\n<p>\u53c2\u8003\u8d44\u6599\uff1a<\/p>\n<ul>\n<li>Webman\u5b98\u65b9\u6587\u6863\uff1ahttps:\/\/webman.io\/<\/li>\n<li>Alipay SDK\u5b98\u65b9\u6587\u6863\uff1ahttps:\/\/github.com\/alipay\/alipay-sdk-java<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u5728\u7ebf\u9884\u8ba2\u548c\u652f\u4ed8\u529f\u80fd\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528webman\u6846\u67b6\u5b9e\u73b0\u5728\u7ebf\u9884\u8ba2\u548c\u652f\u4ed8\u529f\u80fd\uff1f \u5f15\u8a00\uff1aWebman\u662f\u4e00\u4e2a\u57fa\u4e8eJava\u7684\u5feb\u901f\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u5957\u5f00\u53d1\u5de5\u5177\u548c\u4fbf\u6377\u7684API\uff0c\u4f7f\u5f97\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u548c\u9ad8\u6548\u3002\u672c\u6587\u5c06\u4ee5\u5728\u7ebf\u9884\u8ba2\u548c\u652f\u4ed8\u529f\u80fd\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u642d\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u9884\u8ba2\u7cfb\u7edf\uff0c\u5e76\u5b9e\u73b0\u652f\u4ed8\u529f\u80fd\u3002 \u51c6\u5907\u5de5\u4f5c\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u597d\u4e86Java JDK\u548cMaven\u3002\u7136\u540e\uff0c\u5728Maven\u7684pom.xml\u6587\u4ef6\u4e2d\u6dfb\u52a0Webman\u7684\u4f9d\u8d56\u9879\uff1a &lt;dependency&gt;&lt;groupid&gt;org.webmanframework&lt;\/groupid&gt;&lt;artifactid&gt;webman-core&lt;\/artifactid&gt;&lt;version&gt;0.1.0&lt;\/version&gt;&lt;\/dependency&gt; \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa\u9879\u76ee\u7ed3\u6784\u5728\u547d\u4ee4\u884c\u6216IDE\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2aMaven\u9879\u76ee\uff0c\u5e76\u6309\u7167\u4ee5\u4e0b\u7ed3\u6784\u7ec4\u7ec7\u4ee3\u7801\uff1a src \u2514\u2500main \u251c\u2500java \u2502 \u2514\u2500com \u2502 \u2514\u2500example \u2502 \u2514\u2500booking \u2502 \u251c\u2500controller \u2502 \u2502 \u2514\u2500BookingController.java \u2502 \u251c\u2500model \u2502 \u2502 \u2514\u2500Booking.java \u2502 \u2514\u2500service \u2502 \u2514\u2500BookingService.java \u2514\u2500resources \u2514\u2500application.properties \u767b\u5f55\u540e\u590d\u5236 \u7f16\u5199\u4ee3\u7801\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u9884\u8ba2\u6570\u636e\u6a21\u578b\uff0c\u521b\u5efaBooking.java\u6587\u4ef6\uff1a package com.example.booking.model; public class Booking { private String id; private String name; private String date; private double amount; \/\/ getter and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-24116","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=24116"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24116\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}