6 Commits
r23 ... master

Author SHA1 Message Date
司龙
9678c44e50 修改 2025-01-02 17:18:32 +08:00
admin
ab81cecff0 bug 2024-02-26 13:15:12 +08:00
麒麟
595e1a8c20 bug 2023-09-11 23:16:00 +08:00
麒麟
295e1771ab bug 2023-09-11 22:27:14 +08:00
麒麟
7638b8c5cd bug 2023-09-11 22:24:54 +08:00
麒麟
63adb1653a add 2023-09-11 22:05:19 +08:00
9 changed files with 310 additions and 64 deletions

2
.idea/misc.xml generated
View File

@@ -8,7 +8,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@@ -0,0 +1,36 @@
package com.demo;
import com.utils.Utils;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.*;
public class Interceptor implements HandlerInterceptor {
@Override
public boolean preHandle(
HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
if(
Utils.getPeoperties("aliNotifyUrl").replace("null","").trim().length()<1
|| Utils.getPeoperties("appid").replace("null","").trim().length()<1
|| Utils.getPeoperties("private_key").replace("null","").trim().length()<1
|| Utils.getPeoperties("public_key").replace("null","").trim().length()<1
|| Utils.getPeoperties("pwd").replace("null","").trim().length()<1
|| Utils.getPeoperties("dburl").replace("null","").trim().length()<1
|| Utils.getPeoperties("dbport").replace("null","").trim().length()<1
|| Utils.getPeoperties("dbname").replace("null","").trim().length()<1
|| Utils.getPeoperties("dbusername").replace("null","").trim().length()<1
|| Utils.getPeoperties("dbpassword").replace("null","").trim().length()<1
){
response.sendRedirect("./install.html");
return false;
}else return true;
}
}

View File

