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

pull/2/head
YunaiV 2021-10-24 23:02:34 +08:00
parent 44f357cea4
commit 60f5898c9a
8 changed files with 100 additions and 9 deletions

View File

@ -1,7 +1,8 @@
/**
* member .
*
* weixin .
*
* ps pay
*
* mbr
* wx
*/
package cn.iocoder.yudao.userserver.modules.member;
package cn.iocoder.yudao.userserver.modules.member;

View File

@ -12,10 +12,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

View File

@ -1 +0,0 @@
package cn.iocoder.yudao.userserver.modules.pay.controller;

View File

@ -0,0 +1,2 @@
### 请求 /login 接口 => 成功
GET {{userServerUrl}}/wx/mp/get-jsapi-ticket

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.userserver.modules.weixin.controller.mp;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Api(tags = "微信公众号")
@RestController
@RequestMapping("/wx/mp")
@Validated
@Slf4j
public class WxMpController {
@Resource
private WxMpService mpService;
@PostMapping("/create-jsapi-signature")
@ApiOperation(value = "创建微信 JS SDK 初始化所需的签名",
notes = "参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档")
public CommonResult<WxJsapiSignature> createJsapiSignature(@RequestParam("url") String url) throws WxErrorException {
return success(mpService.createJsapiSignature(url));
}
}

View File

@ -0,0 +1,7 @@
/**
* weixin
*
*
* wx
*/
package cn.iocoder.yudao.userserver.modules.weixin;

View File

@ -20,6 +20,10 @@ spring:
write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳
fail-on-empty-beans: false # 允许序列化无属性的 Bean
# 静态资源
mvc:
static-path-pattern: /static/**
# MyBatis Plus 的配置项
mybatis-plus:
configuration:
@ -33,6 +37,8 @@ mybatis-plus:
mapper-locations: classpath*:mapper/*.xml
type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject, ${yudao.core-service.base-package}.modules.*.dal.dataobject
--- #################### 芋道相关配置 ####################
yudao:

View File

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>支付测试页</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>
<body>
<div>点击如下按钮,发起支付的测试</div>
<div>
<button id="wx_pub">微信公众号</button>
</div>
</body>
<script>
$(function() {
// 获得 JsapiTicket
$.ajax({
url: "http://127.0.0.1:28080/api/wx/mp/create-jsapi-signature?url=" + document.location.href,
method: 'POST',
success: function( result ) {
if (result.code !== 0) {
alert('获取 JsapiTicket 失败,原因:' + result.msg)
return;
}
var jsapiTicket = result.data;
jsapiTicket.jsApiList = [];
jsapiTicket.debug = true;
// 初始化 JS
wx.config(jsapiTicket);
}
});
})
$( "#wx_pub").on( "click", function() {
wx.ready(function(){
alert('ok');
});
});
</script>
</html>