初始化
This commit is contained in:
3
WebRoot/META-INF/MANIFEST.MF
Normal file
3
WebRoot/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
21
WebRoot/WEB-INF/classes/applicationContext.xml
Normal file
21
WebRoot/WEB-INF/classes/applicationContext.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/task
|
||||
http://www.springframework.org/schema/task/spring-task-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
">
|
||||
|
||||
<!--
|
||||
<context:component-scan base-package="sc545.pay.*" />
|
||||
|
||||
<task:executor id="executor" pool-size="5" />
|
||||
<task:scheduler id="scheduler" pool-size="10" />
|
||||
<task:annotation-driven executor="executor" scheduler="scheduler" />
|
||||
-->
|
||||
</beans>
|
||||
2
WebRoot/WEB-INF/classes/config.properties
Normal file
2
WebRoot/WEB-INF/classes/config.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
a=b
|
||||
c=d
|
||||
57
WebRoot/WEB-INF/classes/springmvc-servlet.xml
Normal file
57
WebRoot/WEB-INF/classes/springmvc-servlet.xml
Normal file
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-4.0.xsd
|
||||
">
|
||||
<context:annotation-config />
|
||||
<!-- 扫描所有的 controller -->
|
||||
<context:component-scan base-package="sc545.pay" />
|
||||
|
||||
<!-- 将静态资源交于默认的servlet处理 -->
|
||||
<mvc:default-servlet-handler />
|
||||
|
||||
<!-- 启动注解驱动 SpringMVC 功能 -->
|
||||
<mvc:annotation-driven />
|
||||
|
||||
|
||||
<bean
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/" /> <!-- controller 返回的网页地址根目录 -->
|
||||
<!-- <property name="suffix" value=".jsp" /> -->
|
||||
|
||||
</bean>
|
||||
|
||||
<bean id="multipartResolver"
|
||||
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||
<property name="defaultEncoding" value="utf-8"></property>
|
||||
<property name="maxUploadSize" value="10485760000"></property>
|
||||
<property name="maxInMemorySize" value="40960"></property>
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
<!-- 配置静态资源 -->
|
||||
<mvc:resources location="/" mapping="/**/*.js" />
|
||||
<mvc:resources location="/" mapping="/**/*.css" />
|
||||
<mvc:resources location="/assets/" mapping="/assets/**/*" />
|
||||
<mvc:resources location="/images/" mapping="/images/*"
|
||||
cache-period="360000" />
|
||||
|
||||
<mvc:interceptors>
|
||||
<mvc:interceptor>
|
||||
<mvc:mapping path="/**" />
|
||||
<bean class="sc545.pay.interceptor.testInterceptor" />
|
||||
</mvc:interceptor>
|
||||
|
||||
</mvc:interceptors>
|
||||
|
||||
|
||||
</beans>
|
||||
47
WebRoot/WEB-INF/web.xml
Normal file
47
WebRoot/WEB-INF/web.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
<display-name>pay</display-name>
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:applicationContext.xml</param-value>
|
||||
</context-param>
|
||||
<servlet>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:springmvc-servlet.xml</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
<welcome-file-list>
|
||||
<welcome-file>/index.html</welcome-file>
|
||||
<welcome-file>/index.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
<servlet-mapping>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
||||
113
WebRoot/index.html
Normal file
113
WebRoot/index.html
Normal file
@@ -0,0 +1,113 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>顺诚百宝箱</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 10px auto;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<input type="number" name="num" id="num" placeholder="输入金额">
|
||||
<button onclick="getPayQr()">获取二维码</button>
|
||||
<div class="imgs"></div>
|
||||
|
||||
|
||||
<script src='/style/jq-weui/lib/jquery-2.1.4.js'></script>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* 获取支付二维码<br>
|
||||
* 自动开启轮询,检查支付是否成功
|
||||
*
|
||||
* @param {*} n 金额
|
||||
* @param {*} t 备注
|
||||
*/
|
||||
async function getPayQr() {
|
||||
var n = $('#num').val();
|
||||
if (n <= 0 || n > 2000) {
|
||||
alert("金额错误0~2000");
|
||||
return;
|
||||
}
|
||||
|
||||
let response = await fetch('/pay/createOrder?n=' + n + '&t=test');
|
||||
let res = eval("(" + await response.text() + ")");
|
||||
|
||||
if (res.code == 1) {
|
||||
|
||||
var id = res.out_trade_no;
|
||||
var img = res.qrimg;
|
||||
var code = res.qrcode;
|
||||
if (id == null || id.length < 1) {
|
||||
alert('获取订单失败');
|
||||
return;
|
||||
}
|
||||
if (img == null || img.length < 1) {
|
||||
alert('获取二维码失败');
|
||||
return;
|
||||
}
|
||||
$('.imgs').html("<img src='data:image/jpg;base64," + img + "'><br><a href='" + code + "'>手机点这里打开支付宝APP</a><br>使用支付宝扫一扫<br><button onclick='selectPay(" + id + ")'>查询支付状态</button> <button onclick='getPayQr()'>刷新二维码</button>");
|
||||
subscribe(id);
|
||||
|
||||
} else alert('遇到错误 ' + res.msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*轮询检查支付状态
|
||||
*/
|
||||
async function subscribe(id) {
|
||||
let response = await fetch("/pay/queryPay?id=" + id);
|
||||
|
||||
if (response.status == 502) {
|
||||
// 连接超时,重新连接
|
||||
await subscribe(id);
|
||||
} else if (response.status != 200) {
|
||||
// 一个 error —— 让我们显示它
|
||||
alert(response.statusText);
|
||||
// 一秒后重新连接
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await subscribe(id);
|
||||
} else {
|
||||
// 获取并显示消息
|
||||
let message = eval("(" + await response.text() + ")");
|
||||
|
||||
// 再次调用 subscribe() 以获取下一条消息
|
||||
if (message.msg == "已支付") {
|
||||
$('.imgs').html('支付成功<br>');
|
||||
return okPay();
|
||||
}
|
||||
await subscribe(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 手动查询支付状态
|
||||
*/
|
||||
async function selectPay(id) {
|
||||
let response = await fetch('/pay/queryPay?id=' + id);
|
||||
let res = eval("(" + await response.text() + ")");
|
||||
|
||||
if (response.status == 200 && res.msg == "已支付") {
|
||||
return okPay();
|
||||
} else alert(res.msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付成功后的逻辑处理
|
||||
*/
|
||||
function okPay() {
|
||||
console.log('支付成功后要做的事');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user