@@ -22,7 +22,7 @@ import com.utils.Utils;
public class alipay_core { public class alipay_core {
AlipayClient client = null; AlipayClient client = null;
/**支付宝回调的接口地址*/ /**支付宝回调的接口地址*/
private static String aliNotifyUrl = Utils.getPeoperties("aliNotifyUrl")+""; private static String aliNotifyUrl = Utils.getPeoperties("aliNotifyUrl");
/** /**
@@ -30,9 +30,9 @@ public class alipay_core {
*/ */
public void getConfig() { public void getConfig() {
String appid = Utils.getPeoperties("appid")+""; String appid = Utils.getPeoperties("appid");
String private_key = Utils.getPeoperties("private_key")+""; String private_key = Utils.getPeoperties("private_key");
String public_key = Utils.getPeoperties("public_key")+""; String public_key = Utils.getPeoperties("public_key");
String sign_type="RSA2"; String sign_type="RSA2";
client =new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",appid,private_key,"json","utf-8",public_key,sign_type); client =new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",appid,private_key,"json","utf-8",public_key,sign_type);
@@ -46,7 +46,9 @@ public class alipay_core {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(Utils.QrImgB64("aaa",200)); String s = Utils.getPeoperties("private_key");
System.out.println(s);
} }
/** /**

View File

@@ -139,24 +139,26 @@ public class payController {
//检查数据是否已经初始化,若没有,先设置后台密码 //检查数据是否已经初始化,若没有,先设置后台密码
String pwd = Utils.getPeoperties("pwd") + ""; String pwd = Utils.getPeoperties("pwd");
if(pwd.replace("null","").trim().length()>0){ if(pwd.replace("null","").trim().length()>0){
try { Map<String,String> m = new HashMap<>();
response.sendRedirect("./settings.html"); m.put("code","1");
} catch (IOException e) { m.put("msg","已经初始化");
throw new RuntimeException(e); m.put("url","./settings.html");
} return Utils.ObjectToJson(m);
return "{\"code\":\"-1\"}";
}else if(p.replace("null","").trim().length()>0) { }else if(p.replace("null","").trim().length()>0) {
Utils.setPeoperties("pwd",p); Utils.setPeoperties("pwd",p);
return "{\"code\":\"1\"}"; Map<String,String> m = new HashMap<>();
m.put("code","1");
m.put("msg","初始化成功");
m.put("url","./settings.html");
return Utils.ObjectToJson(m);
} }
try {
response.sendRedirect("./install.html"); Map<String,String> m = new HashMap<>();
} catch (IOException e) { m.put("code","-1");
throw new RuntimeException(e); m.put("url","./install.html");
} return Utils.ObjectToJson(m);
return "{\"code\":\"-1\"}";
} }
@RequestMapping(value = "/settings", produces = "text/html;charset=UTF-8") @RequestMapping(value = "/settings", produces = "text/html;charset=UTF-8")
@@ -168,40 +170,95 @@ public class payController {
HttpServletResponse response HttpServletResponse response
) { ) {
String pwd = Utils.getPeoperties("pwd") + ""; System.out.println(v);
String pwd = Utils.getPeoperties("pwd");
if(pwd.replace("null","").trim().length()<1){ if(pwd.replace("null","").trim().length()<1){
try { Map<String,String> m = new HashMap<>();
response.sendRedirect("./install.html"); m.put("code","-1");
} catch (IOException e) { m.put("msg","请前往初始化");
throw new RuntimeException(e); m.put("url","./install.html");
} return Utils.ObjectToJson(m);
return "{\"code\":\"-1\"}";
}else if("get".equals(k)&&pwd.equals(v)){ }else if("get".equals(k)&&pwd.equals(v)){
//获取配置 //获取配置
Map<String,String> m = new HashMap<>(); Map<String,String> m = new HashMap<>();
m.put("code","1"); m.put("code","1");
m.put("pwd#后台密码",Utils.getPeoperties("pwd") + ""); m.put("pwd#后台密码",Utils.getPeoperties("pwd"));
m.put("dbname#数据库库名",Utils.getPeoperties("dbname")+""); m.put("dburl#数据库地址(不含http)",Utils.getPeoperties("dburl"));
m.put("dbport#数据库端口",Utils.getPeoperties("dbport")+""); m.put("dbname#数据库库名",Utils.getPeoperties("dbname"));
m.put("dbusername#数据库用户名",Utils.getPeoperties("dbusername")+""); m.put("dbport#数据库端口",Utils.getPeoperties("dbport"));
m.put("dbpassword#数据库密码",Utils.getPeoperties("dbpassword")+""); m.put("dbusername#数据库用户名",Utils.getPeoperties("dbusername"));
m.put("aliNotifyUrl#当面付回调地址",Utils.getPeoperties("aliNotifyUrl")+""); m.put("dbpassword#数据库密码",Utils.getPeoperties("dbpassword"));
m.put("appid#当面付APPID",Utils.getPeoperties("appid")+""); m.put("aliNotifyUrl#当面付回调地址",Utils.getPeoperties("aliNotifyUrl"));
m.put("private_key#当面付私钥",Utils.getPeoperties("private_key")+""); m.put("appid#当面付APPID",Utils.getPeoperties("appid"));
m.put("public_key#当面付",Utils.getPeoperties("public_key")+""); m.put("private_key#当面付",Utils.getPeoperties("private_key"));
m.put("public_key#当面付公钥",Utils.getPeoperties("public_key"));
return Utils.ObjectToJson(m); return Utils.ObjectToJson(m);
}else if(pwd.equals(p)){ }else if(pwd.equals(p)){
//kv写入properties //kv写入properties
Utils.setPeoperties(k,v);
Map<String,String> m = new HashMap<>();
m.put("code","1");
m.put("msg","已将["+k+"]的值设置为["+v+"]");
return Utils.ObjectToJson(m);
}else{ }else{
Map<String,String> m = new HashMap<>(); Map<String,String> m = new HashMap<>();
m.put("code","-1"); m.put("code","-1");
m.put("msg","请输入后台密码"); m.put("msg","密码不正确");
m.put("url","./settings");
return Utils.ObjectToJson(m); return Utils.ObjectToJson(m);
} }
return null;
} }
@RequestMapping(value = "/createTable", produces = "text/html;charset=UTF-8")
public String createTable(
HttpServletRequest request,
HttpServletResponse response
) {
Map<String,String> m = new HashMap<>();
DBUtil db = new DBUtil();
boolean is = db.cktable("_orders");
if(is){
m.put("code","-1");
m.put("msg","表已存在");
return Utils.ObjectToJson(m);
}else{
String sql ="";
sql += "CREATE TABLE `_orders` (";
sql += " `out_trade_no` bigint(255) NOT NULL COMMENT '商家订单号',";
sql += " `trade_no` varchar(255) DEFAULT '' COMMENT '支付宝订单号',";
sql += " `otitle` varchar(255) DEFAULT '' COMMENT '交易标题',";
sql += " `onum` decimal(11,2) DEFAULT '0.00' COMMENT '交易金额',";
sql += " `ostatus` int(11) DEFAULT '0' COMMENT '交易状态 0:无订单,1:等待付款,2:超时关闭,3:支付成功,4:交易结束',";
sql += " `qrcode` varchar(255) DEFAULT '' COMMENT '二维码地址',";
sql += " `zfbuser` varchar(255) DEFAULT '' COMMENT '买家支付宝账号(已隐藏)',";
sql += " `paynum` decimal(11,2) DEFAULT '0.00' COMMENT '买家实付款',";
sql += " `getnum` decimal(11,2) DEFAULT '0.00' COMMENT '实际收款',";
sql += " `zfbuserid` varchar(255) DEFAULT '' COMMENT '支付宝用户id(16位纯数字)',";
sql += " `buytype` int(11) DEFAULT '0' COMMENT '买家用户类型 0个人1企业',";
sql += " `getbody` text COMMENT '订单body',";
sql += " `remark` varchar(255) DEFAULT NULL,";
sql += " `payuser` varchar(255) DEFAULT '' COMMENT '对应本站用户id',";
sql += " `payway` varchar(255) DEFAULT '' COMMENT '对应本站付款原因(可以是打赏,购买等)',";
sql += " `paytag` varchar(255) DEFAULT '' COMMENT '绑定物品(若是购买填写物品id)',";
sql += " `createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,";
sql += " PRIMARY KEY (`out_trade_no`)";
sql += ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
db.execUpdate(sql,null);
if(db.cktable("_orders")){
m.put("code","1");
m.put("msg","建表成功");
return Utils.ObjectToJson(m);
}else{
m.put("code","-1");
m.put("msg","建表失败,请检查参数配置");
return Utils.ObjectToJson(m);
}
}
}
} }

View File

@@ -16,11 +16,11 @@ import java.util.Map;
public class DBUtil { public class DBUtil {
// 四大金刚 // 四大金刚
String dname = Utils.getPeoperties("dbname")+""; String dname = Utils.getPeoperties("dbname");
String driver = "com.mysql.jdbc.Driver";// 驱动名称 String driver = "com.mysql.jdbc.Driver";// 驱动名称
String url = "jdbc:mysql://127.0.0.1:"+Utils.getPeoperties("dbport")+"/"+dname+"?useUnicode=false&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接 String url = "jdbc:mysql://"+Utils.getPeoperties("dburl")+":"+Utils.getPeoperties("dbport")+"/"+dname+"?useUnicode=false&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接
String username = Utils.getPeoperties("dbusername")+"";// 用户名 String username = Utils.getPeoperties("dbusername");// 用户名
String password = Utils.getPeoperties("dbpassword")+"";// 密码 String password = Utils.getPeoperties("dbpassword");// 密码
// 三剑客 // 三剑客
Connection con = null;// 连接对象 Connection con = null;// 连接对象
@@ -258,4 +258,27 @@ public class DBUtil {
} }
/**
* 检查某个表是否存在
* @param name
* @return
*/
public boolean cktable(String name){
boolean is = false;
try {
this.getConnection();// 获得连接对象
ResultSet tables = this.con.getMetaData().getTables(null, null, name, null);
if (tables.next()) is = true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
this.close(this.rs, this.pstmt, this.con);
}
return is;
}
} }

