├── .gitignore ├── README.md ├── images ├── WeChat.png └── alipay.png ├── pay-platform ├── .gitignore ├── README.md ├── lib │ ├── alipay-sdk-1.5.jar │ ├── aopalliance-1.0.jar │ ├── aspectjweaver-1.8.6.jar │ ├── commons-beanutils-1.8.0.jar │ ├── commons-codec-1.6.jar │ ├── commons-collections-3.2.1.jar │ ├── commons-dbcp-1.4.jar │ ├── commons-fileupload-1.2.2.jar │ ├── commons-httpclient-3.1.jar │ ├── commons-io-2.4.jar │ ├── commons-lang-2.6.jar │ ├── commons-lang3-3.1.jar │ ├── commons-logging-1.1.1.jar │ ├── commons-pool-1.5.4.jar │ ├── dom4j-1.6.1.jar │ ├── ezmorph-1.0.6.jar │ ├── fastjson-1.1.34.jar │ ├── gson-2.3.1.jar │ ├── guava-14.0.1.jar │ ├── httpclient-4.3.4.jar │ ├── httpcore-4.3.2.jar │ ├── jackson-annotations-2.6.0.jar │ ├── jackson-core-2.6.0.jar │ ├── jackson-databind-2.6.0.jar │ ├── jackson-dataformat-xml-2.6.0.jar │ ├── jackson-module-jaxb-annotations-2.6.0.jar │ ├── jdom-1.1.jar │ ├── joda-time-2.2.jar │ ├── json-lib-2.4-jdk15.jar │ ├── jstl-1.2.jar │ ├── log4j-1.2.16.jar │ ├── mybatis-3.4.0.jar │ ├── mybatis-spring-1.3.0.jar │ ├── mysql-connector-java-5.1.26.jar │ ├── pay-api-model-1.0-SNAPSHOT.jar │ ├── pay-service-1.0-SNAPSHOT.jar │ ├── servlet-api-2.5.jar │ ├── spring-aop-4.2.0.RELEASE.jar │ ├── spring-aspects-4.2.0.RELEASE.jar │ ├── spring-beans-4.2.0.RELEASE.jar │ ├── spring-context-4.2.0.RELEASE.jar │ ├── spring-context-support-4.2.0.RELEASE.jar │ ├── spring-core-4.2.0.RELEASE.jar │ ├── spring-expression-4.2.0.RELEASE.jar │ ├── spring-instrument-4.2.0.RELEASE.jar │ ├── spring-instrument-tomcat-4.2.0.RELEASE.jar │ ├── spring-jdbc-4.2.0.RELEASE.jar │ ├── spring-jms-4.2.0.RELEASE.jar │ ├── spring-messaging-4.2.0.RELEASE.jar │ ├── spring-orm-4.2.0.RELEASE.jar │ ├── spring-test-4.2.0.RELEASE.jar │ ├── spring-tx-4.2.0.RELEASE.jar │ ├── spring-web-4.2.0.RELEASE.jar │ ├── spring-webmvc-4.2.0.RELEASE.jar │ ├── springside-core-4.0.0.GA.jar │ ├── stax2-api-3.1.4.jar │ ├── web-common-1.0-SNAPSHOT.jar │ └── xml-apis-1.0.b2.jar ├── pay-api-model │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── kk │ │ ├── api │ │ ├── ApiException.java │ │ ├── ApiRequest.java │ │ ├── ApiResponse.java │ │ ├── request │ │ │ ├── PayQueryRequest.java │ │ │ ├── PayRequest.java │ │ │ ├── PayTypeRequest.java │ │ │ ├── RefundQueryRequest.java │ │ │ └── RefundRequest.java │ │ └── response │ │ │ ├── PayNotifyResponse.java │ │ │ ├── PayQueryResponse.java │ │ │ ├── PayResponse.java │ │ │ ├── PaySynResponse.java │ │ │ ├── PayTypeResponse.java │ │ │ ├── RefundQueryResponse.java │ │ │ └── RefundResponse.java │ │ ├── platform │ │ └── enums │ │ │ ├── PayException.java │ │ │ ├── PayStatus.java │ │ │ ├── PayTypeCode.java │ │ │ ├── RefundStatus.java │ │ │ ├── ResultCode.java │ │ │ └── TradeTypeCode.java │ │ ├── util │ │ ├── Base64Util.java │ │ ├── BeanUtil.java │ │ ├── ConsoleLogger.java │ │ ├── DateUtil.java │ │ ├── HttpClientUtil.java │ │ ├── MD5Util.java │ │ ├── RSA.java │ │ ├── SHA1Util.java │ │ ├── SignUtils.java │ │ ├── URLUtil.java │ │ ├── XmlUtil.java │ │ └── sign.md │ │ └── validate │ │ ├── Assert.java │ │ ├── CollectionUtils.java │ │ ├── ObjectUtils.java │ │ └── StringUtils.java ├── pay-api │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── kk │ │ │ │ └── controller │ │ │ │ ├── api │ │ │ │ ├── AliRefundPwdTestController.java │ │ │ │ ├── ConfigController.java │ │ │ │ ├── PayController.java │ │ │ │ └── RefundController.java │ │ │ │ └── notify │ │ │ │ ├── AliNotifyController.java │ │ │ │ └── WechatPayNotifyController.java │ │ ├── resources │ │ │ ├── Configuration.xml │ │ │ ├── applicationContext-core.xml │ │ │ └── web.properties │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── ebay-servlet.xml │ │ │ ├── log4j.xml │ │ │ └── web.xml │ │ │ └── views │ │ │ └── errors │ │ │ ├── 404.jsp │ │ │ └── error.jsp │ │ └── test │ │ └── java │ │ └── com │ │ └── kk │ │ └── test │ │ ├── api │ │ ├── ConfigTest.java │ │ ├── PayTest.java │ │ ├── RefundTest.java │ │ └── WeChatMicroPayTest.java │ │ └── util │ │ ├── BeanUtilTest.java │ │ ├── Consts.java │ │ ├── JsonTest.java │ │ ├── RequestTest.java │ │ └── ResponseTest.java ├── pay-caller │ ├── README.md │ ├── cashier.jsp │ ├── images │ │ ├── icon-back.png │ │ └── loading.gif │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── kk │ │ │ ├── controller │ │ │ ├── AliH5PayController.java │ │ │ ├── NotifyController.java │ │ │ └── WeChatH5PayController.java │ │ │ └── util │ │ │ └── Consts.java │ │ ├── resources │ │ ├── applicationContext-core.xml │ │ └── web.properties │ │ └── webapp │ │ ├── WEB-INF │ │ ├── ebay-servlet.xml │ │ ├── log4j.xml │ │ └── web.xml │ │ └── views │ │ ├── alipay │ │ ├── alipay.jsp │ │ ├── ap.js │ │ └── pay.jsp │ │ ├── errors │ │ ├── 404.jsp │ │ └── error.jsp │ │ └── weixin │ │ └── pay.jsp ├── pay-service │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── kk │ │ ├── alipay │ │ ├── client │ │ │ ├── DefaultAliPayParser.java │ │ │ └── MyDefaultAliPayClient.java │ │ ├── exception │ │ │ └── AliPayException.java │ │ ├── response │ │ │ ├── AliPayNotifyResponse.java │ │ │ ├── AliPayRefundNotifyResponse.java │ │ │ └── AliPayResponse.java │ │ └── service │ │ │ ├── AliPayService.java │ │ │ └── AliRefundService.java │ │ ├── api │ │ └── service │ │ │ ├── AbstractPayService.java │ │ │ ├── ConfigService.java │ │ │ ├── InternalPayService.java │ │ │ ├── InternalRefundService.java │ │ │ ├── PayService.java │ │ │ └── RefundService.java │ │ ├── platform │ │ ├── dao │ │ │ ├── FileResourceDao.java │ │ │ ├── MyBatisRepository.java │ │ │ ├── PayChannelDao.java │ │ │ ├── PayMerchantChannelDao.java │ │ │ ├── PayMerchantDao.java │ │ │ ├── PayOrderDao.java │ │ │ └── RefundOrderDao.java │ │ ├── model │ │ │ ├── FileResource.java │ │ │ ├── PayChannel.java │ │ │ ├── PayMerchant.java │ │ │ ├── PayMerchantChannel.java │ │ │ ├── PayOrder.java │ │ │ └── RefundOrder.java │ │ ├── service │ │ │ ├── FileResourceService.java │ │ │ ├── PayChannelService.java │ │ │ ├── PayMerchantChannelService.java │ │ │ ├── PayMerchantService.java │ │ │ ├── PayOrderService.java │ │ │ └── RefundOrderService.java │ │ └── utils │ │ │ └── SnUtils.java │ │ └── wechat │ │ ├── annotation │ │ ├── ApiRequestField.java │ │ └── ApiResponseField.java │ │ ├── client │ │ └── WechatPayClient.java │ │ ├── exception │ │ └── WechatPayException.java │ │ ├── model │ │ ├── SignatureItem.java │ │ ├── WechatPayMicroPayModel.java │ │ ├── WechatPayModel.java │ │ ├── WechatPayPrePayModel.java │ │ ├── WechatPayQueryModel.java │ │ ├── WechatPayRefundModel.java │ │ └── WechatPayTradeStatus.java │ │ ├── request │ │ ├── WechatPayMicroPayRequest.java │ │ ├── WechatPayPrePayRequest.java │ │ ├── WechatPayQueryRequest.java │ │ ├── WechatPayRefundRequest.java │ │ └── WechatPayRequest.java │ │ ├── response │ │ ├── ResultCode.java │ │ ├── WechatPayMicroPayResponse.java │ │ ├── WechatPayPayNotifyResponse.java │ │ ├── WechatPayPrePayResponse.java │ │ ├── WechatPayQueryResponse.java │ │ ├── WechatPayRefundResponse.java │ │ └── WechatPayResponse.java │ │ ├── service │ │ ├── WechatPayService.java │ │ └── WechatRefundService.java │ │ └── util │ │ └── WeixinUtil.java ├── pom.xml ├── sql │ ├── file_resource.sql │ ├── pay_channel.sql │ ├── pay_merchant.sql │ ├── pay_merchant_channel.sql │ ├── pay_order.sql │ └── refund_order.sql ├── web-common │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ ├── kk │ │ └── utils │ │ │ ├── IPUtil.java │ │ │ ├── JsonUtil.java │ │ │ ├── LocalIPUtil.java │ │ │ ├── Model2StringUtil.java │ │ │ └── WebPropertiesUtil.java │ │ └── thirdparty │ │ └── spring │ │ └── ex │ │ └── SimpleMappingExceptionResolver.java └── 支付宝私钥公钥.txt └── pay ├── README.md ├── alipay.md ├── pom.xml ├── src └── main │ ├── java │ └── com │ │ ├── alipay │ │ ├── config │ │ │ └── AlipayConfig.java │ │ ├── demo │ │ │ └── trade │ │ │ │ ├── config │ │ │ │ ├── Configs.java │ │ │ │ └── Constants.java │ │ │ │ ├── model │ │ │ │ ├── ExtendParams.java │ │ │ │ ├── GoodsDetail.java │ │ │ │ ├── TradeStatus.java │ │ │ │ ├── builder │ │ │ │ │ ├── AlipayHeartbeatSynContentBuilder.java │ │ │ │ │ ├── AlipayTradeCancelCententBuilder.java │ │ │ │ │ ├── AlipayTradePayContentBuilder.java │ │ │ │ │ ├── AlipayTradePrecreateContentBuilder.java │ │ │ │ │ ├── AlipayTradeQueryCententBuilder.java │ │ │ │ │ ├── AlipayTradeRefundContentBuilder.java │ │ │ │ │ └── RequestBuilder.java │ │ │ │ ├── hb │ │ │ │ │ ├── EquipStatus.java │ │ │ │ │ ├── EquipStatusAdapter.java │ │ │ │ │ ├── ExceptionInfo.java │ │ │ │ │ ├── ExceptionInfoAdapter.java │ │ │ │ │ ├── HbStatus.java │ │ │ │ │ ├── PosTradeInfo.java │ │ │ │ │ ├── Product.java │ │ │ │ │ ├── SysTradeInfo.java │ │ │ │ │ ├── TradeInfo.java │ │ │ │ │ ├── TradeInfoAdapter.java │ │ │ │ │ └── Type.java │ │ │ │ └── result │ │ │ │ │ ├── AlipayF2FPayResult.java │ │ │ │ │ ├── AlipayF2FPrecreateResult.java │ │ │ │ │ ├── AlipayF2FQueryResult.java │ │ │ │ │ ├── AlipayF2FRefundResult.java │ │ │ │ │ └── Result.java │ │ │ │ ├── service │ │ │ │ ├── AlipayMonitorService.java │ │ │ │ ├── AlipayTradeService.java │ │ │ │ └── impl │ │ │ │ │ ├── AbsAlipayService.java │ │ │ │ │ ├── AbsAlipayTradeService.java │ │ │ │ │ ├── AlipayMonitorServiceImpl.java │ │ │ │ │ ├── AlipayTradeServiceImpl.java │ │ │ │ │ ├── AlipayTradeWithHBServiceImpl.java │ │ │ │ │ └── hb │ │ │ │ │ ├── AbsHbRunner.java │ │ │ │ │ ├── HbListener.java │ │ │ │ │ ├── HbQueue.java │ │ │ │ │ └── TradeListener.java │ │ │ │ └── utils │ │ │ │ ├── GsonFactory.java │ │ │ │ ├── Utils.java │ │ │ │ └── ZxingUtils.java │ │ ├── read.me │ │ ├── sign │ │ │ ├── Base64.java │ │ │ └── RSA.java │ │ └── util │ │ │ ├── AlipayCore.java │ │ │ ├── AlipayNotify.java │ │ │ ├── AlipaySubmit.java │ │ │ ├── UtilDate.java │ │ │ └── httpClient │ │ │ ├── HttpProtocolHandler.java │ │ │ ├── HttpRequest.java │ │ │ ├── HttpResponse.java │ │ │ └── HttpResultType.java │ │ └── kk │ │ └── pay │ │ ├── alipay │ │ ├── controller │ │ │ ├── AlipayCancelController.java │ │ │ ├── AlipayH5Controller.java │ │ │ ├── AlipayQueryController.java │ │ │ ├── AlipayRefundController.java │ │ │ └── AlipayScanController.java │ │ └── service │ │ │ └── AlipayInitService.java │ │ ├── base │ │ ├── model │ │ │ ├── PayResult.java │ │ │ └── enums │ │ │ │ └── ResultCode.java │ │ └── service │ │ │ └── Validator.java │ │ ├── util │ │ ├── Base64Util.java │ │ ├── BeanUtil.java │ │ ├── DateUtil.java │ │ ├── EncryptUtil.java │ │ ├── JsonUtil.java │ │ ├── LocalIPUtil.java │ │ ├── SignUtil.java │ │ ├── ValidateUtil.java │ │ ├── WebPropertiesUtil.java │ │ ├── WeixinUtil.java │ │ └── XmlUtil.java │ │ └── weixin │ │ ├── controller │ │ ├── WeixinBillController.java │ │ ├── WeixinH5PayController.java │ │ ├── WeixinQueryPayController.java │ │ ├── WeixinRefundPayController.java │ │ └── WeixinScanPayController.java │ │ └── model │ │ ├── PayBillParam.java │ │ ├── PayNotifyResult.java │ │ ├── PayOrderParam.java │ │ ├── PayOrderResult.java │ │ ├── PayQueryParam.java │ │ ├── PayQueryResult.java │ │ ├── PayRefundParam.java │ │ ├── PayRefundQueryParam.java │ │ ├── PayRefundQueryResult.java │ │ ├── PayRefundResult.java │ │ ├── WeixinResult.java │ │ └── enums │ │ ├── PayBillField.java │ │ ├── PayOrderField.java │ │ ├── PayQueryField.java │ │ ├── PayRefundField.java │ │ ├── PayRefundQueryField.java │ │ └── TradeType.java │ ├── resources │ ├── Configuration.xml │ ├── applicationContext-core.xml │ ├── web.properties │ └── zfbinfo.properties │ └── webapp │ ├── WEB-INF │ ├── ebay-servlet.xml │ ├── log4j.xml │ └── web.xml │ ├── alipay │ ├── alipayapi.jsp │ ├── index.jsp │ ├── notify_url.jsp │ └── return_url.jsp │ ├── index.jsp │ └── views │ ├── alipay │ ├── alipay.jsp │ ├── ap.js │ └── pay.jsp │ └── weixin │ └── pay.jsp ├── target └── pay │ ├── WEB-INF │ ├── ebay-servlet.xml │ ├── lib │ │ ├── activation-1.1.jar │ │ ├── alipay-sdk-1.5.jar │ │ ├── aopalliance-1.0.jar │ │ ├── aspectjrt-1.7.0.jar │ │ ├── aspectjweaver-1.7.0.jar │ │ ├── cglib-nodep-2.1_3.jar │ │ ├── commons-beanutils-1.8.0.jar │ │ ├── commons-beanutils-core-1.8.0.jar │ │ ├── commons-codec-1.6.jar │ │ ├── commons-collections-3.2.1.jar │ │ ├── commons-configuration-1.6.jar │ │ ├── commons-dbcp-1.4.jar │ │ ├── commons-digester-1.8.jar │ │ ├── commons-fileupload-1.2.2.jar │ │ ├── commons-httpclient-3.1.jar │ │ ├── commons-io-2.4.jar │ │ ├── commons-lang-2.6.jar │ │ ├── commons-lang3-3.1.jar │ │ ├── commons-logging-1.1.1.jar │ │ ├── commons-pool-1.5.4.jar │ │ ├── core-2.1.jar │ │ ├── dom4j-1.6.1.jar │ │ ├── ezmorph-1.0.6.jar │ │ ├── fastjson-1.1.34.jar │ │ ├── freemarker-2.3.20.jar │ │ ├── geohash-1.0.13.jar │ │ ├── gson-2.3.1.jar │ │ ├── guava-14.0.1.jar │ │ ├── httpclient-4.3.4.jar │ │ ├── httpcore-4.3.2.jar │ │ ├── jackson-core-asl-1.8.4.jar │ │ ├── jackson-mapper-asl-1.8.4.jar │ │ ├── javase-2.1.jar │ │ ├── jdom-1.1.jar │ │ ├── joda-time-2.2.jar │ │ ├── json-lib-2.4-jdk15.jar │ │ ├── jsoup-1.7.2.jar │ │ ├── jstl-1.2.jar │ │ ├── log4j-1.2.16.jar │ │ ├── mail-1.4.jar │ │ ├── mybatis-3.2.1.jar │ │ ├── mybatis-spring-1.1.1.jar │ │ ├── mysql-connector-java-5.1.26.jar │ │ ├── poi-3.10.1.jar │ │ ├── spring-aop-3.1.2.RELEASE.jar │ │ ├── spring-asm-3.1.2.RELEASE.jar │ │ ├── spring-beans-3.1.2.RELEASE.jar │ │ ├── spring-context-3.1.2.RELEASE.jar │ │ ├── spring-context-support-3.1.2.RELEASE.jar │ │ ├── spring-core-3.1.2.RELEASE.jar │ │ ├── spring-expression-3.1.2.RELEASE.jar │ │ ├── spring-jdbc-3.1.1.RELEASE.jar │ │ ├── spring-tx-3.1.1.RELEASE.jar │ │ ├── spring-web-3.1.2.RELEASE.jar │ │ ├── spring-webmvc-3.1.2.RELEASE.jar │ │ └── xml-apis-1.0.b2.jar │ ├── log4j.xml │ └── web.xml │ ├── alipay │ ├── alipayapi.jsp │ ├── index.jsp │ ├── notify_url.jsp │ └── return_url.jsp │ ├── index.jsp │ └── views │ ├── alipay │ ├── alipay.jsp │ ├── ap.js │ └── pay.jsp │ └── weixin │ └── pay.jsp └── weixin.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | # Package Files # 3 | *.war 4 | *.ear 5 | #eclipse 6 | .settings 7 | .classpath 8 | .project 9 | #target 10 | classes 11 | 12 | # idea 13 | *.iml 14 | *.eml 15 | *.imd 16 | *.ipr 17 | *.iws 18 | #idea 19 | .iml 20 | .im 21 | .idea 22 | run_task 23 | .DS_Store 24 | .tomcatplugin 25 | .settings 26 | META-INF 27 | .mymetadata 28 | .externalToolBuilders 29 | .mymetadata 30 | out 31 | logs 32 | classes 33 | 34 | *.war 35 | maven-archiver 36 | generated-sources 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 微信支付,支付宝支付 2 | 3 | ## pay 目录为微信、支付宝支付接口联调 4 | ## pay-platform 为支付平台,集成微信、支付宝支付,通过http形式提供给业务方调用,推荐!! -------------------------------------------------------------------------------- /images/WeChat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/images/WeChat.png -------------------------------------------------------------------------------- /images/alipay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/images/alipay.png -------------------------------------------------------------------------------- /pay-platform/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | # Package Files # 3 | *.war 4 | *.ear 5 | #eclipse 6 | .settings 7 | .classpath 8 | .project 9 | #target 10 | classes 11 | 12 | # idea 13 | *.iml 14 | *.eml 15 | *.imd 16 | *.ipr 17 | *.iws 18 | #idea 19 | .iml 20 | .im 21 | .idea 22 | run_task 23 | .DS_Store 24 | .tomcatplugin 25 | .settings 26 | META-INF 27 | .mymetadata 28 | .externalToolBuilders 29 | .mymetadata 30 | out 31 | logs 32 | classes 33 | 34 | *.war 35 | maven-archiver 36 | generated-sources 37 | target 38 | -------------------------------------------------------------------------------- /pay-platform/README.md: -------------------------------------------------------------------------------- 1 | # 支付平台 2 | 3 | #### web-common 4 | * 一些公共的spring组件,util 5 | 6 | #### pay-api 7 | * 支付平台 8 | 9 | #### pay-service 10 | * 支付逻辑, 微信支付,支付宝支付 11 | 12 | #### pay-api-model 13 | * ***支付平台对外提供的接口参数和返回值类型,以及签名计算法方式, 业务方引用 此工程, 调用样例均在 pay-api的test目录和pay-caller工程。*** 14 | 15 | #### pay-caller 16 | * 业务方,通过http请求或者封装好的http的sdk 调用支付平台 17 | 18 | #### pay-admin 19 | * 支付平台后台 20 | 21 | 22 | #### 支付平台主要功能 23 | * 统一下单,网页支付,扫码支付,app支付 24 | * 支付成功异步通知 25 | * 订单查询,同步payOrder 26 | * 订单退款,查询退款 27 | * 后台系统 28 | * 微信刷卡支付 29 | * api以已经调通,但是没有集成到支付平台(如果需要客户输入密码,则订单支付状态为支付中,需要支付平台定时轮询状态,直到成功或超时) 30 | 31 | #### 主要模块 32 | * 商户管理,业务方接入 33 | * 渠道管理(微信,支付宝支付账号), 商户与渠道做关联 34 | * 对账管理 35 | * 订单管理(订单后台) 36 | * 退款管理 37 | * 安全管理(加签名) 38 | * 日志管理(异常日志分析) 39 | 40 | 41 | 42 | #### 注意事项 43 | * 微信退款 需要数字证书 44 | * [支付宝常见注意事项](https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.IH0sUA&treeId=26&articleId=103279&docType=1) 45 | * 支付宝支付需要依赖 [alipay-sdk](https://doc.open.alipay.com/doc2/detail?treeId=54&articleId=103419&docType=1#s2) 46 | * 支付宝支付 需要预先在支付宝开放平台设置 支付宝公钥和私钥,[文档](https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.7W7fUQ&treeId=44&articleId=103242&docType=1) 47 | * 支付宝开放平台一个账号可以创建多个应用,如当面付(扫码支付), 手机网站支付, app支付, 共用一个合作伙伴身份(PID) 48 | * 账户及秘钥管理-PID和公钥管理-合作伙伴秘钥 49 | * pid一致,但是appId 每个应用一个 50 | * 支付宝如果创建应用,则使用 合作伙伴秘钥里面的 开发者公钥(商户公钥)和支付宝公钥 51 | * [查看RSA商户公钥与支付宝公钥](https://doc.open.alipay.com/doc2/detail?treeId=58&articleId=103546&docType=1) 52 | * ***支付宝支付采用了RSA加密签名的安全通信机制,开发者可以通过支付宝的公钥验证消息的来源,同时使用自己的私钥(商户私钥)进行信息加密*** 53 | * ***集成支付宝支付,我们需要在本地留有 商户私钥,支付宝公钥, 在开放平台设置 商户公钥。*** 54 | * ***支付宝私钥,公钥由开放平台提供。*** 55 | * ***支付宝公钥不用设置,申请开通支付宝开放平台后,支付宝会给我们分配一个支付宝公钥,在 账户及秘钥管理-PID和公钥管理-开放平台秘钥, 这个秘钥用于支付宝开放平台,如服务窗口等服务。*** 56 | * ***如果创建应用,则在 账户及秘钥管理-PID和公钥管理-合作伙伴秘钥 , 设置 商户公钥(开发者公钥)后,支付宝公钥会自动分配给我们。*** 57 | * ***支付宝推荐使用rsa加密方式。*** 58 | * ***eb 扫码使用的时候 服务窗应用 开放平台秘钥,wap和app支付使用的合作伙伴秘钥*** 59 | -------------------------------------------------------------------------------- /pay-platform/lib/alipay-sdk-1.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/alipay-sdk-1.5.jar -------------------------------------------------------------------------------- /pay-platform/lib/aopalliance-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/aopalliance-1.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/aspectjweaver-1.8.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/aspectjweaver-1.8.6.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-beanutils-1.8.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-beanutils-1.8.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-codec-1.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-codec-1.6.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-collections-3.2.1.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-dbcp-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-dbcp-1.4.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-fileupload-1.2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-fileupload-1.2.2.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-httpclient-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-httpclient-3.1.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-io-2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-io-2.4.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-lang-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-lang-2.6.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-lang3-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-lang3-3.1.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /pay-platform/lib/commons-pool-1.5.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/commons-pool-1.5.4.jar -------------------------------------------------------------------------------- /pay-platform/lib/dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/dom4j-1.6.1.jar -------------------------------------------------------------------------------- /pay-platform/lib/ezmorph-1.0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/ezmorph-1.0.6.jar -------------------------------------------------------------------------------- /pay-platform/lib/fastjson-1.1.34.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/fastjson-1.1.34.jar -------------------------------------------------------------------------------- /pay-platform/lib/gson-2.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/gson-2.3.1.jar -------------------------------------------------------------------------------- /pay-platform/lib/guava-14.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/guava-14.0.1.jar -------------------------------------------------------------------------------- /pay-platform/lib/httpclient-4.3.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/httpclient-4.3.4.jar -------------------------------------------------------------------------------- /pay-platform/lib/httpcore-4.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/httpcore-4.3.2.jar -------------------------------------------------------------------------------- /pay-platform/lib/jackson-annotations-2.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/jackson-annotations-2.6.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/jackson-core-2.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/jackson-core-2.6.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/jackson-databind-2.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/jackson-databind-2.6.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/jackson-dataformat-xml-2.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/jackson-dataformat-xml-2.6.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/jackson-module-jaxb-annotations-2.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/jackson-module-jaxb-annotations-2.6.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/jdom-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/jdom-1.1.jar -------------------------------------------------------------------------------- /pay-platform/lib/joda-time-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/joda-time-2.2.jar -------------------------------------------------------------------------------- /pay-platform/lib/json-lib-2.4-jdk15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/json-lib-2.4-jdk15.jar -------------------------------------------------------------------------------- /pay-platform/lib/jstl-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/jstl-1.2.jar -------------------------------------------------------------------------------- /pay-platform/lib/log4j-1.2.16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/log4j-1.2.16.jar -------------------------------------------------------------------------------- /pay-platform/lib/mybatis-3.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/mybatis-3.4.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/mybatis-spring-1.3.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/mybatis-spring-1.3.0.jar -------------------------------------------------------------------------------- /pay-platform/lib/mysql-connector-java-5.1.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/mysql-connector-java-5.1.26.jar -------------------------------------------------------------------------------- /pay-platform/lib/pay-api-model-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/pay-api-model-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /pay-platform/lib/pay-service-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/pay-service-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /pay-platform/lib/servlet-api-2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/servlet-api-2.5.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-aop-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-aop-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-aspects-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-aspects-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-beans-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-beans-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-context-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-context-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-context-support-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-context-support-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-core-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-core-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-expression-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-expression-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-instrument-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-instrument-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-instrument-tomcat-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-instrument-tomcat-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-jdbc-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-jdbc-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-jms-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-jms-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-messaging-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-messaging-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-orm-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-orm-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-test-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-test-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-tx-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-tx-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-web-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-web-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/spring-webmvc-4.2.0.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/spring-webmvc-4.2.0.RELEASE.jar -------------------------------------------------------------------------------- /pay-platform/lib/springside-core-4.0.0.GA.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/springside-core-4.0.0.GA.jar -------------------------------------------------------------------------------- /pay-platform/lib/stax2-api-3.1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/stax2-api-3.1.4.jar -------------------------------------------------------------------------------- /pay-platform/lib/web-common-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/web-common-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /pay-platform/lib/xml-apis-1.0.b2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/lib/xml-apis-1.0.b2.jar -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/ApiException.java: -------------------------------------------------------------------------------- 1 | package com.kk.api; 2 | 3 | public class ApiException extends Exception { 4 | int code; 5 | 6 | public ApiException(int code, String message) { 7 | super(message); 8 | this.code = code; 9 | } 10 | 11 | public int getCode() { 12 | return code; 13 | } 14 | 15 | public void setCode(int code) { 16 | this.code = code; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/ApiRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.api; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.kk.validate.Assert; 5 | 6 | /** 7 | * 业务方传递的参数, 8 | * 不能够传 request中没有的字段,否则服务端采用bean方式来计算签名,bean中无此字段,计算签名会有问题, 9 | * 采用json来计算签名没有问题,但是在服务端一般没有采用此种方式, 接口方式和参数,一旦定下来基本上就不再改。 10 | *

