diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/com/demo/alipay_core.java b/src/main/java/com/demo/alipay_core.java index 6a1d6c8..4ab1b32 100644 --- a/src/main/java/com/demo/alipay_core.java +++ b/src/main/java/com/demo/alipay_core.java @@ -22,7 +22,7 @@ import com.utils.Utils; public class alipay_core { AlipayClient client = null; /**支付宝回调的接口地址*/ - private static String aliNotifyUrl = "yourWebUrl/pay/alinotify"; + private static String aliNotifyUrl = Utils.getPeoperties("aliNotifyUrl")+""; /** @@ -30,9 +30,9 @@ public class alipay_core { */ public void getConfig() { - String appid="一串数字ID"; - String private_key="私钥"; - String public_key="公钥"; + String appid = Utils.getPeoperties("appid")+""; + String private_key = Utils.getPeoperties("private_key")+""; + String public_key = Utils.getPeoperties("public_key")+""; String sign_type="RSA2"; client =new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",appid,private_key,"json","utf-8",public_key,sign_type); diff --git a/src/main/java/com/demo/payController.java b/src/main/java/com/demo/payController.java index 5e2cd0b..1954522 100644 --- a/src/main/java/com/demo/payController.java +++ b/src/main/java/com/demo/payController.java @@ -1,5 +1,6 @@ package com.demo; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -18,7 +19,6 @@ import org.springframework.web.bind.annotation.RestController; @CrossOrigin(origins = "*", maxAge = 3600) -@RequestMapping(value="/pay",produces="text/html;charset=UTF-8") @RestController public class payController { @@ -127,11 +127,81 @@ public class payController { + "values("+order_id+",?,?,"+param.get("total_amount")+","+s+",?,"+param.get("buyer_pay_amount")+","+param.get("receipt_amount")+",?,?)", new String[]{param.get("trade_no"),param.get("subject"),param.get("buyer_logon_id"),param.get("buyer_id"),param.toString()}); } - - - } - + + @RequestMapping(value = "/install", produces = "text/html;charset=UTF-8") + public String install( + @RequestParam(required = false, defaultValue = "") String p, + HttpServletRequest request, + HttpServletResponse response + ) { + + //检查数据是否已经初始化,若没有,先设置后台密码 + + String pwd = Utils.getPeoperties("pwd") + ""; + if(pwd.replace("null","").trim().length()>0){ + try { + response.sendRedirect("./settings.html"); + } catch (IOException e) { + throw new RuntimeException(e); + } + return "{\"code\":\"-1\"}"; + }else if(p.replace("null","").trim().length()>0) { + Utils.setPeoperties("pwd",p); + return "{\"code\":\"1\"}"; + } + try { + response.sendRedirect("./install.html"); + } catch (IOException e) { + throw new RuntimeException(e); + } + return "{\"code\":\"-1\"}"; + } + + @RequestMapping(value = "/settings", produces = "text/html;charset=UTF-8") + public String setsettings( + @RequestParam(required = false, defaultValue = "") String p,//后台密码 + @RequestParam(required = false, defaultValue = "") String k,//key + @RequestParam(required = false, defaultValue = "") String v,//value + HttpServletRequest request, + HttpServletResponse response + ) { + + String pwd = Utils.getPeoperties("pwd") + ""; + if(pwd.replace("null","").trim().length()<1){ + try { + response.sendRedirect("./install.html"); + } catch (IOException e) { + throw new RuntimeException(e); + } + return "{\"code\":\"-1\"}"; + }else if("get".equals(k)&&pwd.equals(v)){ + //获取配置 + Map m = new HashMap<>(); + m.put("code","1"); + m.put("pwd#后台密码",Utils.getPeoperties("pwd") + ""); + m.put("dbname#数据库库名",Utils.getPeoperties("dbname")+""); + m.put("dbport#数据库端口",Utils.getPeoperties("dbport")+""); + m.put("dbusername#数据库用户名",Utils.getPeoperties("dbusername")+""); + m.put("dbpassword#数据库密码",Utils.getPeoperties("dbpassword")+""); + m.put("aliNotifyUrl#当面付回调地址",Utils.getPeoperties("aliNotifyUrl")+""); + m.put("appid#当面付APPID",Utils.getPeoperties("appid")+""); + m.put("private_key#当面付私钥",Utils.getPeoperties("private_key")+""); + m.put("public_key#当面付公钥",Utils.getPeoperties("public_key")+""); + return Utils.ObjectToJson(m); + + }else if(pwd.equals(p)){ + //k,v,写入properties + + }else{ + Map m = new HashMap<>(); + m.put("code","-1"); + m.put("msg","请输入后台密码"); + m.put("url","./settings"); + return Utils.ObjectToJson(m); + } + return null; + } } diff --git a/src/main/java/com/utils/DBUtil.java b/src/main/java/com/utils/DBUtil.java index c23a183..872a3b7 100644 --- a/src/main/java/com/utils/DBUtil.java +++ b/src/main/java/com/utils/DBUtil.java @@ -16,11 +16,11 @@ import java.util.Map; public class DBUtil { // 四大金刚 - String dname = "scbox"; + String dname = Utils.getPeoperties("dbname")+""; String driver = "com.mysql.jdbc.Driver";// 驱动名称 - String url = "jdbc:mysql://127.0.0.1:3306/"+dname+"?useUnicode=false&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接 - String username = "root";// 用户名 - String password = "root";// 密码 + String url = "jdbc:mysql://127.0.0.1:"+Utils.getPeoperties("dbport")+"/"+dname+"?useUnicode=false&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接 + String username = Utils.getPeoperties("dbusername")+"";// 用户名 + String password = Utils.getPeoperties("dbpassword")+"";// 密码 // 三剑客 Connection con = null;// 连接对象 @@ -257,4 +257,5 @@ public class DBUtil { return m; } + } diff --git a/src/main/java/com/utils/Utils.java b/src/main/java/com/utils/Utils.java index 255457f..8aad430 100644 --- a/src/main/java/com/utils/Utils.java +++ b/src/main/java/com/utils/Utils.java @@ -10,9 +10,11 @@ import org.apache.commons.codec.binary.Base64; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; +import java.io.*; +import java.net.URL; import java.util.HashMap; import java.util.Map; +import java.util.Properties; import java.util.Random; public class Utils { @@ -139,4 +141,49 @@ public class Utils { return resMatrix; } + public static Properties readPeoperties(){ + InputStream inputStream = Utils.class.getClassLoader().getResourceAsStream("t.properties"); + + Properties p = new Properties(); + try{ + p.load(inputStream); + }catch(Exception e1) { + e1.printStackTrace(); + } + return p; + } + + public static Object getPeoperties(Object k){ + InputStream inputStream = Utils.class.getClassLoader().getResourceAsStream("t.properties"); + + Properties p = new Properties(); + try{ + p.load(inputStream); + }catch(Exception e1) { + e1.printStackTrace(); + } + return p.get(k); + } + + public static void setPeoperties(String k,Object v){ + Properties p = new Properties(); + p.put(k,v); + + URL f = Utils.class.getClassLoader().getResource("t.properties"); + + try{ + System.out.println(f.toURI()); + FileOutputStream fos = new FileOutputStream(new File(f.toURI())); + p.store(new BufferedOutputStream(fos),"save"); + fos.close(); + }catch(Exception e1) { + e1.printStackTrace(); + } + } + public static void main(String[] args) { + Object p = Utils.getPeoperties("1"); + System.out.println(p.toString()); + Utils.setPeoperties("1","3"); + } + } diff --git a/src/main/resources/t.properties b/src/main/resources/t.properties new file mode 100644 index 0000000..79f3703 --- /dev/null +++ b/src/main/resources/t.properties @@ -0,0 +1 @@ +1=2 \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index fb6fcf0..a82f90d 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -38,7 +38,7 @@ return; } - let response = await fetch('./pay/createOrder?n=' + n + '&t=test'); + let response = await fetch('./createOrder?n=' + n + '&t=test'); let res = JSON.parse(await response.text()); if (res.code == 1) { @@ -64,7 +64,7 @@ *轮询检查支付状态 */ async function subscribe(id) { - let response = await fetch("./pay/queryPay?id=" + id); + let response = await fetch("./queryPay?id=" + id); if (response.status == 502) { // 连接超时,重新连接 @@ -93,7 +93,7 @@ * 手动查询支付状态 */ async function selectPay(id) { - let response = await fetch('./pay/queryPay?id=' + id); + let response = await fetch('./queryPay?id=' + id); let res = JSON.parse(await response.text()); if (response.status == 200 && res.msg == "已支付") { diff --git a/src/main/webapp/install.html b/src/main/webapp/install.html new file mode 100644 index 0000000..f259f9f --- /dev/null +++ b/src/main/webapp/install.html @@ -0,0 +1,39 @@ + + + + + + + + 初始化 + + + + +
+


+

首次使用

+

设置后台密码: + +
+ + + + + + + \ No newline at end of file diff --git a/src/main/webapp/settings.html b/src/main/webapp/settings.html new file mode 100644 index 0000000..7455016 --- /dev/null +++ b/src/main/webapp/settings.html @@ -0,0 +1,36 @@ + + + + + + + + 配置 + + + + +


+

参数配置

+

输入后台密码获取配置: + --- 单个单个的参数后面跟一个修改按钮,每个按钮对应一个事件,事件用pkv传给后台,像是当面付回调地址、写上解释怎么填, API接口写一个调用示例解释一下 --- 运行建表程序 + + + + + + + + \ No newline at end of file