diff --git a/.classpath b/.classpath deleted file mode 100644 index e3afd6f..0000000 --- a/.classpath +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore index 364fd9d..5ff6309 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,38 @@ -*.class +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr -# Package Files # -*.jar -*.war -*.ear +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -/WebRoot/WEB-INF/classes +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..132404b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.project b/.project deleted file mode 100644 index 572c742..0000000 --- a/.project +++ /dev/null @@ -1,46 +0,0 @@ - - - pay - - - - - - org.eclipse.wst.jsdt.core.javascriptValidator - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - org.eclipse.wst.validation.validationbuilder - - - - - com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator - - - - - com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder - - - - - - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.jdt.core.javanature - org.eclipse.wst.jsdt.core.jsNature - - diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope deleted file mode 100644 index 2fc9dba..0000000 --- a/.settings/.jsdtscope +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/.settings/com.genuitec.eclipse.core.prefs b/.settings/com.genuitec.eclipse.core.prefs deleted file mode 100644 index 3057485..0000000 --- a/.settings/com.genuitec.eclipse.core.prefs +++ /dev/null @@ -1,3 +0,0 @@ -eclipse.preferences.version=1 -validator.Checked=WebRoot/js,WebRoot/index.html -validator.Unchecked= diff --git a/.settings/com.genuitec.eclipse.j2eedt.core.prefs b/.settings/com.genuitec.eclipse.j2eedt.core.prefs deleted file mode 100644 index 7132d6d..0000000 --- a/.settings/com.genuitec.eclipse.j2eedt.core.prefs +++ /dev/null @@ -1,2 +0,0 @@ -defaultTldInfo=f\=http\://java.sun.com/jsf/core;http\://java.sun.com/jsf/html\=h;http\://struts.apache.org/tags-bean\=bean;http\://java.sun.com/jsp/jstl/fmt\=fmt;bean\=http\://struts.apache.org/tags-bean;nested\=http\://struts.apache.org/tags-nested;http\://java.sun.com/jsp/jstl/sql\=sql;c\=http\://java.sun.com/jsp/jstl/core;fmt\=http\://java.sun.com/jsp/jstl/fmt;http\://struts.apache.org/tags-logic\=logic;http\://java.sun.com/jsp/jstl/xml\=x;http\://java.sun.com/jsp/jstl/core\=c;logic\=http\://struts.apache.org/tags-logic;h\=http\://java.sun.com/jsf/html;http\://struts.apache.org/tags-tiles\=tiles;http\://java.sun.com/jsp/jstl/functions\=fn;tiles\=http\://struts.apache.org/tags-tiles;sql\=http\://java.sun.com/jsp/jstl/sql;http\://struts.apache.org/tags-html\=html;html\=http\://struts.apache.org/tags-html;http\://struts.apache.org/tags-nested\=nested;http\://java.sun.com/jsf/core\=f;fn\=http\://java.sun.com/jsp/jstl/functions;x\=http\://java.sun.com/jsp/jstl/xml -eclipse.preferences.version=1 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index f42de36..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component deleted file mode 100644 index e97d718..0000000 --- a/.settings/org.eclipse.wst.common.component +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml deleted file mode 100644 index 8938ee1..0000000 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container deleted file mode 100644 index 3bd5d0a..0000000 --- a/.settings/org.eclipse.wst.jsdt.ui.superType.container +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name deleted file mode 100644 index 05bd71b..0000000 --- a/.settings/org.eclipse.wst.jsdt.ui.superType.name +++ /dev/null @@ -1 +0,0 @@ -Window \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 19ea282..0000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ -## pay - -当面付个人支付系统 - diff --git a/WebRoot/META-INF/MANIFEST.MF b/WebRoot/META-INF/MANIFEST.MF deleted file mode 100644 index 254272e..0000000 --- a/WebRoot/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Class-Path: - diff --git a/WebRoot/WEB-INF/web.xml b/WebRoot/WEB-INF/web.xml deleted file mode 100644 index 3339d15..0000000 --- a/WebRoot/WEB-INF/web.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - pay - - org.springframework.web.context.ContextLoaderListener - - - - contextConfigLocation - classpath:applicationContext.xml - - - springmvc - org.springframework.web.servlet.DispatcherServlet - - contextConfigLocation - classpath:springmvc-servlet.xml - - - - /index.html - /index.jsp - - - springmvc - / - - - encodingFilter - org.springframework.web.filter.CharacterEncodingFilter - - encoding - UTF-8 - - - forceEncoding - true - - - - encodingFilter - /* - - \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2063e75 --- /dev/null +++ b/pom.xml @@ -0,0 +1,186 @@ + + 4.0.0 + + com.demo + alipayDemo + war + 1.0-SNAPSHOT + + alipayDemo Maven Webapp + http://maven.apache.org + + + UTF-8 + 3.6.3 + 3.6.3 + 5.3.27 + 1.8 + + + + + + + org.springframework + spring-webmvc + ${spring.version} + compile + + + + org.springframework + spring-test + ${spring.version} + compile + + + + + junit + junit + 4.13.2 + test + + + commons-configuration + commons-configuration + 1.10 + compile + + + commons-logging + commons-logging + 1.2 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + commons-lang + commons-lang + 2.6 + compile + + + org.jsoup + jsoup + 1.15.3 + compile + + + com.google.code.gson + gson + 2.10.1 + compile + + + + commons-codec + commons-codec + 1.15 + compile + + + org.apache.httpcomponents + httpclient + 4.5.14 + compile + + + net.coobird + thumbnailator + 0.4.19 + + + com.freewayso + image-combiner + 2.6.3 + + + com.google.zxing + core + 3.5.1 + + + org.dom4j + dom4j + 2.1.4 + compile + + + com.thoughtworks.xstream + xstream + 1.4.20 + compile + + + commons-io + commons-io + 2.11.0 + compile + + + mysql + mysql-connector-java + 5.1.38 + compile + + + com.alipay.sdk + alipay-sdk-java + 4.35.132.ALL + compile + + + + + + javax.servlet.jsp + jsp-api + 2.2 + compile + + + javax.servlet + jstl + 1.2 + compile + + + javax.servlet + javax.servlet-api + 3.1.0 + compile + + + + + + alipayDemo + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 8 + 8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + + + + + diff --git a/src/applicationContext.xml b/src/applicationContext.xml deleted file mode 100644 index b102b73..0000000 --- a/src/applicationContext.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - diff --git a/src/config.properties b/src/config.properties deleted file mode 100644 index 20c0243..0000000 --- a/src/config.properties +++ /dev/null @@ -1,2 +0,0 @@ -a=b -c=d diff --git a/src/sc545/pay/main/core.java b/src/main/java/com/demo/alipay_core.java similarity index 64% rename from src/sc545/pay/main/core.java rename to src/main/java/com/demo/alipay_core.java index f5bf0a1..6a1d6c8 100644 --- a/src/sc545/pay/main/core.java +++ b/src/main/java/com/demo/alipay_core.java @@ -1,14 +1,10 @@ -package sc545.pay.main; +package com.demo; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import sc545.pay.utils.DBUtil; -import sc545.pay.utils.FileUtils; -import sc545.pay.utils.ReadTxt; -import sc545.pay.utils.Utils; import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; @@ -20,22 +16,37 @@ import com.alipay.api.request.AlipayTradeQueryRequest; import com.alipay.api.response.AlipayTradePrecreateResponse; import com.alipay.api.response.AlipayTradeQueryResponse; -public class core { +import com.utils.DBUtil; +import com.utils.Utils; + +public class alipay_core { AlipayClient client = null; /**支付宝回调的接口地址*/ - private static String aliNotifyUrl = ReadTxt.getSetting(null, "setting.ini", "web", "localhost")+"/pay/alinotify"; + private static String aliNotifyUrl = "yourWebUrl/pay/alinotify"; + + + /** + * 接口调用配置 + */ + public void getConfig() { + + String appid="一串数字ID"; + String private_key="私钥"; + String 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); + + + } - public core() { + public alipay_core() { getConfig(); } public static void main(String[] args) { - - //每天定时清空无订单和超时关闭的数据库数据 - core c=new core(); - c.queryOrder("1655263616880"); - c.updateOrder("1655272489467"); + System.out.println(Utils.QrImgB64("aaa",200)); } /** @@ -46,7 +57,7 @@ public class core { HashMap rs = new HashMap<>(); AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); - String h=new Date().getTime()+Utils.randomNum(10, 99)+""; + String h=new Date().getTime()+ Utils.randomNum(10, 99)+""; AlipayTradePrecreateModel model = new AlipayTradePrecreateModel(); model.setOutTradeNo(h);//订单号(保证不重复) @@ -69,7 +80,7 @@ public class core { if(i==1){ rs.put("code", "1"); rs.put("qrcode", response.getQrCode()); - rs.put("qrimg", FileUtils.QrImgB64(response.getQrCode(), 300)); + rs.put("qrimg", Utils.QrImgB64(response.getQrCode(), 300)); rs.put("out_trade_no", response.getOutTradeNo()); }else rs.put("errcode", "-1"); } else { @@ -142,20 +153,5 @@ public class core { return response; } - - /** - * 接口调用配置 - */ - public void getConfig() { - - String appid="2021003131621776"; - String private_key="MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCZu1LRuq3Ka79zzv9OgAYNYFVEFetjSsrBJ/N34aBYY3BIOLe5dIt7EQNjx1QUNlSsWU7EwW3AFurXK6iWjXOZrJHZKcM9tzZfsuQeeufnpDtAU90zMSJcu17JfBsTXaXHUEBtQ0wjbuQJ+ihQMB5FtYBg3CuCxUtLqS2/g/n/qlW9ZKPTdnyBCro8pd8w1S5op591aiQGqIZ8ufW45ysCCfjZdOYkFmZMMM2Z5DQjtkQiXgX4aiN5VY5UhyEcGHd3kr9AaYPTC1hLZNUpZXsc2lgdOKQNrZ1FOmxJU4RpNJ9DxrbAgxUQIpvKj5/uOtBFaBmK/CYiVvjBRK5qilZFAgMBAAECggEBAIaNl1pr6wq9re9d4MXDdgilJVwXV1QrtTTEk+t8dsyGFFOSGPRgVmibpnzhjOy39Pp4nGHH7xhutpMn6kIDgoehrHIHhJRy1EuElvc6mdl8PEP8YyIYQjwp3ze4wTX9BElkK0+21GA7Aard4gT1aLmYt8mPSyIFLvcFFz6F8/1ZqKzOtv4jXigXjDzmu/cHks7jamHhknFOn3D7rzfUUViP+2J4HEiSaJXdmzU05aA5glJSLSw4366/GFHsy/Zh3d4FwcFuRu7L+X8gx5vlsPm6E9J7LAt0k+rL5XZVjdkR+Svzkou6EIX+vyZGgxPcUzsZj/V+jMumwALkqyyWP4ECgYEA5wbEJE+sx1NpzeF0/mrIDaB72mX51xpxX93zFCDLzGEY8HiJeR/+UodsNRtGn/W4kBXGSqh0nRnnASs12LGUO+uXcODS2AvSCcV2l5Uh3ecDFavTSeZfAX6yLlw6aecxvRbtDPugPhZ2+i1yc5elyGs5nTd8TjWrdEz0IrTx5eUCgYEAqlmRZpprAb4mSwAQ9+tr9ldvf5xezLzwYNmqRK221OpjFX9oi82MkZrnjcHuEIxpz8quc09A9C+IJ7a1RquWWL52wvjPk52Lbs/vKmGE1h7CF/5Dz4bTOCSF5Kp3SN3HjUI852InWX1pUw1WL5ufVK4mopGs1C3d8ifTSbW9qOECgYEAtO1inMFdIblcqiUAV+NOiwV9GZw1XtVRpu+OV9wbXxNH0cPEffylUwLFpo2W8N0iTo0O/xcQRJytggfSIsNnwMmPj5Iy7YnMU2S2rJ3ZqQwrKUSosz5cdzI+3vnRsXCjTl/vA/ToGNfFE8aV1JsV9XCr7Ukv65wyi2Fc7PViYFUCgYEAoXp+JjDCtsg1LGtHqntzv/RqMSFdi96eTnCGwsuYwIPeoQZBaCTU10FrtijbLryroNmUPKIoBFD6VAsSE4eb4UvK8E9DFb8F6WkaYaZHcWF+w5e3WAWKO3IDqhsdL+lrvC/J49xbSK1lJeFCjaaLho3++aP1nLxN47p0wy6QNoECgYBi5tW50hn9Kyx8WTgJZJgAPT4udLtrLhiLZsS2fucyvumUa5AWUvqF3jAn81ty4hsVXiY5/jiMplRDTCvOSkmmwD+55pSENuVXMDIJXyi9YCB5EJseSr5s5K3IziaVgYkIsiGBz3wVpordQAXID4gm53tWcuoZM7R9d7gwFkhnmQ=="; - String public_key="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsRU1//mlUZ9h0KP1P0ck/y5lPmDUkgNz9fXhZ9QRK2ZlrwnweYC6abOYauy5/Q2yQEjmWO41DfIUEJcejun2yq0hFJ8vz+BiKzEK7jkaHJfm1+MAQ06Y0QzCsPEgTpLiM/wXHvwezqVRjqvlkv6y9K4H0INyWcMi+1BpM0HWdyVeTDxYAG6grn9k6yLfPrqe0zZmVhRUxxQqkf/opZFjRDPQVpsqWU4kICh6/32J83SMPisvdJ7Ad5DJQnGNR/GCQ4tF2rAX/DEi3xuC6+JjIH+CbGYDQq+ovLNXNIS9se80kNRn0ge9guij91u9+JOF/sSMUrf66aUeMS41pZ3+8QIDAQAB"; - 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/sc545/pay/main/MainController.java b/src/main/java/com/demo/payController.java similarity index 83% rename from src/sc545/pay/main/MainController.java rename to src/main/java/com/demo/payController.java index ef5598f..5e2cd0b 100644 --- a/src/sc545/pay/main/MainController.java +++ b/src/main/java/com/demo/payController.java @@ -1,4 +1,4 @@ -package sc545.pay.main; +package com.demo; import java.util.HashMap; import java.util.Map; @@ -6,6 +6,8 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.utils.DBUtil; +import com.utils.Utils; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -13,21 +15,16 @@ import org.springframework.web.bind.annotation.RestController; -import sc545.pay.utils.DBUtil; -import sc545.pay.utils.GsonUtils; -import sc545.pay.utils.Utils; - - @CrossOrigin(origins = "*", maxAge = 3600) +@RequestMapping(value="/pay",produces="text/html;charset=UTF-8") @RestController -public class MainController { +public class payController { /** * 获取付款码 - * @param param * @param request * @param response * @return @@ -42,10 +39,10 @@ public class MainController { double num = Utils.getNumDouble(n); if(num<0.01||num>2000) return "{\"errcode\":\"-1\",\"msg\":\"0<金额<2000\"}"; - core core=new core(); - HashMap order = core.createOrder(num, t); + alipay_core alipay_core =new alipay_core(); + HashMap order = alipay_core.createOrder(num, t); - return GsonUtils.ObjectToJson(order); + return Utils.ObjectToJson(order); } @@ -64,10 +61,10 @@ public class MainController { ) { - core core=new core(); - Map order = core.queryOrder(id); + alipay_core alipay_core =new alipay_core(); + Map order = alipay_core.queryOrder(id); - return GsonUtils.ObjectToJson(order); + return Utils.ObjectToJson(order); } /** @@ -85,8 +82,8 @@ public class MainController { ) { - core core=new core(); - Map order = core.queryOrder(id); + alipay_core alipay_core =new alipay_core(); + Map order = alipay_core.queryOrder(id); if(order!=null){ if("3".equals(order.get("ostatus")+"")||"4".equals(order.get("ostatus")+"")) return "{\"msg\":\"已支付\"}"; @@ -111,7 +108,7 @@ public class MainController { ) { DBUtil db = new DBUtil(); - core core=new core(); + alipay_core alipay_core =new alipay_core(); //只有支付成功后,支付宝才会回调应用接口,可直接获取支付宝响应的参数 String order_id = param.get("out_trade_no"); @@ -124,7 +121,7 @@ public class MainController { //检查数据库是否有本数据,有就修改,没有新增 int i = db.execSql("select * from _orders where out_trade_no = ?", new String[]{order_id}); - if(i>0) core.updateOrder(order_id); + if(i>0) alipay_core.updateOrder(order_id); else{ db.execUpdate("insert into _orders(out_trade_no,trade_no,otitle,onum,ostatus,zfbuser,paynum,getnum,zfbuserid,getbody) " + "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()}); diff --git a/src/sc545/pay/utils/DBUtil.java b/src/main/java/com/utils/DBUtil.java similarity index 86% rename from src/sc545/pay/utils/DBUtil.java rename to src/main/java/com/utils/DBUtil.java index c0b5049..c23a183 100644 --- a/src/sc545/pay/utils/DBUtil.java +++ b/src/main/java/com/utils/DBUtil.java @@ -1,4 +1,4 @@ -package sc545.pay.utils; +package com.utils; import java.lang.reflect.Field; import java.sql.Connection; @@ -16,11 +16,11 @@ import java.util.Map; public class DBUtil { // 四大金刚 - String dname = ReadTxt.getSetting(null, "setting.ini", "MySqlName","test"); + String dname = "scbox"; String driver = "com.mysql.jdbc.Driver";// 驱动名称 - String url = "jdbc:mysql://"+ReadTxt.getSetting(null, "setting.ini", "MySqlIP","127.0.0.1")+":"+ReadTxt.getSetting(null, "setting.ini", "MySqlPort","3306")+"/"+dname+"?useUnicode=false&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接 - String username = ReadTxt.getSetting(null, "setting.ini", "MySqlUserName","root");// 用户名 - String password = ReadTxt.getSetting(null, "setting.ini", "MySqlPassWord","cheng355217");// 密码 + 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";// 密码 // 三剑客 Connection con = null;// 连接对象 @@ -223,20 +223,20 @@ public class DBUtil { name+="`"+fields[j].getName() + "`,"; // 字段值 - if (fields[j].getType().getName().equals(java.lang.String.class.getName())) {//String + if (fields[j].getType().getName().equals(String.class.getName())) {//String try { value[j]=(fields[j].get(obj)); } catch (Exception e) {e.printStackTrace(); } - } else if (fields[j].getType().getName().equals(java.lang.Long.class.getName()) || fields[j].getType().getName().equals("long")) {//int/long + } else if (fields[j].getType().getName().equals(Long.class.getName()) || fields[j].getType().getName().equals("long")) {//int/long try { value[j]=(fields[j].getLong(obj)); } catch (Exception e) {e.printStackTrace();} - }else if (fields[j].getType().getName().equals(java.lang.Float.class.getName()) || fields[j].getType().getName().equals("float")) {//float/double + }else if (fields[j].getType().getName().equals(Float.class.getName()) || fields[j].getType().getName().equals("float")) {//float/double try { value[j]=(fields[j].getFloat(obj)); diff --git a/src/main/java/com/utils/Utils.java b/src/main/java/com/utils/Utils.java new file mode 100644 index 0000000..255457f --- /dev/null +++ b/src/main/java/com/utils/Utils.java @@ -0,0 +1,142 @@ +package com.utils; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.common.BitMatrix; +import org.apache.commons.codec.binary.Base64; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +public class Utils { + + //线程安全的 + private static final Gson GSON; + private static final Gson GSON_NULL; // 不过滤空值 + static { + GSON = new GsonBuilder().enableComplexMapKeySerialization() //当Map的key为复杂对象时,需要开启该方法 +// .serializeNulls() //当字段值为空或null时,依然对该字段进行转换 +// .excludeFieldsWithoutExposeAnnotation()//打开Export注解,但打开了这个注解,副作用,要转换和不转换都要加注解 + .setDateFormat("yyyy-MM-dd HH:mm:ss")//序列化日期格式 "yyyy-MM-dd" +// .setPrettyPrinting() //自动格式化换行 + .disableHtmlEscaping() //防止特殊字符出现乱码 + .create(); + GSON_NULL = new GsonBuilder().enableComplexMapKeySerialization() //当Map的key为复杂对象时,需要开启该方法 + .serializeNulls() //当字段值为空或null时,依然对该字段进行转换 +// .excludeFieldsWithoutExposeAnnotation()//打开Export注解,但打开了这个注解,副作用,要转换和不转换都要加注解 + .setDateFormat("yyyy-MM-dd HH:mm:ss")//序列化日期格式 "yyyy-MM-dd" +// .setPrettyPrinting() //自动格式化换行 + .disableHtmlEscaping() //防止特殊字符出现乱码 + .create(); + } + + public static String ObjectToJson(Object object) { + return GSON.toJson(object); + } + + public static double getNumDouble(String str) { + + str = str.trim(); + String str2 = ""; + if (str != null && !"".equals(str)) { + for (int i = 0; i < str.length(); i++) { + if ((str.charAt(i) >= 48 && str.charAt(i) <= 57) + || str.charAt(i) == 43 || str.charAt(i) == 45 + || str.charAt(i) == 46) { + str2 += str.charAt(i); + } + } + } + boolean isok = true; + for (int i = 1; i < str2.length(); i++) { + if (str2.charAt(i) == 43 || str2.charAt(i) == 45) { + isok = false; + } + } + if (!isok) + return Double.valueOf(getNum(str)); + if ("".equals(str2)) + str2 = "0"; + return Double.valueOf(str2); + } + + private static double getNum(String str) { + str = str.trim(); + String str2 = ""; + if (str != null && !"".equals(str)) { + for (int i = 0; i < str.length(); i++) { + if (str.charAt(i) >= 48 && str.charAt(i) <= 57) { + str2 += str.charAt(i); + } + } + } + if ("".equals(str2)) + str2 = "-1"; + return Long.valueOf(str2); + } + + public static long randomNum(int min, int max) { + int num = new Random().nextInt(max - min) + min; + return num; + } + + public static String QrImgB64(String content,int widthHeight) { + try { + MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); + Map hints = new HashMap(); + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + BitMatrix bitMatrix= multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, widthHeight, widthHeight, hints); + bitMatrix= deleteQRWhite(bitMatrix); + BufferedImage imgbuf = toBufferedImage(bitMatrix); + ByteArrayOutputStream os = new ByteArrayOutputStream();//新建流。 + ImageIO.write(imgbuf, "jpg", os);//利用ImageIO类提供的write方法,将bi以png图片的数据模式写入流。 + byte b[] = os.toByteArray();//从流中获取数据数组。 + String str = Base64.encodeBase64String(b); + return str; + + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + + public static final int BLACK = 0xFF000000; + public static final int WHITE = 0xFFFFFFFF; + public static BufferedImage toBufferedImage(BitMatrix matrix) { + int width = matrix.getWidth(); + int height = matrix.getHeight(); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE); + } + } + return image; + } + + public static BitMatrix deleteQRWhite(BitMatrix matrix) { + int[] rec = matrix.getEnclosingRectangle(); + int resWidth = rec[2] + 1; + int resHeight = rec[3] + 1; + + BitMatrix resMatrix = new BitMatrix(resWidth, resHeight); + resMatrix.clear(); + for (int i = 0; i < resWidth; i++) { + for (int j = 0; j < resHeight; j++) { + if (matrix.get(i + rec[0], j + rec[1])) + resMatrix.set(i, j); + } + } + return resMatrix; + } + +} diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml new file mode 100644 index 0000000..56d15a1 --- /dev/null +++ b/src/main/resources/applicationContext.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml new file mode 100644 index 0000000..897626b --- /dev/null +++ b/src/main/resources/spring-mvc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9d9a415 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,35 @@ + + + + Archetype Created Web Application + + contextConfigLocation + classpath:applicationContext.xml + + + org.springframework.web.context.ContextLoaderListener + + + dispatcher + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + classpath:spring-mvc.xml + + 1 + + + + 100000000 + + 200000000 + + + + + dispatcher + / + + + + diff --git a/WebRoot/index.html b/src/main/webapp/index.html similarity index 91% rename from WebRoot/index.html rename to src/main/webapp/index.html index 214f611..fb6fcf0 100644 --- a/WebRoot/index.html +++ b/src/main/webapp/index.html @@ -5,7 +5,7 @@ - 支付测试- 顺诚百宝箱 + 支付测试 "); - out.println(""); - out.println(""); - out.println(" "); - out.println(" "); - out.println(" "); - out.println(" "); - out.println(" "); - out.println(" "); - out.println(" " + context + ""); - out.println(" 5秒后自动跳转"); - out.println(" 立即前往"); - out.println(" "); - out.println(" "); - out.println(""); - out.println("
"); - out.println(" "); - out.println("
5秒后自动跳转