11 | * Request中 尽量使用基本类型和Date, 如果使用自定义类,需要重写toString方法。 12 | *

13 | * 可以使用枚举,FastJson会自动处理枚举,BeanUtil会自动调用枚举的toString方法。 14 | *

15 | * 在发起请求之前,可以调用 request.validate方法,来本地校验参数是否齐全, 16 | * 每个继承ApiRequest的类也需要实现自己的validate方法,来校验参数 17 | */ 18 | public class ApiRequest { 19 | private String merchantId; // 商户号 20 | private String sign; // 参数签名 21 | 22 | public String toJsonString() { 23 | return JSON.toJSONString(this); 24 | } 25 | 26 | public void validate() { 27 | Assert.hasLength(merchantId, validateMissMsg("merchantId")); 28 | } 29 | 30 | protected static String validateMissMsg(String fieldName) { 31 | return String.format("[Assertion failed] - %s argument miss", fieldName); 32 | } 33 | 34 | public String getMerchantId() { 35 | return merchantId; 36 | } 37 | 38 | public void setMerchantId(String merchantId) { 39 | this.merchantId = merchantId; 40 | } 41 | 42 | public String getSign() { 43 | return sign; 44 | } 45 | 46 | public void setSign(String sign) { 47 | this.sign = sign; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/ApiResponse.java: -------------------------------------------------------------------------------- 1 | package com.kk.api; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.serializer.SerializerFeature; 5 | import com.kk.platform.enums.ResultCode; 6 | 7 | /** 8 | * 返回给业务方的数据 9 | *

10 | * Response中 尽量使用基本类型, 如果使用自定义类,需要重写toString方法。 11 | *

12 | * 尽量不要使用Date, 如果使用,则需要保证返回给业务方的 date类型 转成 yyyy-MM-dd HH:mm:ss格式(response.toJsonString),与BeanUtil.object2Map保持一致。 13 | *

14 | * 返回给业务方时候,是转成json, 15 | * 计算签名的时候,调用的是 BeanUtil.object2Map方法, 里面对map,list做了处理, 16 | */ 17 | public class ApiResponse { 18 | private String code; // ResultCode:SUCCESS,FAIL, code为FAIL时候 不用校验参数 19 | private String msg; 20 | private String sign; 21 | private String merchantId; 22 | 23 | public ApiResponse() { 24 | } 25 | 26 | public ApiResponse(String code, String msg) { 27 | this.code = code; 28 | this.msg = msg; 29 | } 30 | 31 | public static boolean isSuccess(String code) { 32 | return ResultCode.SUCCESS.toString().equals(code); 33 | } 34 | 35 | public static ApiResponse createErrorResponse(String msg) { 36 | return new ApiResponse(ResultCode.FAIL.toString(), msg); 37 | } 38 | 39 | public String toJsonString() { 40 | return JSON.toJSONString(this, SerializerFeature.WriteDateUseDateFormat); 41 | } 42 | 43 | public String getCode() { 44 | return code; 45 | } 46 | 47 | public void setCode(String code) { 48 | this.code = code; 49 | } 50 | 51 | public String getMsg() { 52 | return msg; 53 | } 54 | 55 | public void setMsg(String msg) { 56 | this.msg = msg; 57 | } 58 | 59 | public String getSign() { 60 | return sign; 61 | } 62 | 63 | public void setSign(String sign) { 64 | this.sign = sign; 65 | } 66 | 67 | public String getMerchantId() { 68 | return merchantId; 69 | } 70 | 71 | public void setMerchantId(String merchantId) { 72 | this.merchantId = merchantId; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/request/PayQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.request; 2 | 3 | 4 | import com.kk.api.ApiRequest; 5 | import org.apache.commons.lang.StringUtils; 6 | 7 | /** 8 | * 优先根据 payOrderNo查询, 建议使用payOrderNo查询 9 | */ 10 | public class PayQueryRequest extends ApiRequest { 11 | private String tradePayNo;// 业务方 支付订单号, 12 | private String payOrderNo;// 用于微信,支付宝的 交易流水号, 唯一索引。 13 | 14 | 15 | @Override 16 | public void validate() { 17 | super.validate(); 18 | if (StringUtils.isBlank(tradePayNo) && StringUtils.isBlank(payOrderNo)) { 19 | throw new IllegalArgumentException("tradePayNo and payOrderNo can not be null at same time!"); 20 | } 21 | } 22 | 23 | public String getTradePayNo() { 24 | return tradePayNo; 25 | } 26 | 27 | public void setTradePayNo(String tradePayNo) { 28 | this.tradePayNo = tradePayNo; 29 | } 30 | 31 | public String getPayOrderNo() { 32 | return payOrderNo; 33 | } 34 | 35 | public void setPayOrderNo(String payOrderNo) { 36 | this.payOrderNo = payOrderNo; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/request/PayTypeRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.request; 2 | 3 | import com.kk.api.ApiRequest; 4 | 5 | /** 6 | * 查询 商户号 是否支持此支付类型 7 | */ 8 | public class PayTypeRequest extends ApiRequest { 9 | private String tradeType; // TradeTypeCode 10 | 11 | public String getTradeType() { 12 | return tradeType; 13 | } 14 | 15 | public void setTradeType(String tradeType) { 16 | this.tradeType = tradeType; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/request/RefundQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.request; 2 | 3 | 4 | import com.kk.api.ApiRequest; 5 | import org.apache.commons.lang.StringUtils; 6 | 7 | /** 8 | * 退款查询 9 | */ 10 | public class RefundQueryRequest extends ApiRequest { 11 | private String refundOrderNo;// 微信,支付宝 退款交易流水号,用于退款, 优先使用此字段 12 | private String tradeRefundNo;// 业务方 退款订单号, (退款的时候如果业务方不设置则 支付平台自己生成,返回给业务方) 13 | 14 | @Override 15 | public void validate() { 16 | super.validate(); 17 | if (StringUtils.isBlank(refundOrderNo) && StringUtils.isBlank(tradeRefundNo)) { 18 | throw new IllegalArgumentException("refundOrderNo and tradeRefundNo cannot be null at the same time!"); 19 | } 20 | } 21 | 22 | public String getRefundOrderNo() { 23 | return refundOrderNo; 24 | } 25 | 26 | public void setRefundOrderNo(String refundOrderNo) { 27 | this.refundOrderNo = refundOrderNo; 28 | } 29 | 30 | public String getTradeRefundNo() { 31 | return tradeRefundNo; 32 | } 33 | 34 | public void setTradeRefundNo(String tradeRefundNo) { 35 | this.tradeRefundNo = tradeRefundNo; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/response/PayNotifyResponse.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.response; 2 | 3 | 4 | import com.kk.api.ApiResponse; 5 | import com.kk.platform.enums.PayTypeCode; 6 | 7 | 8 | /** 9 | * 支付回调内容 10 | */ 11 | public class PayNotifyResponse extends ApiResponse { 12 | private PayTypeCode payType; 13 | private String extra; 14 | private int payAmount; 15 | private String tradePayNo; 16 | private String payOrderNo; 17 | private String status; // ResultCode:SUCCESS,FAIL 18 | private String payTime; // 支付时间, yyyy-MM-dd HH:mm:ss 19 | 20 | public PayNotifyResponse() { 21 | } 22 | 23 | public PayNotifyResponse(String code, String msg) { 24 | super(code, msg); 25 | } 26 | 27 | public PayTypeCode getPayType() { 28 | return payType; 29 | } 30 | 31 | public void setPayType(PayTypeCode payType) { 32 | this.payType = payType; 33 | } 34 | 35 | public String getExtra() { 36 | return extra; 37 | } 38 | 39 | public void setExtra(String extra) { 40 | this.extra = extra; 41 | } 42 | 43 | public int getPayAmount() { 44 | return payAmount; 45 | } 46 | 47 | public void setPayAmount(int payAmount) { 48 | this.payAmount = payAmount; 49 | } 50 | 51 | public String getTradePayNo() { 52 | return tradePayNo; 53 | } 54 | 55 | public void setTradePayNo(String tradePayNo) { 56 | this.tradePayNo = tradePayNo; 57 | } 58 | 59 | public String getPayOrderNo() { 60 | return payOrderNo; 61 | } 62 | 63 | public void setPayOrderNo(String payOrderNo) { 64 | this.payOrderNo = payOrderNo; 65 | } 66 | 67 | public String getStatus() { 68 | return status; 69 | } 70 | 71 | public void setStatus(String status) { 72 | this.status = status; 73 | } 74 | 75 | public String getPayTime() { 76 | return payTime; 77 | } 78 | 79 | public void setPayTime(String payTime) { 80 | this.payTime = payTime; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/response/PayResponse.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.response; 2 | 3 | 4 | import com.kk.api.ApiResponse; 5 | import com.kk.platform.enums.PayTypeCode; 6 | import com.kk.platform.enums.TradeTypeCode; 7 | 8 | public class PayResponse extends ApiResponse { 9 | private String tradePayNo; 10 | private String payOrderNo; 11 | private PayTypeCode payType; 12 | private TradeTypeCode tradeType; 13 | // 如果是 扫码,则返回二维码内容,string类型, 如果是wap和app,则返回 支付凭据 map类型,转成json则为JsonObject 14 | private Object credential; 15 | 16 | public String getTradePayNo() { 17 | return tradePayNo; 18 | } 19 | 20 | public void setTradePayNo(String tradePayNo) { 21 | this.tradePayNo = tradePayNo; 22 | } 23 | 24 | public String getPayOrderNo() { 25 | return payOrderNo; 26 | } 27 | 28 | public void setPayOrderNo(String payOrderNo) { 29 | this.payOrderNo = payOrderNo; 30 | } 31 | 32 | public PayTypeCode getPayType() { 33 | return payType; 34 | } 35 | 36 | public void setPayType(PayTypeCode payType) { 37 | this.payType = payType; 38 | } 39 | 40 | public TradeTypeCode getTradeType() { 41 | return tradeType; 42 | } 43 | 44 | public void setTradeType(TradeTypeCode tradeType) { 45 | this.tradeType = tradeType; 46 | } 47 | 48 | public Object getCredential() { 49 | return credential; 50 | } 51 | 52 | public void setCredential(Object credential) { 53 | this.credential = credential; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/response/PaySynResponse.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.response; 2 | 3 | import com.kk.api.ApiResponse; 4 | 5 | /** 6 | * 同步订单状态 与第三方支付状态保持一致 7 | */ 8 | public class PaySynResponse extends ApiResponse { 9 | private String status;// ResultCode:SUCCESS,FAIL, 表示订单状态是否有变化。 10 | 11 | public String getStatus() { 12 | return status; 13 | } 14 | 15 | public void setStatus(String status) { 16 | this.status = status; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/response/PayTypeResponse.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.response; 2 | 3 | 4 | import com.alibaba.fastjson.JSON; 5 | import com.kk.api.ApiResponse; 6 | import com.kk.platform.enums.PayTypeCode; 7 | import com.kk.platform.enums.TradeTypeCode; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class PayTypeResponse extends ApiResponse { 13 | private List payTypes; 14 | 15 | public PayTypeResponse() { 16 | this.payTypes = new ArrayList(); 17 | } 18 | 19 | public List getPayTypes() { 20 | return payTypes; 21 | } 22 | 23 | public void setPayTypes(List payTypes) { 24 | this.payTypes = payTypes; 25 | } 26 | 27 | public void addPayType(PayTypeCode code, TradeTypeCode tradeType) { 28 | this.payTypes.add(new PayType(code.toString(), code.getName(), tradeType.getName())); 29 | } 30 | 31 | private class PayType { 32 | private String code; // WECHAT_PAY 33 | private String name; // 微信 34 | private String tradeType; // 扫码 35 | 36 | public PayType() { 37 | } 38 | 39 | public PayType(String code, String name, String tradeType) { 40 | this.code = code; 41 | this.name = name; 42 | this.tradeType = tradeType; 43 | } 44 | 45 | public String getCode() { 46 | return code; 47 | } 48 | 49 | public void setCode(String code) { 50 | this.code = code; 51 | } 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | 61 | public String getTradeType() { 62 | return tradeType; 63 | } 64 | 65 | public void setTradeType(String tradeType) { 66 | this.tradeType = tradeType; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return JSON.toJSONString(PayType.this); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/api/response/RefundResponse.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.response; 2 | 3 | 4 | import com.kk.api.ApiResponse; 5 | 6 | /** 7 | * 订单退款 8 | */ 9 | public class RefundResponse extends ApiResponse { 10 | private String tradePayNo;// 业务方 支付订单号, 对应 payOrder表 11 | private String payOrderNo;// 用于微信,支付宝的 支付交易流水号, 唯一索引。 对应 payOrder表 12 | private String tradeRefundNo;// 业务方 退款订单号,如果业务方不设置则 支付平台自己生成 13 | private String refundOrderNo;// 微信,支付宝 退款交易流水号,用于退款 14 | private int payAmount;// 支付金额 对应 payOrder表 15 | private int refundAmount;// 退款金额 16 | 17 | public RefundResponse() { 18 | } 19 | 20 | public RefundResponse(String code, String msg) { 21 | super(code, msg); 22 | } 23 | 24 | public String getTradePayNo() { 25 | return tradePayNo; 26 | } 27 | 28 | public void setTradePayNo(String tradePayNo) { 29 | this.tradePayNo = tradePayNo; 30 | } 31 | 32 | public String getPayOrderNo() { 33 | return payOrderNo; 34 | } 35 | 36 | public void setPayOrderNo(String payOrderNo) { 37 | this.payOrderNo = payOrderNo; 38 | } 39 | 40 | public String getTradeRefundNo() { 41 | return tradeRefundNo; 42 | } 43 | 44 | public void setTradeRefundNo(String tradeRefundNo) { 45 | this.tradeRefundNo = tradeRefundNo; 46 | } 47 | 48 | public String getRefundOrderNo() { 49 | return refundOrderNo; 50 | } 51 | 52 | public void setRefundOrderNo(String refundOrderNo) { 53 | this.refundOrderNo = refundOrderNo; 54 | } 55 | 56 | public int getPayAmount() { 57 | return payAmount; 58 | } 59 | 60 | public void setPayAmount(int payAmount) { 61 | this.payAmount = payAmount; 62 | } 63 | 64 | public int getRefundAmount() { 65 | return refundAmount; 66 | } 67 | 68 | public void setRefundAmount(int refundAmount) { 69 | this.refundAmount = refundAmount; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/platform/enums/PayException.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.enums; 2 | 3 | public class PayException extends RuntimeException { 4 | public PayException() { 5 | } 6 | 7 | public PayException(String message) { 8 | super(message); 9 | } 10 | 11 | public PayException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | public PayException(Throwable cause) { 16 | super(cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/platform/enums/PayStatus.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.enums; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 支付状态 8 | */ 9 | public enum PayStatus { 10 | CREATE_PAYMENT(0, "创建支付订单"), 11 | CREATE_PAYMENT_SUCCESS(1, "创建支付订单成功"), 12 | PAY_SUCCESS(2, "支付成功"), 13 | CREATE_PAYMENT_FAIL(3, "创建支付订单失败"), 14 | PAY_FAIL(4, "支付失败"), 15 | PAY_CHECKING(5, "支付中"), 16 | PAY_CLOSE(6, "支付订单关闭"), 17 | REFUND_PART(7, "部分退款"), 18 | REFUND_SUCCESS(8, "全部退款"), ; 19 | 20 | private int value; 21 | private String name; 22 | 23 | PayStatus(int value, String name) { 24 | this.value = value; 25 | this.name = name; 26 | } 27 | 28 | public int getValue() { 29 | return value; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public static PayStatus getPayStatus(int status) { 37 | for (PayStatus it : PayStatus.values()) { 38 | if (it.getValue() == status) { 39 | return it; 40 | } 41 | } 42 | return null; 43 | } 44 | 45 | private static Map map = new HashMap(PayStatus.values().length); 46 | 47 | static { 48 | for (PayStatus payStatus : PayStatus.values()) { 49 | map.put(payStatus.getValue(), payStatus.getName()); 50 | } 51 | } 52 | 53 | public static Map getPayStatusMap() { 54 | return map; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/platform/enums/PayTypeCode.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.enums; 2 | 3 | /** 4 | * 支付类型 5 | */ 6 | public enum PayTypeCode { 7 | WECHAT_PAY(1, "微信"), ALI_PAY(2, "支付宝"); 8 | 9 | private int id; 10 | private String name; 11 | 12 | PayTypeCode(int id, String name) { 13 | this.id = id; 14 | this.name = name; 15 | } 16 | 17 | public static PayTypeCode getPayType(int id) { 18 | for (PayTypeCode payTypeCode : PayTypeCode.values()) { 19 | if (payTypeCode.getId() == id) { 20 | return payTypeCode; 21 | } 22 | } 23 | return null; 24 | } 25 | 26 | // type:WECHAT_PAY,ALI_PAY 27 | public static PayTypeCode getPayType(String type) { 28 | return PayTypeCode.valueOf(type); 29 | } 30 | 31 | public int getId() { 32 | return id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/platform/enums/RefundStatus.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.enums; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 订单退款状态 8 | */ 9 | public enum RefundStatus { 10 | CREATE_REFUND_SUCCESS(1, "创建退款订单成功"), 11 | REFUND_SUCCESS(2, "退款成功"), 12 | REFUND_FAIL(3, "退款失败"), 13 | REFUND_CHECKING(4, "退款中"); 14 | 15 | private int value; 16 | private String name; 17 | 18 | RefundStatus(int value, String name) { 19 | this.value = value; 20 | this.name = name; 21 | } 22 | 23 | public int getValue() { 24 | return value; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public static RefundStatus getRefundStatus(int status) { 32 | for (RefundStatus it : RefundStatus.values()) { 33 | if (it.getValue() == status) { 34 | return it; 35 | } 36 | } 37 | return null; 38 | } 39 | 40 | private static Map map = new HashMap(RefundStatus.values().length); 41 | 42 | static { 43 | for (RefundStatus refundStatus : RefundStatus.values()) { 44 | map.put(refundStatus.getValue(), refundStatus.getName()); 45 | } 46 | } 47 | 48 | public static Map getRefundStatusMap() { 49 | return map; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/platform/enums/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.enums; 2 | 3 | public enum ResultCode { 4 | SUCCESS("SUCCESS"),FAIL("FAIL"), ; 5 | private String value; 6 | 7 | ResultCode(String value) { 8 | this.value = value; 9 | } 10 | 11 | public String getValue() { 12 | return value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/platform/enums/TradeTypeCode.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.enums; 2 | 3 | /** 4 | * JSAPI 微信公众号, 微信浏览器支付(数据库中配置为 WAP,service中特殊处理即可) 5 | *

6 | * 业务方调用的时候,传以下3中类型即可,payService中对自动把WAP根据需要解析成JSAPI: 7 | * NATIVE 扫码 8 | * App app支付 9 | * WAP 浏览器,网页版支付 10 | *

11 | * 微信支付类型: 12 | * https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=4_2 13 | */ 14 | public enum TradeTypeCode { 15 | JSAPI(1, "WAP支付"), NATIVE(2, "扫码支付"), APP(3, "APP支付"), WAP(4, "WAP支付"), MICROPAY(5, "刷卡支付"); 16 | private int id; 17 | private String name; 18 | 19 | TradeTypeCode(int id, String name) { 20 | this.id = id; 21 | this.name = name; 22 | } 23 | 24 | public static TradeTypeCode getTradeTypeCode(int id) { 25 | for (TradeTypeCode tradeTypeCode : TradeTypeCode.values()) { 26 | if (tradeTypeCode.getId() == id) { 27 | return tradeTypeCode; 28 | } 29 | } 30 | return null; 31 | } 32 | 33 | // type: NATIVE,APP,WAP 等 34 | public static TradeTypeCode getTradeTypeCode(String type) { 35 | return TradeTypeCode.valueOf(type); 36 | } 37 | 38 | public int getId() { 39 | return id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/util/Base64Util.java: -------------------------------------------------------------------------------- 1 | package com.kk.utils; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | 5 | /** 6 | * Created by xienan on 2015/5/20. 7 | */ 8 | public class Base64Util { 9 | // 将 s 进行 BASE64 编码 10 | public static String encode(String s) { 11 | if (s == null) return null; 12 | //return (new sun.misc.BASE64Encoder()).encode( s.getBytes() ).replaceAll("\n", "").replaceAll("\r", ""); 13 | return new String(Base64.encodeBase64(s.getBytes())); 14 | } 15 | 16 | // 将 BASE64 编码的字符串 s 进行解码 17 | public static String decode(String s) { 18 | if (s == null) return null; 19 | //BASE64Decoder decoder = new BASE64Decoder(); 20 | try { 21 | //byte[] b = decoder.decodeBuffer(s); 22 | byte[] b = Base64.decodeBase64(s); 23 | return new String(b); 24 | } catch (Exception e) { 25 | return null; 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/util/MD5Util.java: -------------------------------------------------------------------------------- 1 | package com.kk.utils; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.security.MessageDigest; 5 | import java.security.NoSuchAlgorithmException; 6 | 7 | /** 8 | * MD5加密 9 | * 10 | * @author zhihui.kong 11 | * 12 | */ 13 | public class MD5Util { 14 | public static final String LOGIN_USER_TICKET_SALT = "E_bao_Yang_salt"; 15 | 16 | // MD5 17 | private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', 18 | '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 19 | 20 | /** 21 | * 32位加密 22 | * 23 | * @param text 24 | * @return 25 | */ 26 | public static String md5(String text) { 27 | MessageDigest msgDigest = null; 28 | 29 | try { 30 | msgDigest = MessageDigest.getInstance("MD5"); 31 | } catch (NoSuchAlgorithmException e) { 32 | throw new IllegalStateException( 33 | "System doesn't support MD5 algorithm."); 34 | } 35 | 36 | try { 37 | msgDigest.update(text.getBytes("utf-8")); 38 | 39 | } catch (UnsupportedEncodingException e) { 40 | 41 | throw new IllegalStateException( 42 | "System doesn't support your EncodingException."); 43 | 44 | } 45 | 46 | byte[] bytes = msgDigest.digest(); 47 | 48 | String md5Str = new String(encodeHex(bytes)); 49 | 50 | return md5Str; 51 | } 52 | 53 | public static String generateLoginTicket(String userName, String md5Passwd, String timestamp) { 54 | return md5(userName + md5Passwd + timestamp + LOGIN_USER_TICKET_SALT); 55 | } 56 | 57 | private static char[] encodeHex(byte[] data) { 58 | 59 | int l = data.length; 60 | 61 | char[] out = new char[l << 1]; 62 | 63 | // two characters form the hex value. 64 | for (int i = 0, j = 0; i < l; i++) { 65 | out[j++] = DIGITS[(0xF0 & data[i]) >>> 4]; 66 | out[j++] = DIGITS[0x0F & data[i]]; 67 | } 68 | 69 | return out; 70 | } 71 | 72 | public static void main(String[] args) { 73 | String s = "wl198665"; 74 | System.out.println(md5(s)); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/util/RSA.java: -------------------------------------------------------------------------------- 1 | package com.kk.utils; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | import org.apache.commons.logging.Log; 5 | import org.apache.commons.logging.LogFactory; 6 | 7 | import java.security.KeyFactory; 8 | import java.security.PrivateKey; 9 | import java.security.PublicKey; 10 | import java.security.Signature; 11 | import java.security.spec.PKCS8EncodedKeySpec; 12 | import java.security.spec.X509EncodedKeySpec; 13 | 14 | public class RSA { 15 | private static Log logger = LogFactory.getLog(RSA.class); 16 | 17 | private final static String CHARSET = "UTF-8"; 18 | private final static String RSA = "RSA"; 19 | private final static String DEFAULT_ALGORITHM = "SHA1WithRSA"; 20 | 21 | public final static String encrypt(String content, String privateKey) { 22 | try { 23 | PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)); 24 | KeyFactory factory = KeyFactory.getInstance(RSA); 25 | PrivateKey priKey = factory.generatePrivate(priPKCS8); 26 | 27 | Signature signature = Signature.getInstance(DEFAULT_ALGORITHM); 28 | 29 | signature.initSign(priKey); 30 | signature.update(content.getBytes(CHARSET)); 31 | 32 | byte[] signed = signature.sign(); 33 | 34 | return Base64.encodeBase64String(signed); 35 | } catch (Exception e) { 36 | logger.error(e.getMessage(), e); 37 | } 38 | 39 | return null; 40 | } 41 | 42 | public static boolean verify(String sign, String content, String publicKey) { 43 | try { 44 | KeyFactory keyFactory = KeyFactory.getInstance("RSA"); 45 | byte[] encodedKey = Base64.decodeBase64(publicKey); 46 | PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey)); 47 | 48 | 49 | Signature signature = java.security.Signature.getInstance(DEFAULT_ALGORITHM); 50 | 51 | signature.initVerify(pubKey); 52 | signature.update(content.getBytes(CHARSET)); 53 | 54 | return signature.verify(Base64.decodeBase64(sign)); 55 | 56 | } catch (Exception e) { 57 | logger.error(e.getMessage(), e); 58 | } 59 | 60 | return false; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/util/SHA1Util.java: -------------------------------------------------------------------------------- 1 | package com.kk.utils; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | 6 | /** 7 | * sha1 加密 8 | * 9 | * @author zhihui.kong 10 | * 11 | */ 12 | public class SHA1Util { 13 | 14 | private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', 15 | '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 16 | 17 | public static String sha1(String content) { 18 | MessageDigest messageDigest = null; 19 | try { 20 | messageDigest = MessageDigest.getInstance("SHA-1"); 21 | } catch (NoSuchAlgorithmException e) { 22 | e.printStackTrace(); 23 | } 24 | messageDigest.update(content.getBytes()); 25 | byte[] bytes = messageDigest.digest(); 26 | String sha1 = encodeHex(bytes); 27 | return sha1; 28 | } 29 | 30 | private static String encodeHex(byte[] bytes) { 31 | int len = bytes.length; 32 | StringBuilder buf = new StringBuilder(len * 2); 33 | // 把密文转换成十六进制的字符串形式 34 | for (int j = 0; j < len; j++) { 35 | buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]); 36 | buf.append(HEX_DIGITS[bytes[j] & 0x0f]); 37 | } 38 | 39 | return buf.toString(); 40 | } 41 | 42 | public static void main(String[] args) { 43 | System.out.println(sha1("kongzhidea")); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /pay-platform/pay-api-model/src/main/java/com/kk/util/sign.md: -------------------------------------------------------------------------------- 1 | ### 签名算法------(签名校验工具) 2 | #### 签名生成的通用步骤如下: 3 | * 第一步,设所有发送或者接收到的数据为集合M,将集合M内非空参数值的参数按照参数名ASCII码从小到大排序(字典序),使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串stringA。 4 | 特别注意以下重要规则: 5 | * 参数名ASCII码从小到大排序(字典序); 6 | * 如果参数的值为空不参与签名; 7 | * 参数名区分大小写; 8 | * 验证调用返回或微信主动通知签名时,传送的sign参数不参与签名,将生成的签名与该sign值作校验。 9 | * 微信接口可能增加字段,验证签名时必须支持增加的扩展字段 10 | * 第二步,在stringA最后拼接上key得到stringSignTemp字符串,并对stringSignTemp进行MD5运算,再将得到的字符串所有字符转换为大写,得到sign值signValue。 11 | key设置路径:微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置 12 | * 假设传送的参数如下: 13 | * appid: wxd930ea5d5a258f4f 14 | * mch_id: 10000100 15 | * device_info: 1000 16 | * body: test 17 | * nonce_str: ibuaiVcKdpRxkhJA 18 | * 第一步:对参数按照key=value的格式,并按照参数名ASCII字典序排序如下: 19 | * stringA="appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; 20 | * 第二步:拼接API密钥: 21 | * stringSignTemp="stringA&key=192006250b4c09247ec02edce69f6a2d" 22 | * sign=MD5(stringSignTemp).toUpperCase()="9A0A8659F005D6984697E2CA0A9CF3B7" 23 | 24 | * 生成随机数算法 25 | * 微信支付API接口协议中包含字段nonce_str,主要保证签名不可预测。我们推荐生成随机数算法如下:调用随机数函数生成,将得到的值转换为字符串。 -------------------------------------------------------------------------------- /pay-platform/pay-api/src/main/java/com/kk/controller/api/ConfigController.java: -------------------------------------------------------------------------------- 1 | package com.kk.controller.api; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.kk.api.ApiResponse; 5 | import com.kk.api.request.PayTypeRequest; 6 | import com.kk.api.service.ConfigService; 7 | import org.apache.commons.io.IOUtils; 8 | import org.apache.commons.logging.Log; 9 | import org.apache.commons.logging.LogFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | import java.io.IOException; 18 | 19 | /** 20 | * 调用实例见:ConfigTest 21 | */ 22 | @RestController 23 | @RequestMapping("/config") 24 | public class ConfigController { 25 | private Log logger = LogFactory.getLog(this.getClass()); 26 | @Autowired 27 | ConfigService configService; 28 | 29 | @RequestMapping(value = "/payTypes", method = RequestMethod.POST) 30 | public String payTypes(HttpServletRequest request) { 31 | String data = null; 32 | try { 33 | data = IOUtils.toString(request.getInputStream()); 34 | } catch (IOException e) { 35 | logger.error(e.getMessage(), e); 36 | return ApiResponse.createErrorResponse("参数解析失败").toJsonString(); 37 | } 38 | logger.info("data is " + data); 39 | PayTypeRequest req = JSON.parseObject(data, PayTypeRequest.class); 40 | return configService.getPayTypes(req).toJsonString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/main/java/com/kk/controller/notify/WechatPayNotifyController.java: -------------------------------------------------------------------------------- 1 | package com.kk.controller.notify; 2 | 3 | import com.kk.api.service.PayService; 4 | import com.kk.platform.enums.PayTypeCode; 5 | import com.kk.wechat.response.ResultCode; 6 | import com.kk.wechat.util.WeixinUtil; 7 | import org.apache.commons.io.IOUtils; 8 | import org.apache.commons.lang.StringUtils; 9 | import org.apache.commons.logging.Log; 10 | import org.apache.commons.logging.LogFactory; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | 18 | /** 19 | * 微信支付(扫码,wap,app支付均会回调)成功后 回调接口 20 | */ 21 | @RestController 22 | @RequestMapping("/notify/weixin") 23 | public class WechatPayNotifyController { 24 | private Log logger = LogFactory.getLog(this.getClass()); 25 | 26 | @Autowired 27 | private PayService payService; 28 | 29 | @RequestMapping(value = "", method = {RequestMethod.GET, RequestMethod.POST}) 30 | public Object receiveNotify(HttpServletRequest request) { 31 | try { 32 | String xml = IOUtils.toString(request.getInputStream()); 33 | logger.info("weixin pay notify result is:" + xml); 34 | if (StringUtils.isBlank(xml)) { 35 | return WeixinUtil.getResult(ResultCode.FAIL, "接受参数为空"); 36 | } 37 | 38 | if (payService.handlePayNotify(PayTypeCode.WECHAT_PAY, xml)) { 39 | return WeixinUtil.getResult(ResultCode.SUCCESS, "OK"); 40 | } else { 41 | return WeixinUtil.getResult(ResultCode.FAIL, "FAIL"); 42 | } 43 | } catch (Exception e) { 44 | logger.error(e.getMessage(), e); 45 | return WeixinUtil.getResult(ResultCode.FAIL, "PARSE MESSAGE ERROR"); 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/main/resources/Configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/main/resources/web.properties: -------------------------------------------------------------------------------- 1 | #jdbc 2 | jdbc.driver=com.mysql.jdbc.Driver 3 | jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true 4 | jdbc.username=root 5 | jdbc.password=123456 6 | jdbc.initialSize=2 7 | jdbc.maxActive=2 8 | 9 | #current env 10 | environment=test 11 | # done current env 12 | 13 | 14 | #weixin 15 | wechat.pay.notify.url=http://sandbox.kk.com/notify/weixin 16 | 17 | #zhifubao 18 | ali.pay.notify.url=http://sandbox.kk.com/notify/ali 19 | ali.refund.notify.url=http://sandbox.kk.com/notify/ali/refund 20 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/main/webapp/WEB-INF/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/main/webapp/views/errors/404.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 6 | 7 | 8 | 9 | 404 10 | 11 | 12 | 13 | 14 | 404 15 | 16 | 17 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/main/webapp/views/errors/error.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 6 | 7 | 8 | 9 | 500 10 | 11 | 12 | 13 | 14 | 500 15 | 16 | 17 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/test/java/com/kk/test/api/WeChatMicroPayTest.java: -------------------------------------------------------------------------------- 1 | package com.kk.test.api; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.kk.platform.enums.PayException; 5 | import com.kk.platform.enums.PayStatus; 6 | import com.kk.platform.enums.TradeTypeCode; 7 | import com.kk.platform.model.PayChannel; 8 | import com.kk.utils.ConsoleLogger; 9 | import com.kk.utils.LocalIPUtil; 10 | import com.kk.wechat.client.WechatPayClient; 11 | import com.kk.wechat.exception.WechatPayException; 12 | import com.kk.wechat.model.WechatPayMicroPayModel; 13 | import com.kk.wechat.request.WechatPayMicroPayRequest; 14 | import com.kk.wechat.response.WechatPayMicroPayResponse; 15 | import org.junit.Test; 16 | 17 | /** 18 | * 测试刷卡支付 19 | */ 20 | public class WeChatMicroPayTest { 21 | ConsoleLogger logger = new ConsoleLogger(); 22 | 23 | @Test 24 | public void testPay(){ 25 | PayChannel payChannel = new PayChannel(); 26 | payChannel.setAppId(""); 27 | payChannel.setApiKey(""); 28 | payChannel.setMchId(""); 29 | 30 | WechatPayClient client = new WechatPayClient(payChannel.getAppId(), payChannel.getMchId(), payChannel.getApiKey()); 31 | 32 | WechatPayMicroPayRequest request = new WechatPayMicroPayRequest(); 33 | 34 | // model中 appId,sign,mchId,nonceStr 在WechatClient中设置 35 | WechatPayMicroPayModel model = new WechatPayMicroPayModel(); 36 | model.setOutTradeNo("kk_micr" + System.currentTimeMillis()); 37 | model.setSpbillCreateIp(LocalIPUtil.getLocalAddr()); 38 | model.setBody("刷卡支付测试"); 39 | model.setDetail("刷卡支付测试"); 40 | model.setTotalFee(1); 41 | 42 | //!!!! 43 | model.setAuthCode(""); 44 | 45 | request.setModel(model); 46 | 47 | // 统一下单 48 | WechatPayMicroPayResponse response; 49 | try { 50 | response = client.execute(request); 51 | } catch (WechatPayException e) { 52 | // 支付失败 53 | logger.error(e.getMessage(), e); 54 | throw new PayException(e.getErrMsg()); 55 | } 56 | logger.info(JSON.toJSONString(response)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/test/java/com/kk/test/util/BeanUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.kk.test.util; 2 | 3 | import com.google.common.base.CaseFormat; 4 | import com.kk.api.request.PayTypeRequest; 5 | import com.kk.platform.enums.TradeTypeCode; 6 | import com.kk.util.BeanUtil; 7 | import com.kk.util.SignUtils; 8 | import com.kk.wechat.model.WechatPayPrePayModel; 9 | import org.apache.commons.lang.reflect.FieldUtils; 10 | import org.junit.Test; 11 | 12 | import java.lang.reflect.Field; 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | public class BeanUtilTest { 17 | 18 | @Test 19 | public void testBean() { 20 | PayTypeRequest request = new PayTypeRequest(); 21 | request.setTradeType(TradeTypeCode.NATIVE.toString()); 22 | request.setMerchantId("mchid"); 23 | request.setSign("sign"); 24 | 25 | System.out.println(BeanUtil.object2Map(request)); 26 | } 27 | 28 | @Test 29 | public void testField() { 30 | WechatPayPrePayModel model = new WechatPayPrePayModel(); 31 | 32 | model.setAppId("appid"); 33 | 34 | model.setBody("body"); 35 | 36 | Field ap = FieldUtils.getField(model.getClass(), "appId", true); 37 | System.out.println(ap); 38 | 39 | Field b = FieldUtils.getField(model.getClass(), "body", true); 40 | System.out.println(b); 41 | } 42 | 43 | @Test 44 | public void testStr() { 45 | String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "userName"); 46 | System.out.println(name); // user_name 47 | } 48 | 49 | @Test 50 | public void testSignContent() { 51 | Map map = new HashMap(); 52 | map.put("partner", "2001"); 53 | System.out.println(SignUtils.getSignContent(map, false)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/test/java/com/kk/test/util/Consts.java: -------------------------------------------------------------------------------- 1 | package com.kk.test.util; 2 | 3 | public class Consts { 4 | public static final String domain = "http://sandbox.kk.com"; 5 | 6 | public static final String notifyUrl = "http://www.kk.com/caller/notify"; 7 | 8 | public static final String mchId = "0001"; 9 | public static final String apiKey = "ak"; 10 | 11 | public static final String openId = ""; 12 | } 13 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/test/java/com/kk/test/util/JsonTest.java: -------------------------------------------------------------------------------- 1 | package com.kk.test.util; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.google.gson.Gson; 5 | import org.junit.Test; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | public class JsonTest { 11 | @Test 12 | public void testJson() { 13 | Map params = new HashMap(); 14 | params.put("out_trade_no", "1"); 15 | params.put("seller_id", "a=2"); 16 | System.out.println(JSON.toJSONString(params)); // {"out_trade_no":"1","seller_id":"a=2"} 17 | System.out.println(new Gson().toJson(params)); // {"seller_id":"a\u003d2","out_trade_no":"1"} 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/test/java/com/kk/test/util/RequestTest.java: -------------------------------------------------------------------------------- 1 | package com.kk.test.util; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.kk.api.request.PayRequest; 5 | import com.kk.platform.enums.PayTypeCode; 6 | import com.kk.util.XmlUtil; 7 | import org.junit.Test; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | public class RequestTest { 13 | 14 | @Test 15 | public void testRequest() { 16 | PayRequest request = new PayRequest(); 17 | request.setMerchantId(Consts.mchId); 18 | request.setPayType(PayTypeCode.WECHAT_PAY); 19 | 20 | String str = request.toJsonString(); 21 | 22 | System.out.println(str); 23 | 24 | request = JSON.parseObject(str, PayRequest.class); 25 | 26 | System.out.println(request.getPayType().getName()); 27 | } 28 | 29 | @Test 30 | public void testXml() { 31 | Map data = new HashMap(); 32 | data.put("a", "b"); 33 | 34 | String xml = XmlUtil.toXml(data); 35 | System.out.println(xml); 36 | 37 | data = XmlUtil.parseXml(xml); 38 | System.out.println(data); 39 | 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pay-platform/pay-api/src/test/java/com/kk/test/util/ResponseTest.java: -------------------------------------------------------------------------------- 1 | package com.kk.test.util; 2 | 3 | import com.kk.api.response.PayTypeResponse; 4 | import com.kk.platform.enums.PayTypeCode; 5 | import com.kk.platform.enums.TradeTypeCode; 6 | import org.junit.Test; 7 | 8 | public class ResponseTest { 9 | 10 | @Test 11 | public void testToJson() { 12 | PayTypeResponse response = new PayTypeResponse(); 13 | 14 | response.setMerchantId("mid"); 15 | response.setSign("sign"); 16 | response.setCode("su"); 17 | response.addPayType(PayTypeCode.ALI_PAY, TradeTypeCode.NATIVE); 18 | 19 | System.out.println(response.toJsonString()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /pay-platform/pay-caller/README.md: -------------------------------------------------------------------------------- 1 | # cashier.jsp 2 | 用户扫码微信支付, -------------------------------------------------------------------------------- /pay-platform/pay-caller/images/icon-back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/pay-caller/images/icon-back.png -------------------------------------------------------------------------------- /pay-platform/pay-caller/images/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay-platform/pay-caller/images/loading.gif -------------------------------------------------------------------------------- /pay-platform/pay-caller/src/main/java/com/kk/util/Consts.java: -------------------------------------------------------------------------------- 1 | package com.kk.util; 2 | 3 | public class Consts { 4 | public static final String domain = "http://sandbox.kk.com"; 5 | public static final String domain_caller = "http://www.kk.com"; 6 | 7 | public static final String notifyUrlWeixin = "http://www.kk.com/caller/notify/weixin"; 8 | 9 | public static final String mchId = "0001"; 10 | public static final String apiKey = "ak"; 11 | 12 | public static final String openId = ""; 13 | } 14 | -------------------------------------------------------------------------------- /pay-platform/pay-caller/src/main/resources/web.properties: -------------------------------------------------------------------------------- 1 | #jdbc 2 | jdbc.driver=com.mysql.jdbc.Driver 3 | jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true 4 | jdbc.username=root 5 | jdbc.password=123456 6 | jdbc.initialSize=2 7 | jdbc.maxActive=2 8 | 9 | #current env 10 | environment=test 11 | # done current env 12 | -------------------------------------------------------------------------------- /pay-platform/pay-caller/src/main/webapp/WEB-INF/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /pay-platform/pay-caller/src/main/webapp/views/alipay/ap.js: -------------------------------------------------------------------------------- 1 | (function(){var b={};var a={};a.PADCHAR="=";a.ALPHA="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";a.makeDOMException=function(){var f,d;try{return new DOMException(DOMException.INVALID_CHARACTER_ERR)}catch(d){var c=new Error("DOM Exception 5");c.code=c.number=5;c.name=c.description="INVALID_CHARACTER_ERR";c.toString=function(){return"Error: "+c.name+": "+c.message};return c}};a.getbyte64=function(e,d){var c=a.ALPHA.indexOf(e.charAt(d));if(c===-1){throw a.makeDOMException()}return c};a.decode=function(f){f=""+f;var j=a.getbyte64;var h,e,g;var d=f.length;if(d===0){return f}if(d%4!==0){throw a.makeDOMException()}h=0;if(f.charAt(d-1)===a.PADCHAR){h=1;if(f.charAt(d-2)===a.PADCHAR){h=2}d-=4}var c=[];for(e=0;e>16,(g>>8)&255,g&255))}switch(h){case 1:g=(j(f,e)<<18)|(j(f,e+1)<<12)|(j(f,e+2)<<6);c.push(String.fromCharCode(g>>16,(g>>8)&255));break;case 2:g=(j(f,e)<<18)|(j(f,e+1)<<12);c.push(String.fromCharCode(g>>16));break}return c.join("")};a.getbyte=function(e,d){var c=e.charCodeAt(d);if(c>255){throw a.makeDOMException()}return c};a.encode=function(f){if(arguments.length!==1){throw new SyntaxError("Not enough arguments")}var g=a.PADCHAR;var h=a.ALPHA;var k=a.getbyte;var e,j;var c=[];f=""+f;var d=f.length-f.length%3;if(f.length===0){return f}for(e=0;e>18));c.push(h.charAt((j>>12)&63));c.push(h.charAt((j>>6)&63));c.push(h.charAt(j&63))}switch(f.length-d){case 1:j=k(f,e)<<16;c.push(h.charAt(j>>18)+h.charAt((j>>12)&63)+g+g);break;case 2:j=(k(f,e)<<16)|(k(f,e+1)<<8);c.push(h.charAt(j>>18)+h.charAt((j>>12)&63)+h.charAt((j>>6)&63)+g);break}return c.join("")};b.pay=function(d){var c=encodeURIComponent(a.encode(d));location.href="pay.htm?goto="+c};b.decode=function(c){return a.decode(decodeURIComponent(c))};window._AP=b})(); -------------------------------------------------------------------------------- /pay-platform/pay-caller/src/main/webapp/views/errors/404.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 6 | 7 | 8 | 9 | 404 10 | 11 | 12 | 13 | 14 | 404 15 | 16 | 17 | -------------------------------------------------------------------------------- /pay-platform/pay-caller/src/main/webapp/views/errors/error.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 4 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 6 | 7 | 8 | 9 | 500 10 | 11 | 12 | 13 | 14 | 500 15 | 16 | 17 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/alipay/client/MyDefaultAliPayClient.java: -------------------------------------------------------------------------------- 1 | package com.kk.alipay.client; 2 | 3 | 4 | import com.alipay.api.DefaultAlipayClient; 5 | 6 | /** 7 | * 扫码支付,订单查询 8 | */ 9 | public class MyDefaultAliPayClient extends DefaultAlipayClient { 10 | private static final String SERVER_URL = "https://openapi.alipay.com/gateway.do"; 11 | private static final String DATA_TYPE = "json"; 12 | private static final String CHARSET = "utf-8"; 13 | 14 | public MyDefaultAliPayClient(String appId, String privateKey, String publicKey) { 15 | super(SERVER_URL, appId, privateKey, DATA_TYPE, CHARSET, publicKey); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/alipay/exception/AliPayException.java: -------------------------------------------------------------------------------- 1 | package com.kk.alipay.exception; 2 | 3 | public class AliPayException extends Exception { 4 | private String errCode; 5 | private String errMsg; 6 | 7 | public AliPayException(String errCode, String errMsg) { 8 | super(errCode + ":" + errMsg); 9 | this.errCode = errCode; 10 | this.errMsg = errMsg; 11 | } 12 | 13 | public AliPayException(Throwable cause) { 14 | super(cause); 15 | this.errMsg = cause.getMessage(); 16 | } 17 | 18 | public AliPayException(String message, Throwable cause) { 19 | super(message, cause); 20 | this.errMsg = message; 21 | } 22 | 23 | public AliPayException(String message) { 24 | super(message); 25 | this.errMsg = message; 26 | } 27 | 28 | public String getErrCode() { 29 | return errCode; 30 | } 31 | 32 | public String getErrMsg() { 33 | return errMsg; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/alipay/response/AliPayResponse.java: -------------------------------------------------------------------------------- 1 | package com.kk.alipay.response; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * DefaultAliPayParser.parse 把json转成 实例, 7 | *

8 | * 支持驼峰式写法,与下划线写法的转换, 支持Date类型(yyyy-MM-dd HH:mm:ss格式) 9 | *

10 | * trade_status; 交易状态如下: 11 | * WAIT_BUYER_PAY 交易创建,等待买家付款 12 | * TRADE_CLOSED 未付款交易超时关闭,或支付完成后全额退款 13 | * TRADE_SUCCESS 交易支付成功, 触发通知 14 | * TRADE_FINISHED 交易结束,不可退款 15 | */ 16 | public abstract class AliPayResponse { 17 | private Map params; 18 | 19 | public Map getParams() { 20 | return params; 21 | } 22 | 23 | public void setParams(Map params) { 24 | this.params = params; 25 | } 26 | 27 | public abstract boolean isSuccess(); 28 | 29 | public abstract String getSign(); 30 | } 31 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/api/service/ConfigService.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.service; 2 | 3 | import com.kk.api.request.PayTypeRequest; 4 | import com.kk.api.response.PayTypeResponse; 5 | import com.kk.platform.enums.PayTypeCode; 6 | import com.kk.platform.enums.ResultCode; 7 | import com.kk.platform.enums.TradeTypeCode; 8 | import com.kk.platform.model.PayMerchant; 9 | import com.kk.platform.model.PayMerchantChannel; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | @Service 17 | public class ConfigService extends AbstractPayService { 18 | 19 | public PayTypeResponse getPayTypes(PayTypeRequest request) { 20 | PayMerchant merchant = payMerchantService.getPayMerchant(request.getMerchantId()); 21 | 22 | PayTypeResponse response = (PayTypeResponse) validate(merchant, request, PayTypeResponse.class); 23 | if (response != null) { 24 | return response; 25 | } 26 | 27 | response = new PayTypeResponse(); 28 | 29 | List merchantChannels; 30 | if (StringUtils.isNotBlank(request.getTradeType())) { 31 | merchantChannels = payMerchantChannelService.getPayMerchantChannel(merchant.getId(), request.getTradeType()); 32 | } else { 33 | merchantChannels = payMerchantChannelService.getPayMerchantChannels(merchant.getId()); 34 | } 35 | 36 | for (PayMerchantChannel merchantChannel : merchantChannels) { 37 | PayTypeCode type = PayTypeCode.getPayType(merchantChannel.getPayTypeId()); 38 | TradeTypeCode tradeType = TradeTypeCode.getTradeTypeCode(merchantChannel.getTradeType()); 39 | response.addPayType(type, tradeType); 40 | } 41 | response.setMerchantId(request.getMerchantId()); 42 | response.setCode(ResultCode.SUCCESS.getValue()); 43 | response.setMsg(ResultCode.SUCCESS.getValue()); 44 | response.setSign(sign(response, merchant.getApiKey())); 45 | return response; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/api/service/InternalPayService.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.service; 2 | 3 | 4 | import com.kk.api.response.PayNotifyResponse; 5 | import com.kk.platform.model.PayChannel; 6 | import com.kk.platform.model.PayOrder; 7 | 8 | /** 9 | * 支付接口定义, 微信,支付宝支付逻辑均 继承此接口。 10 | */ 11 | public interface InternalPayService { 12 | /** 13 | * 统一下单接口 14 | * 15 | * @param payChannel 微信,支付宝支付账户 16 | * @param order 支付订单,包含 订单号,title,金额等信息。 17 | * @return 扫码支付则返回二维码(String),其他则返回 支付凭证(Map),返回给客户端,调起支付页面。 18 | */ 19 | Object pay(PayChannel payChannel, PayOrder order); 20 | 21 | /** 22 | * @param notify 回调的内容 23 | * @return 返回支付宝,微信 商户订单号,payorder.payOrderNo 24 | */ 25 | String getOutTradeNo(String notify); 26 | 27 | /** 28 | * 解析支付回调内容,校验签名 29 | * 30 | * @param channel 微信,支付宝支付账户 31 | * @param order 支付订单 32 | * @param notify 回调的内容 33 | * @return 34 | */ 35 | PayNotifyResponse parse(PayChannel channel, PayOrder order, String notify); 36 | 37 | /** 38 | * 同步订单, 查询微信、支付宝 交易查询状态,来同步订单状态 39 | * 40 | * @param channel 41 | * @param order 42 | * @return 43 | */ 44 | boolean synchronize(PayChannel channel, PayOrder order); 45 | } 46 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/api/service/InternalRefundService.java: -------------------------------------------------------------------------------- 1 | package com.kk.api.service; 2 | 3 | 4 | import com.kk.api.response.RefundResponse; 5 | import com.kk.platform.model.PayChannel; 6 | import com.kk.platform.model.RefundOrder; 7 | 8 | /** 9 | * 订单退款 10 | */ 11 | public interface InternalRefundService { 12 | /** 13 | * 实际退款接口, 如果退款失败,一定要抛出异常,在RefundService中如果有异常则返回 业务方。 14 | * 15 | * @param payChannel 16 | * @param refundOrder 17 | * @return 18 | */ 19 | Object refund(PayChannel payChannel, RefundOrder refundOrder); 20 | 21 | /** 22 | * 异步通知时候使用, 目前支付宝调用此方法 23 | * 24 | * @return 25 | */ 26 | RefundResponse parse(PayChannel channel, RefundOrder refundOrder, String notify); 27 | } 28 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/dao/FileResourceDao.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.dao; 2 | 3 | import com.kk.platform.model.FileResource; 4 | import org.apache.ibatis.annotations.Insert; 5 | import org.apache.ibatis.annotations.Options; 6 | import org.apache.ibatis.annotations.Select; 7 | 8 | @MyBatisRepository 9 | public interface FileResourceDao { 10 | 11 | String FIELDS = " id, file_id, data, name, size, file_type "; 12 | String TABLE_NAME = "file_resource"; 13 | 14 | @Insert("insert into " + TABLE_NAME + "(file_id, data, name, size, file_type) " + 15 | "values(#{fileId},#{data},#{name},#{size},#{fileType})") 16 | @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id") 17 | void insert(FileResource fileResource); 18 | 19 | 20 | @Select("select " + FIELDS + " from " + TABLE_NAME + " where id = #{id}") 21 | FileResource selectById(int id); 22 | 23 | @Select("select " + FIELDS + " from " + TABLE_NAME + " where file_id = #{fileId}") 24 | FileResource selectByFileId(String fileId); 25 | } 26 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/dao/MyBatisRepository.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.dao; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 标识MyBatis的DAO,方便 10 | * {@link org.mybatis.spring.mapper.MapperScannerConfigurer}的扫描。 11 | * 12 | * @author calvin 13 | * 14 | */ 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target(ElementType.TYPE) 17 | public @interface MyBatisRepository { 18 | } 19 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/dao/PayChannelDao.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.dao; 2 | 3 | import com.kk.platform.model.PayChannel; 4 | import org.apache.ibatis.annotations.*; 5 | 6 | import java.util.List; 7 | 8 | @MyBatisRepository 9 | public interface PayChannelDao { 10 | String FIELDS = "id, pay_type_id, pay_type_name, pay_type_code, pay_channel_name, sign_type, cert_file_id, api_key, app_id, mch_id, status,mch_key,platform_key,query_channel_id "; 11 | 12 | @Insert("insert into pay_channel(pay_type_id, pay_type_name, pay_type_code, pay_channel_name, sign_type, cert_file_id, api_key, app_id, mch_id, status,mch_key,platform_key) " + 13 | "values (#{payTypeId}, #{payTypeName}, #{payTypeCode}, #{payChannelName}, #{signType}, #{certFileId}, #{apiKey}, #{appId}, #{mchId}, #{status},#{mchKey},#{platformKey})") 14 | @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id") 15 | long insert(PayChannel payChannel); 16 | 17 | @Select("select " + FIELDS + " from pay_channel where id = #{id}") 18 | PayChannel selectById(int id); 19 | 20 | @Update("update pay_channel set pay_type_id = #{payTypeId}, pay_type_name = #{payTypeName}, pay_type_code = #{payTypeCode}, pay_channel_name = #{payChannelName}, sign_type = #{signType}, cert_file_id = #{certFileId}, api_key = #{apiKey}, app_id = #{appId}, mch_id = #{mchId},mch_key=#{mchKey},platform_key=#{platformKey} where id = #{id}") 21 | void update(PayChannel payChannel); 22 | 23 | @Update("update pay_channel set status=#{param2} where id = #{param1}") 24 | void updateStatusById(int id, int status); 25 | 26 | @Update("update pay_channel set pay_type_name=#{param2}, pay_type_code=#{param3} where pay_type_id = #{param1}") 27 | void updateByPayTypeId(int payTypeId, String payTypeName, String payTypeCode); 28 | 29 | @Delete("delete from pay_channel where id=#{id}") 30 | void deleteById(int id); 31 | 32 | @Select("select " + FIELDS + " from pay_channel where id in (${ids})") 33 | List getPayChannelList(@Param("ids") String ids); 34 | } 35 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/dao/PayMerchantChannelDao.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.dao; 2 | 3 | import com.kk.platform.model.PayMerchantChannel; 4 | import org.apache.ibatis.annotations.*; 5 | 6 | import java.util.List; 7 | 8 | 9 | @MyBatisRepository 10 | public interface PayMerchantChannelDao { 11 | String FIELDS = " id, pay_type_id, pay_merchant_id, pay_channel_id, trade_type "; 12 | 13 | @Insert("insert into pay_merchant_channel(pay_type_id, pay_merchant_id, pay_channel_id, trade_type) " + 14 | "values (#{payTypeId}, #{payMerchantId}, #{payChannelId}, #{tradeType})") 15 | @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id") 16 | long insert(PayMerchantChannel payMerchantChannel); 17 | 18 | @Select("select " + FIELDS + " from pay_merchant_channel where id = #{id}") 19 | PayMerchantChannel selectById(int id); 20 | 21 | @Select("select " + FIELDS + " from pay_merchant_channel where pay_merchant_id = #{merchantId}") 22 | List selectByMerchantId(int merchantId); 23 | 24 | @Select("select " + FIELDS + " from pay_merchant_channel where pay_merchant_id = #{merchantId} and trade_type = #{tradeType}") 25 | List selectByTradeType(@Param("merchantId") int merchantId, @Param("tradeType") String tradeType); 26 | 27 | @Select("select " + FIELDS + " from pay_merchant_channel where pay_merchant_id = #{merchantId} and pay_type_id = #{payTypeId} and trade_type = #{tradeType}") 28 | PayMerchantChannel selectByPayType(@Param("merchantId") int merchantId, @Param("payTypeId") int payTypeId, @Param("tradeType") String tradeType); 29 | 30 | @Delete("delete from pay_merchant_channel where id=#{id}") 31 | void deleteById(int id); 32 | } 33 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/dao/PayMerchantDao.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.dao; 2 | 3 | import com.kk.platform.model.PayMerchant; 4 | import org.apache.ibatis.annotations.*; 5 | 6 | @MyBatisRepository 7 | public interface PayMerchantDao { 8 | String FIELDS = " id, name, status, merchant_id, api_key "; 9 | 10 | @Insert("insert into pay_merchant(name, status, merchant_id, api_key) " + 11 | "values (#{name}, #{status}, #{merchantId}, #{apiKey})") 12 | @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id") 13 | long insert(PayMerchant payMerchant); 14 | 15 | @Select("select " + FIELDS + " from pay_merchant where id = #{id}") 16 | PayMerchant selectById(int id); 17 | 18 | @Select("select " + FIELDS + " from pay_merchant where merchant_id = #{merchantId}") 19 | PayMerchant selectByMerchantId(String merchantId); 20 | 21 | @Update("update pay_merchant set name=#{name}, api_key=#{apiKey} where id=#{id}") 22 | void update(PayMerchant payMerchant); 23 | 24 | @Update("update pay_merchant set status=#{param2} where id=#{param1}") 25 | void updateStatusById(int id, int status); 26 | 27 | @Delete("delete from pay_merchant where id=#{id}") 28 | void deleteById(int id); 29 | } 30 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/model/FileResource.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.model; 2 | 3 | /** 4 | * 存储文件, 如微信退款的凭证文件 5 | */ 6 | public class FileResource { 7 | private int id; 8 | private String fileId; 9 | private byte[] data; 10 | private String name; 11 | private long size; 12 | private String fileType; 13 | 14 | public int getId() { 15 | return id; 16 | } 17 | 18 | public void setId(int id) { 19 | this.id = id; 20 | } 21 | 22 | public String getFileId() { 23 | return fileId; 24 | } 25 | 26 | public void setFileId(String fileId) { 27 | this.fileId = fileId; 28 | } 29 | 30 | public byte[] getData() { 31 | return data; 32 | } 33 | 34 | public void setData(byte[] data) { 35 | this.data = data; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public long getSize() { 47 | return size; 48 | } 49 | 50 | public void setSize(long size) { 51 | this.size = size; 52 | } 53 | 54 | public String getFileType() { 55 | return fileType; 56 | } 57 | 58 | public void setFileType(String fileType) { 59 | this.fileType = fileType; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/model/PayMerchant.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.model; 2 | 3 | /** 4 | * 支付平台对外提供的商户号 5 | */ 6 | public class PayMerchant { 7 | public static int STATUS_ACTIVE = 1; 8 | 9 | private int id; 10 | private String name; 11 | private int status; // 1正常,2 不可用 12 | private String merchantId; // 商户Id 13 | private String apiKey; // 秘钥 14 | 15 | public int getId() { 16 | return id; 17 | } 18 | 19 | public void setId(int id) { 20 | this.id = id; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public int getStatus() { 32 | return status; 33 | } 34 | 35 | public void setStatus(int status) { 36 | this.status = status; 37 | } 38 | 39 | public String getMerchantId() { 40 | return merchantId; 41 | } 42 | 43 | public void setMerchantId(String merchantId) { 44 | this.merchantId = merchantId; 45 | } 46 | 47 | public String getApiKey() { 48 | return apiKey; 49 | } 50 | 51 | public void setApiKey(String apiKey) { 52 | this.apiKey = apiKey; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "PayMerchant{" + 58 | "id=" + id + 59 | ", name='" + name + '\'' + 60 | ", status=" + status + 61 | ", merchantId='" + merchantId + '\'' + 62 | ", apiKey='" + apiKey + '\'' + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/model/PayMerchantChannel.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.model; 2 | 3 | import com.kk.platform.enums.TradeTypeCode; 4 | 5 | /** 6 | * 商户允许使用的 支付方式,以及对应的 支付账号。 7 | *

8 | * 每个商户基础配置6个, 微信扫码,微信wap,微信app支付, 支付宝扫码,支付宝wap,支付宝app支付。 9 | */ 10 | public class PayMerchantChannel { 11 | private int id; 12 | private int payTypeId; // PayTypeCode, 微信 1, 支付宝 2 13 | private int payChannelId; // PayChannel 14 | private int payMerchantId; // PayMerchant 15 | private String tradeType; // TradeTypeCode, 如扫码支付,app支付等 。 16 | 17 | private PayChannel payChannel; 18 | private PayMerchant payMerchant; 19 | 20 | public TradeTypeCode getTradeTypeCode() { 21 | return TradeTypeCode.getTradeTypeCode(tradeType); 22 | } 23 | 24 | public int getId() { 25 | return id; 26 | } 27 | 28 | public void setId(int id) { 29 | this.id = id; 30 | } 31 | 32 | public int getPayTypeId() { 33 | return payTypeId; 34 | } 35 | 36 | public void setPayTypeId(int payTypeId) { 37 | this.payTypeId = payTypeId; 38 | } 39 | 40 | public int getPayChannelId() { 41 | return payChannelId; 42 | } 43 | 44 | public void setPayChannelId(int payChannelId) { 45 | this.payChannelId = payChannelId; 46 | } 47 | 48 | public int getPayMerchantId() { 49 | return payMerchantId; 50 | } 51 | 52 | public void setPayMerchantId(int payMerchantId) { 53 | this.payMerchantId = payMerchantId; 54 | } 55 | 56 | public String getTradeType() { 57 | return tradeType; 58 | } 59 | 60 | public void setTradeType(String tradeType) { 61 | this.tradeType = tradeType; 62 | } 63 | 64 | public PayChannel getPayChannel() { 65 | return payChannel; 66 | } 67 | 68 | public void setPayChannel(PayChannel payChannel) { 69 | this.payChannel = payChannel; 70 | } 71 | 72 | public PayMerchant getPayMerchant() { 73 | return payMerchant; 74 | } 75 | 76 | public void setPayMerchant(PayMerchant payMerchant) { 77 | this.payMerchant = payMerchant; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/service/FileResourceService.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.service; 2 | 3 | import com.kk.platform.dao.FileResourceDao; 4 | import com.kk.platform.model.FileResource; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class FileResourceService { 10 | @Autowired 11 | private FileResourceDao fileResourceDao; 12 | 13 | public void createFileResource(FileResource fileResource) { 14 | if (fileResource == null) { 15 | throw new IllegalArgumentException(); 16 | } 17 | 18 | fileResourceDao.insert(fileResource); 19 | } 20 | 21 | public FileResource getFileResource(int id) { 22 | return fileResourceDao.selectById(id); 23 | } 24 | 25 | public FileResource getFileResource(String fileId) { 26 | return fileResourceDao.selectByFileId(fileId); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/service/PayChannelService.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.service; 2 | 3 | import com.kk.platform.dao.PayChannelDao; 4 | import com.kk.platform.model.PayChannel; 5 | import org.apache.commons.lang.StringUtils; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Set; 12 | 13 | @Service 14 | public class PayChannelService { 15 | @Autowired 16 | private PayChannelDao payChannelDao; 17 | 18 | public void createPayChannel(PayChannel payChannel) { 19 | payChannelDao.insert(payChannel); 20 | } 21 | 22 | public PayChannel getPayChannel(int id) { 23 | return payChannelDao.selectById(id); 24 | } 25 | 26 | 27 | public void updatePayChannel(PayChannel payChannel) { 28 | payChannelDao.update(payChannel); 29 | } 30 | 31 | public void updatePayChannel(int id, int status) { 32 | payChannelDao.updateStatusById(id, status); 33 | } 34 | 35 | public void deletePayChannel(int id) { 36 | payChannelDao.deleteById(id); 37 | } 38 | 39 | public List getPayChannel(Set channelIds) { 40 | if(channelIds.size() == 0){ 41 | return new ArrayList(); 42 | } 43 | String ids = StringUtils.join(channelIds,","); 44 | return payChannelDao.getPayChannelList(ids); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/service/PayMerchantService.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.service; 2 | 3 | import com.kk.platform.dao.PayMerchantDao; 4 | import com.kk.platform.model.PayMerchant; 5 | import com.kk.utils.MD5Util; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class PayMerchantService { 11 | @Autowired 12 | private PayMerchantDao payMerchantDao; 13 | 14 | public String generateApiKey() { 15 | return MD5Util.md5(System.currentTimeMillis() + "").toLowerCase(); 16 | } 17 | 18 | public void createPayMerchant(PayMerchant payMerchant) { 19 | payMerchantDao.insert(payMerchant); 20 | } 21 | 22 | public PayMerchant getPayMerchant(int id) { 23 | return payMerchantDao.selectById(id); 24 | } 25 | 26 | public PayMerchant getPayMerchant(String merchantId) { 27 | return payMerchantDao.selectByMerchantId(merchantId); 28 | } 29 | 30 | public void updatePayMerchant(PayMerchant payMerchant) { 31 | payMerchantDao.update(payMerchant); 32 | } 33 | 34 | public void updatePayMerchant(int id, int status) { 35 | payMerchantDao.updateStatusById(id, status); 36 | } 37 | 38 | public void deletePayMerchant(int id) { 39 | payMerchantDao.deleteById(id); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/platform/utils/SnUtils.java: -------------------------------------------------------------------------------- 1 | package com.kk.platform.utils; 2 | 3 | import org.apache.commons.lang3.RandomStringUtils; 4 | import org.apache.commons.lang3.StringUtils; 5 | import org.joda.time.DateTime; 6 | 7 | public class SnUtils { 8 | private static final int DEFAULT_LENGTH = 32; 9 | private static final int PREFIX_LENGTH = 4; 10 | 11 | /** 12 | * 生成 微信,支付宝等第三方支付的 订单号 13 | * 14 | * @param prefix 15 | * @return 16 | */ 17 | public static String generateOrderNo(String prefix) { 18 | return generateOrderNo(prefix, DEFAULT_LENGTH); 19 | } 20 | 21 | public static String generateOrderNo(String prefix, int length) { 22 | if (StringUtils.isBlank(prefix) || prefix.length() < PREFIX_LENGTH || prefix.length() > length || length < DEFAULT_LENGTH) { 23 | throw new IllegalArgumentException("Prefix Illegal"); 24 | } 25 | 26 | String no = prefix; 27 | 28 | if (prefix.length() > PREFIX_LENGTH) { 29 | no = prefix.substring(0, PREFIX_LENGTH); 30 | } 31 | 32 | no += RandomStringUtils.randomNumeric(PREFIX_LENGTH); 33 | 34 | no += DateTime.now().toString("yyyyMMddHHmmss"); 35 | 36 | no += RandomStringUtils.randomNumeric(length - no.length()); 37 | 38 | return no; 39 | } 40 | 41 | public static void main(String[] args) { 42 | System.out.println(generateOrderNo("1001", DEFAULT_LENGTH)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/annotation/ApiRequestField.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 表示model中,对应的微信支付接口中的字段,以及是否为必填项 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.FIELD}) 13 | public @interface ApiRequestField { 14 | 15 | String value() default ""; 16 | 17 | boolean required() default true; 18 | } 19 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/annotation/ApiResponseField.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 微信支付 返回结果参数与class字段的对应关系 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.FIELD}) 13 | public @interface ApiResponseField { 14 | String value() default ""; 15 | } 16 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/exception/WechatPayException.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.exception; 2 | 3 | public class WechatPayException extends Exception { 4 | private String errCode; 5 | private String errMsg; 6 | 7 | public WechatPayException(String errCode, String errMsg) { 8 | super(errCode + ":" + errMsg); 9 | this.errCode = errCode; 10 | this.errMsg = errMsg; 11 | } 12 | 13 | public WechatPayException(Throwable cause) { 14 | super(cause); 15 | this.errMsg = cause.getMessage(); 16 | } 17 | 18 | public WechatPayException(String message, Throwable cause) { 19 | super(message, cause); 20 | this.errMsg = message; 21 | } 22 | 23 | public WechatPayException(String message) { 24 | super(message); 25 | this.errMsg = message; 26 | } 27 | 28 | public String getErrCode() { 29 | return errCode; 30 | } 31 | 32 | public String getErrMsg() { 33 | return errMsg; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/model/SignatureItem.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.model; 2 | 3 | public class SignatureItem { 4 | private String signContent; 5 | private String sign; 6 | 7 | public String getSignContent() { 8 | return signContent; 9 | } 10 | 11 | public void setSignContent(String signContent) { 12 | this.signContent = signContent; 13 | } 14 | 15 | public String getSign() { 16 | return sign; 17 | } 18 | 19 | public void setSign(String sign) { 20 | this.sign = sign; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/model/WechatPayModel.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.model; 2 | 3 | 4 | import com.kk.wechat.annotation.ApiRequestField; 5 | 6 | 7 | /** 8 | * 微信支付接口的 基础 参数 9 | * 10 | * 返回值中,java类中字段可以比 微信返回的xml结果少字段, 在WechatPayClient中对返回值计算签名的时候,是对xml进行校验签名。 11 | * 12 | * WechatPayClient.convert转换, 会处理data类型 13 | */ 14 | public class WechatPayModel { 15 | // 公众账号ID 16 | @ApiRequestField("appid") 17 | protected String appId; 18 | 19 | // 随机字符串 20 | @ApiRequestField("nonce_str") 21 | protected String nonceStr; 22 | 23 | // 签名 24 | @ApiRequestField("sign") 25 | protected String sign; 26 | 27 | // 微信支付 商户号 28 | @ApiRequestField("mch_id") 29 | protected String mchId; 30 | 31 | public WechatPayModel() { 32 | } 33 | 34 | public String getAppId() { 35 | return appId; 36 | } 37 | 38 | public void setAppId(String appId) { 39 | this.appId = appId; 40 | } 41 | 42 | public String getMchId() { 43 | return mchId; 44 | } 45 | 46 | public void setMchId(String mchId) { 47 | this.mchId = mchId; 48 | } 49 | 50 | public String getNonceStr() { 51 | return nonceStr; 52 | } 53 | 54 | public void setNonceStr(String nonceStr) { 55 | this.nonceStr = nonceStr; 56 | } 57 | 58 | public String getSign() { 59 | return sign; 60 | } 61 | 62 | public void setSign(String sign) { 63 | this.sign = sign; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/model/WechatPayQueryModel.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.model; 2 | 3 | 4 | import com.kk.wechat.annotation.ApiRequestField; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * 微信支付订单查询 接口参数 10 | *

11 | * 两个参数 至少传一个 12 | */ 13 | public class WechatPayQueryModel extends WechatPayModel { 14 | // 商户订单号:商户系统内部的订单号,当没提供transaction_id时需要传这个。 15 | @ApiRequestField(value = "out_trade_no", required = false) 16 | private String outTradeNo; 17 | 18 | // 微信订单号,优先使用 19 | @ApiRequestField(value = "transaction_id", required = false) 20 | private String transactionId; 21 | 22 | public String getOutTradeNo() { 23 | return outTradeNo; 24 | } 25 | 26 | public void setOutTradeNo(String outTradeNo) { 27 | this.outTradeNo = outTradeNo; 28 | } 29 | 30 | public String getTransactionId() { 31 | return transactionId; 32 | } 33 | 34 | public void setTransactionId(String transactionId) { 35 | this.transactionId = transactionId; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/model/WechatPayTradeStatus.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.model; 2 | 3 | /** 4 | * 微信支付-订单查询的时候 返回的交易状态 5 | * SUCCESS—支付成功 6 | * REFUND—转入退款 7 | * NOTPAY—未支付 8 | * CLOSED—已关闭 9 | * REVOKED—已撤销(刷卡支付) 10 | * USERPAYING--用户支付中 11 | * PAYERROR--支付失败(其他原因,如银行返回失败) 12 | */ 13 | public enum WechatPayTradeStatus { 14 | SUCCESS, REFUND, NOTPAY, CLOSED, REVOKED, USERPAYING, PAYERROR; 15 | } 16 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/request/WechatPayMicroPayRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.request; 2 | 3 | 4 | import com.kk.wechat.model.WechatPayMicroPayModel; 5 | import com.kk.wechat.response.WechatPayMicroPayResponse; 6 | 7 | /** 8 | * 刷卡支付, 没有notify_url 9 | *

10 | * https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1 11 | *

12 | * 提醒1:提交支付请求后微信会同步返回支付结果。 13 | * 当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果; 14 | * 当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒); 15 | */ 16 | public class WechatPayMicroPayRequest implements WechatPayRequest { 17 | private WechatPayMicroPayModel model; 18 | 19 | @Override 20 | public String getApiAction() { 21 | return "/pay/micropay"; 22 | } 23 | 24 | @Override 25 | public WechatPayMicroPayModel getModel() { 26 | return this.model; 27 | } 28 | 29 | @Override 30 | public void setModel(WechatPayMicroPayModel model) { 31 | this.model = model; 32 | } 33 | 34 | @Override 35 | public Class getObjectClass() { 36 | return WechatPayMicroPayModel.class; 37 | } 38 | 39 | @Override 40 | public Class getResponseClass() { 41 | return WechatPayMicroPayResponse.class; 42 | } 43 | 44 | @Override 45 | public boolean requireCert() { 46 | return false; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/request/WechatPayPrePayRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.request; 2 | 3 | 4 | import com.kk.wechat.model.WechatPayPrePayModel; 5 | import com.kk.wechat.response.WechatPayPrePayResponse; 6 | 7 | /** 8 | * 微信统一下单接口 9 | */ 10 | public class WechatPayPrePayRequest implements WechatPayRequest { 11 | private WechatPayPrePayModel model; 12 | 13 | @Override 14 | public String getApiAction() { 15 | return "/pay/unifiedorder"; 16 | } 17 | 18 | @Override 19 | public WechatPayPrePayModel getModel() { 20 | return this.model; 21 | } 22 | 23 | @Override 24 | public void setModel(WechatPayPrePayModel model) { 25 | this.model = model; 26 | } 27 | 28 | @Override 29 | public Class getObjectClass() { 30 | return WechatPayPrePayModel.class; 31 | } 32 | 33 | @Override 34 | public Class getResponseClass() { 35 | return WechatPayPrePayResponse.class; 36 | } 37 | 38 | @Override 39 | public boolean requireCert() { 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/request/WechatPayQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.request; 2 | 3 | 4 | import com.kk.wechat.model.WechatPayQueryModel; 5 | import com.kk.wechat.response.WechatPayQueryResponse; 6 | 7 | /** 8 | * 微信查询接口 9 | */ 10 | public class WechatPayQueryRequest implements WechatPayRequest { 11 | private WechatPayQueryModel model; 12 | 13 | @Override 14 | public String getApiAction() { 15 | return "/pay/orderquery"; 16 | } 17 | 18 | @Override 19 | public WechatPayQueryModel getModel() { 20 | return this.model; 21 | } 22 | 23 | @Override 24 | public void setModel(WechatPayQueryModel model) { 25 | this.model = model; 26 | } 27 | 28 | @Override 29 | public Class getObjectClass() { 30 | return WechatPayQueryModel.class; 31 | } 32 | 33 | @Override 34 | public Class getResponseClass() { 35 | return WechatPayQueryResponse.class; 36 | } 37 | 38 | @Override 39 | public boolean requireCert() { 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/request/WechatPayRefundRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.request; 2 | 3 | import com.kk.wechat.model.WechatPayRefundModel; 4 | import com.kk.wechat.response.WechatPayRefundResponse; 5 | 6 | /** 7 | * 微信退款接口 8 | */ 9 | public class WechatPayRefundRequest implements WechatPayRequest { 10 | private WechatPayRefundModel wechatPayRefundModel; 11 | 12 | @Override 13 | public WechatPayRefundModel getModel() { 14 | return this.wechatPayRefundModel; 15 | } 16 | 17 | @Override 18 | public void setModel(WechatPayRefundModel model) { 19 | this.wechatPayRefundModel = model; 20 | } 21 | 22 | @Override 23 | public String getApiAction() { 24 | return "/secapi/pay/refund"; 25 | } 26 | 27 | @Override 28 | public Class getObjectClass() { 29 | return WechatPayRefundModel.class; 30 | } 31 | 32 | @Override 33 | public Class getResponseClass() { 34 | return WechatPayRefundResponse.class; 35 | } 36 | 37 | /** 38 | * 微信退款需要数字证书!!!!!! 39 | * 40 | * @return 41 | */ 42 | @Override 43 | public boolean requireCert() { 44 | return true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/request/WechatPayRequest.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.request; 2 | 3 | import com.kk.wechat.model.WechatPayModel; 4 | import com.kk.wechat.response.WechatPayResponse; 5 | 6 | /** 7 | * 微信支付 参数结构 8 | * 9 | * @param WechatPayModel 请求参数 10 | * @param WechatPayResponse 返回结果 11 | */ 12 | public interface WechatPayRequest { 13 | /** 14 | * 返回 WechatPayModel 15 | * 16 | * @return 17 | */ 18 | R getModel(); 19 | 20 | /** 21 | * 设置 WechatPayModel,设置请求参数 22 | * 23 | * @param model 24 | */ 25 | void setModel(R model); 26 | 27 | /** 28 | * 获取支付接口 url后缀 29 | * 30 | * @return 31 | */ 32 | String getApiAction(); 33 | 34 | /** 35 | * 获取model.class 36 | * 37 | * @return 38 | */ 39 | Class getObjectClass(); 40 | 41 | /** 42 | * 获取response.class 43 | * 44 | * @return 45 | */ 46 | Class getResponseClass(); 47 | 48 | /** 49 | * 是否需要带上支付凭证 50 | * 51 | * @return 52 | */ 53 | boolean requireCert(); 54 | } 55 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/response/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.response; 2 | 3 | public enum ResultCode { 4 | SUCCESS("SUCCESS"),FAIL("FAIL"), ; 5 | private String value; 6 | 7 | ResultCode(String value) { 8 | this.value = value; 9 | } 10 | 11 | public String getValue() { 12 | return value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /pay-platform/pay-service/src/main/java/com/kk/wechat/response/WechatPayResponse.java: -------------------------------------------------------------------------------- 1 | package com.kk.wechat.response; 2 | 3 | import com.kk.wechat.annotation.ApiResponseField; 4 | import org.apache.commons.lang3.StringUtils; 5 | 6 | /** 7 | * 微信支付 返回结果 基础参数 8 | *

9 | * WechatPayClient.convert转换, 会处理data类型,WechatPayTradeStatus类型, 10 | */ 11 | public abstract class WechatPayResponse { 12 | // 业务结果 SUCCESS/FAIL !!!!!!!!!!!!!!! 13 | @ApiResponseField("result_code") 14 | protected String resultCode; 15 | 16 | // return_code, return_msg 是所有返回结果的 基础。 17 | 18 | // SUCCESS/FAIL 此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断 19 | @ApiResponseField("return_code") 20 | protected String returnCode; 21 | 22 | // 返回信息,如非空,为错误原因 如,签名失败 ,参数格式校验错误 23 | @ApiResponseField("return_msg") 24 | protected String returnMsg; 25 | 26 | public String getResultCode() { 27 | return resultCode; 28 | } 29 | 30 | public void setResultCode(String resultCode) { 31 | this.resultCode = resultCode; 32 | } 33 | 34 | public String getReturnCode() { 35 | return returnCode; 36 | } 37 | 38 | public void setReturnCode(String returnCode) { 39 | this.returnCode = returnCode; 40 | } 41 | 42 | public String getReturnMsg() { 43 | return returnMsg; 44 | } 45 | 46 | public void setReturnMsg(String returnMsg) { 47 | this.returnMsg = returnMsg; 48 | } 49 | 50 | // 判断操作是否成功,即通信结果和业务结果均为 SUCCESS时候表示操作成功 51 | public boolean isSuccess() { 52 | return StringUtils.isNotBlank(resultCode) && ResultCode.SUCCESS.getValue().equalsIgnoreCase(resultCode); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /pay-platform/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.kk 5 | pay-pltform 6 | pom 7 | 1.0-SNAPSHOT 8 | pay platform 9 | http://pay.kk.com 10 | 11 | 12 | pay-api 13 | pay-api-model 14 | pay-caller 15 | pay-service 16 | web-common 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /pay-platform/sql/file_resource.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50620 6 | Source Host : localhost:3306 7 | Source Database : test 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50620 11 | File Encoding : 65001 12 | 13 | Date: 2016-09-06 19:56:25 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for file_resource 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `file_resource`; 22 | CREATE TABLE `file_resource` ( 23 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 24 | `file_id` varchar(32) NOT NULL DEFAULT '', 25 | `data` mediumblob NOT NULL, 26 | `name` varchar(100) NOT NULL DEFAULT '', 27 | `size` bigint(11) NOT NULL, 28 | `file_type` varchar(50) NOT NULL DEFAULT '', 29 | PRIMARY KEY (`id`) 30 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; 31 | -------------------------------------------------------------------------------- /pay-platform/sql/pay_channel.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50620 6 | Source Host : localhost:3306 7 | Source Database : test 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50620 11 | File Encoding : 65001 12 | 13 | Date: 2016-09-06 19:56:31 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for pay_channel 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `pay_channel`; 22 | CREATE TABLE `pay_channel` ( 23 | `id` int(11) NOT NULL AUTO_INCREMENT, 24 | `pay_type_id` int(11) NOT NULL, 25 | `pay_type_name` varchar(255) DEFAULT NULL, 26 | `pay_type_code` varchar(255) DEFAULT NULL, 27 | `pay_channel_name` varchar(255) DEFAULT NULL, 28 | `sign_type` varchar(255) NOT NULL, 29 | `cert_file_id` varchar(32) DEFAULT NULL, 30 | `api_key` varchar(255) DEFAULT NULL, 31 | `app_id` varchar(255) NOT NULL, 32 | `mch_id` varchar(255) NOT NULL, 33 | `status` smallint(6) NOT NULL, 34 | `mch_key` varchar(1024) DEFAULT NULL, 35 | `platform_key` varchar(1024) DEFAULT NULL, 36 | `query_channel_id` int(11) DEFAULT '0', 37 | PRIMARY KEY (`id`) 38 | ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; 39 | -------------------------------------------------------------------------------- /pay-platform/sql/pay_merchant.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50620 6 | Source Host : localhost:3306 7 | Source Database : test 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50620 11 | File Encoding : 65001 12 | 13 | Date: 2016-09-06 19:56:36 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for pay_merchant 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `pay_merchant`; 22 | CREATE TABLE `pay_merchant` ( 23 | `id` int(11) NOT NULL AUTO_INCREMENT, 24 | `name` varchar(255) NOT NULL, 25 | `merchant_id` varchar(19) NOT NULL, 26 | `api_key` varchar(32) NOT NULL, 27 | `status` smallint(255) NOT NULL, 28 | PRIMARY KEY (`id`) 29 | ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; 30 | -------------------------------------------------------------------------------- /pay-platform/sql/pay_merchant_channel.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50620 6 | Source Host : localhost:3306 7 | Source Database : test 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50620 11 | File Encoding : 65001 12 | 13 | Date: 2016-09-06 19:56:42 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for pay_merchant_channel 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `pay_merchant_channel`; 22 | CREATE TABLE `pay_merchant_channel` ( 23 | `id` int(11) NOT NULL AUTO_INCREMENT, 24 | `pay_type_id` int(11) DEFAULT NULL, 25 | `pay_merchant_id` int(11) DEFAULT NULL, 26 | `pay_channel_id` int(11) NOT NULL, 27 | `trade_type` varchar(255) DEFAULT NULL, 28 | PRIMARY KEY (`id`), 29 | KEY `pay_merchant_id` (`pay_merchant_id`), 30 | KEY `pay_channel_id` (`pay_channel_id`) 31 | ) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8; 32 | -------------------------------------------------------------------------------- /pay-platform/sql/pay_order.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50620 6 | Source Host : localhost:3306 7 | Source Database : test 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50620 11 | File Encoding : 65001 12 | 13 | Date: 2016-09-06 19:56:47 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for pay_order 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `pay_order`; 22 | CREATE TABLE `pay_order` ( 23 | `id` int(11) NOT NULL AUTO_INCREMENT, 24 | `pay_type_code` varchar(50) DEFAULT NULL, 25 | `pay_order_no` varchar(255) NOT NULL, 26 | `trade_pay_no` varchar(255) DEFAULT NULL, 27 | `pre_pay_id` varchar(100) DEFAULT NULL, 28 | `pay_id` varchar(100) DEFAULT NULL, 29 | `user_ip` varchar(50) DEFAULT NULL, 30 | `pay_amount` int(11) DEFAULT NULL, 31 | `pay_time` datetime DEFAULT NULL, 32 | `status` smallint(6) DEFAULT NULL, 33 | `error_code` varchar(32) DEFAULT NULL, 34 | `error_msg` varchar(128) DEFAULT NULL, 35 | `start_time` datetime DEFAULT NULL, 36 | `expire_time` datetime DEFAULT NULL, 37 | `open_id` varchar(255) DEFAULT NULL, 38 | `buyer_logon_id` varchar(255) DEFAULT NULL, 39 | `notify_url` varchar(255) DEFAULT NULL, 40 | `extra` varchar(100) DEFAULT NULL, 41 | `subject` varchar(100) DEFAULT NULL, 42 | `detail` varchar(500) DEFAULT NULL, 43 | `code_url` varchar(255) DEFAULT NULL, 44 | `merchant_id` varchar(255) DEFAULT NULL, 45 | `trade_type` varchar(255) DEFAULT NULL, 46 | `return_url` varchar(255) DEFAULT NULL, 47 | `refund_amount` int(11) DEFAULT NULL, 48 | PRIMARY KEY (`id`), 49 | UNIQUE KEY `pay_order_no` (`pay_order_no`) USING BTREE, 50 | KEY `trade_pay_no` (`trade_pay_no`), 51 | KEY `pay_id` (`pay_id`) 52 | ) ENGINE=InnoDB AUTO_INCREMENT=12478 DEFAULT CHARSET=utf8; 53 | -------------------------------------------------------------------------------- /pay-platform/sql/refund_order.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Version : 50620 6 | Source Host : localhost:3306 7 | Source Database : test 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50620 11 | File Encoding : 65001 12 | 13 | Date: 2016-09-06 19:56:52 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for refund_order 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `refund_order`; 22 | CREATE TABLE `refund_order` ( 23 | `id` int(11) NOT NULL AUTO_INCREMENT, 24 | `pay_channel_id` int(255) DEFAULT NULL, 25 | `pay_type_code` varchar(255) DEFAULT NULL, 26 | `pay_order_no` varchar(255) DEFAULT NULL, 27 | `trade_pay_no` varchar(255) DEFAULT NULL, 28 | `refund_order_no` varchar(255) DEFAULT NULL, 29 | `trade_refund_no` varchar(255) DEFAULT NULL, 30 | `pay_id` varchar(255) DEFAULT NULL, 31 | `pay_amount` int(11) DEFAULT NULL, 32 | `refund_id` varchar(255) DEFAULT NULL, 33 | `refund_amount` int(11) DEFAULT NULL, 34 | `status` smallint(6) DEFAULT NULL, 35 | `error_code` varchar(255) DEFAULT NULL, 36 | `error_msg` varchar(255) DEFAULT NULL, 37 | `refund_time` datetime DEFAULT NULL, 38 | `merchant_id` varchar(255) DEFAULT NULL, 39 | `trade_type` varchar(255) DEFAULT NULL, 40 | `notify_url` varchar(255) DEFAULT NULL, 41 | `refund_reason` varchar(255) DEFAULT NULL, 42 | `create_time` datetime DEFAULT NULL, 43 | PRIMARY KEY (`id`), 44 | UNIQUE KEY `refund_order_no` (`refund_order_no`), 45 | UNIQUE KEY `trade_refund_no_mid` (`trade_refund_no`,`merchant_id`) USING BTREE, 46 | KEY `trade_pay_no` (`trade_pay_no`), 47 | KEY `pay_order_no` (`pay_order_no`) 48 | ) ENGINE=InnoDB AUTO_INCREMENT=246 DEFAULT CHARSET=utf8; 49 | -------------------------------------------------------------------------------- /pay-platform/web-common/src/main/java/com/kk/utils/IPUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.utils; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | /** 6 | * IPUtil 7 | * 8 | * @author xiaochen.sun 9 | * @since 2015-11-06 17:24 10 | */ 11 | public class IPUtil { 12 | 13 | public static String getIpAddr(HttpServletRequest request) { 14 | String ip = request.getHeader("x-forwarded-for"); 15 | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 16 | ip = request.getHeader("Proxy-Client-IP"); 17 | } 18 | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 19 | ip = request.getHeader("WL-Proxy-Client-IP"); 20 | } 21 | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 22 | ip = request.getRemoteAddr(); 23 | } 24 | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 25 | ip = "unknown"; 26 | } 27 | return ip.split(",")[0]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pay-platform/web-common/src/main/java/com/kk/utils/LocalIPUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.utils; 2 | 3 | import java.net.InetAddress; 4 | import java.net.NetworkInterface; 5 | import java.net.SocketException; 6 | import java.util.Enumeration; 7 | 8 | public class LocalIPUtil { 9 | public LocalIPUtil() { 10 | } 11 | 12 | public static String getLocalAddr() { 13 | Enumeration interfaces = null; 14 | 15 | try { 16 | interfaces = NetworkInterface.getNetworkInterfaces(); 17 | } catch (SocketException var4) { 18 | var4.printStackTrace(); 19 | return null; 20 | } 21 | 22 | while (interfaces.hasMoreElements()) { 23 | NetworkInterface ifc = (NetworkInterface) interfaces.nextElement(); 24 | Enumeration addressesOfAnInterface = ifc.getInetAddresses(); 25 | 26 | while (addressesOfAnInterface.hasMoreElements()) { 27 | InetAddress address = (InetAddress) addressesOfAnInterface.nextElement(); 28 | if (address.isSiteLocalAddress()) { 29 | return address.getHostAddress(); 30 | } 31 | } 32 | } 33 | 34 | return null; 35 | } 36 | 37 | public static void main(String[] args) { 38 | System.out.println(getLocalAddr()); 39 | } 40 | } -------------------------------------------------------------------------------- /pay-platform/web-common/src/main/java/com/kk/utils/Model2StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.utils; 2 | 3 | import java.lang.reflect.Field; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | /** 8 | * 9 | * 打印model对象的各个字段信息使用的工具类,功能类似于JSONSerializer.toJSON(model) 10 | * 11 | * 12 | */ 13 | 14 | public class Model2StringUtil { 15 | private static SimpleDateFormat sdf = new SimpleDateFormat( 16 | "yyyy-MM-dd HH:mm:ss"); 17 | 18 | public static String transModel2String(Object o) { 19 | if (o == null) { 20 | return null; 21 | } 22 | StringBuffer sb = new StringBuffer(); 23 | sb.append(o.getClass().getName() + "["); 24 | Field[] farr = o.getClass().getDeclaredFields(); 25 | for (int i = 0; i < farr.length; i++) { 26 | Field field = farr[i]; 27 | try { 28 | if (i > 0) { 29 | sb.append(","); 30 | } 31 | field.setAccessible(true); 32 | sb.append(field.getName()); 33 | sb.append("="); 34 | if (field.get(o) != null && field.get(o) instanceof Date) { 35 | // 日期的处理 36 | sb.append(sdf.format(field.get(o))); 37 | } else { 38 | sb.append(field.get(o)); 39 | } 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | sb.append("]"); 45 | return sb.toString(); 46 | } 47 | } -------------------------------------------------------------------------------- /pay-platform/web-common/src/main/java/com/kk/utils/WebPropertiesUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.utils; 2 | 3 | import org.apache.commons.logging.Log; 4 | import org.apache.commons.logging.LogFactory; 5 | 6 | import java.io.BufferedInputStream; 7 | import java.io.FileInputStream; 8 | import java.io.InputStream; 9 | import java.util.Properties; 10 | 11 | /** 12 | * 操作web.properties文件 13 | * 代码中的配置为测试环境配置,上线后会被替换 14 | */ 15 | public class WebPropertiesUtil { 16 | private static final Log logger = LogFactory.getLog(WebPropertiesUtil.class); 17 | private static WebPropertiesUtil instance = new WebPropertiesUtil(); 18 | 19 | public static final String ENVIRONMENT = "environment";// 当前环境 test/online 20 | public static final String ONLINE_ENVIRONMENT = "online"; 21 | 22 | private Properties props = new Properties(); 23 | 24 | public static WebPropertiesUtil getInstance() { 25 | return instance; 26 | } 27 | 28 | private WebPropertiesUtil() { 29 | initConfigProperties("web.properties"); 30 | } 31 | 32 | private void initConfigProperties(String filePath) { 33 | String path = getClass().getResource("/").getPath(); 34 | InputStream in; 35 | try { 36 | in = new BufferedInputStream(new FileInputStream(path + filePath)); 37 | props.load(in); 38 | 39 | } catch (Exception e) { 40 | logger.error(e.getMessage(), e); 41 | } 42 | } 43 | 44 | public String getValue(String key) { 45 | return props.getProperty(key); 46 | } 47 | 48 | 49 | public Properties getProperty(String filePath) { 50 | Properties propTmp = new Properties(); 51 | String path = getClass().getResource("/").getPath(); 52 | InputStream in; 53 | try { 54 | in = new BufferedInputStream(new FileInputStream(path + filePath)); 55 | propTmp.load(in); 56 | } catch (Exception e) { 57 | logger.error(e.getMessage(), e); 58 | } 59 | return propTmp; 60 | } 61 | 62 | public boolean isOnline() { 63 | String env = getInstance().getValue(ENVIRONMENT); 64 | if (env != null && env.equals(ONLINE_ENVIRONMENT)) { 65 | return true; 66 | } 67 | 68 | return false; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /pay-platform/支付宝私钥公钥.txt: -------------------------------------------------------------------------------- 1 | 创建应用。 并且设置 自己的私钥和公钥,自己的公钥要上传到支付宝, 查看支付宝的公钥。 2 | 3 | 支付宝公钥: 支付宝公钥用来验证返回给开发者的信息是否是支付宝发送的。每个应用的支付宝公钥内容是一样的,使用下载的demo或sdk中自带的支付宝公钥即可;第三方应用使用的支付宝公钥,可以在对应的应用环境中“支付宝公钥”处查看。 4 | 5 | https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.7W7fUQ&treeId=44&articleId=103242&docType=1 6 | 7 | 8 | 9 | 自己的公钥和私钥(公钥上传到支付宝,本地使用私钥加密,支付宝用公钥解密): 10 | 11 | java 需要转成 pkcs8格式(头部不一样, 一般私钥头:-----BEGIN RSA PRIVATE KEY-----, pkcs8私钥头:-----BEGIN PRIVATE KEY-----)。 12 | 13 | openssl pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt -out private_key_pkcs8.pem 14 | 15 | 16 | 17 | 然后把 头部和尾部 信息去掉,并且把中间的回车去掉, 剩下就是 需要的公钥和私钥。 -------------------------------------------------------------------------------- /pay/README.md: -------------------------------------------------------------------------------- 1 | # 微信支付,支付宝支付简单集成,接口调试成功,推荐 pay-platform,做成支付平台,供业务方调用 2 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/config/AlipayConfig.java: -------------------------------------------------------------------------------- 1 | package com.alipay.config; 2 | 3 | /* * 4 | *类名:AlipayConfig 5 | *功能:基础配置类 6 | *详细:设置帐户有关信息及返回路径 7 | *版本:3.4 8 | *修改日期:2016-03-08 9 | *说明: 10 | *以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 11 | *该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 12 | */ 13 | 14 | public class AlipayConfig { 15 | 16 | //↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 17 | 18 | // 合作身份者ID,签约账号,以2088开头由16位纯数字组成的字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm 19 | public static String partner = ""; 20 | 21 | // 收款支付宝账号,以2088开头由16位纯数字组成的字符串,一般情况下收款账号就是签约账号 22 | public static String seller_id = partner; 23 | 24 | //商户的私钥,需要PKCS8格式,RSA公私钥生成:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.nBDxfy&treeId=58&articleId=103242&docType=1 25 | public static String private_key = ""; 26 | 27 | // 支付宝的公钥,查看地址:https://b.alipay.com/order/pidAndKey.htm 28 | public static String alipay_public_key = ""; 29 | 30 | 31 | // 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 32 | // public static String notify_url = "http://www.kk.com/alipay/notify_url.jsp"; 33 | public static String notify_url = "http://www.kk.com/kk/alipay/h5pay/notify"; 34 | 35 | // 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 36 | // public static String return_url = "http://www.kk.com/alipay/return_url.jsp"; 37 | public static String return_url = "http://www.kk.com/kk/alipay/h5pay/return"; 38 | 39 | // 签名方式 40 | public static String sign_type = "RSA"; 41 | 42 | // 字符编码格式 目前支持utf-8 43 | public static String input_charset = "utf-8"; 44 | 45 | // 支付类型 ,无需修改 46 | public static String payment_type = "1"; 47 | 48 | // 调用的接口名,无需修改 49 | public static String service = "alipay.wap.create.direct.pay.by.user"; 50 | 51 | 52 | //↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/config/Constants.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.config; 2 | 3 | public class Constants { 4 | public static final String SUCCESS = "10000"; 5 | public static final String PAYING = "10003"; 6 | public static final String FAILED = "40004"; 7 | public static final String ERROR = "20000"; 8 | } 9 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/ExtendParams.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class ExtendParams { 6 | 7 | @SerializedName("sys_service_provider_id") 8 | private String sysServiceProviderId; 9 | 10 | public String toString() { 11 | StringBuilder sb = new StringBuilder("ExtendParams{"); 12 | sb.append("sysServiceProviderId='").append(this.sysServiceProviderId).append('\''); 13 | sb.append('}'); 14 | return sb.toString(); 15 | } 16 | 17 | public String getSysServiceProviderId() { 18 | return this.sysServiceProviderId; 19 | } 20 | 21 | public ExtendParams setSysServiceProviderId(String sysServiceProviderId) { 22 | this.sysServiceProviderId = sysServiceProviderId; 23 | return this; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/TradeStatus.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model; 2 | 3 | public enum TradeStatus 4 | { 5 | SUCCESS, 6 | 7 | FAILED, 8 | 9 | UNKNOWN; 10 | } 11 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/builder/AlipayTradeCancelCententBuilder.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.builder; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import org.apache.commons.lang.StringUtils; 5 | 6 | public class AlipayTradeCancelCententBuilder extends RequestBuilder 7 | { 8 | 9 | @SerializedName("trade_no") 10 | private String tradeNo; 11 | 12 | @SerializedName("out_trade_no") 13 | private String outTradeNo; 14 | 15 | public boolean validate() 16 | { 17 | if ((StringUtils.isEmpty(this.tradeNo)) && 18 | (StringUtils.isEmpty(this.outTradeNo))) { 19 | throw new IllegalStateException("tradeNo and outTradeNo can not both be NULL!"); 20 | } 21 | return true; 22 | } 23 | 24 | public String toString() 25 | { 26 | StringBuilder sb = new StringBuilder("AlipayTradeQueryCententBuilder{"); 27 | sb.append("tradeNo='").append(this.tradeNo).append('\''); 28 | sb.append(", outTradeNo='").append(this.outTradeNo).append('\''); 29 | sb.append('}'); 30 | return sb.toString(); 31 | } 32 | 33 | public String getTradeNo() { 34 | return this.tradeNo; 35 | } 36 | 37 | public AlipayTradeCancelCententBuilder setTradeNo(String tradeNo) { 38 | this.tradeNo = tradeNo; 39 | return this; 40 | } 41 | 42 | public String getOutTradeNo() { 43 | return this.outTradeNo; 44 | } 45 | 46 | public AlipayTradeCancelCententBuilder setOutTradeNo(String outTradeNo) { 47 | this.outTradeNo = outTradeNo; 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/builder/AlipayTradeQueryCententBuilder.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.builder; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import org.apache.commons.lang.StringUtils; 5 | 6 | public class AlipayTradeQueryCententBuilder extends RequestBuilder 7 | { 8 | 9 | @SerializedName("trade_no") 10 | private String tradeNo; 11 | 12 | @SerializedName("out_trade_no") 13 | private String outTradeNo; 14 | 15 | public boolean validate() 16 | { 17 | if ((StringUtils.isEmpty(this.tradeNo)) && 18 | (StringUtils.isEmpty(this.outTradeNo))) { 19 | throw new IllegalStateException("tradeNo and outTradeNo can not both be NULL!"); 20 | } 21 | return true; 22 | } 23 | 24 | public String toString() 25 | { 26 | StringBuilder sb = new StringBuilder("AlipayTradeQueryCententBuilder{"); 27 | sb.append("tradeNo='").append(this.tradeNo).append('\''); 28 | sb.append(", outTradeNo='").append(this.outTradeNo).append('\''); 29 | sb.append('}'); 30 | return sb.toString(); 31 | } 32 | 33 | public String getTradeNo() { 34 | return this.tradeNo; 35 | } 36 | 37 | public AlipayTradeQueryCententBuilder setTradeNo(String tradeNo) { 38 | this.tradeNo = tradeNo; 39 | return this; 40 | } 41 | 42 | public String getOutTradeNo() { 43 | return this.outTradeNo; 44 | } 45 | 46 | public AlipayTradeQueryCententBuilder setOutTradeNo(String outTradeNo) { 47 | this.outTradeNo = outTradeNo; 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/builder/RequestBuilder.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.builder; 2 | 3 | import com.alipay.demo.trade.utils.GsonFactory; 4 | import com.google.gson.Gson; 5 | 6 | public abstract class RequestBuilder { 7 | public abstract boolean validate(); 8 | 9 | public String toJsonString() { 10 | return GsonFactory.getGson().toJson(this); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/EquipStatus.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | public enum EquipStatus { 4 | ON("10"), 5 | 6 | OFF("20"), 7 | 8 | NORMAL("30"), 9 | 10 | SLEEP("40"), 11 | 12 | AWAKE("41"); 13 | 14 | private String value; 15 | 16 | private EquipStatus(String value) { 17 | this.value = value; 18 | } 19 | 20 | public String getValue() { 21 | return this.value; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/EquipStatusAdapter.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.JsonPrimitive; 5 | import com.google.gson.JsonSerializationContext; 6 | import com.google.gson.JsonSerializer; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | public class EquipStatusAdapter 11 | implements JsonSerializer { 12 | public JsonElement serialize(EquipStatus equipStatus, Type type, JsonSerializationContext jsonSerializationContext) { 13 | return new JsonPrimitive(equipStatus.getValue()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/ExceptionInfo.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | public enum ExceptionInfo 4 | { 5 | HE_PRINTER, 6 | 7 | HE_SCANER, 8 | 9 | HE_OTHER; 10 | } 11 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/ExceptionInfoAdapter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.alipay.demo.trade.model.hb; 3 | 4 | 5 | import com.alipay.demo.trade.utils.Utils; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonPrimitive; 8 | import com.google.gson.JsonSerializationContext; 9 | import com.google.gson.JsonSerializer; 10 | 11 | import java.lang.reflect.Type; 12 | import java.util.List; 13 | 14 | import org.apache.commons.lang.StringUtils; 15 | 16 | 17 | public class ExceptionInfoAdapter 18 | implements JsonSerializer> { 19 | public JsonElement serialize(List exceptionInfos, Type type, JsonSerializationContext jsonSerializationContext) { 20 | 21 | if (Utils.isListEmpty(exceptionInfos)) { 22 | 23 | return null; 24 | 25 | } 26 | 27 | 28 | return new JsonPrimitive(StringUtils.join(exceptionInfos, "|")); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/HbStatus.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | public enum HbStatus { 4 | S, 5 | 6 | I, 7 | 8 | F, 9 | 10 | P, 11 | 12 | X, 13 | 14 | Y, 15 | 16 | Z, 17 | 18 | C, 19 | 20 | T; 21 | } 22 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/PosTradeInfo.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | public class PosTradeInfo 4 | implements TradeInfo { 5 | private HbStatus status; 6 | private String time; 7 | private int timeConsume; 8 | 9 | public static PosTradeInfo newInstance(HbStatus status, String time, int timeConsume) { 10 | PosTradeInfo info = new PosTradeInfo(); 11 | if ((timeConsume > 99) || (timeConsume < 0)) { 12 | timeConsume = 99; 13 | } 14 | info.setTimeConsume(timeConsume); 15 | info.setStatus(status); 16 | info.setTime(time); 17 | return info; 18 | } 19 | 20 | public String toString() { 21 | return this.status.name() + 22 | this.time + 23 | String.format("%02d", new Object[]{Integer.valueOf(this.timeConsume)}); 24 | } 25 | 26 | public HbStatus getStatus() { 27 | return this.status; 28 | } 29 | 30 | public void setStatus(HbStatus status) { 31 | this.status = status; 32 | } 33 | 34 | public String getTime() { 35 | return this.time; 36 | } 37 | 38 | public void setTime(String time) { 39 | this.time = time; 40 | } 41 | 42 | public double getTimeConsume() { 43 | return this.timeConsume; 44 | } 45 | 46 | public void setTimeConsume(int timeConsume) { 47 | this.timeConsume = timeConsume; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/Product.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | public enum Product { 4 | FP, 5 | 6 | MP; 7 | } 8 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/SysTradeInfo.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class SysTradeInfo 6 | implements TradeInfo 7 | { 8 | 9 | @SerializedName("OTN") 10 | private String outTradeNo; 11 | 12 | @SerializedName("TC") 13 | private double timeConsume; 14 | 15 | @SerializedName("STAT") 16 | private HbStatus status; 17 | 18 | public static SysTradeInfo newInstance(String outTradeNo, double timeConsume, HbStatus status) 19 | { 20 | SysTradeInfo info = new SysTradeInfo(); 21 | info.setOutTradeNo(outTradeNo); 22 | if ((timeConsume > 99.0D) || (timeConsume < 0.0D)) { 23 | timeConsume = 99.0D; 24 | } 25 | info.setTimeConsume(timeConsume); 26 | info.setStatus(status); 27 | return info; 28 | } 29 | 30 | public String getOutTradeNo() { 31 | return this.outTradeNo; 32 | } 33 | 34 | public void setOutTradeNo(String outTradeNo) { 35 | this.outTradeNo = outTradeNo; 36 | } 37 | 38 | public HbStatus getStatus() 39 | { 40 | return this.status; 41 | } 42 | 43 | public void setStatus(HbStatus status) { 44 | this.status = status; 45 | } 46 | 47 | public double getTimeConsume() 48 | { 49 | return this.timeConsume; 50 | } 51 | 52 | public void setTimeConsume(double timeConsume) { 53 | this.timeConsume = timeConsume; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/TradeInfo.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | public interface TradeInfo { 4 | HbStatus getStatus(); 5 | 6 | double getTimeConsume(); 7 | } 8 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/TradeInfoAdapter.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | import com.alipay.demo.trade.utils.Utils; 4 | import com.google.gson.JsonElement; 5 | import com.google.gson.JsonPrimitive; 6 | import com.google.gson.JsonSerializationContext; 7 | import com.google.gson.JsonSerializer; 8 | 9 | import java.lang.reflect.Type; 10 | import java.util.List; 11 | 12 | import org.apache.commons.lang.StringUtils; 13 | 14 | public class TradeInfoAdapter 15 | implements JsonSerializer> { 16 | public JsonElement serialize(List tradeInfoList, Type type, JsonSerializationContext jsonSerializationContext) { 17 | if (Utils.isListEmpty(tradeInfoList)) { 18 | return null; 19 | } 20 | 21 | TradeInfo tradeInfo = (TradeInfo) tradeInfoList.get(0); 22 | if ((tradeInfo instanceof PosTradeInfo)) { 23 | return new JsonPrimitive(StringUtils.join(tradeInfoList, "")); 24 | } 25 | 26 | return jsonSerializationContext.serialize(tradeInfoList); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/hb/Type.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.hb; 2 | 3 | public enum Type { 4 | CR, 5 | 6 | STORE, 7 | 8 | VM, 9 | 10 | MD, 11 | 12 | SOFT_POS, 13 | 14 | POS, 15 | 16 | ALI_POS; 17 | } 18 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/result/AlipayF2FPayResult.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.result; 2 | 3 | import com.alipay.api.response.AlipayTradePayResponse; 4 | import com.alipay.demo.trade.model.TradeStatus; 5 | 6 | public class AlipayF2FPayResult 7 | implements Result { 8 | private TradeStatus tradeStatus; 9 | private AlipayTradePayResponse response; 10 | 11 | public AlipayF2FPayResult(AlipayTradePayResponse response) { 12 | this.response = response; 13 | } 14 | 15 | public void setTradeStatus(TradeStatus tradeStatus) { 16 | this.tradeStatus = tradeStatus; 17 | } 18 | 19 | public void setResponse(AlipayTradePayResponse response) { 20 | this.response = response; 21 | } 22 | 23 | public TradeStatus getTradeStatus() { 24 | return this.tradeStatus; 25 | } 26 | 27 | public AlipayTradePayResponse getResponse() { 28 | return this.response; 29 | } 30 | 31 | public boolean isTradeSuccess() { 32 | return (this.response != null) && 33 | (TradeStatus.SUCCESS.equals(this.tradeStatus)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/result/AlipayF2FPrecreateResult.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.result; 2 | 3 | import com.alipay.api.response.AlipayTradePrecreateResponse; 4 | import com.alipay.demo.trade.model.TradeStatus; 5 | 6 | public class AlipayF2FPrecreateResult 7 | implements Result { 8 | private TradeStatus tradeStatus; 9 | private AlipayTradePrecreateResponse response; 10 | 11 | public AlipayF2FPrecreateResult(AlipayTradePrecreateResponse response) { 12 | this.response = response; 13 | } 14 | 15 | public void setTradeStatus(TradeStatus tradeStatus) { 16 | this.tradeStatus = tradeStatus; 17 | } 18 | 19 | public void setResponse(AlipayTradePrecreateResponse response) { 20 | this.response = response; 21 | } 22 | 23 | public TradeStatus getTradeStatus() { 24 | return this.tradeStatus; 25 | } 26 | 27 | public AlipayTradePrecreateResponse getResponse() { 28 | return this.response; 29 | } 30 | 31 | public boolean isTradeSuccess() { 32 | return (this.response != null) && 33 | (TradeStatus.SUCCESS.equals(this.tradeStatus)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/result/AlipayF2FQueryResult.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.result; 2 | 3 | import com.alipay.api.response.AlipayTradeQueryResponse; 4 | import com.alipay.demo.trade.model.TradeStatus; 5 | 6 | public class AlipayF2FQueryResult 7 | implements Result { 8 | private TradeStatus tradeStatus; 9 | private AlipayTradeQueryResponse response; 10 | 11 | public AlipayF2FQueryResult(AlipayTradeQueryResponse response) { 12 | this.response = response; 13 | } 14 | 15 | public void setTradeStatus(TradeStatus tradeStatus) { 16 | this.tradeStatus = tradeStatus; 17 | } 18 | 19 | public void setResponse(AlipayTradeQueryResponse response) { 20 | this.response = response; 21 | } 22 | 23 | public TradeStatus getTradeStatus() { 24 | return this.tradeStatus; 25 | } 26 | 27 | public AlipayTradeQueryResponse getResponse() { 28 | return this.response; 29 | } 30 | 31 | public boolean isTradeSuccess() { 32 | return (this.response != null) && 33 | (TradeStatus.SUCCESS.equals(this.tradeStatus)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/result/AlipayF2FRefundResult.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.result; 2 | 3 | import com.alipay.api.response.AlipayTradeRefundResponse; 4 | import com.alipay.demo.trade.model.TradeStatus; 5 | 6 | public class AlipayF2FRefundResult 7 | implements Result { 8 | private TradeStatus tradeStatus; 9 | private AlipayTradeRefundResponse response; 10 | 11 | public AlipayF2FRefundResult(AlipayTradeRefundResponse response) { 12 | this.response = response; 13 | } 14 | 15 | public void setTradeStatus(TradeStatus tradeStatus) { 16 | this.tradeStatus = tradeStatus; 17 | } 18 | 19 | public void setResponse(AlipayTradeRefundResponse response) { 20 | this.response = response; 21 | } 22 | 23 | public TradeStatus getTradeStatus() { 24 | return this.tradeStatus; 25 | } 26 | 27 | public AlipayTradeRefundResponse getResponse() { 28 | return this.response; 29 | } 30 | 31 | public boolean isTradeSuccess() { 32 | return (this.response != null) && 33 | (TradeStatus.SUCCESS.equals(this.tradeStatus)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/model/result/Result.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.model.result; 2 | 3 | public interface Result { 4 | boolean isTradeSuccess(); 5 | } 6 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/service/AlipayMonitorService.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.service; 2 | 3 | import com.alipay.api.response.MonitorHeartbeatSynResponse; 4 | import com.alipay.demo.trade.model.builder.AlipayHeartbeatSynContentBuilder; 5 | 6 | public interface AlipayMonitorService { 7 | MonitorHeartbeatSynResponse heartbeatSyn(AlipayHeartbeatSynContentBuilder paramAlipayHeartbeatSynContentBuilder); 8 | 9 | MonitorHeartbeatSynResponse heartbeatSyn(AlipayHeartbeatSynContentBuilder paramAlipayHeartbeatSynContentBuilder, String paramString); 10 | } 11 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/service/AlipayTradeService.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.service; 2 | 3 | import com.alipay.api.response.AlipayTradeCancelResponse; 4 | import com.alipay.demo.trade.model.builder.*; 5 | import com.alipay.demo.trade.model.result.AlipayF2FPayResult; 6 | import com.alipay.demo.trade.model.result.AlipayF2FPrecreateResult; 7 | import com.alipay.demo.trade.model.result.AlipayF2FQueryResult; 8 | import com.alipay.demo.trade.model.result.AlipayF2FRefundResult; 9 | 10 | public interface AlipayTradeService { 11 | AlipayF2FPayResult tradePay(AlipayTradePayContentBuilder builder); 12 | 13 | AlipayF2FQueryResult queryTradeResult(AlipayTradeQueryCententBuilder builder); 14 | 15 | AlipayF2FRefundResult tradeRefund(AlipayTradeRefundContentBuilder builder); 16 | 17 | AlipayF2FPrecreateResult tradePrecreate(AlipayTradePrecreateContentBuilder builder, String notifyUrl); 18 | 19 | AlipayTradeCancelResponse tradeCancel(AlipayTradeCancelCententBuilder builder); 20 | } 21 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/service/impl/AbsAlipayService.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.service.impl; 2 | 3 | import com.alipay.api.AlipayApiException; 4 | import com.alipay.api.AlipayClient; 5 | import com.alipay.api.AlipayRequest; 6 | import com.alipay.api.AlipayResponse; 7 | import com.alipay.demo.trade.model.builder.RequestBuilder; 8 | import org.apache.commons.logging.Log; 9 | import org.apache.commons.logging.LogFactory; 10 | 11 | abstract class AbsAlipayService { 12 | protected Log log = LogFactory.getLog(getClass()); 13 | 14 | protected void validateBuilder(RequestBuilder builder) { 15 | if (builder == null) { 16 | throw new NullPointerException("builder should not be NULL!"); 17 | } 18 | 19 | if (!builder.validate()) 20 | throw new IllegalStateException("builder validate failed! " + builder.toString()); 21 | } 22 | 23 | protected AlipayResponse getResponse(AlipayClient client, AlipayRequest request) { 24 | try { 25 | AlipayResponse response = client.execute(request); 26 | if (response != null) { 27 | this.log.info(response.getBody()); 28 | } 29 | return response; 30 | } catch (AlipayApiException e) { 31 | e.printStackTrace(); 32 | } 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/service/impl/hb/HbListener.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.service.impl.hb; 2 | 3 | import com.alipay.demo.trade.model.hb.HbStatus; 4 | import com.alipay.demo.trade.model.hb.SysTradeInfo; 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | 8 | public class HbListener 9 | implements TradeListener 10 | { 11 | private static Log log = LogFactory.getLog(HbListener.class); 12 | 13 | private void offerTradeInfo(String outTradeNo, long beforeCall, HbStatus status) 14 | { 15 | long afterCall = System.currentTimeMillis(); 16 | 17 | double timeConsume = (afterCall - beforeCall) / 1000.0D; 18 | 19 | log.debug(outTradeNo + " offer " + status + ": " + timeConsume); 20 | 21 | HbQueue.offer(SysTradeInfo.newInstance(outTradeNo, timeConsume, status)); 22 | } 23 | 24 | public void onPayTradeSuccess(String outTradeNo, long beforeCall) 25 | { 26 | offerTradeInfo(outTradeNo, beforeCall, HbStatus.S); 27 | } 28 | 29 | public void onPayInProgress(String outTradeNo, long beforeCall) 30 | { 31 | offerTradeInfo(outTradeNo, beforeCall, HbStatus.I); 32 | } 33 | 34 | public void onPayFailed(String outTradeNo, long beforeCall) 35 | { 36 | offerTradeInfo(outTradeNo, beforeCall, HbStatus.F); 37 | } 38 | 39 | public void onConnectException(String outTradeNo, long beforeCall) 40 | { 41 | offerTradeInfo(outTradeNo, beforeCall, HbStatus.X); 42 | } 43 | 44 | public void onSendException(String outTradeNo, long beforeCall) 45 | { 46 | offerTradeInfo(outTradeNo, beforeCall, HbStatus.Y); 47 | } 48 | 49 | public void onReceiveException(String outTradeNo, long beforeCall) 50 | { 51 | offerTradeInfo(outTradeNo, beforeCall, HbStatus.Z); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/service/impl/hb/HbQueue.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.service.impl.hb; 2 | 3 | import com.alipay.demo.trade.model.hb.SysTradeInfo; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.concurrent.ArrayBlockingQueue; 7 | import java.util.concurrent.BlockingQueue; 8 | import org.apache.commons.logging.Log; 9 | import org.apache.commons.logging.LogFactory; 10 | 11 | public class HbQueue 12 | { 13 | private static Log log = LogFactory.getLog(HbQueue.class); 14 | public static final int QUEUE_SIZE = 300; 15 | private static final BlockingQueue queue = new ArrayBlockingQueue(300); 16 | 17 | public static synchronized void offer(SysTradeInfo info) 18 | { 19 | if (info != null) 20 | try 21 | { 22 | queue.put(info); 23 | } catch (InterruptedException e) { 24 | log.warn("interrupted for tradeInfo:" + info); 25 | e.printStackTrace(); 26 | } 27 | } 28 | 29 | public static synchronized List poll() 30 | { 31 | if (queue.isEmpty()) 32 | { 33 | return null; 34 | } 35 | 36 | int size = 30; 37 | List tradeInfoList = new ArrayList(size); 38 | for (int i = 0; i < size; i++) 39 | { 40 | SysTradeInfo info = (SysTradeInfo)queue.poll(); 41 | if (info == null) { 42 | break; 43 | } 44 | tradeInfoList.add(info); 45 | } 46 | return tradeInfoList; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/service/impl/hb/TradeListener.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.service.impl.hb; 2 | 3 | public abstract interface TradeListener 4 | { 5 | public abstract void onPayTradeSuccess(String paramString, long paramLong); 6 | 7 | public abstract void onPayInProgress(String paramString, long paramLong); 8 | 9 | public abstract void onPayFailed(String paramString, long paramLong); 10 | 11 | public abstract void onConnectException(String paramString, long paramLong); 12 | 13 | public abstract void onSendException(String paramString, long paramLong); 14 | 15 | public abstract void onReceiveException(String paramString, long paramLong); 16 | } 17 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/utils/GsonFactory.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.utils; 2 | 3 | import com.alipay.demo.trade.model.hb.EquipStatus; 4 | import com.alipay.demo.trade.model.hb.EquipStatusAdapter; 5 | import com.alipay.demo.trade.model.hb.ExceptionInfo; 6 | import com.alipay.demo.trade.model.hb.ExceptionInfoAdapter; 7 | import com.alipay.demo.trade.model.hb.TradeInfo; 8 | import com.alipay.demo.trade.model.hb.TradeInfoAdapter; 9 | import com.google.gson.Gson; 10 | import com.google.gson.GsonBuilder; 11 | import com.google.gson.reflect.TypeToken; 12 | 13 | import java.lang.reflect.Type; 14 | import java.util.List; 15 | 16 | public class GsonFactory { 17 | public static Gson getGson() { 18 | return GsonHolder.gson; 19 | } 20 | 21 | private static class GsonHolder { 22 | private static Type exceptionListType = new TypeToken>() { 23 | }.getType(); 24 | private static Type tradeInfoListType = new TypeToken>() { 25 | }.getType(); 26 | 27 | private static Gson gson = new GsonBuilder() 28 | .registerTypeAdapter(exceptionListType, new ExceptionInfoAdapter()) 29 | .registerTypeAdapter(tradeInfoListType, new TradeInfoAdapter()) 30 | .registerTypeAdapter(EquipStatus.class, new EquipStatusAdapter()) 31 | .create(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/demo/trade/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.alipay.demo.trade.utils; 2 | 3 | import java.math.BigDecimal; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | import org.apache.commons.lang.StringUtils; 9 | 10 | public class Utils { 11 | public static String toAmount(long amount) { 12 | return new BigDecimal(amount).divide(new BigDecimal(100)).toString(); 13 | } 14 | 15 | public static String toDate(Date date) { 16 | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); 17 | } 18 | 19 | public static boolean isEmpty(Object object) { 20 | if ((object instanceof String)) { 21 | return StringUtils.isEmpty((String) object); 22 | } 23 | return object == null; 24 | } 25 | 26 | public static boolean isNotEmpty(Object object) { 27 | return !isEmpty(object); 28 | } 29 | 30 | public static boolean isListNotEmpty(List list) { 31 | return (list != null) && (list.size() > 0); 32 | } 33 | 34 | public static boolean isListEmpty(List list) { 35 | return !isListNotEmpty(list); 36 | } 37 | 38 | public static void sleep(long time) { 39 | try { 40 | Thread.sleep(time); 41 | } catch (InterruptedException e) { 42 | e.printStackTrace(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/read.me: -------------------------------------------------------------------------------- 1 | demo.trade 当面付 2 | config sign util 网页支付 -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/util/UtilDate.java: -------------------------------------------------------------------------------- 1 | 2 | package com.alipay.util; 3 | 4 | import java.util.Date; 5 | import java.util.Random; 6 | import java.text.SimpleDateFormat; 7 | import java.text.DateFormat; 8 | 9 | /* * 10 | *类名:UtilDate 11 | *功能:自定义订单类 12 | *详细:工具类,可以用作获取系统日期、订单编号等 13 | *版本:3.3 14 | *日期:2012-08-17 15 | *说明: 16 | *以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 17 | *该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 18 | */ 19 | public class UtilDate { 20 | 21 | /** 年月日时分秒(无下划线) yyyyMMddHHmmss */ 22 | public static final String dtLong = "yyyyMMddHHmmss"; 23 | 24 | /** 完整时间 yyyy-MM-dd HH:mm:ss */ 25 | public static final String simple = "yyyy-MM-dd HH:mm:ss"; 26 | 27 | /** 年月日(无下划线) yyyyMMdd */ 28 | public static final String dtShort = "yyyyMMdd"; 29 | 30 | 31 | /** 32 | * 返回系统当前时间(精确到毫秒),作为一个唯一的订单编号 33 | * @return 34 | * 以yyyyMMddHHmmss为格式的当前系统时间 35 | */ 36 | public static String getOrderNum(){ 37 | Date date=new Date(); 38 | DateFormat df=new SimpleDateFormat(dtLong); 39 | return df.format(date); 40 | } 41 | 42 | /** 43 | * 获取系统当前日期(精确到毫秒),格式:yyyy-MM-dd HH:mm:ss 44 | * @return 45 | */ 46 | public static String getDateFormatter(){ 47 | Date date=new Date(); 48 | DateFormat df=new SimpleDateFormat(simple); 49 | return df.format(date); 50 | } 51 | 52 | /** 53 | * 获取系统当期年月日(精确到天),格式:yyyyMMdd 54 | * @return 55 | */ 56 | public static String getDate(){ 57 | Date date=new Date(); 58 | DateFormat df=new SimpleDateFormat(dtShort); 59 | return df.format(date); 60 | } 61 | 62 | /** 63 | * 产生随机的三位数 64 | * @return 65 | */ 66 | public static String getThree(){ 67 | Random rad=new Random(); 68 | return rad.nextInt(1000)+""; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/util/httpClient/HttpResponse.java: -------------------------------------------------------------------------------- 1 | package com.alipay.util.httpClient; 2 | 3 | import com.alipay.config.AlipayConfig; 4 | 5 | import org.apache.commons.httpclient.Header; 6 | import java.io.UnsupportedEncodingException; 7 | 8 | /* * 9 | *类名:HttpResponse 10 | *功能:Http返回对象的封装 11 | *详细:封装Http返回信息 12 | *版本:3.3 13 | *日期:2011-08-17 14 | *说明: 15 | *以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 16 | *该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 17 | */ 18 | 19 | public class HttpResponse { 20 | 21 | /** 22 | * 返回中的Header信息 23 | */ 24 | private Header[] responseHeaders; 25 | 26 | /** 27 | * String类型的result 28 | */ 29 | private String stringResult; 30 | 31 | /** 32 | * btye类型的result 33 | */ 34 | private byte[] byteResult; 35 | 36 | public Header[] getResponseHeaders() { 37 | return responseHeaders; 38 | } 39 | 40 | public void setResponseHeaders(Header[] responseHeaders) { 41 | this.responseHeaders = responseHeaders; 42 | } 43 | 44 | public byte[] getByteResult() { 45 | if (byteResult != null) { 46 | return byteResult; 47 | } 48 | if (stringResult != null) { 49 | return stringResult.getBytes(); 50 | } 51 | return null; 52 | } 53 | 54 | public void setByteResult(byte[] byteResult) { 55 | this.byteResult = byteResult; 56 | } 57 | 58 | public String getStringResult() throws UnsupportedEncodingException { 59 | if (stringResult != null) { 60 | return stringResult; 61 | } 62 | if (byteResult != null) { 63 | return new String(byteResult, AlipayConfig.input_charset); 64 | } 65 | return null; 66 | } 67 | 68 | public void setStringResult(String stringResult) { 69 | this.stringResult = stringResult; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /pay/src/main/java/com/alipay/util/httpClient/HttpResultType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2005 All Rights Reserved. 4 | */ 5 | package com.alipay.util.httpClient; 6 | 7 | /* * 8 | *类名:HttpResultType 9 | *功能:表示Http返回的结果字符方式 10 | *详细:表示Http返回的结果字符方式 11 | *版本:3.3 12 | *日期:2012-08-17 13 | *说明: 14 | *以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 15 | *该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 16 | */ 17 | public enum HttpResultType { 18 | /** 19 | * 字符串方式 20 | */ 21 | STRING, 22 | 23 | /** 24 | * 字节数组方式 25 | */ 26 | BYTES 27 | } 28 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/alipay/service/AlipayInitService.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.alipay.service; 2 | 3 | import com.alipay.demo.trade.config.Configs; 4 | import org.springframework.stereotype.Service; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | @Service 9 | public class AlipayInitService { 10 | 11 | @PostConstruct 12 | private void init() { 13 | /** 一定要在创建AlipayTradeService之前调用Configs.init()设置默认参数 14 | * Configs会读取classpath下的alipayrisk10.properties文件配置信息,如果找不到该文件则确认该文件是否在classpath目录 15 | */ 16 | Configs.init("zfbinfo.properties"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/base/model/PayResult.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.base.model; 2 | 3 | 4 | /** 5 | * 通用支付返回结果 6 | */ 7 | public class PayResult { 8 | private String resultCode; // ResultCode 9 | private String message; 10 | private String errCode; 11 | private String errorMessage; 12 | private String prepayId; 13 | private String codeUrl; 14 | 15 | public String getResultCode() { 16 | return resultCode; 17 | } 18 | 19 | public void setResultCode(String resultCode) { 20 | this.resultCode = resultCode; 21 | } 22 | 23 | 24 | public String getMessage() { 25 | return message; 26 | } 27 | 28 | public void setMessage(String message) { 29 | this.message = message; 30 | } 31 | 32 | public String getErrCode() { 33 | return errCode; 34 | } 35 | 36 | public void setErrCode(String errCode) { 37 | this.errCode = errCode; 38 | } 39 | 40 | public String getErrorMessage() { 41 | return errorMessage; 42 | } 43 | 44 | public void setErrorMessage(String errorMessage) { 45 | this.errorMessage = errorMessage; 46 | } 47 | 48 | public String getPrepayId() { 49 | return prepayId; 50 | } 51 | 52 | public void setPrepayId(String prepayId) { 53 | this.prepayId = prepayId; 54 | } 55 | 56 | public String getCodeUrl() { 57 | return codeUrl; 58 | } 59 | 60 | public void setCodeUrl(String codeUrl) { 61 | this.codeUrl = codeUrl; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/base/model/enums/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.base.model.enums; 2 | 3 | /** 4 | * 支付返回值 5 | */ 6 | public enum ResultCode { 7 | SUCCESS("SUCCESS"), FAIL("FAIL"); 8 | private String code; 9 | 10 | ResultCode(String code) { 11 | this.code = code; 12 | } 13 | 14 | public String getCode() { 15 | return code; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/base/service/Validator.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.base.service; 2 | 3 | public interface Validator { 4 | String getField(); 5 | 6 | boolean isRequired(); 7 | } 8 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/util/Base64Util.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.util; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | 5 | public class Base64Util { 6 | // 将 s 进行 BASE64 编码 7 | public static String encode(String s) { 8 | if (s == null) return null; 9 | //return (new sun.misc.BASE64Encoder()).encode( s.getBytes() ).replaceAll("\n", "").replaceAll("\r", ""); 10 | return new String(Base64.encodeBase64(s.getBytes())); 11 | } 12 | 13 | // 将 BASE64 编码的字符串 s 进行解码 14 | public static String decode(String s) { 15 | if (s == null) return null; 16 | //BASE64Decoder decoder = new BASE64Decoder(); 17 | try { 18 | //byte[] b = decoder.decodeBuffer(s); 19 | byte[] b = Base64.decodeBase64(s); 20 | return new String(b); 21 | } catch (Exception e) { 22 | return null; 23 | } 24 | } 25 | 26 | public static void main(String[] args) { 27 | System.out.println(encode("abcd")); 28 | System.out.println(decode("YWJjZA==")); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/util/EncryptUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.util; 2 | 3 | import java.security.MessageDigest; 4 | import java.util.Random; 5 | import java.util.UUID; 6 | 7 | public class EncryptUtil { 8 | private static final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 9 | 10 | private static final char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 11 | 'h', 'i', 'g', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; 12 | 13 | public final static String md5(String s) { 14 | try { 15 | byte[] btInput = s.getBytes("UTF-8"); 16 | MessageDigest mdInst = MessageDigest.getInstance("MD5"); 17 | mdInst.update(btInput); 18 | byte[] md = mdInst.digest(); 19 | int j = md.length; 20 | char str[] = new char[j * 2]; 21 | int k = 0; 22 | for (int i = 0; i < j; i++) { 23 | byte byte0 = md[i]; 24 | str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 25 | str[k++] = hexDigits[byte0 & 0xf]; 26 | } 27 | return new String(str); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | return null; 31 | } 32 | } 33 | 34 | // 随机32个字符 35 | public static String random() { 36 | char[] array = new char[32]; 37 | Random random = new Random(); 38 | for (int i = 0; i < 32; i++) { 39 | int c = random.nextInt(36); 40 | array[i] = chars[c]; 41 | } 42 | return new String(array); 43 | } 44 | 45 | public static void main(String[] args) { 46 | System.out.println(random()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/util/JsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.util; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | public class JsonUtil { 6 | 7 | public static final int JSON_CODE_OK = 0; 8 | public static final int JSON_CODE_ERROR = -1; 9 | 10 | public static JSONObject getJson(int code, String msg) { 11 | JSONObject json = new JSONObject(); 12 | json.put("code", code + ""); 13 | json.put("msg", msg); 14 | return json; 15 | } 16 | 17 | public static JSONObject getJson(int code, int left) { 18 | JSONObject json = new JSONObject(); 19 | json.put("code", code); 20 | json.put("left", left); 21 | return json; 22 | } 23 | 24 | public static JSONObject getJson(JSONObject obj, int code, String msg) { 25 | obj.put("code", code); 26 | obj.put("msg", msg); 27 | return obj; 28 | } 29 | 30 | public static JSONObject getOkJson(String msg) { 31 | JSONObject json = new JSONObject(); 32 | json.put("code", JSON_CODE_OK); 33 | json.put("msg", msg); 34 | return json; 35 | } 36 | 37 | public static JSONObject getOkJson() { 38 | return getOkJson("OK"); 39 | } 40 | 41 | 42 | public static JSONObject getOkJsonResult(Object value) { 43 | JSONObject obj = getOkJson(); 44 | obj.put("data", value); 45 | return obj; 46 | } 47 | 48 | public static JSONObject getOkJsonResult(String msg, Object obj) { 49 | JSONObject json = new JSONObject(); 50 | json.put("code", 0); 51 | json.put("msg", msg); 52 | json.put("data", obj); 53 | return json; 54 | } 55 | 56 | public static JSONObject getJsonObject(String key, String value) { 57 | JSONObject json = new JSONObject(); 58 | json.put(key, value); 59 | return json; 60 | } 61 | 62 | 63 | public static JSONObject getJson(String code, String message) { 64 | JSONObject json = new JSONObject(); 65 | json.put("code", code); 66 | json.put("msg", message); 67 | return json; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/util/LocalIPUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.util; 2 | 3 | import java.net.InetAddress; 4 | import java.net.NetworkInterface; 5 | import java.net.SocketException; 6 | import java.net.UnknownHostException; 7 | import java.util.Enumeration; 8 | 9 | public class LocalIPUtil { 10 | public LocalIPUtil() { 11 | } 12 | 13 | public static String getLocalAddr() { 14 | Enumeration interfaces = null; 15 | 16 | try { 17 | interfaces = NetworkInterface.getNetworkInterfaces(); 18 | } catch (SocketException var4) { 19 | var4.printStackTrace(); 20 | return null; 21 | } 22 | 23 | while (interfaces.hasMoreElements()) { 24 | NetworkInterface ifc = (NetworkInterface) interfaces.nextElement(); 25 | Enumeration addressesOfAnInterface = ifc.getInetAddresses(); 26 | 27 | while (addressesOfAnInterface.hasMoreElements()) { 28 | InetAddress address = (InetAddress) addressesOfAnInterface.nextElement(); 29 | if (address.isSiteLocalAddress()) { 30 | return address.getHostAddress(); 31 | } 32 | } 33 | } 34 | try { 35 | String ip = InetAddress.getLocalHost().getHostAddress(); 36 | return ip; 37 | } catch (UnknownHostException e) { 38 | e.printStackTrace(); 39 | } 40 | 41 | return null; 42 | } 43 | 44 | public static void main(String[] args) { 45 | System.out.println(getLocalAddr()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/util/SignUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.util; 2 | 3 | import org.apache.commons.logging.Log; 4 | import org.apache.commons.logging.LogFactory; 5 | 6 | import java.util.Iterator; 7 | import java.util.Map; 8 | import java.util.TreeMap; 9 | 10 | public class SignUtil { 11 | public static final Log logger = LogFactory.getLog(SignUtil.class); 12 | 13 | public static String sign(Object object, String key) { 14 | if (object == null) { 15 | return null; 16 | } 17 | 18 | Map data = BeanUtil.object2Map(object); 19 | if (data == null || data.isEmpty()) { 20 | return null; 21 | } 22 | 23 | return sign(data, key); 24 | } 25 | 26 | public static String sign(Map data, String key) { 27 | if (data == null || data.isEmpty()) { 28 | return null; 29 | } 30 | StringBuilder buf = new StringBuilder(); 31 | TreeMap map = new TreeMap(data); 32 | 33 | Iterator> it = map.entrySet().iterator(); 34 | while (it.hasNext()) { 35 | Map.Entry entry = it.next(); 36 | Object k = entry.getKey(); 37 | if ("class".equals(k) || "key".equals(k) || "sign".equals(k)) { 38 | continue; 39 | } 40 | Object v = entry.getValue(); // 非空 41 | if (v == null || "".equals(v.toString())) { 42 | continue; 43 | } 44 | buf.append(k); 45 | buf.append("="); 46 | buf.append(v); 47 | buf.append("&"); 48 | } 49 | buf.append("key=" + key); 50 | logger.debug(buf.toString()); 51 | 52 | String sign = EncryptUtil.md5(buf.toString()).toUpperCase(); 53 | return sign; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/util/ValidateUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.util; 2 | 3 | import com.kk.pay.base.service.Validator; 4 | 5 | import java.util.Map; 6 | 7 | public class ValidateUtil { 8 | public static void validate(Validator[] values, Map data) { 9 | for (Validator v : values) { 10 | if (v.isRequired()) { 11 | if (data.get(v.getField()) == null) { 12 | throw new IllegalArgumentException(v.getField() + "不能为空"); 13 | } 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/util/WebPropertiesUtil.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.util; 2 | 3 | import org.apache.commons.logging.Log; 4 | import org.apache.commons.logging.LogFactory; 5 | 6 | import java.io.BufferedInputStream; 7 | import java.io.FileInputStream; 8 | import java.io.InputStream; 9 | import java.util.Properties; 10 | 11 | /** 12 | * 操作web.properties文件 13 | * 代码中的配置为测试环境配置,上线后会被替换 14 | */ 15 | public class WebPropertiesUtil { 16 | private static final Log logger = LogFactory.getLog(WebPropertiesUtil.class); 17 | private static WebPropertiesUtil instance = new WebPropertiesUtil(); 18 | 19 | public static final String ENVIRONMENT = "environment";// 当前环境 test/online 20 | public static final String ONLINE_ENVIRONMENT = "online"; 21 | 22 | private Properties props = new Properties(); 23 | 24 | public static WebPropertiesUtil getInstance() { 25 | return instance; 26 | } 27 | 28 | private WebPropertiesUtil() { 29 | initConfigProperties("web.properties"); 30 | } 31 | 32 | private void initConfigProperties(String filePath) { 33 | String path = getClass().getResource("/").getPath(); 34 | InputStream in; 35 | try { 36 | in = new BufferedInputStream(new FileInputStream(path + filePath)); 37 | props.load(in); 38 | 39 | } catch (Exception e) { 40 | logger.error(e.getMessage(), e); 41 | } 42 | } 43 | 44 | public String getValue(String key) { 45 | return props.getProperty(key); 46 | } 47 | 48 | 49 | public Properties getProperty(String filePath) { 50 | Properties propTmp = new Properties(); 51 | String path = getClass().getResource("/").getPath(); 52 | InputStream in; 53 | try { 54 | in = new BufferedInputStream(new FileInputStream(path + filePath)); 55 | propTmp.load(in); 56 | } catch (Exception e) { 57 | logger.error(e.getMessage(), e); 58 | } 59 | return propTmp; 60 | } 61 | 62 | public boolean isOnline(){ 63 | String env = getInstance().getValue(ENVIRONMENT); 64 | if (env != null && env.equals(ONLINE_ENVIRONMENT)){ 65 | return true; 66 | } 67 | 68 | return false; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/PayBillParam.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model; 2 | 3 | public class PayBillParam { 4 | private String appid; // 公众账号ID 5 | private String mchId; // 微信支付 商户号 6 | private String deviceInfo; //非必填 设备号 终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB" 7 | private String nonceStr; // 随机字符串 8 | private String sign; // 签名 9 | 10 | private String billDate;// 对账日期 下载对账单的日期,格式:20140603 11 | private String bill_type;// 账单类型 ALL,返回当日所有订单信息,默认值 SUCCESS,返回当日成功支付的订单 REFUND,返回当日退款订单 12 | 13 | public String getAppid() { 14 | return appid; 15 | } 16 | 17 | public void setAppid(String appid) { 18 | this.appid = appid; 19 | } 20 | 21 | public String getMchId() { 22 | return mchId; 23 | } 24 | 25 | public void setMchId(String mchId) { 26 | this.mchId = mchId; 27 | } 28 | 29 | public String getDeviceInfo() { 30 | return deviceInfo; 31 | } 32 | 33 | public void setDeviceInfo(String deviceInfo) { 34 | this.deviceInfo = deviceInfo; 35 | } 36 | 37 | public String getNonceStr() { 38 | return nonceStr; 39 | } 40 | 41 | public void setNonceStr(String nonceStr) { 42 | this.nonceStr = nonceStr; 43 | } 44 | 45 | public String getSign() { 46 | return sign; 47 | } 48 | 49 | public void setSign(String sign) { 50 | this.sign = sign; 51 | } 52 | 53 | public String getBillDate() { 54 | return billDate; 55 | } 56 | 57 | public void setBillDate(String billDate) { 58 | this.billDate = billDate; 59 | } 60 | 61 | public String getBill_type() { 62 | return bill_type; 63 | } 64 | 65 | public void setBill_type(String bill_type) { 66 | this.bill_type = bill_type; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/PayQueryParam.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model; 2 | 3 | public class PayQueryParam { 4 | private String appid; 5 | private String mchId; 6 | private String nonceStr; 7 | private String sign; 8 | // 客户,微信 订单号 二选一; 9 | private String outTradeNo; // 客户订单号 商户系统内部的订单号,当没提供transaction_id时需要传这个。 10 | private String transactionId; // 微信订单号 微信的订单号,优先使用; 11 | 12 | public String getAppid() { 13 | return appid; 14 | } 15 | 16 | public void setAppid(String appid) { 17 | this.appid = appid; 18 | } 19 | 20 | public String getMchId() { 21 | return mchId; 22 | } 23 | 24 | public void setMchId(String mchId) { 25 | this.mchId = mchId; 26 | } 27 | 28 | public String getNonceStr() { 29 | return nonceStr; 30 | } 31 | 32 | public void setNonceStr(String nonceStr) { 33 | this.nonceStr = nonceStr; 34 | } 35 | 36 | public String getSign() { 37 | return sign; 38 | } 39 | 40 | public void setSign(String sign) { 41 | this.sign = sign; 42 | } 43 | 44 | public String getOutTradeNo() { 45 | return outTradeNo; 46 | } 47 | 48 | public void setOutTradeNo(String outTradeNo) { 49 | this.outTradeNo = outTradeNo; 50 | } 51 | 52 | public String getTransactionId() { 53 | return transactionId; 54 | } 55 | 56 | public void setTransactionId(String transactionId) { 57 | this.transactionId = transactionId; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/PayRefundQueryParam.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model; 2 | 3 | public class PayRefundQueryParam { 4 | private String appid; 5 | private String mchId; // 商户号 6 | private String deviceInfo; // 设备号 7 | private String nonceStr; 8 | private String sign; 9 | // 客户,微信 订单号 四选一; 10 | private String outTradeNo; // 客户订单号 商户系统内部的订单号,当没提供transaction_id时需要传这个。 11 | private String transactionId; // 微信订单号 微信的订单号,优先使用; 12 | 13 | private String outRefundNo;// 商户退款单号 14 | private String refundId;//微信退款单号 15 | 16 | public String getAppid() { 17 | return appid; 18 | } 19 | 20 | public void setAppid(String appid) { 21 | this.appid = appid; 22 | } 23 | 24 | public String getMchId() { 25 | return mchId; 26 | } 27 | 28 | public void setMchId(String mchId) { 29 | this.mchId = mchId; 30 | } 31 | 32 | public String getDeviceInfo() { 33 | return deviceInfo; 34 | } 35 | 36 | public void setDeviceInfo(String deviceInfo) { 37 | this.deviceInfo = deviceInfo; 38 | } 39 | 40 | public String getNonceStr() { 41 | return nonceStr; 42 | } 43 | 44 | public void setNonceStr(String nonceStr) { 45 | this.nonceStr = nonceStr; 46 | } 47 | 48 | public String getSign() { 49 | return sign; 50 | } 51 | 52 | public void setSign(String sign) { 53 | this.sign = sign; 54 | } 55 | 56 | public String getOutTradeNo() { 57 | return outTradeNo; 58 | } 59 | 60 | public void setOutTradeNo(String outTradeNo) { 61 | this.outTradeNo = outTradeNo; 62 | } 63 | 64 | public String getTransactionId() { 65 | return transactionId; 66 | } 67 | 68 | public void setTransactionId(String transactionId) { 69 | this.transactionId = transactionId; 70 | } 71 | 72 | public String getOutRefundNo() { 73 | return outRefundNo; 74 | } 75 | 76 | public void setOutRefundNo(String outRefundNo) { 77 | this.outRefundNo = outRefundNo; 78 | } 79 | 80 | public String getRefundId() { 81 | return refundId; 82 | } 83 | 84 | public void setRefundId(String refundId) { 85 | this.refundId = refundId; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/WeixinResult.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model; 2 | 3 | public class WeixinResult { 4 | private String returnCode;//SUCCESS/FAIL 此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断 5 | private String returnMsg;// 返回信息,如非空,为错误原因 如,签名失败 ,参数格式校验错误 6 | 7 | public String getReturnCode() { 8 | return returnCode; 9 | } 10 | 11 | public void setReturnCode(String returnCode) { 12 | this.returnCode = returnCode; 13 | } 14 | 15 | public String getReturnMsg() { 16 | return returnMsg; 17 | } 18 | 19 | public void setReturnMsg(String returnMsg) { 20 | this.returnMsg = returnMsg; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/enums/PayBillField.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model.enums; 2 | 3 | import com.kk.pay.base.service.Validator; 4 | 5 | public enum PayBillField implements Validator { 6 | APP_ID("appid", true), 7 | MCH_ID("mch_id", true), 8 | DEVICE_INFO("device_info", false), 9 | NONCE_STR("nonce_str", true), 10 | SIGN("sign", true), 11 | BILL_DATE("bill_date", false), 12 | BILL_TYPE("bill_type", false),; 13 | 14 | private String field; 15 | private boolean required; 16 | 17 | PayBillField(String field, boolean required) { 18 | this.field = field; 19 | this.required = required; 20 | } 21 | 22 | @Override 23 | public String getField() { 24 | return field; 25 | } 26 | 27 | @Override 28 | public boolean isRequired() { 29 | return required; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/enums/PayOrderField.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model.enums; 2 | 3 | 4 | import com.kk.pay.base.service.Validator; 5 | 6 | /** 7 | * payOrderParam 参数 必填信息 8 | */ 9 | public enum PayOrderField implements Validator { 10 | APP_ID("appid", true), 11 | MCH_ID("mch_id", true), 12 | DEVICE_INFO("device_info", false), 13 | NONCE_STR("nonce_str", true), 14 | SIGN("sign", true), 15 | BODY("body", true), 16 | DETAIL("detail", false), 17 | ATTACH("attach", false), 18 | OUT_TRADE_NO("out_trade_no", true), 19 | FEE_TYPE("fee_type", false), 20 | TOTAL_FEE("total_fee", true), 21 | SPBILL_CREATE_IP("spbill_create_ip", true), 22 | TIME_START("time_start", false), 23 | TIME_EXPIRE("time_expire", false), 24 | GOODS_TAG("goods_tag", false), 25 | NOTIFY_URL("notify_url", true), 26 | TRADE_TYPE("trade_type", true), 27 | PRODUCT_ID("product_id", false), 28 | LIMIT_PAY("limit_pay", false), 29 | OPEN_ID("openid", false),; 30 | 31 | private String field; 32 | private boolean required; 33 | 34 | PayOrderField(String field, boolean required) { 35 | this.field = field; 36 | this.required = required; 37 | } 38 | 39 | @Override 40 | public String getField() { 41 | return field; 42 | } 43 | 44 | @Override 45 | public boolean isRequired() { 46 | return required; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/enums/PayQueryField.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model.enums; 2 | 3 | import com.kk.pay.base.service.Validator; 4 | 5 | public enum PayQueryField implements Validator { 6 | APP_ID("appid", true), 7 | MCH_ID("mch_id", true), 8 | NONCE_STR("nonce_str", true), 9 | SIGN("sign", true), 10 | OUT_TRADE_NO("out_trade_no", false), 11 | TRANSACTION_ID("transaction_id", false),; 12 | 13 | private String field; 14 | private boolean required; 15 | 16 | PayQueryField(String field, boolean required) { 17 | this.field = field; 18 | this.required = required; 19 | } 20 | 21 | @Override 22 | public String getField() { 23 | return field; 24 | } 25 | 26 | @Override 27 | public boolean isRequired() { 28 | return required; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/enums/PayRefundField.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model.enums; 2 | 3 | import com.kk.pay.base.service.Validator; 4 | 5 | public enum PayRefundField implements Validator { 6 | APP_ID("appid", true), 7 | MCH_ID("mch_id", true), 8 | DEVICE_INFO("device_info", false), 9 | NONCE_STR("nonce_str", true), 10 | SIGN("sign", true), 11 | OUT_TRADE_NO("out_trade_no", false), 12 | TRANSACTION_ID("transaction_id", false), 13 | OUT_REFUND_NO("out_refund_no", true), 14 | TOTAL_FEE("total_fee", true), 15 | REFUND_FEE("refund_fee", true), 16 | REFUND_FEE_TYPE("refund_fee_type", false), 17 | OP_USER_ID("op_user_id", true),; 18 | 19 | private String field; 20 | private boolean required; 21 | 22 | PayRefundField(String field, boolean required) { 23 | this.field = field; 24 | this.required = required; 25 | } 26 | 27 | @Override 28 | public String getField() { 29 | return field; 30 | } 31 | 32 | @Override 33 | public boolean isRequired() { 34 | return required; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/enums/PayRefundQueryField.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model.enums; 2 | 3 | import com.kk.pay.base.service.Validator; 4 | 5 | public enum PayRefundQueryField implements Validator { 6 | APP_ID("appid", true), 7 | MCH_ID("mch_id", true), 8 | DEVICE_INFO("device_info", false), 9 | NONCE_STR("nonce_str", true), 10 | SIGN("sign", true), 11 | OUT_TRADE_NO("out_trade_no", false), 12 | TRANSACTION_ID("transaction_id", false), 13 | OUT_REFUND_NO("out_refund_no", false), 14 | REFUND_ID("refund_id", false),; 15 | 16 | private String field; 17 | private boolean required; 18 | 19 | PayRefundQueryField(String field, boolean required) { 20 | this.field = field; 21 | this.required = required; 22 | } 23 | 24 | @Override 25 | public String getField() { 26 | return field; 27 | } 28 | 29 | @Override 30 | public boolean isRequired() { 31 | return required; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pay/src/main/java/com/kk/pay/weixin/model/enums/TradeType.java: -------------------------------------------------------------------------------- 1 | package com.kk.pay.weixin.model.enums; 2 | 3 | public enum TradeType { 4 | JSAPI, NATIVE, APP, WAP; 5 | } 6 | -------------------------------------------------------------------------------- /pay/src/main/resources/Configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /pay/src/main/resources/web.properties: -------------------------------------------------------------------------------- 1 | #jdbc 2 | jdbc.driver=com.mysql.jdbc.Driver 3 | jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true 4 | jdbc.username= 5 | jdbc.password= 6 | jdbc.initialSize=2 7 | jdbc.maxActive=2 8 | 9 | 10 | #weixin mp.weixin 11 | weixin.appid= 12 | weixin.appsecret= 13 | 14 | #pay.weixin 15 | weixin.mchid= 16 | weixin.pay.unifiedorder=https://api.mch.weixin.qq.com/pay/unifiedorder 17 | weixin.pay.orderquery=https://api.mch.weixin.qq.com/pay/orderquery 18 | weixin.pay.refund=https://api.mch.weixin.qq.com/secapi/pay/refund 19 | weixin.pay.refundquery=https://api.mch.weixin.qq.com/pay/refundquery 20 | weixin.pay.bill=https://api.mch.weixin.qq.com/pay/downloadbill 21 | 22 | # weixin sign.key 23 | weixin.pay.apikey= 24 | 25 | #end weixin 26 | 27 | 28 | 29 | #alipay 30 | 31 | #end alipay 32 | 33 | 34 | #current env 35 | environment=test 36 | server.url=http://www.kk.com 37 | # done current env -------------------------------------------------------------------------------- /pay/src/main/resources/zfbinfo.properties: -------------------------------------------------------------------------------- 1 | # zfbtest19@service.aliyun.com 2 | # AlipayConfig 同步此类数据,与配置文件一致。 AlipayConfig中可以修改为从 Configs中获取,这样配置保持统一 3 | # 此配置文件 对应 Configs类 4 | # 支付宝网关名、partnerId和appId 5 | open_api_domain = https://openapi.alipay.com/gateway.do 6 | mcloud_api_domain = http://mcloudmonitor.com/gateway.do 7 | pid = 8 | appid = 9 | 10 | # RSA私钥、公钥和支付宝公钥 (public_key 本地不需要配置,本地只需要配置 private_key,alipay_public_key ) 11 | private_key = 12 | public_key = 13 | alipay_public_key = 14 | 15 | # 当面付最大查询次数和查询间隔(毫秒) 16 | max_query_retry = 5 17 | query_duration = 5000 18 | 19 | # 当面付最大撤销次数和撤销间隔(毫秒) 20 | max_cancel_retry = 3 21 | cancel_duration = 2000 22 | 23 | # 交易保障线程第一次调度延迟和调度间隔(秒) 24 | heartbeat_delay = 5 25 | heartbeat_duration = 900 26 | -------------------------------------------------------------------------------- /pay/src/main/webapp/WEB-INF/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /pay/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | pay.index 8 | 9 | 10 | -------------------------------------------------------------------------------- /pay/src/main/webapp/views/alipay/ap.js: -------------------------------------------------------------------------------- 1 | (function(){var b={};var a={};a.PADCHAR="=";a.ALPHA="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";a.makeDOMException=function(){var f,d;try{return new DOMException(DOMException.INVALID_CHARACTER_ERR)}catch(d){var c=new Error("DOM Exception 5");c.code=c.number=5;c.name=c.description="INVALID_CHARACTER_ERR";c.toString=function(){return"Error: "+c.name+": "+c.message};return c}};a.getbyte64=function(e,d){var c=a.ALPHA.indexOf(e.charAt(d));if(c===-1){throw a.makeDOMException()}return c};a.decode=function(f){f=""+f;var j=a.getbyte64;var h,e,g;var d=f.length;if(d===0){return f}if(d%4!==0){throw a.makeDOMException()}h=0;if(f.charAt(d-1)===a.PADCHAR){h=1;if(f.charAt(d-2)===a.PADCHAR){h=2}d-=4}var c=[];for(e=0;e>16,(g>>8)&255,g&255))}switch(h){case 1:g=(j(f,e)<<18)|(j(f,e+1)<<12)|(j(f,e+2)<<6);c.push(String.fromCharCode(g>>16,(g>>8)&255));break;case 2:g=(j(f,e)<<18)|(j(f,e+1)<<12);c.push(String.fromCharCode(g>>16));break}return c.join("")};a.getbyte=function(e,d){var c=e.charCodeAt(d);if(c>255){throw a.makeDOMException()}return c};a.encode=function(f){if(arguments.length!==1){throw new SyntaxError("Not enough arguments")}var g=a.PADCHAR;var h=a.ALPHA;var k=a.getbyte;var e,j;var c=[];f=""+f;var d=f.length-f.length%3;if(f.length===0){return f}for(e=0;e>18));c.push(h.charAt((j>>12)&63));c.push(h.charAt((j>>6)&63));c.push(h.charAt(j&63))}switch(f.length-d){case 1:j=k(f,e)<<16;c.push(h.charAt(j>>18)+h.charAt((j>>12)&63)+g+g);break;case 2:j=(k(f,e)<<16)|(k(f,e+1)<<8);c.push(h.charAt(j>>18)+h.charAt((j>>12)&63)+h.charAt((j>>6)&63)+g);break}return c.join("")};b.pay=function(d){var c=encodeURIComponent(a.encode(d));location.href="pay.htm?goto="+c};b.decode=function(c){return a.decode(decodeURIComponent(c))};window._AP=b})(); -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/activation-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/activation-1.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/alipay-sdk-1.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/alipay-sdk-1.5.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/aopalliance-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/aopalliance-1.0.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/aspectjrt-1.7.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/aspectjrt-1.7.0.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/aspectjweaver-1.7.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/aspectjweaver-1.7.0.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/cglib-nodep-2.1_3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/cglib-nodep-2.1_3.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-beanutils-1.8.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-beanutils-1.8.0.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-beanutils-core-1.8.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-beanutils-core-1.8.0.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-codec-1.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-codec-1.6.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-collections-3.2.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-configuration-1.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-configuration-1.6.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-dbcp-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-dbcp-1.4.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-digester-1.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-digester-1.8.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-fileupload-1.2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-fileupload-1.2.2.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-httpclient-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-httpclient-3.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-io-2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-io-2.4.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-lang-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-lang-2.6.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-lang3-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-lang3-3.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/commons-pool-1.5.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/commons-pool-1.5.4.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/core-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/core-2.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/dom4j-1.6.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/ezmorph-1.0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/ezmorph-1.0.6.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/fastjson-1.1.34.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/fastjson-1.1.34.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/freemarker-2.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/freemarker-2.3.20.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/geohash-1.0.13.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/geohash-1.0.13.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/gson-2.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/gson-2.3.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/guava-14.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/guava-14.0.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/httpclient-4.3.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/httpclient-4.3.4.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/httpcore-4.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/httpcore-4.3.2.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/jackson-core-asl-1.8.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/jackson-core-asl-1.8.4.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/jackson-mapper-asl-1.8.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/jackson-mapper-asl-1.8.4.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/javase-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/javase-2.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/jdom-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/jdom-1.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/joda-time-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/joda-time-2.2.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/json-lib-2.4-jdk15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/json-lib-2.4-jdk15.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/jsoup-1.7.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/jsoup-1.7.2.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/jstl-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/jstl-1.2.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/log4j-1.2.16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/log4j-1.2.16.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/mail-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/mail-1.4.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/mybatis-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/mybatis-3.2.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/mybatis-spring-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/mybatis-spring-1.1.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/mysql-connector-java-5.1.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/mysql-connector-java-5.1.26.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/poi-3.10.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/poi-3.10.1.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-aop-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-aop-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-asm-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-asm-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-beans-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-beans-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-context-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-context-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-context-support-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-context-support-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-core-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-core-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-expression-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-expression-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-jdbc-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-jdbc-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-tx-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-tx-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-web-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-web-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/spring-webmvc-3.1.2.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/spring-webmvc-3.1.2.RELEASE.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/lib/xml-apis-1.0.b2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongzhidea/pay/fa684b64d74c1b851dccff9ae957dd2f7bb81074/pay/target/pay/WEB-INF/lib/xml-apis-1.0.b2.jar -------------------------------------------------------------------------------- /pay/target/pay/WEB-INF/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /pay/target/pay/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 7 | pay.index 8 | 9 | 10 | -------------------------------------------------------------------------------- /pay/target/pay/views/alipay/ap.js: -------------------------------------------------------------------------------- 1 | (function(){var b={};var a={};a.PADCHAR="=";a.ALPHA="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";a.makeDOMException=function(){var f,d;try{return new DOMException(DOMException.INVALID_CHARACTER_ERR)}catch(d){var c=new Error("DOM Exception 5");c.code=c.number=5;c.name=c.description="INVALID_CHARACTER_ERR";c.toString=function(){return"Error: "+c.name+": "+c.message};return c}};a.getbyte64=function(e,d){var c=a.ALPHA.indexOf(e.charAt(d));if(c===-1){throw a.makeDOMException()}return c};a.decode=function(f){f=""+f;var j=a.getbyte64;var h,e,g;var d=f.length;if(d===0){return f}if(d%4!==0){throw a.makeDOMException()}h=0;if(f.charAt(d-1)===a.PADCHAR){h=1;if(f.charAt(d-2)===a.PADCHAR){h=2}d-=4}var c=[];for(e=0;e>16,(g>>8)&255,g&255))}switch(h){case 1:g=(j(f,e)<<18)|(j(f,e+1)<<12)|(j(f,e+2)<<6);c.push(String.fromCharCode(g>>16,(g>>8)&255));break;case 2:g=(j(f,e)<<18)|(j(f,e+1)<<12);c.push(String.fromCharCode(g>>16));break}return c.join("")};a.getbyte=function(e,d){var c=e.charCodeAt(d);if(c>255){throw a.makeDOMException()}return c};a.encode=function(f){if(arguments.length!==1){throw new SyntaxError("Not enough arguments")}var g=a.PADCHAR;var h=a.ALPHA;var k=a.getbyte;var e,j;var c=[];f=""+f;var d=f.length-f.length%3;if(f.length===0){return f}for(e=0;e>18));c.push(h.charAt((j>>12)&63));c.push(h.charAt((j>>6)&63));c.push(h.charAt(j&63))}switch(f.length-d){case 1:j=k(f,e)<<16;c.push(h.charAt(j>>18)+h.charAt((j>>12)&63)+g+g);break;case 2:j=(k(f,e)<<16)|(k(f,e+1)<<8);c.push(h.charAt(j>>18)+h.charAt((j>>12)&63)+h.charAt((j>>6)&63)+g);break}return c.join("")};b.pay=function(d){var c=encodeURIComponent(a.encode(d));location.href="pay.htm?goto="+c};b.decode=function(c){return a.decode(decodeURIComponent(c))};window._AP=b})(); -------------------------------------------------------------------------------- /pay/weixin.md: -------------------------------------------------------------------------------- 1 | ``` 2 | 文档地址:https://pay.weixin.qq.com/wiki/doc/api/index.html 3 | 4 | 5 | 商户在微信公众平台(申请扫码支付、公众号支付,刷卡支付)或开放平台:mp.weixin.qq.com (申请APP支付) 6 | 申请开通微信支付 文档: http://kf.qq.com/faq/140225MveaUz150107UVFNjy.html 7 | 8 | 微信支付后台; 9 | https://pay.weixin.qq.com/index.php/home/login 10 | 11 | 12 | 开通微信支付后,会把 微信支付的账号,密码,以及 apikey发给开发者。 13 | ``` 14 | 15 | 16 | * 确保 商户功能 审核通过,会有官方邮件 17 | * js支付: 支付授权目录(注意看文档,大小写关系很大 点击支付按钮,提示“access_denied” 网上有很多关于此问题的解决) , url 一定要 以 / 结尾, 如:http://kk/h5/pay/cashier/ 18 | * 支付的时候,要先提交表单 到后端, 后端 先调用 统一下单接口, 设置openId,支付方式,回调url等信息,再生成 前端需要的参数信息,例如 package,paySign等。 前端收到请求后 直接调用微信js方法。 19 | * 获取openId 需要进行微信授权。 具体操作 见 微信公众平台:微信auth认证。 20 | * 在 微信 公众平台, 微信支付--开发配置 , 配置授权目录,以及测试白名单用户。 21 | 点击支付按钮,提示“access_not_allow” 需要将测试人的微信帐号加入白名单 22 | * 【在开发调试阶段,测试链接需要在公众号内点击打开 白名单用户在公众号内向公众号发一条消息,消息内容即为测试链接,然后点击打开】文档中写得很清楚,但中招的人还是不计其数(偶也中了……)。 23 | * 计算签名时候,【参数大小写敏感】md5 运算后,字符串的字符要转换为大写,注意是MD5运算模块。 参与计算签名的值 均 非空。 24 | * body 字段 最长128个字符。 编码要是 utf-8编码。 25 | * 微信支付 退款 需要证书。 26 | * 微信支付 返回结果,如果中文乱码,需要 进行转码: 27 | 28 | 29 | ``` 30 | try { 31 | resultStr = new String(resultStr.getBytes("ISO-8859-1"), "utf-8"); 32 | } catch (UnsupportedEncodingException e) { 33 | e.printStackTrace(); 34 | } 35 | ``` 36 | * 退款时候 需要安装证书:apiclient_cert.p12,默认密码是 商户号。 37 | * https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3 38 | 39 | ``` 40 | --------------------------------------------------------------------------------