forked from sfms3.0/sfms3.0
10 changed files with 90 additions and 135 deletions
@ -0,0 +1,21 @@ |
|||
package com.win.framework.util; |
|||
|
|||
import cn.hutool.extra.spring.SpringUtil; |
|||
import org.springframework.context.MessageSource; |
|||
import org.springframework.context.i18n.LocaleContextHolder; |
|||
|
|||
public class MessageUtil { |
|||
|
|||
/** |
|||
* 根据消息键和参数 获取消息 委托给spring messageSource |
|||
* |
|||
* @param code 消息键 |
|||
* @param args 参数 |
|||
* @return 获取国际化翻译值 |
|||
*/ |
|||
public static String message(String code, Object... args) { |
|||
MessageSource messageSource = SpringUtil.getBean(MessageSource.class); |
|||
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale()); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,44 @@ |
|||
package com.win.framework.web.core.filter; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.context.i18n.LocaleContextHolder; |
|||
import org.springframework.web.servlet.HandlerInterceptor; |
|||
import org.springframework.web.servlet.ModelAndView; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.util.Locale; |
|||
|
|||
@Slf4j |
|||
public class MyI18nInterceptor implements HandlerInterceptor { |
|||
|
|||
@Override |
|||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|||
final String key = "language"; |
|||
String language = request.getHeader(key); |
|||
// 前端传递的language必须是zh-CN格式的,中间的-必须要完整,不能只传递zh或en
|
|||
log.info("当前语言={}", language); |
|||
if(language == null || language.equals("")) { |
|||
language = "zh-CN"; |
|||
} |
|||
Locale locale = new Locale(language.split("-")[0],language.split("-")[1]); |
|||
// 这样赋值以后,MessageUtil.message方法就不用修改了
|
|||
LocaleContextHolder.setLocale(locale); |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* 请求处理之后进行调用,但是在视图被渲染之前(Controller方法调用之后) |
|||
*/ |
|||
@Override |
|||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { |
|||
} |
|||
|
|||
/** |
|||
* 在整个请求结束之后被调用,也就是在DispatcherServlet 渲染了对应的视图之后执行(主要是用于进行资源清理工作) |
|||
*/ |
|||
@Override |
|||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { |
|||
} |
|||
|
|||
} |
@ -0,0 +1,2 @@ |
|||
captcha.code.not.null=\u9a8c\u8bc1\u7801\u4e0d\u80fd\u4e3a\u7a7a |
|||
captcha.code.error=\u9a8c\u8bc1\u7801\u9519\u8bef |
@ -0,0 +1,2 @@ |
|||
captcha.code.not.null=The verification code cannot be empty |
|||
captcha.code.error=Incorrect verification code |
@ -0,0 +1,2 @@ |
|||
captcha.code.not.null=\u9a8c\u8bc1\u7801\u4e0d\u80fd\u4e3a\u7a7a |
|||
captcha.code.error=\u9a8c\u8bc1\u7801\u9519\u8bef |
@ -1 +0,0 @@ |
|||
DKOvVzFP7vPwwHx2 |
@ -1,13 +0,0 @@ |
|||
## 微信公众号 |
|||
|
|||
参考文章:https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df |
|||
|
|||
① 访问 social-login.html 选择【微信公众号】 |
|||
|
|||
② 微信公众号授权完成后,跳转回 social-login2.html,输入手机号 + 密码,进行绑定 |
|||
|
|||
## 微信小程序 |
|||
|
|||
参考文章:https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa |
|||
|
|||
① 暂时使用 mini-program-test 项目 |
@ -1,120 +0,0 @@ |
|||
<!DOCTYPE html> |
|||
<html> |
|||
<head> |
|||
<meta charset="UTF-8"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/> |
|||
<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> |
|||
let shopOrderId = undefined; |
|||
let payOrderId = undefined; |
|||
let server = 'http://127.0.0.1:48080'; |
|||
// let server = 'http://niubi.natapp1.cc'; |
|||
// TODO openid |
|||
let openid = "ockUAwIZ-0OeMZl9ogcZ4ILrGba0"; |
|||
$(function() { |
|||
// 获得 JsapiTicket |
|||
// 参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档 |
|||
$.ajax({ |
|||
url: server + "/app-api/wx/mp/create-jsapi-signature?url=" + document.location.href, |
|||
method: 'POST', |
|||
headers: { |
|||
'tenant-id': 1 |
|||
}, |
|||
success: function( result ) { |
|||
if (result.code !== 0) { |
|||
alert('获取 JsapiTicket 失败,原因:' + result.msg) |
|||
return; |
|||
} |
|||
var jsapiTicket = result.data; |
|||
jsapiTicket.jsApiList = ['chooseWXPay']; |
|||
jsapiTicket.debug = false; |
|||
|
|||
// 初始化 JS |
|||
wx.config(jsapiTicket); |
|||
} |
|||
}); |
|||
|
|||
// 自动发起商城订单编号 |
|||
$.ajax({ |
|||
url: server + "/app-api/shop/order/create", |
|||
method: 'POST', |
|||
success: function( result ) { |
|||
if (result.code !== 0) { |
|||
alert('创建商城订单失败,原因:' + result.msg) |
|||
return; |
|||
} |
|||
shopOrderId = result.data.id; |
|||
payOrderId = result.data.payOrderId; |
|||
console.log("商城订单:" + shopOrderId) |
|||
console.log("支付订单:" + payOrderId) |
|||
} |
|||
}) |
|||
}) |
|||
|
|||
// 微信公众号 |
|||
$( "#wx_pub").on( "click", function() { |
|||
if (typeof WeixinJSBridge == "undefined") { |
|||
// if (document.addEventListener) { |
|||
// document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); |
|||
// } else if (document.attachEvent) { |
|||
// document.attachEvent('WeixinJSBridgeReady', onBridgeReady); |
|||
// document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); |
|||
// } |
|||
alert('微信支付,只支持在微信客户端中使用!'); |
|||
return; |
|||
} |
|||
if (navigator.userAgent.indexOf('wechatdevtools') >= 0) { |
|||
alert('微信支付,无法在微信开发者工具中使用!请使用微信客户端!'); |
|||
return; |
|||
} |
|||
|
|||
// 提交支付 |
|||
// 参考 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6 文档 |
|||
// 参考 https://segmentfault.com/a/1190000020704650 文档 |
|||
$.ajax({ |
|||
url: server + "/app-api/pay/order/submit", |
|||
method: 'POST', |
|||
dataType: "json", |
|||
contentType: "application/json", |
|||
data: JSON.stringify({ |
|||
"id": payOrderId, |
|||
"channelCode": 'wx_pub', |
|||
"channelExtras": { |
|||
"openid": openid |
|||
} |
|||
}), |
|||
success: function( result ) { |
|||
if (result.code !== 0) { |
|||
alert('提交支付订单失败,原因:' + result.msg) |
|||
return; |
|||
} |
|||
alert('点击确定,开始微信支付'); |
|||
// 开始调用微信支付 |
|||
let data = result.data.invokeResponse; |
|||
wx.chooseWXPay({ |
|||
timestamp: data.timeStamp, |
|||
nonceStr: data.nonceStr, |
|||
package: data.packageValue, |
|||
signType: data.signType, |
|||
paySign: data.paySign, |
|||
success: function (res) { |
|||
alert(JSON.stringify(res)); |
|||
}, |
|||
error: function(e) { |
|||
alert(JSON.stringify(e)); |
|||
} |
|||
}); |
|||
} |
|||
}) |
|||
}); |
|||
</script> |
|||
</html> |
Loading…
Reference in new issue