Commit 60f5898c9af1467f0192de57fee3323b2827a7de

Authored by YunaiV
1 parent 44f357ce

增加 pay.html 前端,对接微信 JS SDK

yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/package-info.java
1 1 /**
2   - * member 包下,我们放会员业务.
3   - * 例如说:会员中心等等
  2 + * weixin 包下,我们放微信相关业务.
  3 + * 例如说:微信公众号、等等
  4 + * ps:微信支付,还是放在 pay 包下
4 5 *
5   - * 缩写:mbr
  6 + * 缩写:wx
6 7 */
7   -package cn.iocoder.yudao.userserver.modules.member;
8 8 \ No newline at end of file
  9 +package cn.iocoder.yudao.userserver.modules.member;
... ...
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/PayOrderController.java
... ... @@ -12,10 +12,7 @@ import io.swagger.annotations.Api;
12 12 import io.swagger.annotations.ApiOperation;
13 13 import lombok.extern.slf4j.Slf4j;
14 14 import org.springframework.validation.annotation.Validated;
15   -import org.springframework.web.bind.annotation.PostMapping;
16   -import org.springframework.web.bind.annotation.RequestBody;
17   -import org.springframework.web.bind.annotation.RequestMapping;
18   -import org.springframework.web.bind.annotation.RestController;
  15 +import org.springframework.web.bind.annotation.*;
19 16  
20 17 import javax.annotation.Resource;
21 18  
... ...
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/package-info.java deleted
1   -package cn.iocoder.yudao.userserver.modules.pay.controller;
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/weixin/controller/mp/WxMpController.http 0 → 100644
  1 +### 请求 /login 接口 => 成功
  2 +GET {{userServerUrl}}/wx/mp/get-jsapi-ticket
... ...
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/weixin/controller/mp/WxMpController.java 0 → 100644
  1 +package cn.iocoder.yudao.userserver.modules.weixin.controller.mp;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import io.swagger.annotations.Api;
  5 +import io.swagger.annotations.ApiOperation;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +import me.chanjar.weixin.common.bean.WxJsapiSignature;
  8 +import me.chanjar.weixin.common.error.WxErrorException;
  9 +import me.chanjar.weixin.mp.api.WxMpService;
  10 +import org.springframework.validation.annotation.Validated;
  11 +import org.springframework.web.bind.annotation.PostMapping;
  12 +import org.springframework.web.bind.annotation.RequestMapping;
  13 +import org.springframework.web.bind.annotation.RequestParam;
  14 +import org.springframework.web.bind.annotation.RestController;
  15 +
  16 +import javax.annotation.Resource;
  17 +
  18 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  19 +
  20 +@Api(tags = "微信公众号")
  21 +@RestController
  22 +@RequestMapping("/wx/mp")
  23 +@Validated
  24 +@Slf4j
  25 +public class WxMpController {
  26 +
  27 + @Resource
  28 + private WxMpService mpService;
  29 +
  30 + @PostMapping("/create-jsapi-signature")
  31 + @ApiOperation(value = "创建微信 JS SDK 初始化所需的签名",
  32 + notes = "参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档")
  33 + public CommonResult<WxJsapiSignature> createJsapiSignature(@RequestParam("url") String url) throws WxErrorException {
  34 + return success(mpService.createJsapiSignature(url));
  35 + }
  36 +
  37 +}
... ...
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/weixin/package-info.java 0 → 100644
  1 +/**
  2 + * weixin 包下,我们放通用业务,支撑上层的核心业务。
  3 + * 例如说:用户、部门、权限、数据字典等等
  4 + *
  5 + * 缩写:wx
  6 + */
  7 +package cn.iocoder.yudao.userserver.modules.weixin;
... ...
yudao-user-server/src/main/resources/application.yaml
... ... @@ -20,6 +20,10 @@ spring:
20 20 write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳
21 21 fail-on-empty-beans: false # 允许序列化无属性的 Bean
22 22  
  23 + # 静态资源
  24 + mvc:
  25 + static-path-pattern: /static/**
  26 +
23 27 # MyBatis Plus 的配置项
24 28 mybatis-plus:
25 29 configuration:
... ... @@ -33,6 +37,8 @@ mybatis-plus:
33 37 mapper-locations: classpath*:mapper/*.xml
34 38 type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject, ${yudao.core-service.base-package}.modules.*.dal.dataobject
35 39  
  40 +
  41 +
36 42 --- #################### 芋道相关配置 ####################
37 43  
38 44 yudao:
... ...
yudao-user-server/src/main/resources/static/pay.html
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <meta charset="UTF-8">
  5 + <title>支付测试页</title>
  6 + <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  7 + <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  8 +</head>
  9 +<body>
  10 +<div>点击如下按钮,发起支付的测试</div>
  11 +<div>
  12 + <button id="wx_pub">微信公众号</button>
  13 +</div>
  14 +</body>
  15 +<script>
  16 + $(function() {
  17 + // 获得 JsapiTicket
  18 + $.ajax({
  19 + url: "http://127.0.0.1:28080/api/wx/mp/create-jsapi-signature?url=" + document.location.href,
  20 + method: 'POST',
  21 + success: function( result ) {
  22 + if (result.code !== 0) {
  23 + alert('获取 JsapiTicket 失败,原因:' + result.msg)
  24 + return;
  25 + }
  26 + var jsapiTicket = result.data;
  27 + jsapiTicket.jsApiList = [];
  28 + jsapiTicket.debug = true;
  29 +
  30 + // 初始化 JS
  31 + wx.config(jsapiTicket);
  32 + }
  33 + });
  34 + })
  35 +
  36 + $( "#wx_pub").on( "click", function() {
  37 + wx.ready(function(){
  38 + alert('ok');
  39 + });
  40 + });
  41 +</script>
  42 +</html>
... ...