View File

@@ -12,6 +12,7 @@ import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@@ -141,7 +142,8 @@ public class Utils {
return resMatrix; return resMatrix;
} }
public static Properties readPeoperties(){
public static String getPeoperties(Object k){
InputStream inputStream = Utils.class.getClassLoader().getResourceAsStream("t.properties"); InputStream inputStream = Utils.class.getClassLoader().getResourceAsStream("t.properties");
Properties p = new Properties(); Properties p = new Properties();
@@ -150,29 +152,27 @@ public class Utils {
}catch(Exception e1) { }catch(Exception e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
return p;
}
public static Object getPeoperties(Object k){
InputStream inputStream = Utils.class.getClassLoader().getResourceAsStream("t.properties");
Properties p = new Properties();
try{ return p.get(k)+"";
p.load(inputStream);
}catch(Exception e1) {
e1.printStackTrace();
}
return p.get(k);
} }
public static void setPeoperties(String k,Object v){ public static void setPeoperties(String k,Object v){
Properties p = new Properties(); Properties p = new Properties();
InputStream inputStream = Utils.class.getClassLoader().getResourceAsStream("t.properties");
try{
p.load(inputStream);
}catch(Exception e1) {
e1.printStackTrace();
}
p.put(k,v); p.put(k,v);
URL f = Utils.class.getClassLoader().getResource("t.properties"); URL f = Utils.class.getClassLoader().getResource("t.properties");
try{ try{
System.out.println(f.toURI());
FileOutputStream fos = new FileOutputStream(new File(f.toURI())); FileOutputStream fos = new FileOutputStream(new File(f.toURI()));
p.store(new BufferedOutputStream(fos),"save"); p.store(new BufferedOutputStream(fos),"save");
fos.close(); fos.close();

View File

@@ -27,6 +27,25 @@
<bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver"/> <bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver"/>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/install" />
<mvc:exclude-mapping path="/settings" />
<mvc:exclude-mapping path="/install.html" />
<mvc:exclude-mapping path="/settings.html" />
<mvc:exclude-mapping path="/createTable" />
<mvc:exclude-mapping path="/**/fonts/*" />
<mvc:exclude-mapping path="/**/*.css" />
<mvc:exclude-mapping path="/**/*.js" />
<mvc:exclude-mapping path="/**/*.png" />
<mvc:exclude-mapping path="/**/*.gif" />
<mvc:exclude-mapping path="/**/*.jpg" />
<mvc:exclude-mapping path="/**/*.jpeg" />
<bean class="com.demo.Interceptor" />
</mvc:interceptor>
</mvc:interceptors>
<!-- 自动扫描装配,扫描controller包的注解加入到容器中 --> <!-- 自动扫描装配,扫描controller包的注解加入到容器中 -->
<context:component-scan base-package="com.*"/> <context:component-scan base-package="com.*"/>

View File

@@ -29,10 +29,23 @@
var p = $('#p').val(); var p = $('#p').val();
let response = await fetch('./install?p=' + p); let response = await fetch('./install?p=' + p);
let res = JSON.parse(await response.text()); let res = JSON.parse(await response.text());
if (res.code / 1 == 1) {
window.location.href = "./settings.html"; if(res.msg) alert(res.msg);
} if(res.url) window.location.href = res.url;
} }
$.get("./install").done((r =>{
let res = JSON.parse(r);
if(res.msg)alert(res.msg);
if(res.url){
var u = res.url.substring(1);
var au = window.location.href.substring(window.location.href.length - u.length);
if(u != au) window.location.href = res.url;
}
}));
</script> </script>
</body> </body>

View File

@@ -14,11 +14,51 @@
</style> </style>
</head> </head>
<body> <body style="padding:10px 20px;">
<br><br><br> <br><br><br>
<h3>参数配置</h3> <h3>参数配置</h3>
<br><br> 输入后台密码获取配置: <br>
<input type="text" name="p" id="p"> <button onclick="setp()">提交</button> --- 单个单个的参数后面跟一个修改按钮每个按钮对应一个事件事件用pkv传给后台像是当面付回调地址、写上解释怎么填 API接口写一个调用示例解释一下 --- 运行建表程序 <br>每一项填完都要点一次[修改]
<div id="kvs">
第一步:输入后台密码获取配置:
<input type="text" name="p" id="p" placeholder="输入密码"> <button onclick="setp()">获取</button>
</div>
<br>
第二步请先在你的MySql数据库中建好上述填写的数据库名,再点击此按钮<br>
<button onclick="createTable()">运行数据库建表程序</button>
<br> <br> <br> <br>
<h3>开通引导</h3>
<br>
<a href="https://moyubao.cn/bbs/info?id=3" target="_blank">官网教程</a>
<br> 因支付宝安全性限制,本程序无法在本地调试,请事先准备好服务器及域名
<br> 支付宝开放平台https://open.alipay.com/
<hr>
<br> 本人以_创建网页应用_做步骤展示:
<br> 1.在控制台点击【网页/移动应用】创建网页移动应用(根据自己需求可以创建其他的)
<br> <hr>
<br> 2.创建成功后,点击“开发设置”,设置【接口加签方式】选择“秘钥”,根据步骤提示下载"秘钥工具"安装,根据提示步骤生成秘钥,按照步骤填写公钥,下载生成的公钥文件,一定要保存好。
<br> <hr>
<br> 3.还是上步骤的“开发设置”里填写【支付宝网关地址】此地址与上述参数配置里的当面付回调地址是一个东西本测试代码填写的是yourweb/war名称[根目录此项去掉]/alinotify。
<br> 系统监测到你应该填写:<span style="color: red;" id="al"></span> (仅供参考,若错误请自行填写)
<br> 用户支付成功后支付宝会将成功数据发送到你填的这个网关地址上
<br> <hr>
<br> 4.在“产品绑定”页面,点击去绑定,在产品里找到"当面付",选中,点击确定。
<br> <hr>
<br> 5.在当面付“未开通”后面的上鼠标悬浮弹框中点击“去开通”根据要求填写内容不用上传营业执照店铺招牌和店铺内景自己从百度找一张高清无水印的写的什么名称就搜什么名称的图片一般都能搜到同名的店内景无所谓只要合适就行有能力的可以ps一下提交审核就可以。
<br> <hr>
<br> 6.回到支付宝开放平台“网页应用”界面,将应用提交审核.
<hr>
<br> <br> <br>
API接口说明
<br> ./createOrder?n=金额&t=备注 ==> 获取付款码
<br>
<br> ./queryOrder?id=生成的订单号 ==> 查询订单
<br>
<br> ./queryPay?id=生成的订单号 ==> 查询订单是否支付成功
<br>
<br> 一般通过 轮询 查询订单是否支付成功 即可实现支付成功回调.
<script src='https://libs.baidu.com/jquery/2.0.0/jquery.min.js'></script> <script src='https://libs.baidu.com/jquery/2.0.0/jquery.min.js'></script>
@@ -28,8 +68,64 @@
var p = $('#p').val(); var p = $('#p').val();
let response = await fetch('./settings?k=get&v=' + p); let response = await fetch('./settings?k=get&v=' + p);
let res = JSON.parse(await response.text()); let res = JSON.parse(await response.text());
console.log(res); if(res.code / 1 == 1){
$('#kvs').empty();
for(var k in res){
if(k=='code') continue;
var v = res[k];
var ks = k.split('#');
if(v=='null') v='';
var span1 = document.createElement('span');
var e0 = document.createElement('span');
e0.innerHTML=ks[1]+"";
var e1 = document.createElement('textarea');
e1.setAttribute("name",ks[0]);
e1.setAttribute("id",ks[0]);
e1.innerHTML = v;
var e2 = document.createElement('button');
e2.setAttribute("onclick","setk('"+res['pwd#后台密码']+"','"+ks[0]+"')");
e2.innerHTML = "修改";
var e3 = document.createElement('hr');
span1.appendChild(e0);
span1.appendChild(e1);
span1.appendChild(e2);
span1.appendChild(e3);
$('#kvs').append(span1);
}
}else{
if(res.msg)alert(res.msg);
if(res.url) window.location.href = res.url;
}
} }
async function setk(pwd,k) {
var p = $('#'+k).val();
let response = await fetch('./settings?p='+pwd+'&k='+k+'&v=' + encodeURIComponent(p));
let res = JSON.parse(await response.text());
if(res.code / 1 == 1){
alert(res.msg);
}else alert(res.msg);
}
async function createTable(){
let response = await fetch('./createTable');
let res = JSON.parse(await response.text());
if(res.msg) alert(res.msg);
if(res.url) window.location.href = res.url;
}
var ph = window.location.pathname.split('/');
$("#al").html(window.location.protocol+'//'+window.location.host+(ph.length>2?('/'+ph[1]):ph[0])+'/alinotify');
</script> </script>
</body> </body>