├── .gitignore ├── LICENSE ├── README.md ├── binapi-backend ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── niuma │ │ │ └── binapi │ │ │ ├── BinapiBackendApplication.java │ │ │ ├── annotation │ │ │ └── AuthCheck.java │ │ │ ├── aop │ │ │ ├── AuthInterceptor.java │ │ │ └── LogInterceptor.java │ │ │ ├── common │ │ │ └── RedisTokenBucket.java │ │ │ ├── config │ │ │ ├── CorsConfig.java │ │ │ ├── Knife4jConfig.java │ │ │ ├── MyBatisPlusConfig.java │ │ │ ├── RedisConfig.java │ │ │ ├── SmsRabbitMqConfig.java │ │ │ └── mq │ │ │ │ ├── MqProperties.java │ │ │ │ ├── QueueExchangeBinding.java │ │ │ │ └── RabbitMqConfig.java │ │ │ ├── controller │ │ │ ├── AnalysisController.java │ │ │ ├── InterfaceAuditController.java │ │ │ ├── InterfaceChargingController.java │ │ │ ├── InterfaceInfoController.java │ │ │ ├── UserController.java │ │ │ └── UserInterfaceController.java │ │ │ ├── datasource │ │ │ ├── Apiaa1DataSource.java │ │ │ ├── DataSourceRegistry.java │ │ │ ├── InterfaceInfoDataSource.java │ │ │ └── NativeDataSource.java │ │ │ ├── facade │ │ │ └── InterfaceInfoSearchFacade.java │ │ │ ├── mapper │ │ │ ├── InterfaceAuditMapper.java │ │ │ ├── InterfaceChargingMapper.java │ │ │ ├── InterfaceInfoMapper.java │ │ │ ├── UserInterfaceInfoMapper.java │ │ │ └── UserMapper.java │ │ │ ├── model │ │ │ ├── dto │ │ │ │ ├── interfaceAudit │ │ │ │ │ ├── InterfaceAuditQueryRequest.java │ │ │ │ │ └── InterfaceAuditRequest.java │ │ │ │ ├── interfaceCharging │ │ │ │ │ ├── InterfaceChargingAddRequest.java │ │ │ │ │ ├── InterfaceChargingQueryRequest.java │ │ │ │ │ └── InterfaceChargingUpdateRequest.java │ │ │ │ ├── interfaceinfo │ │ │ │ │ ├── InterfaceInfoAddRequest.java │ │ │ │ │ ├── InterfaceInfoInvokeRequest.java │ │ │ │ │ ├── InterfaceInfoQueryRequest.java │ │ │ │ │ ├── InterfaceInfoSearchRequest.java │ │ │ │ │ └── InterfaceInfoUpdateRequest.java │ │ │ │ ├── user │ │ │ │ │ ├── UserAddRequest.java │ │ │ │ │ ├── UserLoginRequest.java │ │ │ │ │ ├── UserQueryRequest.java │ │ │ │ │ ├── UserRegisterRequest.java │ │ │ │ │ └── UserUpdateRequest.java │ │ │ │ └── userInterfaceinfo │ │ │ │ │ ├── UserInterfaceInfoAddRequest.java │ │ │ │ │ ├── UserInterfaceInfoQueryRequest.java │ │ │ │ │ └── UserInterfaceInfoUpdateRequest.java │ │ │ ├── entity │ │ │ │ ├── InterfaceAudit.java │ │ │ │ └── InterfaceCharging.java │ │ │ ├── enums │ │ │ │ ├── InterfaceInfoAuditStatusEnum.java │ │ │ │ ├── InterfaceInfoSearchEnum.java │ │ │ │ └── InterfaceInfoStatusEnum.java │ │ │ ├── excel │ │ │ │ ├── InterfaceInfoInvokeExcel.java │ │ │ │ └── InterfaceInfoOrderExcel.java │ │ │ └── vo │ │ │ │ ├── InterfaceAuditVO.java │ │ │ │ ├── InterfaceInfoVO.java │ │ │ │ ├── UserDevKeyVO.java │ │ │ │ └── UserInterfaceInfoVO.java │ │ │ ├── service │ │ │ ├── InterfaceAuditService.java │ │ │ ├── InterfaceChargingService.java │ │ │ ├── InterfaceInfoService.java │ │ │ ├── UserInterfaceInfoService.java │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ ├── InterfaceAuditServiceImpl.java │ │ │ │ ├── InterfaceChargingServiceImpl.java │ │ │ │ ├── InterfaceInfoServiceImpl.java │ │ │ │ ├── UserInterfaceInfoServiceImpl.java │ │ │ │ ├── UserServiceImpl.java │ │ │ │ └── inner │ │ │ │ ├── InnerInterfaceChargingServiceImpl.java │ │ │ │ ├── InnerInterfaceInfoServiceImpl.java │ │ │ │ ├── InnerUserInterfaceInfoServiceImpl.java │ │ │ │ └── InnerUserServiceImpl.java │ │ │ └── utils │ │ │ ├── FileUploadUtil.java │ │ │ ├── OssConstantPropertiesUtil.java │ │ │ ├── SmsRabbitMqUtils.java │ │ │ └── SmsUtils.java │ └── resources │ │ ├── application.yaml │ │ ├── banner.txt │ │ ├── binapi-client-sdk-0.0.1.jar │ │ ├── bootstrap.yml │ │ └── mapper │ │ ├── InterfaceAuditMapper.xml │ │ ├── InterfaceChargingMapper.xml │ │ ├── InterfaceInfoMapper.xml │ │ ├── UserInterfaceInfoMapper.xml │ │ └── UserMapper.xml │ └── test │ └── java │ └── com │ └── niuma │ └── binapi │ └── service │ ├── BinApiClientTest.java │ ├── CrawlerTest.java │ ├── JwtTest.java │ ├── UserServiceTest.java │ ├── impl │ └── InterfaceInfoServiceImplTest.java │ └── inner │ └── InnerUserInterfaceInfoServiceImplTest.java ├── binapi-client-sdk ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── niuma │ │ └── binapiclientsdk │ │ ├── BinApiClientConfig.java │ │ ├── client │ │ └── BinApiClient.java │ │ ├── model │ │ └── User.java │ │ └── util │ │ └── SignUtil.java │ └── resources │ ├── META-INF │ └── spring.factories │ └── application.properties ├── binapi-common ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── niuma │ │ └── binapicommon │ │ ├── common │ │ ├── BaseResponse.java │ │ ├── DeleteRequest.java │ │ ├── ErrorCode.java │ │ ├── IdRequest.java │ │ ├── PageRequest.java │ │ └── ResultUtils.java │ │ ├── constant │ │ ├── CommonConstant.java │ │ ├── CookieConstant.java │ │ ├── LockConstant.java │ │ ├── RabbitMqConstant.java │ │ ├── RedisConstant.java │ │ └── UserConstant.java │ │ ├── exception │ │ ├── BusinessException.java │ │ └── GlobalExceptionHandler.java │ │ ├── model │ │ ├── dto │ │ │ ├── SmsDTO.java │ │ │ ├── UnLockAvailablePiecesDTO.java │ │ │ ├── UpdateAvailablePiecesDTO.java │ │ │ └── UpdateUserInterfaceInfoDTO.java │ │ ├── entity │ │ │ ├── InterfaceInfo.java │ │ │ ├── Order.java │ │ │ ├── User.java │ │ │ └── UserInterfaceInfo.java │ │ ├── enums │ │ │ ├── InterfaceInfoStatusEnum.java │ │ │ ├── PostGenderEnum.java │ │ │ └── PostReviewStatusEnum.java │ │ └── vo │ │ │ ├── OrderVO.java │ │ │ └── UserVO.java │ │ ├── service │ │ ├── InnerInterfaceChargingService.java │ │ ├── InnerInterfaceInfoService.java │ │ ├── InnerOrderService.java │ │ ├── InnerUserInterfaceInfoService.java │ │ └── InnerUserService.java │ │ └── utils │ │ └── AuthPhoneNumberUtil.java │ └── resources │ └── application.properties ├── binapi-config ├── binapi-backend-dev.yaml ├── binapi-gateway-dev.yaml ├── binapi-interface-dev.yml ├── binapi-order-dev.yml └── binapi-third-party-dev.yml ├── binapi-gateway ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── niuma │ │ │ └── binapigateway │ │ │ ├── BinapiGatewayApplication.java │ │ │ ├── config │ │ │ ├── CorsConfig.java │ │ │ └── GatewayConfig.java │ │ │ └── filter │ │ │ ├── CustomGlobalFilter.java │ │ │ └── InterfaceFilter.java │ └── resources │ │ ├── application.yaml │ │ └── bootstrap.yml │ └── test │ └── java │ └── com │ └── niuma │ └── binapigateway │ └── BinapiGatewayApplicationTests.java ├── binapi-interface ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── niuma │ │ │ └── binapiinterface │ │ │ ├── BinapiInterfaceApplication.java │ │ │ ├── NacosServerInfo.java │ │ │ └── controller │ │ │ ├── InterfaceController.java │ │ │ └── NameController.java │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml │ └── test │ └── java │ └── com │ └── niuma │ └── binapiinterface │ └── BinapiInterfaceApplicationTests.java ├── binapi-order ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── niuma │ │ │ └── binapiorder │ │ │ ├── BinapiOrderApplication.java │ │ │ ├── config │ │ │ ├── MyBatisPlusConfig.java │ │ │ ├── OrderRabbitMqConfig.java │ │ │ └── RedisConfig.java │ │ │ ├── controller │ │ │ └── OrderController.java │ │ │ ├── listener │ │ │ ├── AlipaySuccessListener.java │ │ │ └── OrderTimeOutListener.java │ │ │ ├── mapper │ │ │ ├── OrderLockMapper.java │ │ │ └── OrderMapper.java │ │ │ ├── model │ │ │ ├── dto │ │ │ │ ├── OrderAddRequest.java │ │ │ │ └── OrderQueryRequest.java │ │ │ ├── entity │ │ │ │ └── OrderLock.java │ │ │ └── enums │ │ │ │ ├── LockOrderStatusEnum.java │ │ │ │ └── OrderStatusEnum.java │ │ │ ├── schedule │ │ │ └── SendOrderInfoFailedSchedule.java │ │ │ ├── service │ │ │ ├── OrderLockService.java │ │ │ ├── OrderService.java │ │ │ └── impl │ │ │ │ ├── InnerOrderServiceImpl.java │ │ │ │ ├── OrderLockServiceImpl.java │ │ │ │ └── OrderServiceImpl.java │ │ │ └── utils │ │ │ └── OrderMqUtils.java │ └── resources │ │ ├── application.yml │ │ ├── bootstrap.yml │ │ └── mapper │ │ ├── OrderLockMapper.xml │ │ └── OrderMapper.xml │ └── test │ └── java │ └── com │ └── niuma │ └── binapiorder │ └── BinapiOrderApplicationTests.java ├── binapi-third-party ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── niuma │ │ │ └── binapithirdparty │ │ │ ├── BinapiThirdPartyApplication.java │ │ │ ├── config │ │ │ ├── AliPayConfig.java │ │ │ ├── AliPayRabbitMqConfig.java │ │ │ ├── RedisConfig.java │ │ │ └── TencentClient.java │ │ │ ├── controller │ │ │ └── AliPayController.java │ │ │ ├── listener │ │ │ └── SendSmsListener.java │ │ │ ├── mapper │ │ │ └── AlipayInfoMapper.java │ │ │ ├── model │ │ │ ├── dto │ │ │ │ └── AlipayRequest.java │ │ │ └── entity │ │ │ │ └── AlipayInfo.java │ │ │ ├── schedule │ │ │ └── SendOrderPaySuccessInfoFailedSchedule.java │ │ │ ├── service │ │ │ ├── AlipayInfoService.java │ │ │ └── impl │ │ │ │ └── AlipayInfoServiceImpl.java │ │ │ └── utils │ │ │ ├── ExcelUtils.java │ │ │ ├── OrderPaySuccessMqUtils.java │ │ │ └── SendSmsUtils.java │ └── resources │ │ ├── application-alipay.properties │ │ ├── application.yml │ │ ├── bootstrap.yml │ │ └── mapper │ │ └── AlipayInfoMapper.xml │ └── test │ └── java │ └── com │ └── niuma │ └── binapithirdparty │ ├── AlipayTest.java │ ├── BinapiThirdPartyApplicationTests.java │ └── YuCongMingTest.java ├── pom.xml └── sql └── ddl.sql /.gitignore: -------------------------------------------------------------------------------- 1 | /derby.log 2 | /erl_crash.dump 3 | 4 | /logs/ 5 | /binapi-config/binapi-config.iml 6 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 dogbin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /binapi-backend/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /binapi-backend/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishuaige/binapi/e03ee4c651494791a7c7674f04416e0942838f35/binapi-backend/README.md -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/BinapiBackendApplication.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi; 2 | 3 | import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | 9 | @SpringBootApplication(scanBasePackages = "com.niuma") 10 | @MapperScan("com.niuma.binapi.mapper") 11 | @EnableDubbo 12 | public class BinapiBackendApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(BinapiBackendApplication.class, args); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/annotation/AuthCheck.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.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 | * 权限校验 10 | * 11 | * @author niuma 12 | */ 13 | @Target(ElementType.METHOD) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface AuthCheck { 16 | 17 | /** 18 | * 有任何一个角色 19 | * 20 | * @return 21 | */ 22 | String[] anyRole() default ""; 23 | 24 | /** 25 | * 必须有某个角色 26 | * 27 | * @return 28 | */ 29 | String mustRole() default ""; 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/aop/AuthInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.aop; 2 | 3 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; 4 | import com.niuma.binapi.annotation.AuthCheck; 5 | import com.niuma.binapi.service.UserService; 6 | import com.niuma.binapicommon.common.ErrorCode; 7 | import com.niuma.binapicommon.exception.BusinessException; 8 | import com.niuma.binapicommon.model.entity.User; 9 | import org.apache.commons.lang3.StringUtils; 10 | import org.aspectj.lang.ProceedingJoinPoint; 11 | import org.aspectj.lang.annotation.Around; 12 | import org.aspectj.lang.annotation.Aspect; 13 | import org.springframework.stereotype.Component; 14 | import org.springframework.web.context.request.RequestAttributes; 15 | import org.springframework.web.context.request.RequestContextHolder; 16 | import org.springframework.web.context.request.ServletRequestAttributes; 17 | 18 | import javax.annotation.Resource; 19 | import javax.servlet.http.HttpServletRequest; 20 | import java.util.Arrays; 21 | import java.util.List; 22 | import java.util.stream.Collectors; 23 | 24 | 25 | /** 26 | * 权限校验 AOP 27 | * 28 | * @author niuma 29 | */ 30 | @Aspect 31 | @Component 32 | public class AuthInterceptor { 33 | 34 | @Resource 35 | private UserService userService; 36 | 37 | /** 38 | * 执行拦截 39 | * 40 | * @param joinPoint 41 | * @param authCheck 42 | * @return 43 | */ 44 | @Around("@annotation(authCheck)") 45 | public Object doInterceptor(ProceedingJoinPoint joinPoint, AuthCheck authCheck) throws Throwable { 46 | List anyRole = Arrays.stream(authCheck.anyRole()).filter(StringUtils::isNotBlank).collect(Collectors.toList()); 47 | String mustRole = authCheck.mustRole(); 48 | RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); 49 | HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); 50 | // 当前登录用户 51 | User user = userService.getLoginUser(request); 52 | // 拥有任意权限即通过 53 | if (CollectionUtils.isNotEmpty(anyRole)) { 54 | String userRole = user.getUserRole(); 55 | if (!anyRole.contains(userRole)) { 56 | throw new BusinessException(ErrorCode.NO_AUTH_ERROR); 57 | } 58 | } 59 | // 必须有所有权限才通过 60 | if (StringUtils.isNotBlank(mustRole)) { 61 | String userRole = user.getUserRole(); 62 | if (!mustRole.equals(userRole)) { 63 | throw new BusinessException(ErrorCode.NO_AUTH_ERROR); 64 | } 65 | } 66 | // 通过权限校验,放行 67 | return joinPoint.proceed(); 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/aop/LogInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.aop; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.commons.lang3.StringUtils; 5 | import org.aspectj.lang.ProceedingJoinPoint; 6 | import org.aspectj.lang.annotation.Around; 7 | import org.aspectj.lang.annotation.Aspect; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.util.StopWatch; 10 | import org.springframework.web.context.request.RequestAttributes; 11 | import org.springframework.web.context.request.RequestContextHolder; 12 | import org.springframework.web.context.request.ServletRequestAttributes; 13 | 14 | import javax.servlet.http.HttpServletRequest; 15 | import java.util.UUID; 16 | 17 | /** 18 | * 请求响应日志 AOP 19 | * 20 | * @author niuma 21 | **/ 22 | @Aspect 23 | @Component 24 | @Slf4j 25 | public class LogInterceptor { 26 | 27 | /** 28 | * 执行拦截 29 | */ 30 | @Around("execution(* com.niuma.binapi.controller.*.*(..))") 31 | public Object doInterceptor(ProceedingJoinPoint point) throws Throwable { 32 | // 计时 33 | StopWatch stopWatch = new StopWatch(); 34 | stopWatch.start(); 35 | // 获取请求路径 36 | RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); 37 | HttpServletRequest httpServletRequest = ((ServletRequestAttributes) requestAttributes).getRequest(); 38 | // 生成请求唯一 id 39 | String requestId = UUID.randomUUID().toString(); 40 | String url = httpServletRequest.getRequestURI(); 41 | // 获取请求参数 42 | Object[] args = point.getArgs(); 43 | String reqParam = "[" + StringUtils.join(args, ", ") + "]"; 44 | // 输出请求日志 45 | log.info("request start,id: {}, path: {}, ip: {}, params: {}", requestId, url, 46 | httpServletRequest.getRemoteHost(), reqParam); 47 | // 执行原方法 48 | Object result = point.proceed(); 49 | // 输出响应日志 50 | stopWatch.stop(); 51 | long totalTimeMillis = stopWatch.getTotalTimeMillis(); 52 | log.info("request end, id: {}, cost: {}ms", requestId, totalTimeMillis); 53 | return result; 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/common/RedisTokenBucket.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.common; 2 | 3 | import com.niuma.binapicommon.constant.RedisConstant; 4 | import org.springframework.data.redis.core.RedisTemplate; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.annotation.Resource; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * @author YukeSeko 12 | */ 13 | @Component 14 | public class RedisTokenBucket { 15 | 16 | @Resource 17 | private RedisTemplate redisTemplate; 18 | 19 | /** 20 | * 过期时间,400秒后过期 21 | */ 22 | private final long EXPIRE_TIME = 400; 23 | 24 | /** 25 | * 令牌桶算法,一分钟以内,每个手机号只能发送一次 26 | * @param phoneNum 27 | * @return 28 | */ 29 | public boolean tryAcquire(String phoneNum) { 30 | // 每个手机号码一分钟内只能发送一条短信 31 | int permitsPerMinute = 1; 32 | // 令牌桶容量 33 | int maxPermits = 1; 34 | // 获取当前时间戳 35 | long now = System.currentTimeMillis(); 36 | String key = RedisConstant.SMS_BUCKET_PREFIX + phoneNum; 37 | // 计算令牌桶内令牌数 38 | int tokens = Integer.parseInt(redisTemplate.opsForValue().get(key + "_tokens") == null ? "0" : redisTemplate.opsForValue().get(key + "_tokens")); 39 | // 计算令牌桶上次填充的时间戳 40 | long lastRefillTime = Long.parseLong(redisTemplate.opsForValue().get(key + "_last_refill_time") == null ? "0" : redisTemplate.opsForValue().get(key + "_last_refill_time")); 41 | // 计算当前时间与上次填充时间的时间差 42 | long timeSinceLast = now - lastRefillTime; 43 | // 计算需要填充的令牌数 44 | int refill = (int) (timeSinceLast / 1000 * permitsPerMinute / 60); 45 | // 更新令牌桶内令牌数 46 | tokens = Math.min(refill + tokens, maxPermits); 47 | // 更新上次填充时间戳 48 | redisTemplate.opsForValue().set(key + "_last_refill_time", String.valueOf(now),EXPIRE_TIME, TimeUnit.SECONDS); 49 | // 如果令牌数大于等于1,则获取令牌 50 | if (tokens >= 1) { 51 | tokens--; 52 | redisTemplate.opsForValue().set(key + "_tokens", String.valueOf(tokens),EXPIRE_TIME, TimeUnit.SECONDS); 53 | // 如果获取到令牌,则返回true 54 | return true; 55 | } 56 | // 如果没有获取到令牌,则返回false 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * 全局跨域配置 9 | * 10 | * @author niuma 11 | */ 12 | //@Configuration 在网关配置了跨域这里就不用配置了,配置了反而会报错!! 13 | public class CorsConfig implements WebMvcConfigurer { 14 | 15 | @Override 16 | public void addCorsMappings(CorsRegistry registry) { 17 | // 覆盖所有请求 18 | registry.addMapping("/**") 19 | // 允许发送 Cookie 20 | .allowCredentials(true) 21 | // 放行哪些域名(必须用 patterns,否则 * 会和 allowCredentials 冲突) 22 | .allowedOriginPatterns("*") 23 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") 24 | .allowedHeaders("*") 25 | .exposedHeaders("*"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/config/Knife4jConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | 13 | /** 14 | * Knife4j 接口文档配置 15 | * https://doc.xiaominfo.com/knife4j/documentation/get_start.html 16 | * 17 | * @author niuma 18 | */ 19 | @Configuration 20 | @EnableSwagger2 21 | @Profile("dev") 22 | public class Knife4jConfig { 23 | 24 | @Bean 25 | public Docket defaultApi2() { 26 | return new Docket(DocumentationType.SWAGGER_2) 27 | .apiInfo(new ApiInfoBuilder() 28 | .title("binapi-backend") 29 | .description("binapi-backend") 30 | .version("1.0") 31 | .build()) 32 | .select() 33 | // 指定 Controller 扫描包路径 34 | .apis(RequestHandlerSelectors.basePackage("com.niuma.binapi.controller")) 35 | .paths(PathSelectors.any()) 36 | .build(); 37 | } 38 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * MyBatis Plus 配置 12 | * 13 | * @author niuma 14 | */ 15 | @Configuration 16 | @MapperScan("com.niuma.binapi.mapper") 17 | public class MyBatisPlusConfig { 18 | 19 | /** 20 | * 拦截器配置 21 | * 22 | * @return 23 | */ 24 | @Bean 25 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 26 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 27 | // 分页插件 28 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 29 | return interceptor; 30 | } 31 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.data.redis.connection.RedisConnectionFactory; 6 | import org.springframework.data.redis.core.RedisTemplate; 7 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; 8 | import org.springframework.data.redis.serializer.RedisSerializer; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * @author niumazlb 13 | * @create 2022-08-08 22:19 14 | */ 15 | @Component 16 | @Data 17 | public class RedisConfig { 18 | 19 | @Bean 20 | public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) { 21 | // 创建RedisTemplate对象 22 | RedisTemplate template = new RedisTemplate<>(); 23 | // 设置连接工厂 24 | template.setConnectionFactory(connectionFactory); 25 | // 创建JSON序列化工具 26 | GenericJackson2JsonRedisSerializer jsonRedisSerializer = 27 | new GenericJackson2JsonRedisSerializer(); 28 | // 设置Key的序列化 29 | template.setKeySerializer(RedisSerializer.string()); 30 | template.setHashKeySerializer(RedisSerializer.string()); 31 | // 设置Value的序列化 32 | template.setValueSerializer(jsonRedisSerializer); 33 | template.setHashValueSerializer(jsonRedisSerializer); 34 | // 返回 35 | return template; 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/config/SmsRabbitMqConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.amqp.core.*; 5 | import org.springframework.amqp.rabbit.connection.ConnectionFactory; 6 | import org.springframework.amqp.rabbit.core.RabbitAdmin; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Lazy; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.HashMap; 12 | 13 | import static com.niuma.binapicommon.constant.RabbitMqConstant.*; 14 | 15 | /** 16 | * RabbitMQ配置-已废弃,该方法在队列和交换机数量增加时,不便于管理和维护,并且采用的为延迟加载方式,在启动时不会自动创建队列,导致其他项目因为找不到队列而报错 17 | * @author niumazlb 18 | */ 19 | @Slf4j 20 | //@Configuration 21 | @Deprecated 22 | public class SmsRabbitMqConfig { 23 | 24 | @Resource 25 | @Lazy 26 | RabbitAdmin rabbitAdmin; 27 | 28 | /** 29 | * 普通队列 30 | * @return 31 | */ 32 | @Bean 33 | public Queue smsQueue(){ 34 | //声明死信队列和交换机消息,过期时间:1分钟 35 | return QueueBuilder.durable(SMS_QUEUE_NAME) 36 | .deadLetterExchange(SMS_EXCHANGE_TOPIC_NAME) 37 | .deadLetterRoutingKey(SMS_DELAY_EXCHANGE_ROUTING_KEY) 38 | .ttl(60000).build(); 39 | } 40 | 41 | /** 42 | * 死信队列:消息重试三次后放入死信队列 43 | * @return 44 | */ 45 | @Bean 46 | public Queue smsDeadLetter(){ 47 | return QueueBuilder.durable(SMS_DELAY_QUEUE_NAME).build(); 48 | } 49 | 50 | /** 51 | * 主题交换机 52 | * @return 53 | */ 54 | @Bean 55 | public Exchange smsExchange() { 56 | return ExchangeBuilder.topicExchange(SMS_EXCHANGE_TOPIC_NAME).durable(true).build(); 57 | } 58 | 59 | 60 | /** 61 | * 交换机和普通队列绑定 62 | * @return 63 | */ 64 | @Bean 65 | public Binding smsBinding(){ 66 | return BindingBuilder.bind(smsQueue()).to(smsExchange()).with(SMS_EXCHANGE_ROUTING_KEY).and(new HashMap<>()); 67 | } 68 | 69 | /** 70 | * 交换机和死信队列绑定 71 | * @return 72 | */ 73 | @Bean 74 | public Binding smsDelayBinding(){ 75 | return BindingBuilder.bind(smsDeadLetter()).to(smsExchange()).with(SMS_DELAY_EXCHANGE_ROUTING_KEY).and(new HashMap<>()); 76 | } 77 | 78 | 79 | @Bean 80 | public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) { 81 | RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory); 82 | rabbitAdmin.setAutoStartup(true); 83 | return rabbitAdmin; 84 | } 85 | @Bean 86 | public void init(){ 87 | // 使用这个方法它才会在项目启动时自动创建队列 88 | rabbitAdmin.declareExchange(smsExchange()); 89 | rabbitAdmin.declareQueue(smsQueue()); 90 | rabbitAdmin.declareQueue(smsDeadLetter()); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/config/mq/QueueExchangeBinding.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.config.mq; 2 | 3 | import com.niuma.binapicommon.constant.RabbitMqConstant; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.*; 7 | 8 | 9 | /** 10 | * 队列交换机绑定关系 11 | * @author niuma 12 | */ 13 | @Component 14 | public class QueueExchangeBinding { 15 | 16 | /** 队列-交换机,绑定关系 */ 17 | private Map> queueExchangeBindingMap; 18 | 19 | public QueueExchangeBinding () { 20 | } 21 | 22 | /** 23 | * 获取绑定交换机和队列 24 | * @return 25 | */ 26 | public synchronized Map> getQueueExchangeBindingMap() { 27 | if (queueExchangeBindingMap != null) { 28 | return queueExchangeBindingMap; 29 | } 30 | 31 | // 声明binapi这个vhost的监听队列,并绑定到交换机 32 | List binApi = getBinApiQueueBinding(); 33 | 34 | // 聚合:vhost -> queueBinding 35 | Map> bindingMap = new HashMap<>(); 36 | bindingMap.put(MqProperties.VHOST.BINAPI, binApi); 37 | queueExchangeBindingMap = Collections.unmodifiableMap(bindingMap); 38 | 39 | return queueExchangeBindingMap; 40 | } 41 | 42 | private List getBinApiQueueBinding(){ 43 | return Arrays.asList( 44 | new MqProperties.QueueBinding(RabbitMqConstant.SMS_EXCHANGE_TOPIC_NAME, RabbitMqConstant.SMS_QUEUE_NAME, RabbitMqConstant.SMS_EXCHANGE_ROUTING_KEY), 45 | new MqProperties.QueueBinding(RabbitMqConstant.SMS_EXCHANGE_TOPIC_NAME, RabbitMqConstant.SMS_DELAY_QUEUE_NAME, RabbitMqConstant.SMS_DELAY_EXCHANGE_ROUTING_KEY), 46 | 47 | new MqProperties.QueueBinding(RabbitMqConstant.ORDER_EXCHANGE_TOPIC_NAME, RabbitMqConstant.ORDER_SEND_QUEUE_NAME, RabbitMqConstant.ORDER_SEND_EXCHANGE_ROUTING_KEY), 48 | new MqProperties.QueueBinding(RabbitMqConstant.ORDER_EXCHANGE_TOPIC_NAME, RabbitMqConstant.ORDER_TIMEOUT_QUEUE_NAME, RabbitMqConstant.ORDER_TIMEOUT_EXCHANGE_ROUTING_KEY), 49 | new MqProperties.QueueBinding(RabbitMqConstant.ORDER_EXCHANGE_TOPIC_NAME, RabbitMqConstant.ORDER_SUCCESS_QUEUE_NAME, RabbitMqConstant.ORDER_SUCCESS_EXCHANGE_ROUTING_KEY) 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/datasource/Apiaa1DataSource.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.datasource; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.niuma.binapicommon.common.ErrorCode; 5 | import com.niuma.binapicommon.exception.BusinessException; 6 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 7 | import org.jsoup.Jsoup; 8 | import org.jsoup.nodes.Document; 9 | import org.jsoup.nodes.Element; 10 | import org.jsoup.select.Elements; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * 获取 https://api.aa1.cn/网站的接口,如有不合适,请联系,非常感谢 18 | * @author niuma 19 | * @create 2023-05-28 14:28 20 | */ 21 | @Component 22 | public class Apiaa1DataSource implements InterfaceInfoDataSource{ 23 | @Override 24 | public Page doSearch(String searchText, long pageNum, long pageSize) { 25 | Page interfaceInfoPage = null; 26 | try { 27 | String url = String.format("https://api.aa1.cn/v1/apilist?search=%s", searchText); 28 | Document doc = Jsoup.connect(url).get(); 29 | Elements elements = doc.select(".flink-list-item"); 30 | List interfaceInfoList = new ArrayList<>(); 31 | for (Element element : elements) { 32 | // 取url 33 | String href = element.select(".cf-friends-link").attr("href"); 34 | Elements infoEle = element.select(".flink-item-info"); 35 | String name = infoEle.select(".flink-item-name").text(); 36 | String desc = infoEle.select(".flink-item-desc").text();; 37 | String interfaceDocUrl = "https://api.aa1.cn" + href; 38 | 39 | InterfaceInfo interfaceInfo = new InterfaceInfo(); 40 | interfaceInfo.setName(name); 41 | interfaceInfo.setDescription(desc); 42 | interfaceInfo.setUrl(interfaceDocUrl); 43 | interfaceInfoList.add(interfaceInfo); 44 | } 45 | interfaceInfoPage = new Page<>(pageNum,pageSize); 46 | interfaceInfoPage.setRecords(interfaceInfoList); 47 | } catch (Exception e) { 48 | throw new BusinessException(ErrorCode.SYSTEM_ERROR,"查询第三方失败!"); 49 | } 50 | return interfaceInfoPage; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/datasource/DataSourceRegistry.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.datasource; 2 | 3 | import com.niuma.binapi.model.enums.InterfaceInfoSearchEnum; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.annotation.PostConstruct; 7 | import javax.annotation.Resource; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * @author niuma 13 | * @create 2023-05-28 14:36 14 | */ 15 | @Component 16 | public class DataSourceRegistry { 17 | 18 | @Resource 19 | private NativeDataSource nativeDataSource; 20 | 21 | @Resource 22 | private Apiaa1DataSource apiaa1DataSource; 23 | 24 | Map typeDataSourceMap; 25 | 26 | public InterfaceInfoDataSource getDataSourceByType(String type) { 27 | if (typeDataSourceMap == null) { 28 | return null; 29 | } 30 | return typeDataSourceMap.get(type); 31 | } 32 | 33 | @PostConstruct 34 | public void doInit() { 35 | typeDataSourceMap = new HashMap() { 36 | { 37 | put(InterfaceInfoSearchEnum.NATIVE.getValue(), nativeDataSource); 38 | put(InterfaceInfoSearchEnum.APIAA1.getValue(), apiaa1DataSource); 39 | } 40 | }; 41 | } 42 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/datasource/InterfaceInfoDataSource.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.datasource; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | 5 | 6 | /** 7 | * @author niuma 8 | * @create 2023-03-22 20:57 9 | */ 10 | public interface InterfaceInfoDataSource { 11 | 12 | /** 13 | * 数据源接口,新接入数据源必须实现 14 | * @param searchText 15 | * @param pageNum 16 | * @param pageSize 17 | * @return 18 | */ 19 | Page doSearch(String searchText, long pageNum, long pageSize); 20 | } 21 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/datasource/NativeDataSource.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.datasource; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.niuma.binapi.model.dto.interfaceinfo.InterfaceInfoQueryRequest; 5 | import com.niuma.binapi.service.InterfaceInfoService; 6 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * @author niuma 13 | * @create 2023-05-28 14:16 14 | */ 15 | @Component 16 | public class NativeDataSource implements InterfaceInfoDataSource{ 17 | @Resource 18 | InterfaceInfoService interfaceInfoService; 19 | 20 | @Override 21 | public Page doSearch(String searchText, long pageNum, long pageSize) { 22 | InterfaceInfoQueryRequest interfaceInfoQueryRequest = new InterfaceInfoQueryRequest(); 23 | interfaceInfoQueryRequest.setDescription(searchText); 24 | interfaceInfoQueryRequest.setName(searchText); 25 | interfaceInfoQueryRequest.setPageSize(pageSize); 26 | interfaceInfoQueryRequest.setCurrent(pageNum); 27 | return interfaceInfoService.getInterfaceInfoPage(interfaceInfoQueryRequest); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/facade/InterfaceInfoSearchFacade.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.facade; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.niuma.binapi.datasource.DataSourceRegistry; 5 | import com.niuma.binapi.datasource.InterfaceInfoDataSource; 6 | import com.niuma.binapi.model.dto.interfaceinfo.InterfaceInfoSearchRequest; 7 | import com.niuma.binapi.model.enums.InterfaceInfoSearchEnum; 8 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 9 | import org.apache.commons.lang3.StringUtils; 10 | import org.springframework.stereotype.Component; 11 | 12 | import javax.annotation.Resource; 13 | 14 | /** 15 | * @author niuma 16 | * @create 2023-05-28 14:34 17 | */ 18 | @Component 19 | public class InterfaceInfoSearchFacade { 20 | 21 | @Resource 22 | DataSourceRegistry dataSourceRegistry; 23 | 24 | public Page searchAll(InterfaceInfoSearchRequest interfaceInfoSearchRequest) { 25 | String searchText = interfaceInfoSearchRequest.getSearchText(); 26 | String type = interfaceInfoSearchRequest.getType(); 27 | long current = interfaceInfoSearchRequest.getCurrent(); 28 | long pageSize = interfaceInfoSearchRequest.getPageSize(); 29 | 30 | if (StringUtils.isBlank(type)) { 31 | type = InterfaceInfoSearchEnum.NATIVE.getValue(); 32 | } 33 | InterfaceInfoDataSource dataSourceByType = dataSourceRegistry.getDataSourceByType(type); 34 | return dataSourceByType.doSearch(searchText, current, pageSize); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/mapper/InterfaceAuditMapper.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.mapper; 2 | 3 | import com.niuma.binapi.model.entity.InterfaceAudit; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * @author niumazlb 8 | * @description 针对表【interface_audit】的数据库操作Mapper 9 | * @createDate 2023-06-12 22:26:29 10 | * @Entity com.niuma.binapi.model.entity.InterfaceAudit 11 | */ 12 | public interface InterfaceAuditMapper extends BaseMapper { 13 | 14 | } 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/mapper/InterfaceChargingMapper.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.mapper; 2 | 3 | import com.niuma.binapi.model.entity.InterfaceCharging; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * @author niumazlb 8 | * @description 针对表【interface_charging】的数据库操作Mapper 9 | * @createDate 2023-04-30 20:44:10 10 | * @Entity com.niuma.binapi.model.entity.InterfaceCharging 11 | */ 12 | public interface InterfaceChargingMapper extends BaseMapper { 13 | 14 | } 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/mapper/InterfaceInfoMapper.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 6 | 7 | /** 8 | * @author niumazlb 9 | * @description 针对表【interface_info(接口信息)】的数据库操作Mapper 10 | * @createDate 2022-10-30 16:12:43 11 | * @Entity generator.domain.InterfaceInfo 12 | */ 13 | public interface InterfaceInfoMapper extends BaseMapper { 14 | 15 | } 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/mapper/UserInterfaceInfoMapper.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.niuma.binapicommon.model.entity.UserInterfaceInfo; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author niumazlb 11 | * @description 针对表【user_interface_info(用户调用接口关系)】的数据库操作Mapper 12 | * @createDate 2022-11-21 14:33:34 13 | * @Entity generator.domain.UserInterfaceInfo 14 | */ 15 | public interface UserInterfaceInfoMapper extends BaseMapper { 16 | List listTopInvokeInterfaceInfo(int limit); 17 | } 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.niuma.binapicommon.model.entity.User; 5 | 6 | /** 7 | * @Entity com.niuma.binapi.model.domain.User 8 | */ 9 | public interface UserMapper extends BaseMapper { 10 | 11 | } 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceAudit/InterfaceAuditQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceAudit; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.niuma.binapicommon.common.PageRequest; 7 | import lombok.Data; 8 | 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | /** 13 | * 创建请求 14 | * 15 | * @author niumazlb 16 | * @TableName product 17 | */ 18 | @Data 19 | public class InterfaceAuditQueryRequest extends PageRequest implements Serializable { 20 | private static final long serialVersionUID = 4489941418648280203L; 21 | 22 | /** 23 | * 接口ID 24 | */ 25 | private Long interfaceId; 26 | /** 27 | * 审批人ID 28 | */ 29 | private Long approverId; 30 | /** 31 | * 申请人ID 32 | */ 33 | private Long userId; 34 | /** 35 | * 备注 36 | */ 37 | private String remark; 38 | 39 | /** 40 | * 审批状态 41 | */ 42 | private Integer auditStatus; 43 | 44 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceAudit/InterfaceAuditRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceAudit; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * 创建请求 11 | * 12 | * @author niumazlb 13 | * @TableName product 14 | */ 15 | @Data 16 | public class InterfaceAuditRequest implements Serializable { 17 | private static final long serialVersionUID = 4489941418648280203L; 18 | 19 | /** 20 | * 主键 21 | */ 22 | private Long id; 23 | 24 | 25 | /** 26 | * 备注 27 | */ 28 | private String remark; 29 | 30 | /** 31 | * 审批状态 1-通过 2-拒绝 32 | */ 33 | private Integer auditStatus; 34 | 35 | 36 | 37 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceCharging/InterfaceChargingAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceCharging; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 创建请求 9 | * 10 | * @TableName product 11 | */ 12 | @Data 13 | public class InterfaceChargingAddRequest implements Serializable { 14 | /** 15 | * 名称 16 | */ 17 | private String name; 18 | 19 | /** 20 | * 描述 21 | */ 22 | private String description; 23 | 24 | /** 25 | * 接口地址 26 | */ 27 | private String url; 28 | 29 | /** 30 | * 请求参数 31 | */ 32 | private String requestParams; 33 | 34 | /** 35 | * 请求头 36 | */ 37 | private String requestHeader; 38 | 39 | /** 40 | * 响应头 41 | */ 42 | private String responseHeader; 43 | 44 | /** 45 | * 请求类型 46 | */ 47 | private String method; 48 | 49 | private static final long serialVersionUID = 1L; 50 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceCharging/InterfaceChargingQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceCharging; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.niuma.binapicommon.common.PageRequest; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * 查询请求 13 | * 14 | * @author niuma 15 | */ 16 | @EqualsAndHashCode(callSuper = true) 17 | @Data 18 | public class InterfaceChargingQueryRequest extends PageRequest implements Serializable { 19 | /** 20 | * 主键 21 | */ 22 | @TableId(type = IdType.AUTO) 23 | private Long id; 24 | 25 | /** 26 | * 名称 27 | */ 28 | private String name; 29 | 30 | /** 31 | * 描述 32 | */ 33 | private String description; 34 | 35 | /** 36 | * 接口地址 37 | */ 38 | private String url; 39 | 40 | /** 41 | * 请求参数 42 | */ 43 | private String requestParams; 44 | 45 | /** 46 | * 请求头 47 | */ 48 | private String requestHeader; 49 | 50 | /** 51 | * 响应头 52 | */ 53 | private String responseHeader; 54 | 55 | /** 56 | * 接口状态(0-关闭,1-开启) 57 | */ 58 | private Integer status; 59 | 60 | /** 61 | * 请求类型 62 | */ 63 | private String method; 64 | 65 | /** 66 | * 创建人 67 | */ 68 | private Long userId; 69 | 70 | private static final long serialVersionUID = 1L; 71 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceCharging/InterfaceChargingUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceCharging; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 更新请求 9 | * 10 | * @author niumazlb 11 | * @TableName product 12 | */ 13 | @Data 14 | public class InterfaceChargingUpdateRequest implements Serializable { 15 | /** 16 | * 主键 17 | */ 18 | private Long id; 19 | 20 | /** 21 | * 名称 22 | */ 23 | private String name; 24 | 25 | /** 26 | * 描述 27 | */ 28 | private String description; 29 | 30 | /** 31 | * 接口地址 32 | */ 33 | private String url; 34 | 35 | /** 36 | * 请求头 37 | */ 38 | private String requestHeader; 39 | 40 | /** 41 | * 响应头 42 | */ 43 | private String responseHeader; 44 | 45 | /** 46 | * 请求参数 47 | */ 48 | private String requestParams; 49 | 50 | /** 51 | * 接口状态(0-关闭,1-开启) 52 | */ 53 | private Integer status; 54 | 55 | /** 56 | * 请求类型 57 | */ 58 | private String method; 59 | 60 | /** 61 | * 创建人 62 | */ 63 | private Long userId; 64 | 65 | private static final long serialVersionUID = 1L; 66 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceinfo/InterfaceInfoAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceinfo; 2 | 3 | import com.niuma.binapi.model.enums.InterfaceInfoStatusEnum; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * 创建请求 10 | * 11 | * @TableName product 12 | */ 13 | @Data 14 | public class InterfaceInfoAddRequest implements Serializable { 15 | /** 16 | * 名称 17 | */ 18 | private String name; 19 | 20 | /** 21 | * 描述 22 | */ 23 | private String description; 24 | 25 | /** 26 | * 接口地址 27 | */ 28 | private String url; 29 | 30 | /** 31 | * 请求参数 32 | */ 33 | private String requestParams; 34 | 35 | /** 36 | * 请求头 37 | */ 38 | private String requestHeader; 39 | 40 | /** 41 | * 响应头 42 | */ 43 | private String responseHeader; 44 | 45 | /** 46 | * 请求类型 47 | */ 48 | private String method; 49 | 50 | /** 51 | * 是否收费(默认免费) 52 | */ 53 | private Integer isCharging = InterfaceInfoStatusEnum.FEE_FREE.getValue(); 54 | 55 | /** 56 | * 计费规则(元/条) 57 | */ 58 | private Double charging; 59 | 60 | /** 61 | * 接口剩余可调用次数 62 | */ 63 | private String availablePieces; 64 | 65 | 66 | private static final long serialVersionUID = 1L; 67 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceinfo/InterfaceInfoInvokeRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceinfo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 接口调用请求 9 | * 10 | * @author niumazlb 11 | * @TableName product 12 | */ 13 | @Data 14 | public class InterfaceInfoInvokeRequest implements Serializable { 15 | /** 16 | * 主键 17 | */ 18 | private Long id; 19 | 20 | /** 21 | * 请求参数 22 | */ 23 | private String userRequestParams; 24 | 25 | 26 | private static final long serialVersionUID = 1L; 27 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceinfo/InterfaceInfoQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceinfo; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.niuma.binapi.model.enums.InterfaceInfoStatusEnum; 6 | import com.niuma.binapicommon.common.PageRequest; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | * 查询请求 14 | * 15 | * @author niuma 16 | */ 17 | @EqualsAndHashCode(callSuper = true) 18 | @Data 19 | public class InterfaceInfoQueryRequest extends PageRequest implements Serializable { 20 | /** 21 | * 主键 22 | */ 23 | @TableId(type = IdType.AUTO) 24 | private Long id; 25 | 26 | /** 27 | * 名称 28 | */ 29 | private String name; 30 | 31 | /** 32 | * 描述 33 | */ 34 | private String description; 35 | 36 | /** 37 | * 接口地址 38 | */ 39 | private String url; 40 | 41 | /** 42 | * 请求参数 43 | */ 44 | private String requestParams; 45 | 46 | /** 47 | * 请求头 48 | */ 49 | private String requestHeader; 50 | 51 | /** 52 | * 响应头 53 | */ 54 | private String responseHeader; 55 | 56 | /** 57 | * 接口状态(0-关闭,1-开启) 58 | */ 59 | private Integer status; 60 | 61 | /** 62 | * 请求类型 63 | */ 64 | private String method; 65 | 66 | /** 67 | * 创建人 68 | */ 69 | private Long userId; 70 | 71 | /** 72 | * 是否收费(默认免费) 73 | */ 74 | private Integer isCharging; 75 | 76 | private static final long serialVersionUID = 1L; 77 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceinfo/InterfaceInfoSearchRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceinfo; 2 | 3 | import com.niuma.binapicommon.common.PageRequest; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author niuma 10 | * @create 2023-05-28 13:57 11 | */ 12 | @Data 13 | public class InterfaceInfoSearchRequest extends PageRequest implements Serializable { 14 | private static final long serialVersionUID = -6270861325558763872L; 15 | private String searchText; 16 | private String type; 17 | } 18 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/interfaceinfo/InterfaceInfoUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.interfaceinfo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 更新请求 9 | * 10 | * @author niumazlb 11 | * @TableName product 12 | */ 13 | @Data 14 | public class InterfaceInfoUpdateRequest implements Serializable { 15 | /** 16 | * 主键 17 | */ 18 | private Long id; 19 | 20 | /** 21 | * 名称 22 | */ 23 | private String name; 24 | 25 | /** 26 | * 描述 27 | */ 28 | private String description; 29 | 30 | /** 31 | * 接口地址 32 | */ 33 | private String url; 34 | 35 | /** 36 | * 请求头 37 | */ 38 | private String requestHeader; 39 | 40 | /** 41 | * 响应头 42 | */ 43 | private String responseHeader; 44 | 45 | /** 46 | * 请求参数 47 | */ 48 | private String requestParams; 49 | 50 | /** 51 | * 接口状态(0-关闭,1-开启) 52 | */ 53 | private Integer status; 54 | 55 | /** 56 | * 请求类型 57 | */ 58 | private String method; 59 | 60 | /** 61 | * 创建人 62 | */ 63 | private Long userId; 64 | 65 | private static final long serialVersionUID = 1L; 66 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/user/UserAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 用户创建请求 9 | * 10 | * @author niuma 11 | */ 12 | @Data 13 | public class UserAddRequest implements Serializable { 14 | 15 | /** 16 | * 用户昵称 17 | */ 18 | private String userName; 19 | 20 | /** 21 | * 账号 22 | */ 23 | private String userAccount; 24 | 25 | /** 26 | * 用户头像 27 | */ 28 | private String userAvatar; 29 | 30 | /** 31 | * 性别 32 | */ 33 | private Integer gender; 34 | 35 | /** 36 | * 用户角色: user, admin 37 | */ 38 | private String userRole; 39 | 40 | /** 41 | * 密码 42 | */ 43 | private String userPassword; 44 | 45 | private static final long serialVersionUID = 1L; 46 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/user/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 用户登录请求体 9 | * 10 | * @author niuma 11 | */ 12 | @Data 13 | public class UserLoginRequest implements Serializable { 14 | 15 | private static final long serialVersionUID = 3191241716373120793L; 16 | 17 | private String userAccount; 18 | 19 | private String userPassword; 20 | 21 | private String phoneNum; 22 | 23 | private String phoneCaptcha; 24 | } 25 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/user/UserQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.user; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.niuma.binapicommon.common.PageRequest; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | 11 | /** 12 | * 用户查询请求 13 | * 14 | * @author niuma 15 | */ 16 | @EqualsAndHashCode(callSuper = true) 17 | @Data 18 | public class UserQueryRequest extends PageRequest implements Serializable { 19 | /** 20 | * id 21 | */ 22 | private Long id; 23 | 24 | /** 25 | * 用户昵称 26 | */ 27 | private String userName; 28 | 29 | /** 30 | * 账号 31 | */ 32 | private String userAccount; 33 | /** 34 | * 手机号 35 | */ 36 | private String phoneNum; 37 | 38 | /** 39 | * 用户头像 40 | */ 41 | private String userAvatar; 42 | 43 | /** 44 | * 性别 45 | */ 46 | private Integer gender; 47 | 48 | /** 49 | * 用户角色: user, admin 50 | */ 51 | private String userRole; 52 | 53 | /** 54 | * 创建时间 55 | */ 56 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 57 | private String createTime; 58 | 59 | /** 60 | * 更新时间 61 | */ 62 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 63 | private String updateTime; 64 | 65 | private static final long serialVersionUID = 1L; 66 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/user/UserRegisterRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 用户注册请求体 9 | * 10 | * @author niuma 11 | */ 12 | @Data 13 | public class UserRegisterRequest implements Serializable { 14 | 15 | private static final long serialVersionUID = 3191241716373120793L; 16 | 17 | private String userName; 18 | 19 | private String userAccount; 20 | 21 | private String userPassword; 22 | 23 | private String checkPassword; 24 | 25 | private String phoneNum; 26 | 27 | private String phoneCaptcha; 28 | 29 | private String captcha; 30 | } 31 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/user/UserUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.user; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * 用户更新请求 10 | * 11 | * @author niuma 12 | */ 13 | @Data 14 | public class UserUpdateRequest implements Serializable { 15 | /** 16 | * id 17 | */ 18 | private Long id; 19 | 20 | /** 21 | * 用户昵称 22 | */ 23 | private String userName; 24 | 25 | /** 26 | * 账号 27 | */ 28 | private String userAccount; 29 | 30 | /** 31 | * 用户头像 32 | */ 33 | private String userAvatar; 34 | 35 | /** 36 | * 性别 37 | */ 38 | private Integer gender; 39 | 40 | /** 41 | * 用户角色: user, admin 42 | */ 43 | private String userRole; 44 | 45 | /** 46 | * 密码 47 | */ 48 | private String userPassword; 49 | 50 | @TableField(exist = false) 51 | private static final long serialVersionUID = 1L; 52 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/userInterfaceinfo/UserInterfaceInfoAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.userInterfaceinfo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 创建请求 9 | * 10 | * @TableName product 11 | */ 12 | @Data 13 | public class UserInterfaceInfoAddRequest implements Serializable { 14 | 15 | /** 16 | * 调用者 id 17 | */ 18 | private Long userId; 19 | 20 | /** 21 | * 接口 id 22 | */ 23 | private Long interfaceInfoId; 24 | 25 | /** 26 | * 总调用次数 27 | */ 28 | private Integer totalNum; 29 | 30 | /** 31 | * 剩余调用次数 32 | */ 33 | private Integer leftNum; 34 | 35 | 36 | 37 | private static final long serialVersionUID = 1L; 38 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/userInterfaceinfo/UserInterfaceInfoQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.userInterfaceinfo; 2 | 3 | import com.niuma.binapicommon.common.PageRequest; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * 查询请求 11 | * 12 | * @author niuma 13 | */ 14 | @EqualsAndHashCode(callSuper = true) 15 | @Data 16 | public class UserInterfaceInfoQueryRequest extends PageRequest implements Serializable { 17 | /** 18 | * 主键 19 | */ 20 | private Long id; 21 | 22 | /** 23 | * 调用者 id 24 | */ 25 | private Long userId; 26 | 27 | /** 28 | * 接口 id 29 | */ 30 | private Long interfaceInfoId; 31 | 32 | /** 33 | * 总调用次数 34 | */ 35 | private Integer totalNum; 36 | 37 | /** 38 | * 剩余调用次数 39 | */ 40 | private Integer leftNum; 41 | 42 | /** 43 | * 0-正常,1-禁用 44 | */ 45 | private Integer status; 46 | 47 | private static final long serialVersionUID = 1L; 48 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/dto/userInterfaceinfo/UserInterfaceInfoUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.dto.userInterfaceinfo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 更新请求 9 | * 10 | * @TableName product 11 | */ 12 | @Data 13 | public class UserInterfaceInfoUpdateRequest implements Serializable { 14 | /** 15 | * 主键 16 | */ 17 | private Long id; 18 | 19 | /** 20 | * 总调用次数 21 | */ 22 | private Integer totalNum; 23 | 24 | /** 25 | * 剩余调用次数 26 | */ 27 | private Integer leftNum; 28 | 29 | /** 30 | * 0-正常,1-禁用 31 | */ 32 | private Integer status; 33 | 34 | private static final long serialVersionUID = 1L; 35 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/entity/InterfaceAudit.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | import lombok.Data; 8 | 9 | /** 10 | * 11 | * @TableName interface_audit 12 | */ 13 | @TableName(value ="interface_audit") 14 | @Data 15 | public class InterfaceAudit implements Serializable { 16 | /** 17 | * 主键 18 | */ 19 | @TableId(type = IdType.AUTO) 20 | private Long id; 21 | 22 | /** 23 | * 接口ID 24 | */ 25 | private Long interfaceId; 26 | 27 | /** 28 | * 审批人ID 29 | */ 30 | private Long approverId; 31 | /** 32 | * 申请人ID 33 | */ 34 | private Long userId; 35 | /** 36 | * 备注 37 | */ 38 | private String remark; 39 | 40 | /** 41 | * 审批状态 42 | */ 43 | private Integer auditStatus; 44 | 45 | /** 46 | * 创建时间 47 | */ 48 | private Date createTime; 49 | 50 | /** 51 | * 更新时间 52 | */ 53 | private Date updateTime; 54 | 55 | /** 56 | * 逻辑删除标志 57 | */ 58 | @TableLogic 59 | private Integer isDeleted; 60 | 61 | @TableField(exist = false) 62 | private static final long serialVersionUID = 1L; 63 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/entity/InterfaceCharging.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import java.util.Date; 9 | import lombok.Data; 10 | 11 | /** 12 | * 13 | * @TableName interface_charging 14 | */ 15 | @TableName(value ="interface_charging") 16 | @Data 17 | public class InterfaceCharging implements Serializable { 18 | /** 19 | * 主键 20 | */ 21 | @TableId(type = IdType.AUTO) 22 | private Long id; 23 | 24 | /** 25 | * 接口id 26 | */ 27 | private Long interfaceId; 28 | 29 | /** 30 | * 计费规则(元/条) 31 | */ 32 | private Double charging; 33 | 34 | /** 35 | * 接口剩余可调用次数 36 | */ 37 | private String availablePieces; 38 | 39 | /** 40 | * 创建人 41 | */ 42 | private Long userId; 43 | 44 | /** 45 | * 创建时间 46 | */ 47 | private Date createTime; 48 | 49 | /** 50 | * 更新时间 51 | */ 52 | private Date updateTime; 53 | 54 | /** 55 | * 是否删除(0-未删, 1-已删) 56 | */ 57 | private Integer isDelete; 58 | 59 | @TableField(exist = false) 60 | private static final long serialVersionUID = 1L; 61 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/enums/InterfaceInfoAuditStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * 接口状态枚举 9 | * 10 | * @author niuma 11 | */ 12 | public enum InterfaceInfoAuditStatusEnum { 13 | 14 | PENDING("待审核", 0), 15 | // 审核通过 16 | PASS("审核通过", 1), 17 | // 审核不通过 18 | FAIL("审核不通过", 2); 19 | 20 | private final String text; 21 | 22 | private final int value; 23 | 24 | InterfaceInfoAuditStatusEnum(String text, int value) { 25 | this.text = text; 26 | this.value = value; 27 | } 28 | 29 | /** 30 | * 获取值列表 31 | * 32 | * @return 33 | */ 34 | public static List getValues() { 35 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 36 | } 37 | 38 | public int getValue() { 39 | return value; 40 | } 41 | 42 | public String getText() { 43 | return text; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/enums/InterfaceInfoSearchEnum.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * @author niuma 9 | * @create 2023-05-28 14:38 10 | */ 11 | public enum InterfaceInfoSearchEnum { 12 | NATIVE("本地", "native"), 13 | APIAA1("Apiaa1", "Apiaa1"); 14 | 15 | private final String text; 16 | 17 | private final String value; 18 | 19 | InterfaceInfoSearchEnum(String text, String value) { 20 | this.text = text; 21 | this.value = value; 22 | } 23 | 24 | /** 25 | * 获取值列表 26 | * 27 | * @return 28 | */ 29 | public static List getValues() { 30 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 31 | } 32 | 33 | public String getValue() { 34 | return value; 35 | } 36 | 37 | public String getText() { 38 | return text; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/enums/InterfaceInfoStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * 接口状态枚举 9 | * 10 | * @author niuma 11 | */ 12 | public enum InterfaceInfoStatusEnum { 13 | 14 | OFFLINE("关闭", 0), 15 | ONLINE("上线", 1), 16 | PENDING("待审核", 2), 17 | // 是否收费 18 | FEE_FREE("免费", 0), 19 | FEE_PAY("收费", 1); 20 | 21 | private final String text; 22 | 23 | private final int value; 24 | 25 | InterfaceInfoStatusEnum(String text, int value) { 26 | this.text = text; 27 | this.value = value; 28 | } 29 | 30 | /** 31 | * 获取值列表 32 | * 33 | * @return 34 | */ 35 | public static List getValues() { 36 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 37 | } 38 | 39 | public int getValue() { 40 | return value; 41 | } 42 | 43 | public String getText() { 44 | return text; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/excel/InterfaceInfoInvokeExcel.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.excel; 2 | 3 | import com.alibaba.excel.annotation.ExcelProperty; 4 | import com.alibaba.excel.annotation.write.style.ColumnWidth; 5 | import com.alibaba.excel.annotation.write.style.ContentRowHeight; 6 | import com.alibaba.excel.annotation.write.style.HeadRowHeight; 7 | import com.fasterxml.jackson.annotation.JsonFormat; 8 | import lombok.Data; 9 | 10 | import java.io.Serializable; 11 | import java.util.Date; 12 | 13 | /** 14 | * @author niuma 15 | * @create 2023-05-06 20:46 16 | */ 17 | @Data 18 | @ContentRowHeight(20) 19 | @HeadRowHeight(30) 20 | @ColumnWidth(25) 21 | public class InterfaceInfoInvokeExcel implements Serializable { 22 | private static final long serialVersionUID = -5504766653977176865L; 23 | /** 24 | * 主键 25 | */ 26 | @ExcelProperty("接口Id") 27 | private Long id; 28 | 29 | /** 30 | * 名称 31 | */ 32 | @ExcelProperty("接口名") 33 | private String name; 34 | 35 | /** 36 | * 描述 37 | */ 38 | @ExcelProperty("接口描述") 39 | private String description; 40 | 41 | /** 42 | * 接口地址 43 | */ 44 | @ExcelProperty("接口地址") 45 | private String url; 46 | 47 | 48 | 49 | /** 50 | * 已调用次数 51 | */ 52 | @ExcelProperty("已调用次数") 53 | private Integer totalNum; 54 | 55 | 56 | /** 57 | * 接口状态(0-关闭,1-开启) 58 | */ 59 | @ExcelProperty("接口状态(0-关闭,1-开启)") 60 | private Integer status; 61 | 62 | /** 63 | * 创建人 64 | */ 65 | @ExcelProperty("创建人") 66 | private Long userId; 67 | 68 | /** 69 | * 创建时间 70 | */ 71 | @ExcelProperty("创建时间") 72 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 73 | private Date createTime; 74 | 75 | /** 76 | * 更新时间 77 | */ 78 | @ExcelProperty("更新时间") 79 | 80 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 81 | private Date updateTime; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/excel/InterfaceInfoOrderExcel.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.excel; 2 | 3 | import com.alibaba.excel.annotation.ExcelProperty; 4 | import com.alibaba.excel.annotation.write.style.ColumnWidth; 5 | import com.alibaba.excel.annotation.write.style.ContentRowHeight; 6 | import com.alibaba.excel.annotation.write.style.HeadRowHeight; 7 | import lombok.Data; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * @author niuma 13 | * @create 2023-05-04 14:11 14 | */ 15 | @Data 16 | @ContentRowHeight(20) 17 | @HeadRowHeight(25) 18 | @ColumnWidth(25) 19 | public class InterfaceInfoOrderExcel implements Serializable { 20 | 21 | /** 22 | * 接口id 23 | */ 24 | @ExcelProperty("接口id") 25 | private Long interfaceId; 26 | 27 | /** 28 | * 接口名 29 | */ 30 | @ExcelProperty("接口名") 31 | 32 | private String interfaceName; 33 | 34 | /** 35 | * 接口描述 36 | */ 37 | @ExcelProperty("接口描述") 38 | private String interfaceDesc; 39 | 40 | /** 41 | * 购买数量 42 | */ 43 | @ExcelProperty("购买数量") 44 | private Long total; 45 | 46 | 47 | private static final long serialVersionUID = 1L; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/vo/InterfaceAuditVO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.vo; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 8 | import lombok.Data; 9 | 10 | import java.io.Serializable; 11 | import java.util.Date; 12 | 13 | /** 14 | * 15 | * @author niumazlb 16 | * @TableName interface_audit 17 | */ 18 | @Data 19 | public class InterfaceAuditVO implements Serializable { 20 | /** 21 | * 主键 22 | */ 23 | @TableId(type = IdType.AUTO) 24 | private Long id; 25 | 26 | /** 27 | * 接口信息 28 | */ 29 | private InterfaceInfo interfaceInfo; 30 | 31 | 32 | /** 33 | * 审批人ID 34 | */ 35 | private Long approverId; 36 | /** 37 | * 申请人ID 38 | */ 39 | private Long userId; 40 | 41 | /** 42 | * 审批人账号 43 | */ 44 | private String approverAccount; 45 | /** 46 | * 申请人ID 47 | */ 48 | private String userAccount; 49 | 50 | /** 51 | * 备注 52 | */ 53 | private String remark; 54 | 55 | /** 56 | * 审批状态 57 | */ 58 | private Integer auditStatus; 59 | 60 | /** 61 | * 创建时间 62 | */ 63 | private Date createTime; 64 | 65 | /** 66 | * 更新时间 67 | */ 68 | private Date updateTime; 69 | 70 | @TableField(exist = false) 71 | private static final long serialVersionUID = 1L; 72 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/vo/InterfaceInfoVO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.vo; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.niuma.binapi.model.enums.InterfaceInfoStatusEnum; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | import java.util.Date; 9 | 10 | /** 11 | * @author niuma 12 | * @create 2023-05-06 20:46 13 | */ 14 | @Data 15 | public class InterfaceInfoVO implements Serializable { 16 | private static final long serialVersionUID = -5504766653977176865L; 17 | /** 18 | * 主键 19 | */ 20 | 21 | private Long id; 22 | 23 | /** 24 | * 名称 25 | */ 26 | private String name; 27 | 28 | /** 29 | * 描述 30 | */ 31 | private String description; 32 | 33 | /** 34 | * 接口地址 35 | */ 36 | private String url; 37 | 38 | /** 39 | * 请求参数 40 | */ 41 | private String requestParams; 42 | /** 43 | * 计费规则(元/条) 44 | */ 45 | private Double charging; 46 | 47 | /** 48 | * 计费Id 49 | */ 50 | private Long chargingId; 51 | 52 | /** 53 | * 接口剩余可调用次数 54 | */ 55 | private String availablePieces; 56 | 57 | /** 58 | * 已调用次数 59 | */ 60 | private Integer totalNum; 61 | 62 | /** 63 | * 请求头 64 | */ 65 | private String requestHeader; 66 | 67 | /** 68 | * 响应头 69 | */ 70 | private String responseHeader; 71 | 72 | /** 73 | * 接口状态(0-关闭,1-开启) 74 | */ 75 | private Integer status; 76 | 77 | /** 78 | * 请求类型 79 | */ 80 | private String method; 81 | 82 | /** 83 | * 创建人 84 | */ 85 | private Long userId; 86 | 87 | /** 88 | * 创建时间 89 | */ 90 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 91 | private Date createTime; 92 | 93 | /** 94 | * 更新时间 95 | */ 96 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 97 | private Date updateTime; 98 | 99 | /** 100 | * 是否收费(默认免费) 101 | */ 102 | private Integer isCharging; 103 | 104 | } 105 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/vo/UserDevKeyVO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author niuma 9 | * @create 2023-05-11 14:13 10 | */ 11 | @Data 12 | public class UserDevKeyVO implements Serializable { 13 | private static final long serialVersionUID = 6703326011663561616L; 14 | 15 | private String accessKey; 16 | private String secretKey; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/model/vo/UserInterfaceInfoVO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.model.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author niuma 9 | * @create 2023-05-08 21:18 10 | */ 11 | @Data 12 | public class UserInterfaceInfoVO implements Serializable { 13 | private static final long serialVersionUID = -1277232101530908019L; 14 | 15 | private Long id; 16 | private Long interfaceInfoId; 17 | /** 18 | * 名称 19 | */ 20 | private String name; 21 | 22 | /** 23 | * 描述 24 | */ 25 | private String description; 26 | 27 | /** 28 | * 接口地址 29 | */ 30 | private String url; 31 | 32 | /** 33 | * 接口状态(0-关闭,1-开启) 34 | */ 35 | private Integer interfaceStatus; 36 | 37 | /** 38 | * 请求类型 39 | */ 40 | private String method; 41 | 42 | /** 43 | * 已调用次数 44 | */ 45 | private Integer totalNum; 46 | 47 | /** 48 | * 剩余调用次数 49 | */ 50 | private Integer leftNum; 51 | 52 | /** 53 | * 0-正常,1-禁用) 54 | */ 55 | private Integer status; 56 | } 57 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/InterfaceAuditService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.niuma.binapi.model.dto.interfaceAudit.InterfaceAuditQueryRequest; 5 | import com.niuma.binapi.model.dto.interfaceAudit.InterfaceAuditRequest; 6 | import com.niuma.binapi.model.dto.interfaceinfo.InterfaceInfoAddRequest; 7 | import com.niuma.binapi.model.entity.InterfaceAudit; 8 | import com.baomidou.mybatisplus.extension.service.IService; 9 | import com.niuma.binapi.model.vo.InterfaceAuditVO; 10 | import com.niuma.binapicommon.model.entity.User; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | 14 | /** 15 | * @author niumazlb 16 | * @description 针对表【interface_audit】的数据库操作Service 17 | * @createDate 2023-06-12 22:26:29 18 | */ 19 | public interface InterfaceAuditService extends IService { 20 | /** 21 | * 审核接口通过 22 | * @param interfaceAuditRequest 23 | * @param loginUser 24 | * @return 25 | */ 26 | boolean auditInterface(InterfaceAuditRequest interfaceAuditRequest, User loginUser); 27 | 28 | /** 29 | * 分页获取审核接口列表 30 | * @param interfaceAuditQueryRequest 31 | * @return 32 | */ 33 | Page getInterfaceAuditListPage(InterfaceAuditQueryRequest interfaceAuditQueryRequest); 34 | } 35 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/InterfaceChargingService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service; 2 | 3 | import com.niuma.binapi.model.entity.InterfaceCharging; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.niuma.binapicommon.model.dto.UnLockAvailablePiecesDTO; 6 | 7 | /** 8 | * @author niumazlb 9 | * @description 针对表【interface_charging】的数据库操作Service 10 | * @createDate 2023-04-30 20:44:10 11 | */ 12 | public interface InterfaceChargingService extends IService { 13 | 14 | /** 15 | * 检查某个接口的库存是否充足 16 | * @param id 17 | * @return 18 | */ 19 | boolean checkInventory(Long id); 20 | 21 | /** 22 | * 解锁库存 23 | * @param unLockAvailablePiecesDTO 24 | * @return 25 | */ 26 | boolean unLockAvailablePieces(UnLockAvailablePiecesDTO unLockAvailablePiecesDTO); 27 | } 28 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/InterfaceInfoService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.niuma.binapi.model.dto.interfaceinfo.InterfaceInfoAddRequest; 6 | import com.niuma.binapi.model.dto.interfaceinfo.InterfaceInfoQueryRequest; 7 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 8 | import com.niuma.binapicommon.model.entity.User; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | 12 | /** 13 | * @author niumazlb 14 | * @description 针对表【interface_info(接口信息)】的数据库操作Service 15 | * @createDate 2022-10-30 16:12:43 16 | */ 17 | public interface InterfaceInfoService extends IService { 18 | 19 | 20 | /** 21 | * 添加接口信息-用户使用 22 | * @param interfaceInfoAddRequest 23 | * @param user 24 | * @return 25 | */ 26 | Long userAddInterface(InterfaceInfoAddRequest interfaceInfoAddRequest, User user); 27 | 28 | /** 29 | * 添加接口信息-管理员使用 30 | * @param interfaceInfoAddRequest 31 | * @param user 32 | * @return 33 | */ 34 | Long adminAddInterface(InterfaceInfoAddRequest interfaceInfoAddRequest, User user); 35 | 36 | /** 37 | * 校验 38 | * 39 | * @param interfaceInfo 40 | * @param add 是否为创建校验 41 | */ 42 | void validInterfaceInfo(InterfaceInfo interfaceInfo, boolean add); 43 | 44 | /** 45 | * 上线接口 46 | * @param id 47 | * @return 48 | */ 49 | Boolean onlineInterfaceInfo(long id); 50 | 51 | /** 52 | * 下线接口 53 | * @param id 54 | * @return 55 | */ 56 | Boolean offlineInterfaceInfo(long id); 57 | 58 | /** 59 | * 搜索分页接口信息 60 | * @param interfaceInfoQueryRequest 61 | * @return 62 | */ 63 | Page getInterfaceInfoPage(InterfaceInfoQueryRequest interfaceInfoQueryRequest); 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/UserInterfaceInfoService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.niuma.binapi.model.vo.InterfaceInfoVO; 6 | import com.niuma.binapi.model.vo.UserInterfaceInfoVO; 7 | import com.niuma.binapicommon.model.dto.UpdateUserInterfaceInfoDTO; 8 | import com.niuma.binapicommon.model.entity.UserInterfaceInfo; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import java.util.List; 12 | 13 | /** 14 | * @author niumazlb 15 | * @description 针对表【user_interface_info(用户调用接口关系)】的数据库操作Service 16 | * @createDate 2022-11-21 14:33:34 17 | */ 18 | public interface UserInterfaceInfoService extends IService { 19 | 20 | /** 21 | * 校验 22 | * 23 | * @param userInterfaceInfo 24 | * @param add 是否为创建校验 25 | */ 26 | void validUserInterfaceInfo(UserInterfaceInfo userInterfaceInfo, boolean add); 27 | 28 | /** 29 | * 调用次数 + 1 30 | * @param interfaceInfoId 31 | * @param userId 32 | * @return 33 | */ 34 | boolean invokeCount(long interfaceInfoId, long userId) ; 35 | 36 | /** 37 | * 获取调用次数前limit的接口信息 38 | * @param limit 39 | * @return 40 | */ 41 | List interfaceInvokeTopAnalysis(int limit); 42 | 43 | /** 44 | * 更新用户接口信息 45 | * @param updateUserInterfaceInfoDTO 46 | * @return 47 | */ 48 | boolean updateUserInterfaceInfo(UpdateUserInterfaceInfoDTO updateUserInterfaceInfoDTO); 49 | 50 | /** 51 | * 检验用户是否有调用次数 52 | * @param userId 53 | * @param interfaceInfoId 54 | * @return 55 | */ 56 | boolean checkUserInvokeAuth(Long userId, Long interfaceInfoId); 57 | 58 | /** 59 | * 根据Id获取某个用户拥有的接口信息 60 | * @param userId 61 | * @param request 62 | * @return 63 | */ 64 | List getInterfaceInfoByUserId(Long userId, HttpServletRequest request); 65 | } 66 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/impl/InterfaceChargingServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 5 | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import com.niuma.binapi.model.entity.InterfaceCharging; 8 | import com.niuma.binapi.service.InterfaceChargingService; 9 | import com.niuma.binapi.mapper.InterfaceChargingMapper; 10 | import com.niuma.binapicommon.common.ErrorCode; 11 | import com.niuma.binapicommon.exception.BusinessException; 12 | import com.niuma.binapicommon.model.dto.UnLockAvailablePiecesDTO; 13 | import org.springframework.stereotype.Service; 14 | 15 | /** 16 | * @author niumazlb 17 | * @description 针对表【interface_charging】的数据库操作Service实现 18 | * @createDate 2023-04-30 20:44:10 19 | */ 20 | @Service 21 | public class InterfaceChargingServiceImpl extends ServiceImpl 22 | implements InterfaceChargingService{ 23 | 24 | @Override 25 | public boolean checkInventory(Long id) { 26 | if(id == null){ 27 | throw new BusinessException(ErrorCode.PARAMS_ERROR); 28 | } 29 | InterfaceCharging interfaceCharging = this.getById(id); 30 | return Integer.parseInt(interfaceCharging.getAvailablePieces())>= 0; 31 | } 32 | 33 | @Override 34 | public boolean unLockAvailablePieces(UnLockAvailablePiecesDTO unLockAvailablePiecesDTO) { 35 | Long interfaceId = unLockAvailablePiecesDTO.getInterfaceId(); 36 | Long count = unLockAvailablePiecesDTO.getCount(); 37 | UpdateWrapper updateWrapper = new UpdateWrapper<>(); 38 | updateWrapper.eq("interfaceId", interfaceId).setSql("availablePieces = availablePieces + " + count); 39 | boolean update = this.update(updateWrapper); 40 | if(!update){ 41 | throw new BusinessException(ErrorCode.OPERATION_ERROR); 42 | } 43 | return update; 44 | } 45 | } 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/impl/inner/InnerInterfaceChargingServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service.impl.inner; 2 | 3 | import com.niuma.binapi.model.entity.InterfaceCharging; 4 | import com.niuma.binapi.service.InterfaceChargingService; 5 | import com.niuma.binapicommon.common.ErrorCode; 6 | import com.niuma.binapicommon.exception.BusinessException; 7 | import com.niuma.binapicommon.model.dto.UnLockAvailablePiecesDTO; 8 | import com.niuma.binapicommon.model.dto.UpdateAvailablePiecesDTO; 9 | import com.niuma.binapicommon.service.InnerInterfaceChargingService; 10 | import org.apache.dubbo.config.annotation.DubboService; 11 | 12 | import javax.annotation.Resource; 13 | 14 | /** 15 | * @author niuma 16 | * @create 2023-05-03 16:21 17 | */ 18 | @DubboService 19 | public class InnerInterfaceChargingServiceImpl implements InnerInterfaceChargingService { 20 | @Resource 21 | InterfaceChargingService interfaceChargingService; 22 | 23 | @Override 24 | public boolean checkInventory(Long id) { 25 | return interfaceChargingService.checkInventory(id); 26 | } 27 | 28 | @Override 29 | public boolean updateAvailablePieces(UpdateAvailablePiecesDTO updateAvailablePiecesDTO) { 30 | Long chargingId = updateAvailablePiecesDTO.getChargingId(); 31 | Long count = updateAvailablePiecesDTO.getCount(); 32 | if (null == chargingId || null == count || count < 0) { 33 | throw new BusinessException(ErrorCode.PARAMS_ERROR); 34 | } 35 | 36 | InterfaceCharging interfaceCharging = interfaceChargingService.getById(chargingId); 37 | if (interfaceCharging == null) { 38 | throw new BusinessException(ErrorCode.NOT_FOUND_ERROR); 39 | } 40 | 41 | String availablePieces = interfaceCharging.getAvailablePieces(); 42 | long b = Long.parseLong(availablePieces) - count; 43 | if (b < 0) { 44 | throw new BusinessException(ErrorCode.OPERATION_ERROR, "库存不足"); 45 | } 46 | 47 | InterfaceCharging updateInterfaceCharging = new InterfaceCharging(); 48 | updateInterfaceCharging.setId(chargingId); 49 | updateInterfaceCharging.setAvailablePieces(String.valueOf(b)); 50 | boolean update = interfaceChargingService.updateById(updateInterfaceCharging); 51 | return update; 52 | } 53 | 54 | @Override 55 | public boolean unLockAvailablePieces(UnLockAvailablePiecesDTO unLockAvailablePiecesDTO) { 56 | return interfaceChargingService.unLockAvailablePieces(unLockAvailablePiecesDTO); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/impl/inner/InnerInterfaceInfoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service.impl.inner; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.niuma.binapi.mapper.InterfaceInfoMapper; 5 | import com.niuma.binapicommon.common.ErrorCode; 6 | import com.niuma.binapicommon.exception.BusinessException; 7 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 8 | import com.niuma.binapicommon.service.InnerInterfaceInfoService; 9 | import org.apache.commons.lang3.StringUtils; 10 | import org.apache.dubbo.config.annotation.DubboService; 11 | 12 | import javax.annotation.Resource; 13 | 14 | /** 15 | * @author niuma 16 | * @create 2023-02-27 16:13 17 | */ 18 | @DubboService 19 | public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService { 20 | @Resource 21 | InterfaceInfoMapper interfaceInfoMapper; 22 | @Override 23 | public InterfaceInfo getInterfaceInfo(String url, String method) { 24 | if(StringUtils.isAnyBlank(url,method)){ 25 | throw new BusinessException(ErrorCode.PARAMS_ERROR); 26 | } 27 | QueryWrapper queryWrapper = new QueryWrapper<>(); 28 | queryWrapper.eq("url",url); 29 | queryWrapper.eq("method",method); 30 | InterfaceInfo interfaceInfo = interfaceInfoMapper.selectOne(queryWrapper); 31 | 32 | return interfaceInfo; 33 | } 34 | 35 | @Override 36 | public InterfaceInfo getInterfaceInfoById(Long id) { 37 | 38 | InterfaceInfo interfaceInfo = interfaceInfoMapper.selectById(id); 39 | return interfaceInfo; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/impl/inner/InnerUserInterfaceInfoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service.impl.inner; 2 | 3 | 4 | import com.niuma.binapi.service.UserInterfaceInfoService; 5 | import com.niuma.binapicommon.model.dto.UpdateUserInterfaceInfoDTO; 6 | import com.niuma.binapicommon.service.InnerUserInterfaceInfoService; 7 | import org.apache.dubbo.config.annotation.DubboService; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * @author niuma 13 | * @create 2023-02-27 15:47 14 | */ 15 | @DubboService 16 | public class InnerUserInterfaceInfoServiceImpl implements InnerUserInterfaceInfoService { 17 | 18 | @Resource 19 | UserInterfaceInfoService userInterfaceInfoService; 20 | 21 | @Override 22 | public boolean invokeCount(long interfaceInfoId, long userId) { 23 | 24 | return userInterfaceInfoService.invokeCount(interfaceInfoId, userId); 25 | } 26 | 27 | @Override 28 | public boolean updateUserInterfaceInfo(UpdateUserInterfaceInfoDTO updateUserInterfaceInfoDTO) { 29 | return userInterfaceInfoService.updateUserInterfaceInfo(updateUserInterfaceInfoDTO); 30 | } 31 | 32 | @Override 33 | public boolean checkUserInvokeAuth(Long userId, Long interfaceId) { 34 | return userInterfaceInfoService.checkUserInvokeAuth(userId, interfaceId); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/service/impl/inner/InnerUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service.impl.inner; 2 | 3 | import cn.hutool.core.exceptions.ValidateException; 4 | import cn.hutool.json.JSONObject; 5 | import cn.hutool.json.JSONUtil; 6 | import cn.hutool.jwt.JWT; 7 | import cn.hutool.jwt.JWTPayload; 8 | import cn.hutool.jwt.JWTUtil; 9 | import cn.hutool.jwt.JWTValidator; 10 | import cn.hutool.jwt.signers.JWTSignerUtil; 11 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 12 | import com.niuma.binapi.mapper.UserMapper; 13 | import com.niuma.binapi.service.UserService; 14 | import com.niuma.binapicommon.common.ErrorCode; 15 | import com.niuma.binapicommon.exception.BusinessException; 16 | import com.niuma.binapicommon.model.entity.User; 17 | import com.niuma.binapicommon.model.vo.UserVO; 18 | import com.niuma.binapicommon.service.InnerUserService; 19 | import org.apache.commons.lang3.StringUtils; 20 | import org.apache.dubbo.config.annotation.DubboService; 21 | 22 | import javax.annotation.Resource; 23 | 24 | import static com.niuma.binapicommon.constant.CookieConstant.COOKIE_KEY; 25 | import static com.niuma.binapicommon.constant.CookieConstant.COOKIE_USER_KEY; 26 | 27 | 28 | /** 29 | * @author niuma 30 | * @create 2023-02-27 16:13 31 | */ 32 | @DubboService 33 | public class InnerUserServiceImpl implements InnerUserService { 34 | 35 | @Resource 36 | UserMapper userMapper; 37 | @Resource 38 | UserService userService; 39 | 40 | @Override 41 | public User getInvokeUser(String ak) { 42 | if (StringUtils.isAnyBlank(ak)) { 43 | throw new BusinessException(ErrorCode.PARAMS_ERROR); 44 | } 45 | QueryWrapper queryWrapper = new QueryWrapper<>(); 46 | queryWrapper.eq("accessKey", ak); 47 | User user = userMapper.selectOne(queryWrapper); 48 | 49 | return user; 50 | } 51 | 52 | @Override 53 | public UserVO getLoginUser(String cookie) { 54 | return userService.getLoginUser(cookie); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/utils/OssConstantPropertiesUtil.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.utils; 2 | 3 | import org.springframework.beans.factory.InitializingBean; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.stereotype.Component; 6 | 7 | //常量类,读取配置文件application中的配置 8 | @Component 9 | public class OssConstantPropertiesUtil implements InitializingBean { 10 | 11 | @Value("${aliyun.oss.file.endpoint}") 12 | private String endpoint; 13 | 14 | @Value("${aliyun.oss.file.keyid}") 15 | private String keyid; 16 | 17 | @Value("${aliyun.oss.file.keysecret}") 18 | private String keysecret; 19 | 20 | @Value("${aliyun.oss.file.bucketname}") 21 | private String bucketname; 22 | 23 | public static String END_POINT; 24 | public static String KEY_ID; 25 | public static String KEY_SECRET; 26 | public static String BUCKET_NAME; 27 | 28 | 29 | @Override 30 | public void afterPropertiesSet() throws Exception { 31 | KEY_ID=this.keyid; 32 | KEY_SECRET=this.keysecret; 33 | END_POINT=this.endpoint; 34 | BUCKET_NAME=this.bucketname; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /binapi-backend/src/main/java/com/niuma/binapi/utils/SmsUtils.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.utils; 2 | 3 | import com.niuma.binapi.common.RedisTokenBucket; 4 | import com.niuma.binapicommon.constant.RedisConstant; 5 | import com.niuma.binapicommon.model.dto.SmsDTO; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.springframework.data.redis.core.RedisTemplate; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.annotation.Resource; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | /** 15 | * @author niuma 16 | * @create 2023-04-28 22:18 17 | */ 18 | @Component 19 | @Slf4j 20 | public class SmsUtils { 21 | @Resource 22 | private RedisTemplate redisTemplate; 23 | @Resource 24 | private RedisTokenBucket redisTokenBucket; 25 | @Resource 26 | private SmsRabbitMqUtils rabbitMqUtils; 27 | 28 | public boolean sendSms(SmsDTO smsDTO) { 29 | // 从令牌桶中取得令牌,未取得不允许发送短信 30 | boolean acquire = redisTokenBucket.tryAcquire(smsDTO.getPhoneNum()); 31 | if (!acquire) { 32 | log.info("phoneNum:{},send SMS frequent", smsDTO.getPhoneNum()); 33 | return false; 34 | } 35 | log.info("发送短信:{}",smsDTO); 36 | String phoneNum = smsDTO.getPhoneNum(); 37 | String code = smsDTO.getCode(); 38 | 39 | // 将手机号对应的验证码存入Redis,方便后续检验 40 | redisTemplate.opsForValue().set(RedisConstant.SMS_CODE_PREFIX + phoneNum, String.valueOf(code), 5, TimeUnit.MINUTES); 41 | 42 | // 利用消息队列,异步发送短信 43 | rabbitMqUtils.sendSmsAsync(smsDTO); 44 | return true; 45 | } 46 | 47 | public boolean verifyCode(String phoneNum, String code) { 48 | String key = RedisConstant.SMS_CODE_PREFIX + phoneNum; 49 | String checkCode = redisTemplate.opsForValue().get(key); 50 | if (StringUtils.isNotBlank(code) && code.equals(checkCode)) { 51 | redisTemplate.delete(key); 52 | return true; 53 | } 54 | return false; 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | #spring: 2 | # profiles: 3 | # active: dev 4 | # application: 5 | # name: binapi-backend 6 | # cloud: 7 | # nacos: 8 | # discovery: 9 | # server-addr: localhost:8848 10 | # # DataSource Config 11 | # datasource: 12 | # driver-class-name: com.mysql.cj.jdbc.Driver 13 | # url: jdbc:mysql://localhost:3306/binapi 14 | # username: root 15 | # password: 123456 16 | # mvc: 17 | # pathmatch: 18 | # matching-strategy: ANT_PATH_MATCHER 19 | # # session 失效时间(分钟) 20 | # session: 21 | # timeout: 86400 22 | # store-type: redis 23 | # # redis 配置 24 | # redis: 25 | # port: 6379 26 | # host: localhost 27 | # database: 0 28 | # rabbitmq: 29 | # host: localhost 30 | # port: 5672 31 | # publisher-confirm-type: correlated #开启发送端确认 32 | # publisher-returns: true #开启发送端消息抵达队列的确认 33 | # template: 34 | # mandatory: true #只要抵达队列,以异步发送优先回调我们这个returnsConfirm 35 | #server: 36 | # port: 8080 37 | # servlet: 38 | # context-path: /api 39 | #mybatis-plus: 40 | # configuration: 41 | # map-underscore-to-camel-case: false 42 | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 43 | # global-config: 44 | # db-config: 45 | # logic-delete-field: isDelete # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) 46 | # logic-delete-value: 1 # 逻辑已删除值(默认为 1) 47 | # logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) 48 | # 49 | #aliyun: 50 | # oss: 51 | # file: 52 | # endpoint: xxxxxxxxxx 53 | # keyid: xxxxxxxxxxxxxx 54 | # keysecret: xxxxxxxxxxxxxx 55 | # bucketname: xxxxxxxxxxxxxx 56 | # 57 | #dubbo: 58 | # application: 59 | # name: binapi-backend-dubbo 60 | # protocol: 61 | # name: dubbo 62 | # port: -1 63 | # registry: 64 | # address: nacos://localhost:8848 65 | # parameters: 66 | # namespace: 16239c21-ac42-46bc-a4e7-690e64272f5a 67 | # check: false 68 | # consumer: 69 | # check: false 70 | -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | 我的项目 -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/binapi-client-sdk-0.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishuaige/binapi/e03ee4c651494791a7c7674f04416e0942838f35/binapi-backend/src/main/resources/binapi-client-sdk-0.0.1.jar -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | application: 5 | name: binapi-backend 6 | cloud: 7 | nacos: 8 | discovery: 9 | server-addr: localhost:8848 10 | config: 11 | file-extension: yaml 12 | namespace: 1ce6c2fb-611e-4d1e-834d-567340760462 13 | shared-configs[0]: 14 | dataId: db.yaml 15 | refresh: true 16 | shared-configs[1]: 17 | dataId: rabbitmq.yaml 18 | refresh: true 19 | shared-configs[2]: 20 | dataId: dubbo.yaml 21 | refresh: true 22 | shared-configs[3]: 23 | dataId: sentinel-dev.yaml 24 | refresh: true 25 | -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/mapper/InterfaceAuditMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | id,interfaceId,approverId,remark,auditStatus, 21 | createTime,updateTime,isDeleted 22 | 23 | 24 | -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/mapper/InterfaceChargingMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | id,interfaceId,charging, 20 | availablePieces,userId,createTime, 21 | updateTime,isDelete 22 | 23 | 24 | -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/mapper/InterfaceInfoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | id,name,methodName,description, 27 | url,requestHeader,responseHeader, 28 | status,method,userId,requestParams, 29 | createTime,updateTime,isDelete,isCharging 30 | 31 | 32 | -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/mapper/UserInterfaceInfoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | id,userId,interfaceInfoId, 21 | totalNum,leftNum,status, 22 | createTime,updateTime,isDelete 23 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /binapi-backend/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | id 24 | ,userName,userAccount, 25 | userAvatar,gender,userRole,,accessKey,secretKey, 26 | userPassword,createTime,updateTime, 27 | isDelete 28 | 29 | 30 | -------------------------------------------------------------------------------- /binapi-backend/src/test/java/com/niuma/binapi/service/BinApiClientTest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service; 2 | 3 | import com.niuma.binapiclientsdk.client.BinApiClient; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | /** 8 | * @author niuma 9 | * @create 2023-03-28 16:25 10 | */ 11 | @SpringBootTest 12 | public class BinApiClientTest { 13 | 14 | @Test 15 | public void testRenjian(){ 16 | BinApiClient binApiClient = new BinApiClient("niuma","asdfg"); 17 | String renjian = binApiClient.renjian(); 18 | System.out.println(renjian); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /binapi-backend/src/test/java/com/niuma/binapi/service/CrawlerTest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service; 2 | 3 | 4 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 5 | import org.jsoup.Jsoup; 6 | import org.jsoup.nodes.Document; 7 | import org.jsoup.nodes.Element; 8 | import org.jsoup.select.Elements; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * @author niuma 17 | * @create 2023-03-17 9:17 18 | */ 19 | @SpringBootTest 20 | public class CrawlerTest { 21 | 22 | 23 | public static void main(String[] args) throws IOException { 24 | testFetchPicture(); 25 | } 26 | 27 | 28 | public static void testFetchPicture() throws IOException { 29 | String keyword = "图片"; 30 | String url = String.format("https://api.aa1.cn/v1/apilist?search=%s", keyword); 31 | Document doc = Jsoup.connect(url).get(); 32 | Elements elements = doc.select(".flink-list-item"); 33 | List interfaceInfoList = new ArrayList<>(); 34 | for (Element element : elements) { 35 | // 取url 36 | String href = element.select(".cf-friends-link").attr("href"); 37 | Elements infoEle = element.select(".flink-item-info"); 38 | String name = infoEle.select(".flink-item-name").text(); 39 | String desc = infoEle.select(".flink-item-desc").text();; 40 | String interfaceDocUrl = "https://api.aa1.cn/doc" + href; 41 | 42 | InterfaceInfo interfaceInfo = new InterfaceInfo(); 43 | interfaceInfo.setName(name); 44 | interfaceInfo.setDescription(desc); 45 | interfaceInfo.setUrl(interfaceDocUrl); 46 | interfaceInfoList.add(interfaceInfo); 47 | 48 | } 49 | System.out.println(interfaceInfoList); 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /binapi-backend/src/test/java/com/niuma/binapi/service/JwtTest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service; 2 | 3 | import cn.hutool.core.date.DateUtil; 4 | import cn.hutool.jwt.JWT; 5 | import cn.hutool.jwt.JWTUtil; 6 | import cn.hutool.jwt.signers.JWTSignerUtil; 7 | import org.junit.jupiter.api.Test; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | import java.util.Date; 11 | import java.util.HashMap; 12 | 13 | /** 14 | * @author niuma 15 | * @create 2023-05-03 23:07 16 | */ 17 | @SpringBootTest 18 | public class JwtTest { 19 | @Test 20 | public void testJwt() { 21 | String token = JWTUtil.createToken(new HashMap() {{ 22 | put("name", "jj"); 23 | }}, JWTSignerUtil.hs256("niuma".getBytes())); 24 | String sign = JWT.create() 25 | .addPayloads(new HashMap() {{ 26 | put("name", "jj"); 27 | }}) 28 | .setSigner(JWTSignerUtil.hs256("niuma".getBytes())) 29 | .setExpiresAt(DateUtil.offsetHour(new Date(), 3)).sign(); 30 | System.out.println(token); 31 | JWT jwt = JWTUtil.parseToken(token); 32 | JWT jwt1 = JWTUtil.parseToken(sign); 33 | System.out.println(jwt); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /binapi-backend/src/test/java/com/niuma/binapi/service/UserServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service; 2 | 3 | import com.niuma.binapicommon.model.entity.User; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.util.DigestUtils; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * 用户服务测试 13 | * 14 | * @author niuma 15 | */ 16 | @SpringBootTest 17 | class UserServiceTest { 18 | 19 | @Resource 20 | private UserService userService; 21 | 22 | 23 | @Test 24 | void userRegister() { 25 | // 注册一个用户,无需手机验证码 26 | String password = DigestUtils.md5DigestAsHex(("dogbin" + "12345678").getBytes()); 27 | User user = new User(); 28 | user.setUserName("dogbin"); 29 | user.setUserAccount("dogbin"); 30 | user.setGender(0); 31 | user.setUserRole("admin"); 32 | user.setUserPassword(password); 33 | user.setPhoneNum("13623123123"); 34 | user.setAccessKey("aaaaa"); 35 | user.setSecretKey("bbbbb"); 36 | boolean save = userService.save(user); 37 | System.out.println(save); 38 | } 39 | 40 | @Test 41 | void testAddUser() { 42 | User user = new User(); 43 | boolean result = userService.save(user); 44 | System.out.println(user.getId()); 45 | Assertions.assertTrue(result); 46 | } 47 | 48 | @Test 49 | void testUpdateUser() { 50 | User user = new User(); 51 | boolean result = userService.updateById(user); 52 | Assertions.assertTrue(result); 53 | } 54 | 55 | @Test 56 | void testDeleteUser() { 57 | boolean result = userService.removeById(1L); 58 | Assertions.assertTrue(result); 59 | } 60 | 61 | @Test 62 | void testGetUser() { 63 | User user = userService.getById(1L); 64 | Assertions.assertNotNull(user); 65 | } 66 | 67 | 68 | } -------------------------------------------------------------------------------- /binapi-backend/src/test/java/com/niuma/binapi/service/impl/InterfaceInfoServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service.impl; 2 | 3 | import com.niuma.binapi.service.InterfaceInfoService; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import javax.annotation.Resource; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | /** 12 | * @author niumazlb 13 | * @create 2022-11-16 14:09 14 | */ 15 | @SpringBootTest 16 | class InterfaceInfoServiceImplTest { 17 | 18 | @Resource 19 | InterfaceInfoService interfaceInfoService; 20 | @Test 21 | void shangxianjiekou() { 22 | 23 | Boolean shangxianjiekou = interfaceInfoService.onlineInterfaceInfo(22); 24 | System.out.println(shangxianjiekou); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /binapi-backend/src/test/java/com/niuma/binapi/service/inner/InnerUserInterfaceInfoServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapi.service.inner; 2 | 3 | import com.niuma.binapicommon.service.InnerUserInterfaceInfoService; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * @author niumazlb 11 | * @create 2022-11-16 14:09 12 | */ 13 | @SpringBootTest 14 | class InnerUserInterfaceInfoServiceImplTest { 15 | 16 | @Resource 17 | InnerUserInterfaceInfoService userInterfaceInfoService; 18 | @Test 19 | void shangxianjiekou() { 20 | 21 | Boolean shangxianjiekou = userInterfaceInfoService.invokeCount(1l,1l); 22 | System.out.println(shangxianjiekou); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /binapi-client-sdk/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /binapi-client-sdk/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.5 9 | 10 | 11 | com.niuma 12 | binapi-client-sdk 13 | 0.0.1 14 | binapi-client-sdk 15 | binapi-client-sdk 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-configuration-processor 28 | true 29 | 30 | 31 | org.projectlombok 32 | lombok 33 | true 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | cn.hutool 42 | hutool-all 43 | 5.8.9 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /binapi-client-sdk/src/main/java/com/niuma/binapiclientsdk/BinApiClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiclientsdk; 2 | 3 | import com.niuma.binapiclientsdk.client.BinApiClient; 4 | import lombok.Data; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.ComponentScan; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * @author niumazlb 12 | * @create 2022-11-09 20:38 13 | */ 14 | @Configuration 15 | @ConfigurationProperties("binapi-client") 16 | @Data 17 | @ComponentScan 18 | public class BinApiClientConfig { 19 | 20 | 21 | private String accessKey; 22 | private String secretKey; 23 | 24 | @Bean 25 | public BinApiClient binApiClient(){ 26 | BinApiClient binApiClient = new BinApiClient(accessKey,secretKey); 27 | return binApiClient; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /binapi-client-sdk/src/main/java/com/niuma/binapiclientsdk/client/BinApiClient.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiclientsdk.client; 2 | 3 | import cn.hutool.core.util.RandomUtil; 4 | import cn.hutool.http.HttpRequest; 5 | import cn.hutool.json.JSONUtil; 6 | import com.niuma.binapiclientsdk.model.User; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | import static com.niuma.binapiclientsdk.util.SignUtil.genSign; 12 | 13 | 14 | /** 15 | * @author niumazlb 16 | * @create 2022-11-09 15:06 17 | */ 18 | public class BinApiClient { 19 | 20 | private String accessKey; 21 | private String secretKey; 22 | private static final String GATEWAY_HOST ="http://localhost:8002"; 23 | 24 | public BinApiClient(String accessKey, String secretKey) { 25 | this.accessKey = accessKey; 26 | this.secretKey = secretKey; 27 | } 28 | 29 | private Map getHeaderMap(String body) { 30 | HashMap hashMap = new HashMap<>(); 31 | hashMap.put("accessKey", accessKey); 32 | // hashMap.put("secretKey",secretKey); 33 | hashMap.put("nonce", RandomUtil.randomNumbers(4)); 34 | hashMap.put("body", body); 35 | hashMap.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000)); 36 | hashMap.put("sign", genSign(body, secretKey)); 37 | return hashMap; 38 | } 39 | 40 | public String getUserByPost(User user) { 41 | String json = JSONUtil.toJsonStr(user); 42 | String result2 = HttpRequest.post(GATEWAY_HOST +"/api/interface/user") 43 | .addHeaders(getHeaderMap(json)) 44 | .body(json) 45 | .execute().body(); 46 | return result2; 47 | } 48 | 49 | public String renjian() { 50 | String result2 = HttpRequest.get(GATEWAY_HOST +"/api/interface/renjian") 51 | .addHeaders(getHeaderMap("")) 52 | .execute().body(); 53 | return result2; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /binapi-client-sdk/src/main/java/com/niuma/binapiclientsdk/model/User.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiclientsdk.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author niumazlb 7 | * @create 2022-11-09 10:58 8 | */ 9 | @Data 10 | public class User { 11 | private String username; 12 | } 13 | -------------------------------------------------------------------------------- /binapi-client-sdk/src/main/java/com/niuma/binapiclientsdk/util/SignUtil.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiclientsdk.util; 2 | 3 | import cn.hutool.crypto.digest.DigestAlgorithm; 4 | import cn.hutool.crypto.digest.Digester; 5 | 6 | /** 7 | * @author niumazlb 8 | * @create 2022-11-09 16:03 9 | */ 10 | public class SignUtil { 11 | public static String genSign(String body, String secretKey) { 12 | Digester digester = new Digester(DigestAlgorithm.SHA256); 13 | String content = body + "." + secretKey; 14 | return digester.digestHex(content); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /binapi-client-sdk/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.niuma.binapiclientsdk.BinApiClientConfig -------------------------------------------------------------------------------- /binapi-client-sdk/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /binapi-common/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/common/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.common; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 通用返回类 9 | * 10 | * @param 11 | * @author niuma 12 | */ 13 | @Data 14 | public class BaseResponse implements Serializable { 15 | 16 | private int code; 17 | 18 | private T data; 19 | 20 | private String message; 21 | 22 | public BaseResponse(int code, T data, String message) { 23 | this.code = code; 24 | this.data = data; 25 | this.message = message; 26 | } 27 | 28 | public BaseResponse(int code, T data) { 29 | this(code, data, ""); 30 | } 31 | 32 | public BaseResponse(ErrorCode errorCode) { 33 | this(errorCode.getCode(), null, errorCode.getMessage()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/common/DeleteRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.common; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 删除请求 9 | * 10 | * @author niuma 11 | */ 12 | @Data 13 | public class DeleteRequest implements Serializable { 14 | /** 15 | * id 16 | */ 17 | private Long id; 18 | 19 | private static final long serialVersionUID = 1L; 20 | } -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/common/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.common; 2 | 3 | /** 4 | * 错误码 5 | * 6 | * @author niuma 7 | */ 8 | public enum ErrorCode { 9 | 10 | SUCCESS(0, "ok"), 11 | PARAMS_ERROR(40000, "请求参数错误"), 12 | NOT_LOGIN_ERROR(40100, "未登录"), 13 | NO_AUTH_ERROR(40101, "无权限"), 14 | FORBIDDEN_ERROR(40300, "禁止访问"), 15 | NOT_FOUND_ERROR(40400, "请求数据不存在"), 16 | SYSTEM_ERROR(50000, "系统内部异常"), 17 | OPERATION_ERROR(50001, "操作失败"); 18 | 19 | /** 20 | * 状态码 21 | */ 22 | private final int code; 23 | 24 | /** 25 | * 信息 26 | */ 27 | private final String message; 28 | 29 | ErrorCode(int code, String message) { 30 | this.code = code; 31 | this.message = message; 32 | } 33 | 34 | public int getCode() { 35 | return code; 36 | } 37 | 38 | public String getMessage() { 39 | return message; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/common/IdRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.common; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 9 | * @author niuma 10 | */ 11 | @Data 12 | public class IdRequest implements Serializable { 13 | /** 14 | * id 15 | */ 16 | private Long id; 17 | 18 | private static final long serialVersionUID = 1L; 19 | } -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/common/PageRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.common; 2 | 3 | import com.niuma.binapicommon.constant.CommonConstant; 4 | import lombok.Data; 5 | 6 | /** 7 | * 分页请求 8 | * 9 | * @author niuma 10 | */ 11 | @Data 12 | public class PageRequest { 13 | 14 | /** 15 | * 当前页号 16 | */ 17 | private long current = 1; 18 | 19 | /** 20 | * 页面大小 21 | */ 22 | private long pageSize = 10; 23 | 24 | /** 25 | * 排序字段 26 | */ 27 | private String sortField; 28 | 29 | /** 30 | * 排序顺序(默认升序) 31 | */ 32 | private String sortOrder = CommonConstant.SORT_ORDER_ASC; 33 | } 34 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/common/ResultUtils.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.common; 2 | 3 | /** 4 | * 返回工具类 5 | * 6 | * @author niuma 7 | */ 8 | public class ResultUtils { 9 | 10 | /** 11 | * 成功 12 | * 13 | * @param data 14 | * @param 15 | * @return 16 | */ 17 | public static BaseResponse success(T data) { 18 | return new BaseResponse<>(0, data, "ok"); 19 | } 20 | 21 | /** 22 | * 失败 23 | * 24 | * @param errorCode 25 | * @return 26 | */ 27 | public static BaseResponse error(ErrorCode errorCode) { 28 | return new BaseResponse<>(errorCode); 29 | } 30 | 31 | /** 32 | * 失败 33 | * 34 | * @param code 35 | * @param message 36 | * @return 37 | */ 38 | public static BaseResponse error(int code, String message) { 39 | return new BaseResponse(code, null, message); 40 | } 41 | 42 | /** 43 | * 失败 44 | * 45 | * @param errorCode 46 | * @return 47 | */ 48 | public static BaseResponse error(ErrorCode errorCode, String message) { 49 | return new BaseResponse(errorCode.getCode(), null, message); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/constant/CommonConstant.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.constant; 2 | 3 | /** 4 | * 通用常量 5 | * 6 | * @author niuma 7 | */ 8 | public interface CommonConstant { 9 | 10 | /** 11 | * 升序 12 | */ 13 | String SORT_ORDER_ASC = "ascend"; 14 | 15 | /** 16 | * 降序 17 | */ 18 | String SORT_ORDER_DESC = " descend"; 19 | } 20 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/constant/CookieConstant.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.constant; 2 | 3 | /** 4 | * @author niuma 5 | * @create 2023-05-04 10:35 6 | */ 7 | public interface CookieConstant { 8 | String COOKIE_KEY = "cookie"; 9 | String COOKIE_USER_KEY = "user"; 10 | } 11 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/constant/LockConstant.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.constant; 2 | 3 | /** 4 | * @author niuma 5 | * @create 2023-05-04 16:33 6 | */ 7 | public interface LockConstant { 8 | String ORDER_SEND_FAILED = "order-send-failed"; 9 | String ORDER_PAY_SUCCESS = "order-pay-success"; 10 | } 11 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/constant/RabbitMqConstant.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.constant; 2 | 3 | /** 4 | * @author niuma 5 | * @create 2023-04-28 21:30 6 | */ 7 | public interface RabbitMqConstant { 8 | /* 短信相关 */ 9 | 10 | String SMS_EXCHANGE_TOPIC_NAME = "sms.exchange.topic"; 11 | String SMS_QUEUE_NAME = "sms.queue"; 12 | String SMS_EXCHANGE_ROUTING_KEY = "sms.send"; 13 | 14 | String SMS_DELAY_QUEUE_NAME = "sms.delay.queue"; 15 | String SMS_DELAY_EXCHANGE_ROUTING_KEY = "sms.release"; 16 | 17 | 18 | /* 订单相关 */ 19 | 20 | String ORDER_EXCHANGE_TOPIC_NAME = "order.exchange.topic"; 21 | 22 | String ORDER_SEND_QUEUE_NAME = "order.send.queue"; 23 | String ORDER_SEND_EXCHANGE_ROUTING_KEY = "order.send"; 24 | 25 | String ORDER_SUCCESS_QUEUE_NAME = "order.pay.success.queue"; 26 | String ORDER_SUCCESS_EXCHANGE_ROUTING_KEY = "order.pay.success"; 27 | 28 | String ORDER_TIMEOUT_QUEUE_NAME = "order.timeout.queue"; 29 | String ORDER_TIMEOUT_EXCHANGE_ROUTING_KEY = "order.timeout"; 30 | } 31 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/constant/RedisConstant.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.constant; 2 | 3 | /** 4 | * @author niuma 5 | * @create 2023-04-28 22:05 6 | */ 7 | public interface RedisConstant { 8 | String SMS_PREFIX = "sms:"; 9 | String SMS_BUCKET_PREFIX = SMS_PREFIX + "bucket:"; 10 | String SMS_CODE_PREFIX = SMS_PREFIX + "code:"; 11 | String SMS_MESSAGE_PREFIX = SMS_PREFIX + "mq:messageId:"; 12 | String MQ_PRODUCER = SMS_PREFIX + "mq:producer:fail"; 13 | 14 | String SEND_ORDER_PREFIX = "order:sendOrderNumInfo:"; 15 | String ORDER_PAY_SUCCESS_INFO = "order:paySuccess:"; 16 | String ORDER_PAY_RABBITMQ = "order:pay:rabbitMq:"; 17 | String ALIPAY_TRADE_INFO = "alipay:tradeInfo:"; 18 | } 19 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/constant/UserConstant.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.constant; 2 | 3 | /** 4 | * 用户常量 5 | * 6 | * @author niuma 7 | */ 8 | public interface UserConstant { 9 | 10 | /** 11 | * 用户登录态键 12 | */ 13 | String USER_LOGIN_STATE = "userLoginState"; 14 | 15 | /** 16 | * 系统用户 id(虚拟用户) 17 | */ 18 | long SYSTEM_USER_ID = 0; 19 | 20 | // region 权限 21 | 22 | /** 23 | * 默认权限 24 | */ 25 | String DEFAULT_ROLE = "user"; 26 | 27 | /** 28 | * 管理员权限 29 | */ 30 | String ADMIN_ROLE = "admin"; 31 | 32 | // endregion 33 | 34 | int USERACCOUNT_MINLENGTH = 4; 35 | int USERACCOUNT_MAXLENGTH = 13; 36 | int USERNAME_LENGTH = 7; 37 | 38 | int USERPASSWORD_LENGTH = 8; 39 | } 40 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/exception/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.exception; 2 | 3 | 4 | import com.niuma.binapicommon.common.ErrorCode; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * 自定义异常类 10 | * 11 | * @author niuma 12 | */ 13 | public class BusinessException extends RuntimeException implements Serializable { 14 | 15 | private final int code; 16 | 17 | public BusinessException(int code, String message) { 18 | super(message); 19 | this.code = code; 20 | } 21 | 22 | public BusinessException(ErrorCode errorCode) { 23 | super(errorCode.getMessage()); 24 | this.code = errorCode.getCode(); 25 | } 26 | 27 | public BusinessException(ErrorCode errorCode, String message) { 28 | super(message); 29 | this.code = errorCode.getCode(); 30 | } 31 | 32 | public int getCode() { 33 | return code; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.exception; 2 | 3 | import com.niuma.binapicommon.common.BaseResponse; 4 | import com.niuma.binapicommon.common.ErrorCode; 5 | import com.niuma.binapicommon.common.ResultUtils; 6 | import com.niuma.binapicommon.exception.BusinessException; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestControllerAdvice; 10 | 11 | /** 12 | * 全局异常处理器 13 | * 14 | * @author niuma 15 | */ 16 | @RestControllerAdvice 17 | @Slf4j 18 | public class GlobalExceptionHandler { 19 | 20 | @ExceptionHandler(BusinessException.class) 21 | public BaseResponse businessExceptionHandler(BusinessException e) { 22 | log.error("businessException: " + e.getMessage(), e); 23 | return ResultUtils.error(e.getCode(), e.getMessage()); 24 | } 25 | 26 | @ExceptionHandler(RuntimeException.class) 27 | public BaseResponse runtimeExceptionHandler(RuntimeException e) { 28 | log.error("runtimeException", e); 29 | return ResultUtils.error(ErrorCode.SYSTEM_ERROR, e.getMessage()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/dto/SmsDTO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * 短信服务传输对象 10 | * @author niuma 11 | * @create 2023-04-28 21:16 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | public class SmsDTO implements Serializable { 16 | 17 | private static final long serialVersionUID = 8504215015474691352L; 18 | String phoneNum; 19 | 20 | String code; 21 | } 22 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/dto/UnLockAvailablePiecesDTO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author niuma 9 | * @create 2023-05-04 13:49 10 | */ 11 | @Data 12 | public class UnLockAvailablePiecesDTO implements Serializable { 13 | private static final long serialVersionUID = 1354230288973784689L; 14 | 15 | /** 16 | * 计费ID 17 | */ 18 | private Long interfaceId; 19 | 20 | /** 21 | * 锁定次数 22 | */ 23 | private Long count; 24 | } 25 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/dto/UpdateAvailablePiecesDTO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author niuma 9 | * @create 2023-05-04 13:49 10 | */ 11 | @Data 12 | public class UpdateAvailablePiecesDTO implements Serializable { 13 | private static final long serialVersionUID = 1354230288973784689L; 14 | 15 | /** 16 | * 计费ID 17 | */ 18 | private Long chargingId; 19 | 20 | /** 21 | * 锁定次数 22 | */ 23 | private Long count; 24 | } 25 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/dto/UpdateUserInterfaceInfoDTO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 9 | * @author niuma 10 | * @create 2023-05-06 13:46 11 | */ 12 | @Data 13 | public class UpdateUserInterfaceInfoDTO implements Serializable { 14 | 15 | private static final long serialVersionUID = 1472097902521779075L; 16 | 17 | private Long userId; 18 | 19 | private Long interfaceId; 20 | 21 | private Long lockNum; 22 | } 23 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/entity/InterfaceInfo.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * 接口信息 11 | * @TableName interface_info 12 | */ 13 | @TableName(value ="interface_info") 14 | @Data 15 | public class InterfaceInfo implements Serializable { 16 | /** 17 | * 主键 18 | */ 19 | @TableId(type = IdType.AUTO) 20 | private Long id; 21 | 22 | /** 23 | * 名称 24 | */ 25 | private String name; 26 | 27 | /** 28 | * SDK中的方法名 29 | */ 30 | private String methodName; 31 | 32 | /** 33 | * 描述 34 | */ 35 | private String description; 36 | 37 | /** 38 | * 接口地址 39 | */ 40 | private String url; 41 | 42 | /** 43 | * 请求参数 44 | */ 45 | private String requestParams; 46 | 47 | /** 48 | * 请求头 49 | */ 50 | private String requestHeader; 51 | 52 | /** 53 | * 响应头 54 | */ 55 | private String responseHeader; 56 | 57 | /** 58 | * 接口状态(0-关闭,1-开启) 59 | */ 60 | private Integer status; 61 | 62 | /** 63 | * 请求类型 64 | */ 65 | private String method; 66 | 67 | /** 68 | * 创建人 69 | */ 70 | private Long userId; 71 | 72 | /** 73 | * 创建时间 74 | */ 75 | private Date createTime; 76 | 77 | /** 78 | * 更新时间 79 | */ 80 | private Date updateTime; 81 | 82 | /** 83 | * 是否删除(0-未删除,1-已删除) 84 | */ 85 | @TableLogic 86 | private Integer isDelete; 87 | /** 88 | * 是否收费(0-否,1-是) 89 | */ 90 | private Integer isCharging; 91 | 92 | @TableField(exist = false) 93 | private static final long serialVersionUID = 1L; 94 | } -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/entity/Order.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | import com.fasterxml.jackson.annotation.JsonFormat; 10 | import lombok.Data; 11 | 12 | /** 13 | * 14 | * @TableName order 15 | */ 16 | @TableName(value ="api_order") 17 | @Data 18 | public class Order implements Serializable { 19 | /** 20 | * 主键 21 | */ 22 | @TableId 23 | private Long id; 24 | 25 | /** 26 | * 接口id 27 | */ 28 | private Long interfaceId; 29 | 30 | /** 31 | * 用户id 32 | */ 33 | private Long userId; 34 | 35 | /** 36 | * 订单号 37 | */ 38 | private String orderNumber; 39 | 40 | /** 41 | * 购买数量 42 | */ 43 | private Long total; 44 | 45 | /** 46 | * 单价 47 | */ 48 | private Double charging; 49 | 50 | /** 51 | * 交易金额 52 | */ 53 | private Double totalAmount; 54 | 55 | /** 56 | * 交易状态【0->待付款;1->已完成;2->无效订单】 57 | */ 58 | private Integer status; 59 | 60 | /** 61 | * 创建时间 62 | */ 63 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 64 | private Date createTime; 65 | 66 | /** 67 | * 更新时间 68 | */ 69 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 70 | private Date updateTime; 71 | 72 | /** 73 | * 是否删除(0-未删, 1-已删) 74 | */ 75 | private Integer isDelete; 76 | @TableField(exist = false) 77 | private static final long serialVersionUID = 4594019187390533308L; 78 | } -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | import java.util.Date; 9 | 10 | /** 11 | * 用户 12 | * 13 | * @TableName user 14 | */ 15 | @TableName(value = "user") 16 | @Data 17 | public class User implements Serializable { 18 | /** 19 | * id 20 | */ 21 | @TableId(type = IdType.AUTO) 22 | private Long id; 23 | 24 | /** 25 | * 用户昵称 26 | */ 27 | private String userName; 28 | 29 | /** 30 | * 账号 31 | */ 32 | private String userAccount; 33 | 34 | /** 35 | * 用户头像 36 | */ 37 | private String userAvatar; 38 | 39 | /** 40 | * 性别 41 | */ 42 | private Integer gender; 43 | 44 | /** 45 | * 用户角色: user, admin 46 | */ 47 | private String userRole; 48 | 49 | /** 50 | * 密码 51 | */ 52 | private String userPassword; 53 | /** 54 | * 密码 55 | */ 56 | private String phoneNum; 57 | /** 58 | * accessKey 59 | */ 60 | private String accessKey; 61 | /** 62 | * secretKey 63 | */ 64 | private String secretKey; 65 | 66 | /** 67 | * 创建时间 68 | */ 69 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 70 | private Date createTime; 71 | 72 | /** 73 | * 更新时间 74 | */ 75 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 76 | private Date updateTime; 77 | 78 | /** 79 | * 是否删除 80 | */ 81 | @TableLogic 82 | private Integer isDelete; 83 | 84 | @TableField(exist = false) 85 | private static final long serialVersionUID = 1L; 86 | } -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/entity/UserInterfaceInfo.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * 用户调用接口关系 11 | * @TableName user_interface_info 12 | */ 13 | @TableName(value ="user_interface_info") 14 | @Data 15 | public class UserInterfaceInfo implements Serializable { 16 | /** 17 | * 主键 18 | */ 19 | @TableId(type = IdType.AUTO) 20 | private Long id; 21 | 22 | /** 23 | * 调用者 id 24 | */ 25 | private Long userId; 26 | 27 | /** 28 | * 接口 id 29 | */ 30 | private Long interfaceInfoId; 31 | 32 | /** 33 | * 已调用次数 34 | */ 35 | private Integer totalNum; 36 | 37 | /** 38 | * 剩余调用次数 39 | */ 40 | private Integer leftNum; 41 | 42 | /** 43 | * 0-正常,1-禁用) 44 | */ 45 | private Integer status; 46 | 47 | /** 48 | * 创建时间 49 | */ 50 | private Date createTime; 51 | 52 | /** 53 | * 更新时间 54 | */ 55 | private Date updateTime; 56 | 57 | /** 58 | * 是否删除(0-未删除,1-已删除) 59 | */ 60 | @TableLogic 61 | private Integer isDelete; 62 | 63 | @TableField(exist = false) 64 | private static final long serialVersionUID = 1L; 65 | } -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/enums/InterfaceInfoStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * 接口状态枚举 9 | * 10 | * @author niuma 11 | */ 12 | public enum InterfaceInfoStatusEnum { 13 | 14 | OFFLINE("关闭", 0), 15 | ONLINE("上线", 1); 16 | 17 | private final String text; 18 | 19 | private final int value; 20 | 21 | InterfaceInfoStatusEnum(String text, int value) { 22 | this.text = text; 23 | this.value = value; 24 | } 25 | 26 | /** 27 | * 获取值列表 28 | * 29 | * @return 30 | */ 31 | public static List getValues() { 32 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 33 | } 34 | 35 | public int getValue() { 36 | return value; 37 | } 38 | 39 | public String getText() { 40 | return text; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/enums/PostGenderEnum.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * 帖子性别枚举 9 | * 10 | * @author niuma 11 | */ 12 | public enum PostGenderEnum { 13 | 14 | MALE("男", 0), 15 | FEMALE("女", 1); 16 | 17 | private final String text; 18 | 19 | private final int value; 20 | 21 | PostGenderEnum(String text, int value) { 22 | this.text = text; 23 | this.value = value; 24 | } 25 | 26 | /** 27 | * 获取值列表 28 | * 29 | * @return 30 | */ 31 | public static List getValues() { 32 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 33 | } 34 | 35 | public int getValue() { 36 | return value; 37 | } 38 | 39 | public String getText() { 40 | return text; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/enums/PostReviewStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * 帖子审核状态枚举 9 | * 10 | * @author niuma 11 | */ 12 | public enum PostReviewStatusEnum { 13 | 14 | REVIEWING("待审核", 0), 15 | PASS("通过", 1), 16 | REJECT("拒绝", 2); 17 | 18 | private final String text; 19 | 20 | private final int value; 21 | 22 | PostReviewStatusEnum(String text, int value) { 23 | this.text = text; 24 | this.value = value; 25 | } 26 | 27 | /** 28 | * 获取值列表 29 | * 30 | * @return 31 | */ 32 | public static List getValues() { 33 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 34 | } 35 | 36 | public int getValue() { 37 | return value; 38 | } 39 | 40 | public String getText() { 41 | return text; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/vo/OrderVO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.vo; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * @author niuma 11 | * @create 2023-05-04 14:11 12 | */ 13 | @Data 14 | public class OrderVO implements Serializable { 15 | 16 | /** 17 | * 接口id 18 | */ 19 | private Long interfaceId; 20 | 21 | /** 22 | * 用户id 23 | */ 24 | private Long userId; 25 | 26 | /** 27 | * 订单号 28 | */ 29 | private String orderNumber; 30 | /** 31 | * 接口名 32 | */ 33 | private String interfaceName; 34 | 35 | /** 36 | * 接口描述 37 | */ 38 | private String interfaceDesc; 39 | 40 | /** 41 | * 购买数量 42 | */ 43 | private Long total; 44 | 45 | /** 46 | * 单价 47 | */ 48 | private Double charging; 49 | 50 | /** 51 | * 交易金额 52 | */ 53 | private Double totalAmount; 54 | 55 | /** 56 | * 交易状态【0->待付款;1->已完成;2->无效订单】 57 | */ 58 | private Integer status; 59 | 60 | /** 61 | * 创建时间 62 | */ 63 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 64 | private Date createTime; 65 | 66 | /** 67 | * 过期时间 68 | */ 69 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 70 | private Date expirationTime; 71 | 72 | private static final long serialVersionUID = 1L; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/model/vo/UserVO.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.model.vo; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * 用户视图 11 | * 12 | * @author niumazlb 13 | * @TableName user 14 | */ 15 | @Data 16 | public class UserVO implements Serializable { 17 | /** 18 | * id 19 | */ 20 | private Long id; 21 | 22 | /** 23 | * 用户昵称 24 | */ 25 | private String userName; 26 | 27 | /** 28 | * 账号 29 | */ 30 | private String userAccount; 31 | /** 32 | * 手机号 33 | */ 34 | private String phoneNum; 35 | /** 36 | * 用户头像 37 | */ 38 | private String userAvatar; 39 | 40 | /** 41 | * 性别 42 | */ 43 | private Integer gender; 44 | 45 | /** 46 | * 用户角色: user, admin 47 | */ 48 | private String userRole; 49 | 50 | /** 51 | * 创建时间 52 | */ 53 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 54 | private Date createTime; 55 | 56 | /** 57 | * 更新时间 58 | */ 59 | @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 60 | private Date updateTime; 61 | 62 | private static final long serialVersionUID = 1L; 63 | } -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/service/InnerInterfaceChargingService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.service; 2 | 3 | import com.niuma.binapicommon.model.dto.UnLockAvailablePiecesDTO; 4 | import com.niuma.binapicommon.model.dto.UpdateAvailablePiecesDTO; 5 | 6 | /** 7 | * @author niuma 8 | * @create 2023-05-03 16:22 9 | */ 10 | public interface InnerInterfaceChargingService { 11 | /** 12 | * 检查某个接口的库存是否充足 13 | * @param id 14 | * @return 15 | */ 16 | boolean checkInventory(Long id); 17 | 18 | /** 19 | * 更新某个接口的库存 20 | * @param updateAvailablePiecesDTO 21 | * @return 22 | */ 23 | boolean updateAvailablePieces(UpdateAvailablePiecesDTO updateAvailablePiecesDTO); 24 | 25 | /** 26 | * 解锁某个接口的库存 27 | * @param unLockAvailablePiecesDTO 28 | * @return 29 | */ 30 | boolean unLockAvailablePieces(UnLockAvailablePiecesDTO unLockAvailablePiecesDTO); 31 | } 32 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/service/InnerInterfaceInfoService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.service; 2 | 3 | import com.niuma.binapicommon.model.dto.UpdateUserInterfaceInfoDTO; 4 | import com.niuma.binapicommon.model.entity.InterfaceInfo; 5 | 6 | /** 7 | * @author niuma 8 | * @create 2023-02-27 15:40 9 | */ 10 | public interface InnerInterfaceInfoService { 11 | 12 | /** 13 | * 获取调用的接口信息 14 | * @param url 15 | * @param method 16 | * @return 17 | */ 18 | InterfaceInfo getInterfaceInfo(String url, String method); 19 | 20 | /** 21 | * 根据ID获取接口信息 22 | * @param id 23 | * @return 24 | */ 25 | InterfaceInfo getInterfaceInfoById(Long id); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/service/InnerOrderService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.service; 2 | 3 | import com.niuma.binapicommon.model.entity.Order; 4 | import com.niuma.binapicommon.model.vo.OrderVO; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author niuma 10 | * @create 2023-05-11 22:57 11 | */ 12 | 13 | public interface InnerOrderService { 14 | /** 15 | * 获取前 limit 购买数量的接口 16 | * @param limit 17 | * @return 18 | */ 19 | List listTopBuyInterfaceInfo(int limit); 20 | } 21 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/service/InnerUserInterfaceInfoService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.niuma.binapicommon.model.dto.UpdateUserInterfaceInfoDTO; 5 | import com.niuma.binapicommon.model.entity.User; 6 | import com.niuma.binapicommon.model.entity.UserInterfaceInfo; 7 | 8 | /** 9 | * @author niuma 10 | * @create 2023-02-27 15:40 11 | */ 12 | public interface InnerUserInterfaceInfoService { 13 | 14 | /** 15 | * 接口调用次数+1 16 | * @param interfaceInfoId 17 | * @param userId 18 | * @return 19 | */ 20 | boolean invokeCount(long interfaceInfoId,long userId); 21 | 22 | /** 23 | * 更新用户接口信息 24 | * @param updateUserInterfaceInfoDTO 25 | * @return 26 | */ 27 | boolean updateUserInterfaceInfo(UpdateUserInterfaceInfoDTO updateUserInterfaceInfoDTO); 28 | 29 | 30 | /** 31 | * 检验用户是否有调用次数 32 | * @param userId 33 | * @param interfaceId 34 | * @return 35 | */ 36 | boolean checkUserInvokeAuth(Long userId,Long interfaceId); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/service/InnerUserService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.service; 2 | 3 | import com.niuma.binapicommon.model.entity.User; 4 | import com.niuma.binapicommon.model.vo.UserVO; 5 | 6 | /** 7 | * @author niuma 8 | * @create 2023-02-27 15:40 9 | */ 10 | public interface InnerUserService { 11 | 12 | /** 13 | * 通过ak获取调用的用户 14 | * @param ak 15 | * @return 16 | */ 17 | User getInvokeUser(String ak); 18 | 19 | /** 20 | * 获取登录的用户 21 | * @param cookie 22 | * @return 23 | */ 24 | UserVO getLoginUser(String cookie); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /binapi-common/src/main/java/com/niuma/binapicommon/utils/AuthPhoneNumberUtil.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapicommon.utils; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * @author YukeSeko 8 | */ 9 | 10 | public class AuthPhoneNumberUtil { 11 | 12 | /** 13 | * 验证手机号是否符合要求 14 | * @param phone 15 | * @return 16 | */ 17 | public boolean isPhoneNum(String phone){ 18 | String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(16[5,6])|(17[0-8])|(18[0-9])|(19[1、5、8、9]))\\d{8}$"; 19 | Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); 20 | Matcher m = p.matcher(phone); 21 | return m.matches(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /binapi-common/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /binapi-config/binapi-backend-dev.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | application: 5 | name: binapi-backend 6 | cloud: 7 | nacos: 8 | discovery: 9 | server-addr: localhost:8848 10 | # DataSource Config 11 | datasource: 12 | driver-class-name: com.mysql.cj.jdbc.Driver 13 | url: jdbc:mysql://localhost:3306/binapi 14 | username: root 15 | password: 123456 16 | mvc: 17 | pathmatch: 18 | matching-strategy: ANT_PATH_MATCHER 19 | # session 失效时间(分钟) 20 | session: 21 | timeout: 86400 22 | store-type: redis 23 | # redis 配置 24 | redis: 25 | port: 6379 26 | host: localhost 27 | database: 0 28 | rabbitmq: 29 | host: localhost 30 | port: 5672 31 | publisher-confirm-type: correlated #开启发送端确认 32 | publisher-returns: true #开启发送端消息抵达队列的确认 33 | template: 34 | mandatory: true #只要抵达队列,以异步发送优先回调我们这个returnsConfirm 35 | server: 36 | port: 8080 37 | servlet: 38 | context-path: /api 39 | mybatis-plus: 40 | configuration: 41 | map-underscore-to-camel-case: false 42 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 43 | global-config: 44 | db-config: 45 | logic-delete-field: isDelete # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) 46 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) 47 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) 48 | dubbo: 49 | application: 50 | name: binapi-backend-dubbo 51 | protocol: 52 | name: dubbo 53 | port: -1 54 | registry: 55 | address: nacos://localhost:8848 56 | parameters: 57 | namespace: 16239c21-ac42-46bc-a4e7-690e64272f5a 58 | check: false 59 | consumer: 60 | check: false 61 | -------------------------------------------------------------------------------- /binapi-config/binapi-gateway-dev.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8002 3 | logging: 4 | level: 5 | org: 6 | springframework: 7 | cloud: 8 | gateway: trace 9 | spring: 10 | application: 11 | name: binapi-gateway 12 | cloud: 13 | nacos: 14 | discovery: 15 | server-addr: localhost:8848 16 | gateway: 17 | routes: 18 | # 这个路由使用配置类配置自定义拦截器,用配置文件不知道怎么回事总是找不到 Bean 19 | # - id: binapi-interface 20 | # uri: lb://binapi-interface 21 | # predicates: 22 | # - Path=/api/interface/** 23 | # filters: 24 | # - interfaceFilter 25 | - id: binapi-order 26 | uri: lb://binapi-order 27 | predicates: 28 | - Path=/api/order/** 29 | - id: binapi-third 30 | uri: lb://binapi-third 31 | predicates: 32 | - Path=/api/third/** 33 | - id: binapi-backend 34 | uri: lb://binapi-backend 35 | predicates: 36 | - Path=/api/** 37 | dubbo: 38 | application: 39 | name: customer 40 | protocol: 41 | name: dubbo 42 | port: -1 43 | registry: 44 | address: nacos://localhost:8848 45 | # 配置namespace 46 | parameters: 47 | namespace: 16239c21-ac42-46bc-a4e7-690e64272f5a -------------------------------------------------------------------------------- /binapi-config/binapi-interface-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | nacos: 4 | discovery: 5 | server-addr: localhost:8848 6 | # DataSource Config 7 | datasource: 8 | driver-class-name: com.mysql.cj.jdbc.Driver 9 | url: jdbc:mysql://localhost:3306/binapi 10 | username: root 11 | password: 123456 12 | mvc: 13 | pathmatch: 14 | matching-strategy: ANT_PATH_MATCHER 15 | application: 16 | name: binapi-interface 17 | 18 | server: 19 | port: 8001 20 | servlet: 21 | context-path: /api/interface 22 | 23 | dubbo: 24 | application: 25 | name: binapi-interface 26 | protocol: 27 | name: dubbo 28 | port: -1 29 | registry: 30 | address: nacos://localhost:8848 31 | 32 | -------------------------------------------------------------------------------- /binapi-config/binapi-order-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: binapi-order 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: localhost:8848 8 | # DataSource Config 9 | datasource: 10 | driver-class-name: com.mysql.cj.jdbc.Driver 11 | url: jdbc:mysql://localhost:3306/binapi 12 | username: root 13 | password: 123456 14 | mvc: 15 | pathmatch: 16 | matching-strategy: ANT_PATH_MATCHER 17 | # redis 18 | redis: 19 | port: 6379 20 | host: localhost 21 | database: 0 22 | rabbitmq: 23 | host: localhost 24 | port: 5672 25 | publisher-confirm-type: correlated #开启发送端确认 26 | publisher-returns: true #开启发送端消息抵达队列的确认 27 | template: 28 | mandatory: true #只要抵达队列,以异步发送优先回调我们这个returnsConfirm 29 | listener: 30 | simple: 31 | retry: 32 | initial-interval: 60000 33 | server: 34 | port: 8003 35 | servlet: 36 | context-path: /api/order 37 | mybatis-plus: 38 | configuration: 39 | map-underscore-to-camel-case: false 40 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 41 | global-config: 42 | db-config: 43 | logic-delete-field: isDelete 44 | logic-delete-value: 1 45 | logic-not-delete-value: 0 46 | 47 | dubbo: 48 | application: 49 | name: binapi-order-dubbo 50 | protocol: 51 | name: dubbo 52 | port: -1 53 | registry: 54 | address: nacos://localhost:8848 55 | # 配置namespace 56 | parameters: 57 | namespace: 16239c21-ac42-46bc-a4e7-690e64272f5a 58 | check: false 59 | consumer: 60 | check: false 61 | -------------------------------------------------------------------------------- /binapi-config/binapi-third-party-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: binapi-third 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: localhost:8848 8 | # DataSource Config 9 | datasource: 10 | driver-class-name: com.mysql.cj.jdbc.Driver 11 | url: jdbc:mysql://localhost:3306/binapi 12 | username: root 13 | password: 123456 14 | mvc: 15 | pathmatch: 16 | matching-strategy: ANT_PATH_MATCHER 17 | # redis 18 | redis: 19 | port: 6379 20 | host: localhost 21 | database: 0 22 | rabbitmq: 23 | host: 127.0.0.1 24 | port: 5672 25 | publisher-confirm-type: correlated #开启发送端确认 26 | publisher-returns: true #开启发送端消息抵达队列的确认 27 | template: 28 | mandatory: true #只要抵达队列,以异步发送优先回调我们这个returnsConfirm 29 | server: 30 | port: 8004 31 | servlet: 32 | context-path: /api/third 33 | mybatis-plus: 34 | configuration: 35 | map-underscore-to-camel-case: false 36 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 37 | global-config: 38 | db-config: 39 | logic-delete-field: isDelete 40 | logic-delete-value: 1 41 | logic-not-delete-value: 0 42 | dubbo: 43 | application: 44 | name: binapi-third-party-dubbo 45 | protocol: 46 | name: dubbo 47 | port: -1 48 | registry: 49 | address: nacos://localhost:8848 50 | # 配置namespace 51 | parameters: 52 | namespace: 16239c21-ac42-46bc-a4e7-690e64272f5a 53 | #腾讯短信服务 54 | tencent: 55 | secretId: xxx 56 | secretKey: xxx 57 | sdkAppId: xxx 58 | signName: xxx 59 | templateId: xxx 60 | #阿里云oss 61 | aliyun: 62 | oss: 63 | file: 64 | endpoint: oss-cn-guangzhou.aliyuncs.com 65 | keyid: yourAccessKeyId 66 | keysecret: yourSecret 67 | bucketname: niumazlb -------------------------------------------------------------------------------- /binapi-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /binapi-gateway/src/main/java/com/niuma/binapigateway/BinapiGatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapigateway; 2 | 3 | import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 7 | import org.springframework.context.annotation.ComponentScan; 8 | 9 | /** 10 | * @author niumazlb 11 | */ 12 | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class},scanBasePackages = "com.niuma") 13 | @EnableDubbo 14 | public class BinapiGatewayApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(BinapiGatewayApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /binapi-gateway/src/main/java/com/niuma/binapigateway/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapigateway.config; 2 | 3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.cors.CorsConfiguration; 7 | import org.springframework.web.cors.reactive.CorsWebFilter; 8 | import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; 9 | import org.springframework.web.reactive.function.client.WebClient; 10 | 11 | /** 12 | * 全局跨域配置 13 | * @author niumazlb 14 | */ 15 | @Configuration 16 | public class CorsConfig{ 17 | 18 | @Bean 19 | public CorsWebFilter corsWebFilter(){ 20 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 21 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 22 | //1、配置跨域 23 | corsConfiguration.addAllowedHeader("*"); 24 | corsConfiguration.addAllowedMethod("*"); 25 | corsConfiguration.addAllowedOriginPattern("*"); 26 | corsConfiguration.setAllowCredentials(true); 27 | source.registerCorsConfiguration("/**",corsConfiguration); 28 | return new CorsWebFilter(source); 29 | } 30 | 31 | @Bean 32 | @LoadBalanced // 如果不添加,无法通过服务名进行调用,只能通过ip调用 33 | public WebClient.Builder webBuilder(){ 34 | return WebClient.builder(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /binapi-gateway/src/main/java/com/niuma/binapigateway/config/GatewayConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapigateway.config; 2 | 3 | import com.niuma.binapigateway.filter.InterfaceFilter; 4 | 5 | import org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory; 6 | import org.springframework.cloud.gateway.route.RouteLocator; 7 | import org.springframework.cloud.gateway.route.builder.GatewayFilterSpec; 8 | import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | import javax.annotation.Resource; 13 | 14 | /** 15 | * @author niuma 16 | * @create 2023-05-03 21:28 17 | */ 18 | @Configuration 19 | public class GatewayConfig { 20 | 21 | @Resource 22 | InterfaceFilter interfaceFilter; 23 | 24 | @Bean 25 | public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { 26 | return builder.routes() 27 | .route("binapi-interface", r -> r.path("/api/interface/**") 28 | .filters(f -> f.filter(interfaceFilter)) 29 | .uri("lb://binapi-interface")) 30 | .build(); 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /binapi-gateway/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | #server: 2 | # port: 8002 3 | #logging: 4 | # level: 5 | # org: 6 | # springframework: 7 | # cloud: 8 | # gateway: trace 9 | #spring: 10 | # application: 11 | # name: binapi-gateway 12 | # cloud: 13 | # nacos: 14 | # discovery: 15 | # server-addr: localhost:8848 16 | # gateway: 17 | # routes: 18 | ## 这个路由使用配置类配置自定义拦截器,用配置文件不知道怎么回事总是找不到 Bean 19 | ## - id: binapi-interface 20 | ## uri: lb://binapi-interface 21 | ## predicates: 22 | ## - Path=/api/interface/** 23 | ## filters: 24 | ## - interfaceFilter 25 | # - id: binapi-order 26 | # uri: lb://binapi-order 27 | # predicates: 28 | # - Path=/api/order/** 29 | # - id: binapi-third 30 | # uri: lb://binapi-third 31 | # predicates: 32 | # - Path=/api/third/** 33 | # - id: binapi-backend 34 | # uri: lb://binapi-backend 35 | # predicates: 36 | # - Path=/api/** 37 | #dubbo: 38 | # application: 39 | # name: customer 40 | # protocol: 41 | # name: dubbo 42 | # port: -1 43 | # registry: 44 | # address: nacos://localhost:8848 45 | # # 配置namespace 46 | # parameters: 47 | # namespace: 16239c21-ac42-46bc-a4e7-690e64272f5a -------------------------------------------------------------------------------- /binapi-gateway/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: binapi-gateway 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: localhost:8848 8 | config: 9 | file-extension: yaml 10 | namespace: 1ce6c2fb-611e-4d1e-834d-567340760462 11 | shared-configs[0]: 12 | dataId: dubbo.yaml 13 | refresh: true 14 | profiles: 15 | active: dev -------------------------------------------------------------------------------- /binapi-gateway/src/test/java/com/niuma/binapigateway/BinapiGatewayApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapigateway; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BinapiGatewayApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /binapi-interface/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /binapi-interface/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.niuma 7 | binapi 8 | 1.0-SNAPSHOT 9 | 10 | binapi-interface 11 | 0.0.1-SNAPSHOT 12 | binapi-interface 13 | binapi-interface 14 | jar 15 | 16 | 1.8 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | 25 | org.projectlombok 26 | lombok 27 | true 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-test 32 | test 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-maven-plugin 42 | 43 | 44 | 45 | org.projectlombok 46 | lombok 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /binapi-interface/src/main/java/com/niuma/binapiinterface/BinapiInterfaceApplication.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiinterface; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BinapiInterfaceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BinapiInterfaceApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /binapi-interface/src/main/java/com/niuma/binapiinterface/NacosServerInfo.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiinterface; 2 | 3 | import com.alibaba.cloud.nacos.NacosConfigProperties; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class NacosServerInfo implements CommandLineRunner { 10 | 11 | @Autowired 12 | private NacosConfigProperties nacosConfigProperties; 13 | 14 | @Override 15 | public void run(String... args) throws Exception { 16 | String dataId = nacosConfigProperties.getName(); 17 | String group = nacosConfigProperties.getGroup(); 18 | String serverAddr = nacosConfigProperties.getServerAddr(); 19 | String namespace = nacosConfigProperties.getNamespace(); 20 | 21 | System.out.println("dataId: " + dataId); 22 | System.out.println("group: " + group); 23 | System.out.println("serverAddr: " + serverAddr); 24 | System.out.println("namespace: " + namespace); 25 | } 26 | } -------------------------------------------------------------------------------- /binapi-interface/src/main/java/com/niuma/binapiinterface/controller/InterfaceController.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiinterface.controller; 2 | 3 | import cn.hutool.http.HttpRequest; 4 | import cn.hutool.http.HttpUtil; 5 | import com.niuma.binapiclientsdk.model.User; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | 10 | /** 11 | * @author niuma 12 | * @create 2023-03-28 15:33 13 | */ 14 | @RestController 15 | public class InterfaceController { 16 | @PostMapping("/user") 17 | public String getUserByPost(@RequestBody User user, HttpServletRequest request){ 18 | return "用户叫"+user.getUsername(); 19 | } 20 | 21 | @GetMapping("/renjian") 22 | public String getRenjian(){ 23 | return HttpRequest.get("https://v.api.aa1.cn/api/api-renjian/index.php?type=json").execute().body(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /binapi-interface/src/main/java/com/niuma/binapiinterface/controller/NameController.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiinterface.controller; 2 | 3 | import com.niuma.binapiclientsdk.model.User; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | 9 | /** 10 | * @author niumazlb 11 | * @create 2022-11-09 10:55 12 | */ 13 | @RestController 14 | @RequestMapping("/name") 15 | public class NameController { 16 | 17 | @PostMapping("/user") 18 | public String getUserByPost(@RequestBody User user, HttpServletRequest request){ 19 | return "Post用户叫"+user.getUsername(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /binapi-interface/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #spring: 2 | # cloud: 3 | # nacos: 4 | # discovery: 5 | # server-addr: localhost:8848 6 | # # DataSource Config 7 | # datasource: 8 | # driver-class-name: com.mysql.cj.jdbc.Driver 9 | # url: jdbc:mysql://localhost:3306/binapi 10 | # username: root 11 | # password: 123456 12 | # mvc: 13 | # pathmatch: 14 | # matching-strategy: ANT_PATH_MATCHER 15 | # application: 16 | # name: binapi-interface 17 | # 18 | #server: 19 | # port: 8001 20 | # servlet: 21 | # context-path: /api/interface 22 | # 23 | #dubbo: 24 | # application: 25 | # name: binapi-interface 26 | # protocol: 27 | # name: dubbo 28 | # port: -1 29 | # registry: 30 | # address: nacos://localhost:8848 31 | # 32 | -------------------------------------------------------------------------------- /binapi-interface/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | nacos: 4 | discovery: 5 | server-addr: localhost:8848 6 | config: 7 | file-extension: yaml 8 | namespace: 1ce6c2fb-611e-4d1e-834d-567340760462 9 | shared-configs[0]: 10 | dataId: db.yaml 11 | refresh: true 12 | shared-configs[1]: 13 | dataId: sentinel-dev.yaml 14 | refresh: true 15 | profiles: 16 | active: dev 17 | application: 18 | name: binapi-interface 19 | -------------------------------------------------------------------------------- /binapi-interface/src/test/java/com/niuma/binapiinterface/BinapiInterfaceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiinterface; 2 | 3 | import com.niuma.binapiclientsdk.client.BinApiClient; 4 | import com.niuma.binapiclientsdk.model.User; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | import javax.annotation.Resource; 9 | 10 | @SpringBootTest 11 | class BinapiInterfaceApplicationTests { 12 | @Resource 13 | private BinApiClient binApiClient; 14 | 15 | @Test 16 | void contextLoads() { 17 | 18 | User user = new User(); 19 | user.setUsername("niuma"); 20 | String userByPost = binApiClient.getUserByPost(user); 21 | System.out.println(userByPost); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /binapi-order/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/BinapiOrderApplication.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder; 2 | 3 | import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | 9 | @SpringBootApplication(scanBasePackages = "com.niuma") 10 | @EnableDubbo 11 | @MapperScan("com.niuma.binapiorder.mapper") 12 | public class BinapiOrderApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(BinapiOrderApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * MyBatis Plus 配置 12 | * 13 | * @author niuma 14 | */ 15 | @Configuration 16 | @MapperScan("com.niuma.binapi.mapper") 17 | public class MyBatisPlusConfig { 18 | 19 | /** 20 | * 拦截器配置 21 | * 22 | * @return 23 | */ 24 | @Bean 25 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 26 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 27 | // 分页插件 28 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 29 | return interceptor; 30 | } 31 | } -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/config/OrderRabbitMqConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.amqp.core.*; 5 | import org.springframework.beans.factory.annotation.Qualifier; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | import static com.niuma.binapicommon.constant.RabbitMqConstant.*; 13 | 14 | /** 15 | * RabbitMQ配置 - 统一在backend模块创建 16 | * @author niumazlb 17 | */ 18 | @Slf4j 19 | //@Configuration 20 | @Deprecated 21 | public class OrderRabbitMqConfig { 22 | 23 | 24 | /** 25 | * 普通队列 26 | * @return 27 | */ 28 | @Bean("ORDER_QUEUE") 29 | public Queue orderQueue(){ 30 | Map arguments = new HashMap<>(); 31 | //声明死信队列和交换机消息,过期时间:30分钟 32 | arguments.put("x-dead-letter-exchange", ORDER_EXCHANGE_TOPIC_NAME); 33 | arguments.put("x-dead-letter-routing-key", ORDER_TIMEOUT_EXCHANGE_ROUTING_KEY); 34 | arguments.put("x-message-ttl", 30*60000); 35 | // arguments.put("x-message-ttl", 60000);// 这里测试1分钟 36 | return QueueBuilder 37 | .durable(ORDER_SEND_QUEUE_NAME) 38 | .deadLetterExchange(ORDER_EXCHANGE_TOPIC_NAME) 39 | .deadLetterRoutingKey(ORDER_TIMEOUT_EXCHANGE_ROUTING_KEY) 40 | .ttl(30 * 60000).build(); 41 | } 42 | 43 | /** 44 | * 死信队列:消息重试三次后放入死信队列 45 | * @return 46 | */ 47 | @Bean("ORDER_DEAD_LETTER") 48 | public Queue orderDeadLetter(){ 49 | return QueueBuilder.durable(ORDER_TIMEOUT_QUEUE_NAME).build(); 50 | } 51 | 52 | /** 53 | * 主题交换机 54 | * @return 55 | */ 56 | @Bean("ORDER_EXCHANGE") 57 | public Exchange orderExchange() { 58 | return ExchangeBuilder.topicExchange(ORDER_EXCHANGE_TOPIC_NAME).durable(true).build(); 59 | } 60 | 61 | 62 | /** 63 | * 交换机和普通队列绑定 64 | * @return 65 | */ 66 | @Bean 67 | public Binding orderBinding(@Qualifier("ORDER_QUEUE") Queue orderQueue,@Qualifier("ORDER_EXCHANGE") Exchange orderExchange){ 68 | return BindingBuilder.bind(orderQueue).to(orderExchange).with(ORDER_SEND_EXCHANGE_ROUTING_KEY).noargs(); 69 | } 70 | 71 | /** 72 | * 交换机和死信队列绑定 73 | * @return 74 | */ 75 | @Bean 76 | public Binding orderDelayBinding(@Qualifier("ORDER_DEAD_LETTER") Queue orderDeadLetter,@Qualifier("ORDER_EXCHANGE") Exchange orderExchange){ 77 | return BindingBuilder.bind(orderDeadLetter).to(orderExchange).with(ORDER_TIMEOUT_EXCHANGE_ROUTING_KEY).noargs(); 78 | } 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.config; 2 | 3 | import lombok.Data; 4 | import org.redisson.Redisson; 5 | import org.redisson.api.RedissonClient; 6 | import org.redisson.config.Config; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.data.redis.connection.RedisConnectionFactory; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; 12 | import org.springframework.data.redis.serializer.RedisSerializer; 13 | import org.springframework.stereotype.Component; 14 | 15 | /** 16 | * @author niumazlb 17 | * @create 2022-08-08 22:19 18 | */ 19 | @Component 20 | @ConfigurationProperties(prefix = "spring.redis") 21 | @Data 22 | public class RedisConfig { 23 | 24 | private String host; 25 | private String port; 26 | private String password; 27 | 28 | @Bean 29 | public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) { 30 | // 创建RedisTemplate对象 31 | RedisTemplate template = new RedisTemplate<>(); 32 | // 设置连接工厂 33 | template.setConnectionFactory(connectionFactory); 34 | // 创建JSON序列化工具 35 | GenericJackson2JsonRedisSerializer jsonRedisSerializer = 36 | new GenericJackson2JsonRedisSerializer(); 37 | // 设置Key的序列化 38 | template.setKeySerializer(RedisSerializer.string()); 39 | template.setHashKeySerializer(RedisSerializer.string()); 40 | // 设置Value的序列化 41 | template.setValueSerializer(jsonRedisSerializer); 42 | template.setHashValueSerializer(jsonRedisSerializer); 43 | // 返回 44 | return template; 45 | } 46 | 47 | @Bean 48 | public RedissonClient redissonConfig() { 49 | // 1. Create config object 50 | Config config = new Config(); 51 | String redisAdd = String.format("redis://%s:%s", host, port); 52 | config.useSingleServer().setAddress(redisAdd).setDatabase(2).setPassword(password); 53 | RedissonClient redisson = Redisson.create(config); 54 | return redisson; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.controller; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.niuma.binapicommon.common.BaseResponse; 5 | import com.niuma.binapicommon.common.ResultUtils; 6 | import com.niuma.binapiorder.model.dto.OrderAddRequest; 7 | import com.niuma.binapiorder.model.dto.OrderQueryRequest; 8 | import com.niuma.binapicommon.model.vo.OrderVO; 9 | import com.niuma.binapiorder.service.OrderService; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import javax.annotation.Resource; 13 | import javax.servlet.http.HttpServletRequest; 14 | 15 | /** 16 | * @author niuma 17 | * @create 2023-05-03 15:53 18 | */ 19 | @RestController 20 | @RequestMapping("/") 21 | public class OrderController { 22 | 23 | @Resource 24 | OrderService orderService; 25 | 26 | @PostMapping("/addOrder") 27 | public BaseResponse addOrder(@RequestBody OrderAddRequest addOrderRequest, HttpServletRequest request) { 28 | OrderVO orderVO = orderService.addOrder(addOrderRequest, request); 29 | return ResultUtils.success(orderVO); 30 | } 31 | 32 | @GetMapping("/list") 33 | public BaseResponse> listPageOrder(OrderQueryRequest orderQueryRequest, HttpServletRequest request){ 34 | Page orderPage = orderService.listPageOrder(orderQueryRequest, request); 35 | return ResultUtils.success(orderPage); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/mapper/OrderLockMapper.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.mapper; 2 | 3 | import com.niuma.binapiorder.model.entity.OrderLock; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * @author niumazlb 8 | * @description 针对表【order_lock】的数据库操作Mapper 9 | * @createDate 2023-05-03 15:52:09 10 | * @Entity com.niuma.binapiorder.model.entity.OrderLock 11 | */ 12 | public interface OrderLockMapper extends BaseMapper { 13 | 14 | } 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/mapper/OrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.mapper; 2 | 3 | import com.niuma.binapicommon.model.entity.Order; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author niumazlb 10 | * @description 针对表【order】的数据库操作Mapper 11 | * @createDate 2023-05-03 15:52:09 12 | * @Entity com.niuma.binapicommon.model.entity.Order 13 | */ 14 | public interface OrderMapper extends BaseMapper { 15 | /** 16 | * 获取前 limit 购买数量的接口 17 | * @param limit 18 | * @return 19 | */ 20 | List listTopBuyInterfaceInfo(int limit); 21 | 22 | } 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/model/dto/OrderAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.model.dto; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import lombok.Data; 5 | 6 | /** 7 | * @author niuma 8 | * @create 2023-05-03 16:02 9 | */ 10 | @Data 11 | public class OrderAddRequest { 12 | 13 | /** 14 | * 接口id 15 | */ 16 | private Long interfaceId; 17 | 18 | /** 19 | * 计费Id 20 | */ 21 | private Long chargingId; 22 | 23 | /** 24 | * 用户id 25 | */ 26 | private Long userId; 27 | 28 | /** 29 | * 购买数量 30 | */ 31 | private Long count; 32 | 33 | /** 34 | * 单价 35 | */ 36 | private Double charging; 37 | 38 | /** 39 | * 交易金额 40 | */ 41 | private Double totalAmount; 42 | 43 | @TableField(exist = false) 44 | private static final long serialVersionUID = 1L; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/model/dto/OrderQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.model.dto; 2 | 3 | import com.niuma.binapicommon.common.PageRequest; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author niuma 10 | * @create 2023-05-07 20:30 11 | */ 12 | @Data 13 | public class OrderQueryRequest extends PageRequest implements Serializable { 14 | private String type; 15 | } 16 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/model/entity/OrderLock.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | import lombok.Data; 9 | 10 | /** 11 | * 12 | * @TableName order_lock 13 | */ 14 | @TableName(value ="order_lock") 15 | @Data 16 | public class OrderLock implements Serializable { 17 | /** 18 | * 主键 19 | */ 20 | @TableId 21 | private Long id; 22 | 23 | /** 24 | * 订单编号 25 | */ 26 | private String orderNumber; 27 | 28 | /** 29 | * 计费id 30 | */ 31 | private Long chargingId; 32 | 33 | /** 34 | * 用户id 35 | */ 36 | private Long userId; 37 | 38 | /** 39 | * 锁定数量 40 | */ 41 | private Long lockNum; 42 | 43 | /** 44 | * 锁定状态(1-已锁定 0-已解锁 2-扣减) 45 | */ 46 | private Integer lockStatus; 47 | 48 | /** 49 | * 创建时间 50 | */ 51 | private Date createTime; 52 | 53 | /** 54 | * 更新时间 55 | */ 56 | private Date updateTime; 57 | 58 | @TableField(exist = false) 59 | private static final long serialVersionUID = 1L; 60 | } -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/model/enums/LockOrderStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * 订单状态枚举类 9 | * @author niuma 10 | * @create 2023-05-03 20:19 11 | */ 12 | public enum LockOrderStatusEnum { 13 | 14 | UNLOCK("已解锁", 0), 15 | 16 | LOCK("已锁定", 1), 17 | DEDUCT("已扣减", 2); 18 | 19 | private final String text; 20 | 21 | private final int value; 22 | 23 | LockOrderStatusEnum(String text, int value) { 24 | this.text = text; 25 | this.value = value; 26 | } 27 | 28 | /** 29 | * 获取值列表 30 | * 31 | * @return 32 | */ 33 | public static List getValues() { 34 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 35 | } 36 | 37 | public int getValue() { 38 | return value; 39 | } 40 | 41 | public String getText() { 42 | return text; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/model/enums/OrderStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * 订单状态枚举类 9 | * @author niuma 10 | * @create 2023-05-03 20:19 11 | */ 12 | public enum OrderStatusEnum { 13 | 14 | TOBEPAID("待支付", 0), 15 | 16 | DONE("已完成", 1), 17 | FAILURE("失效", 2); 18 | 19 | private final String text; 20 | 21 | private final int value; 22 | 23 | OrderStatusEnum(String text, int value) { 24 | this.text = text; 25 | this.value = value; 26 | } 27 | 28 | /** 29 | * 获取值列表 30 | * 31 | * @return 32 | */ 33 | public static List getValues() { 34 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 35 | } 36 | 37 | public int getValue() { 38 | return value; 39 | } 40 | 41 | public String getText() { 42 | return text; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/schedule/SendOrderInfoFailedSchedule.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.schedule; 2 | 3 | import com.niuma.binapicommon.common.ErrorCode; 4 | import com.niuma.binapicommon.constant.RedisConstant; 5 | import com.niuma.binapicommon.exception.BusinessException; 6 | import com.niuma.binapicommon.model.entity.Order; 7 | import com.niuma.binapiorder.utils.OrderMqUtils; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.redisson.api.RLock; 10 | import org.redisson.api.RedissonClient; 11 | import org.springframework.data.redis.core.RedisTemplate; 12 | import org.springframework.scheduling.annotation.EnableAsync; 13 | import org.springframework.scheduling.annotation.EnableScheduling; 14 | import org.springframework.scheduling.annotation.Scheduled; 15 | import org.springframework.stereotype.Component; 16 | 17 | import javax.annotation.Resource; 18 | import java.util.Set; 19 | import java.util.concurrent.TimeUnit; 20 | 21 | import static com.niuma.binapicommon.constant.LockConstant.ORDER_SEND_FAILED; 22 | 23 | /** 24 | * 订单发送失败重试定时任务 25 | * @author niuma 26 | * @create 2023-05-04 16:29 27 | */ 28 | @Slf4j 29 | @Component 30 | @EnableAsync 31 | @EnableScheduling 32 | public class SendOrderInfoFailedSchedule { 33 | @Resource 34 | RedissonClient redissonClient; 35 | @Resource 36 | private RedisTemplate redisTemplate; 37 | @Resource 38 | OrderMqUtils orderMqUtils; 39 | 40 | @Scheduled(cron = "*/60 * * * * ?") 41 | public void sendOrderInfoFailed(){ 42 | RLock lock = redissonClient.getLock(ORDER_SEND_FAILED); 43 | try { 44 | boolean tryLock = lock.tryLock(20, 10, TimeUnit.SECONDS); 45 | if(tryLock){ 46 | Set keys = redisTemplate.keys(RedisConstant.SEND_ORDER_PREFIX + "*"); 47 | for (Object key : keys) { 48 | //重新发送 49 | Order order = (Order) redisTemplate.opsForValue().get(key); 50 | redisTemplate.delete(key); 51 | orderMqUtils.sendOrderSnInfo(order); 52 | } 53 | } 54 | } catch (InterruptedException e) { 55 | log.error("===定时任务:获取失败生产者发送消息redis出现bug==="); 56 | throw new BusinessException(ErrorCode.OPERATION_ERROR,e.getMessage()); 57 | }finally { 58 | lock.unlock(); 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/service/OrderLockService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.service; 2 | 3 | import com.niuma.binapiorder.model.entity.OrderLock; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * @author niumazlb 8 | * @description 针对表【order_lock】的数据库操作Service 9 | * @createDate 2023-05-03 15:52:09 10 | */ 11 | public interface OrderLockService extends IService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.niuma.binapiorder.model.dto.OrderAddRequest; 5 | import com.niuma.binapiorder.model.dto.OrderQueryRequest; 6 | import com.niuma.binapicommon.model.entity.Order; 7 | import com.baomidou.mybatisplus.extension.service.IService; 8 | import com.niuma.binapicommon.model.vo.OrderVO; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import java.util.List; 12 | 13 | /** 14 | * @author niumazlb 15 | * @description 针对表【order】的数据库操作Service 16 | * @createDate 2023-05-03 15:52:09 17 | */ 18 | public interface OrderService extends IService { 19 | 20 | /** 21 | * 创建订单 22 | * @param addOrderRequest 23 | * @return 24 | */ 25 | OrderVO addOrder(OrderAddRequest addOrderRequest, HttpServletRequest request); 26 | 27 | /** 28 | * 获取订单列表 29 | * @param orderQueryRequest 30 | * @param request 31 | * @return 32 | */ 33 | Page listPageOrder(OrderQueryRequest orderQueryRequest, HttpServletRequest request); 34 | 35 | /** 36 | * 获取前 limit 购买数量的接口 37 | * @param limit 38 | * @return 39 | */ 40 | List listTopBuyInterfaceInfo(int limit); 41 | } 42 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/service/impl/InnerOrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.service.impl; 2 | 3 | import com.niuma.binapicommon.model.entity.Order; 4 | import com.niuma.binapicommon.model.vo.OrderVO; 5 | import com.niuma.binapicommon.service.InnerOrderService; 6 | import com.niuma.binapiorder.service.OrderService; 7 | import org.apache.dubbo.config.annotation.DubboService; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.List; 11 | 12 | /** 13 | * @author niuma 14 | * @create 2023-05-11 23:00 15 | */ 16 | @DubboService 17 | public class InnerOrderServiceImpl implements InnerOrderService { 18 | @Resource 19 | OrderService orderService; 20 | @Override 21 | public List listTopBuyInterfaceInfo(int limit) { 22 | return orderService.listTopBuyInterfaceInfo(limit); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /binapi-order/src/main/java/com/niuma/binapiorder/service/impl/OrderLockServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.niuma.binapiorder.model.entity.OrderLock; 5 | import com.niuma.binapiorder.service.OrderLockService; 6 | import com.niuma.binapiorder.mapper.OrderLockMapper; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @author niumazlb 11 | * @description 针对表【order_lock】的数据库操作Service实现 12 | * @createDate 2023-05-03 15:52:09 13 | */ 14 | @Service 15 | public class OrderLockServiceImpl extends ServiceImpl 16 | implements OrderLockService{ 17 | 18 | } 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /binapi-order/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #spring: 2 | # application: 3 | # name: binapi-order 4 | # cloud: 5 | # nacos: 6 | # discovery: 7 | # server-addr: localhost:8848 8 | # # DataSource Config 9 | # datasource: 10 | # driver-class-name: com.mysql.cj.jdbc.Driver 11 | # url: jdbc:mysql://localhost:3306/binapi 12 | # username: root 13 | # password: 123456 14 | # mvc: 15 | # pathmatch: 16 | # matching-strategy: ANT_PATH_MATCHER 17 | # # redis 18 | # redis: 19 | # port: 6379 20 | # host: localhost 21 | # database: 0 22 | # rabbitmq: 23 | # host: localhost 24 | # port: 5672 25 | # publisher-confirm-type: correlated #开启发送端确认 26 | # publisher-returns: true #开启发送端消息抵达队列的确认 27 | # template: 28 | # mandatory: true #只要抵达队列,以异步发送优先回调我们这个returnsConfirm 29 | # listener: 30 | # simple: 31 | # retry: 32 | # initial-interval: 60000 33 | #server: 34 | # port: 8003 35 | # servlet: 36 | # context-path: /api/order 37 | #mybatis-plus: 38 | # configuration: 39 | # map-underscore-to-camel-case: false 40 | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 41 | # global-config: 42 | # db-config: 43 | # logic-delete-field: isDelete 44 | # logic-delete-value: 1 45 | # logic-not-delete-value: 0 46 | # 47 | #dubbo: 48 | # application: 49 | # name: binapi-order-dubbo 50 | # protocol: 51 | # name: dubbo 52 | # port: -1 53 | # registry: 54 | # address: nacos://localhost:8848 55 | # # 配置namespace 56 | # parameters: 57 | # namespace: 16239c21-ac42-46bc-a4e7-690e64272f5a 58 | # check: false 59 | # consumer: 60 | # check: false 61 | -------------------------------------------------------------------------------- /binapi-order/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: binapi-order 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: localhost:8848 8 | config: 9 | file-extension: yaml 10 | namespace: 1ce6c2fb-611e-4d1e-834d-567340760462 11 | shared-configs[0]: 12 | dataId: db.yaml 13 | refresh: true 14 | shared-configs[1]: 15 | dataId: rabbitmq.yaml 16 | refresh: true 17 | shared-configs[2]: 18 | dataId: dubbo.yaml 19 | refresh: true 20 | shared-configs[3]: 21 | dataId: sentinel-dev.yaml 22 | refresh: true 23 | profiles: 24 | active: dev -------------------------------------------------------------------------------- /binapi-order/src/main/resources/mapper/OrderLockMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | id,orderNumber,chargingId, 20 | userId,lockNum,lockStatus, 21 | createTime,updateTime 22 | 23 | 24 | -------------------------------------------------------------------------------- /binapi-order/src/main/resources/mapper/OrderMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | id,interfaceId,userId, 23 | orderNumber,total,charging, 24 | totalAmount,status,createTime, 25 | updateTime,isDelete 26 | 27 | 33 | 34 | -------------------------------------------------------------------------------- /binapi-order/src/test/java/com/niuma/binapiorder/BinapiOrderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapiorder; 2 | 3 | import com.niuma.binapiorder.mapper.OrderMapper; 4 | import com.niuma.binapicommon.model.entity.Order; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | import javax.annotation.Resource; 9 | import java.util.List; 10 | 11 | @SpringBootTest 12 | class BinapiOrderApplicationTests { 13 | 14 | @Resource 15 | OrderMapper orderMapper; 16 | @Test 17 | void contextLoads() { 18 | List orders = orderMapper.listTopBuyInterfaceInfo(3); 19 | System.out.println(orders); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /binapi-third-party/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/BinapiThirdPartyApplication.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author niumazlb 9 | */ 10 | @SpringBootApplication(scanBasePackages = "com.niuma") 11 | @MapperScan("com.niuma.binapithirdparty.mapper") 12 | public class BinapiThirdPartyApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(BinapiThirdPartyApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/config/AliPayConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.PropertySource; 7 | 8 | /** 9 | * @author niumazlb 10 | */ 11 | @Configuration 12 | @PropertySource("classpath:application-alipay.properties") 13 | @ConfigurationProperties(prefix = "alipay") 14 | @Data 15 | public class AliPayConfig { 16 | /** 17 | * APPID 18 | */ 19 | private String appId; 20 | 21 | /** 22 | * 商户私钥, 即PKCS8格式RSA2私钥 23 | */ 24 | private String privateKey; 25 | 26 | /** 27 | * 支付宝公钥 28 | */ 29 | private String publicKey; 30 | 31 | /** 32 | * 服务器异步通知页面路径,需http://格式的完整路径 33 | * 踩坑:不能加?type=abc这类自定义参数 34 | */ 35 | private String notifyUrl; 36 | 37 | /** 38 | * 页面跳转同步通知页面路径,需http://格式的完整路径 39 | * 踩坑:不能加?type=abc这类自定义参数 40 | */ 41 | private String returnUrl; 42 | 43 | /** 44 | * 签名方式 45 | */ 46 | private String signType; 47 | 48 | /** 49 | * 字符编码格式 50 | */ 51 | private String charset; 52 | 53 | /** 54 | * 支付宝网关 55 | */ 56 | private String gatewayUrl; 57 | 58 | /** 59 | * 日志打印地址 60 | */ 61 | private String logPath; 62 | } -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/config/AliPayRabbitMqConfig.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.amqp.core.Binding; 5 | import org.springframework.amqp.core.BindingBuilder; 6 | import org.springframework.amqp.core.Queue; 7 | import org.springframework.amqp.core.QueueBuilder; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | import static com.niuma.binapicommon.constant.RabbitMqConstant.*; 12 | 13 | /** 14 | * RabbitMQ配置 - 统一在backend模块创建 15 | * @author niumazlb 16 | */ 17 | @Slf4j 18 | //@Configuration 19 | @Deprecated 20 | public class AliPayRabbitMqConfig { 21 | 22 | 23 | /** 24 | * 普通队列 25 | * @return 26 | */ 27 | @Bean 28 | public Queue alipayQueue(){ 29 | return QueueBuilder.durable(ORDER_SUCCESS_QUEUE_NAME).build(); 30 | } 31 | 32 | 33 | /** 34 | * 交换机和普通队列绑定 35 | * @return 36 | */ 37 | @Bean 38 | public Binding alipayBinding(){ 39 | return new Binding(ORDER_SUCCESS_QUEUE_NAME, Binding.DestinationType.QUEUE, ORDER_EXCHANGE_TOPIC_NAME,ORDER_SUCCESS_EXCHANGE_ROUTING_KEY,null); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/config/TencentClient.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.config; 2 | 3 | import com.tencentcloudapi.common.Credential; 4 | import com.tencentcloudapi.sms.v20210111.SmsClient; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.stereotype.Component; 8 | /** 9 | * @author YukeSeko 10 | */ 11 | @Component 12 | public class TencentClient { 13 | 14 | @Value("${tencent.secretId}") 15 | private String secretId; 16 | 17 | @Value("${tencent.secretKey}") 18 | private String secretKey; 19 | 20 | /** 21 | * Tencent应用客户端 22 | * @return 23 | */ 24 | @Bean 25 | public SmsClient client(){ 26 | Credential cred = new Credential(secretId, secretKey); 27 | SmsClient smsClient = new SmsClient(cred, "ap-guangzhou"); 28 | return smsClient; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/mapper/AlipayInfoMapper.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.mapper; 2 | 3 | import com.niuma.binapithirdparty.model.entity.AlipayInfo; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * @author niumazlb 8 | * @description 针对表【alipay_info】的数据库操作Mapper 9 | * @createDate 2023-05-06 10:01:53 10 | * @Entity com.niuma.binapithirdparty.model.entity.AlipayInfo 11 | */ 12 | public interface AlipayInfoMapper extends BaseMapper { 13 | 14 | } 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/model/dto/AlipayRequest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.model.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author niuma 9 | * @create 2023-05-06 9:06 10 | */ 11 | @Data 12 | public class AlipayRequest implements Serializable { 13 | private static final long serialVersionUID = -8597630489529830444L; 14 | 15 | private String traceNo; 16 | private double totalAmount; 17 | private String subject; 18 | private String alipayTraceNo; 19 | } 20 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/model/entity/AlipayInfo.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | import lombok.Data; 9 | 10 | /** 11 | * 12 | * @TableName alipay_info 13 | */ 14 | @TableName(value ="alipay_info") 15 | @Data 16 | public class AlipayInfo implements Serializable { 17 | /** 18 | * 订单id 19 | */ 20 | @TableId 21 | private String orderNumber; 22 | 23 | /** 24 | * 交易名称 25 | */ 26 | private String subject; 27 | 28 | /** 29 | * 交易金额 30 | */ 31 | private Double totalAmount; 32 | 33 | /** 34 | * 买家付款金额 35 | */ 36 | private Double buyerPayAmount; 37 | 38 | /** 39 | * 买家在支付宝的唯一id 40 | */ 41 | private String buyerId; 42 | 43 | /** 44 | * 支付宝交易凭证号 45 | */ 46 | private String tradeNo; 47 | 48 | /** 49 | * 交易状态 50 | */ 51 | private String tradeStatus; 52 | 53 | /** 54 | * 买家付款时间 55 | */ 56 | private Date gmtPayment; 57 | 58 | @TableField(exist = false) 59 | private static final long serialVersionUID = 1L; 60 | } -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/schedule/SendOrderPaySuccessInfoFailedSchedule.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.schedule; 2 | 3 | 4 | import com.niuma.binapicommon.constant.LockConstant; 5 | import com.niuma.binapicommon.constant.RedisConstant; 6 | import com.niuma.binapithirdparty.utils.OrderPaySuccessMqUtils; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.redisson.api.RLock; 9 | import org.redisson.api.RedissonClient; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.scheduling.annotation.EnableAsync; 12 | import org.springframework.scheduling.annotation.EnableScheduling; 13 | import org.springframework.scheduling.annotation.Scheduled; 14 | import org.springframework.stereotype.Component; 15 | 16 | import javax.annotation.Resource; 17 | import java.util.Set; 18 | import java.util.concurrent.TimeUnit; 19 | 20 | 21 | /** 22 | * 支付成功消息重发任务 23 | * @author niumazlb 24 | */ 25 | @Slf4j 26 | @Component 27 | @EnableAsync 28 | @EnableScheduling 29 | public class SendOrderPaySuccessInfoFailedSchedule { 30 | 31 | @Resource 32 | private RedissonClient redissonClient; 33 | 34 | @Resource 35 | private RedisTemplate redisTemplate; 36 | 37 | 38 | @Resource 39 | private OrderPaySuccessMqUtils orderPaySuccessMqUtils; 40 | 41 | /** 42 | * 消息可靠性保证(发送端可靠性保证) 43 | * 每分钟从生产者redis中重新发送发送订单支付成功的消息 44 | */ 45 | @Scheduled(cron = "*/60 * * * * ?") 46 | public void sendFailedOrderPaySuccess(){ 47 | RLock lock = redissonClient.getLock(LockConstant.ORDER_PAY_SUCCESS); 48 | try { 49 | // 为加锁等待20秒时间,并在加锁成功10秒钟后自动解开 50 | boolean tryLock = lock.tryLock(20, 10, TimeUnit.SECONDS); 51 | if (tryLock){ 52 | //重新向mq中发送订单消息 53 | Set keys = redisTemplate.keys(RedisConstant.ORDER_PAY_SUCCESS_INFO + "*"); 54 | for (Object key : keys) { 55 | String orderSn = (String) redisTemplate.opsForValue().get(key); 56 | //删除reids中的该条记录 57 | redisTemplate.delete(key.toString()); 58 | orderPaySuccessMqUtils.sendOrderPaySuccess(orderSn); 59 | } 60 | } 61 | } catch (InterruptedException e) { 62 | log.error("===定时任务:获取失败生产者发送消息redis出现bug==="); 63 | throw new RuntimeException(e); 64 | }finally { 65 | lock.unlock(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/service/AlipayInfoService.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.service; 2 | 3 | import com.niuma.binapithirdparty.model.entity.AlipayInfo; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * @author niumazlb 8 | * @description 针对表【alipay_info】的数据库操作Service 9 | * @createDate 2023-05-06 10:01:53 10 | */ 11 | public interface AlipayInfoService extends IService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/service/impl/AlipayInfoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.niuma.binapithirdparty.model.entity.AlipayInfo; 5 | import com.niuma.binapithirdparty.service.AlipayInfoService; 6 | import com.niuma.binapithirdparty.mapper.AlipayInfoMapper; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @author niumazlb 11 | * @description 针对表【alipay_info】的数据库操作Service实现 12 | * @createDate 2023-05-06 10:01:53 13 | */ 14 | @Service 15 | public class AlipayInfoServiceImpl extends ServiceImpl 16 | implements AlipayInfoService { 17 | 18 | } 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/utils/ExcelUtils.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.utils; 2 | 3 | import cn.hutool.core.collection.CollUtil; 4 | import com.alibaba.excel.EasyExcel; 5 | import com.alibaba.excel.support.ExcelTypeEnum; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.apache.commons.lang3.ObjectUtils; 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.springframework.web.multipart.MultipartFile; 10 | 11 | import java.io.IOException; 12 | import java.util.LinkedHashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | import java.util.stream.Collectors; 16 | 17 | /** 18 | * Excel 相关工具类 19 | */ 20 | @Slf4j 21 | public class ExcelUtils { 22 | 23 | /** 24 | * excel 转 csv 25 | * 26 | * @param multipartFile 27 | * @return 28 | */ 29 | public static String excelToCsv(MultipartFile multipartFile) { 30 | // File file = null; 31 | // try { 32 | // file = ResourceUtils.getFile("classpath:网站数据.xlsx"); 33 | // } catch (FileNotFoundException e) { 34 | // e.printStackTrace(); 35 | // } 36 | // 读取数据 37 | List> list = null; 38 | try { 39 | list = EasyExcel.read(multipartFile.getInputStream()) 40 | .excelType(ExcelTypeEnum.XLSX) 41 | .sheet() 42 | .headRowNumber(0) 43 | .doReadSync(); 44 | } catch (IOException e) { 45 | log.error("表格处理错误", e); 46 | } 47 | if (CollUtil.isEmpty(list)) { 48 | return ""; 49 | } 50 | // 转换为 csv 51 | StringBuilder stringBuilder = new StringBuilder(); 52 | // 读取表头 53 | LinkedHashMap headerMap = (LinkedHashMap) list.get(0); 54 | List headerList = headerMap.values().stream().filter(ObjectUtils::isNotEmpty).collect(Collectors.toList()); 55 | stringBuilder.append(StringUtils.join(headerList, ",")).append("\n"); 56 | // 读取数据 57 | for (int i = 1; i < list.size(); i++) { 58 | LinkedHashMap dataMap = (LinkedHashMap) list.get(i); 59 | List dataList = dataMap.values().stream().filter(ObjectUtils::isNotEmpty).collect(Collectors.toList()); 60 | stringBuilder.append(StringUtils.join(dataList, ",")).append("\n"); 61 | } 62 | return stringBuilder.toString(); 63 | } 64 | 65 | public static void main(String[] args) { 66 | excelToCsv(null); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/java/com/niuma/binapithirdparty/utils/OrderPaySuccessMqUtils.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty.utils; 2 | 3 | import com.niuma.binapicommon.constant.RedisConstant; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.amqp.core.MessageProperties; 6 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 7 | import org.springframework.data.redis.core.RedisTemplate; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.UUID; 12 | 13 | import static com.niuma.binapicommon.constant.RabbitMqConstant.ORDER_EXCHANGE_TOPIC_NAME; 14 | import static com.niuma.binapicommon.constant.RabbitMqConstant.ORDER_SUCCESS_EXCHANGE_ROUTING_KEY; 15 | 16 | /** 17 | * @author niuma 18 | * @create 2023-05-06 10:03 19 | */ 20 | @Component 21 | @Slf4j 22 | public class OrderPaySuccessMqUtils { 23 | @Resource 24 | private RedisTemplate redisTemplate; 25 | 26 | @Resource 27 | private RabbitTemplate rabbitTemplate; 28 | 29 | private String finalId = null; 30 | 31 | 32 | /** 33 | * @param outTradeNo 我们自己的订单号 34 | */ 35 | public void sendOrderPaySuccess(String outTradeNo){ 36 | finalId = outTradeNo; 37 | redisTemplate.opsForValue().set(RedisConstant.ORDER_PAY_SUCCESS_INFO+outTradeNo,outTradeNo); 38 | String finalMessageId = UUID.randomUUID().toString(); 39 | rabbitTemplate.convertAndSend(ORDER_EXCHANGE_TOPIC_NAME,ORDER_SUCCESS_EXCHANGE_ROUTING_KEY,outTradeNo, message -> { 40 | MessageProperties messageProperties = message.getMessageProperties(); 41 | //生成全局唯一id 42 | messageProperties.setMessageId(finalMessageId); 43 | messageProperties.setContentEncoding("utf-8"); 44 | return message; 45 | }); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /binapi-third-party/src/main/resources/application-alipay.properties: -------------------------------------------------------------------------------- 1 | # APPID 2 | alipay.appId=2021000122668239 3 | alipay.privateKey=MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCRdGLd5uOSY54NPGyfrdwFI8n9S4bXXv6WNZNueYnQNXslblAo37qgyc8b+X++rBDNcf3ea/lBBrCjBtGvzAnaxGIPhO8Is0XWJPxuz7wfYx0fc2FbgGpNvY0ftjyuHMOygTeIphCq1skKuOaspDsVfSDt/mXj5N83V4GCeqfMTgG0TktJJgT5X25kba07iDnaYn2F4ut3LRycN3ZgmIWG9ZSLJo1uPRITXEL46aaQZ0G6ixO7yWbucx8pfIRmCrH4vpSxEB6nkl93rAr0lL5rcw7h5vIL/bAT0V2xFf5GqS88/RjG+6CBoEfOE9Y7wwpI2fPdKW+EjaBdmkQcBkpvAgMBAAECggEAN0XK7Bf5En/YZ582h9dBbJKVBzPUIbNvexUQ2UJGJGCuUyMAQwgBm2gU08STzpkEKY3Pst3E8fjg1pKYy/z1IbTOrqcNTnkRaLbVViaKjkLTpkfqDyNVQgVtw0c099TmaMbBm6O/YawM6Y4p2iDuctQB1258uYUXbahLBpIlgXTwXl6Dv5E0BChEI5OQulMTewwSYnhTAHdhI3ODgEzZNfUxbZGyLGcdkrS9J/k3DZi2T71IAxXp13vP6LZ8H0pHJClKefjxvp3V19jFEMalSy+O+xBJdUxMFfH+OKztmUVispPFjIMs8NVf+gbOQUR0sbH/f+EgO5I66U+Sypq2wQKBgQDIUxgW1P1hG7/DecgzTUnkm/Hn/+b2bOt7AJi1Bra42VhcrUujOLH1m1GyM2veA0wmFl/WfX+ZQQFL8KgP1UbZfKn6BhtNOovsJUY/cWw99A3g37Pfbdcc4OdqB1D15vjWMlM3cSblQ56sPi+d2NNJHae7zVsBMs1n/BYcWp6fvQKBgQC54Vi434H+Wiq5rfWcp+SN12cnQprx6C+v+FWTga443yLwnz3Y4H+T8FQV8epYOrVCiL9ZMyAkN2DO+0B2pO3iXnid7HaMRSUpK0SFbnqXzXI7of28yddJFNXX7BoAARZHhpvRDLdGrEK65mqCJrZK7sQs276j+JT61QgvDVWPmwKBgBRGXLTK3845ScJWDA4tL2Jk6inp+41LXtX3LH197XZuAQR4QaSGc3SBQNaBX9R7jvR35UFHOGfhbWkrNUdM9bvDY0y7232IhGrlJuP67dKjZdgxq/ncGx6AIMvZa7dHpj2/oC6HVEF2A5Q5QwZ90Hyg9L4MPb60TpfMqsw5274dAoGBAKp050qp1GiuwQ2DZH/jSul0Belv3+1Eki6Z2cgqHN2UalMkhK/Ut8mvkzyImvGL7Nr10ht3kdsEWaeVqrjiaC+1mICh7tiVNA272ttNw+hfg4kB9VDh+6XOEIgwwGsOlCLFYzBiq9OIdq00TanK3FJ9ALNuVDXD6MLZBuc3ICZPAoGAI0x3BNAFBHxz5uoyOw0/aOma73T6waKR5EZvHuAvlgFrO5g/LDh0igtHqXCPsYPcV7h9aVQrJP57bfc6haiUqJMkpYqeLPjoxDQFi2DTxG9RnFdGud3YcSPcubaRGLb85JJXTrk2F7DYifEdb3tkWbv/WmMI8DWBsdolVqEgNuY= 4 | alipay.publicKey=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv/4vU1kN6ohNAQ1SiGsmpzVmb0alJeMo7FQEWCxeZg5yywBPA5kKNpQFc0jUaRS/sZrqhoGPT3c0QsdvYiliRyLyb5yu/VoMD17Sa/Bnw3AoNSDOCT9qIIPf8kQqdxXOVJSmIqeGz/Il1zYvQO8G7Xw7rcpYu/LdcAGBAtuwsO6RrMPSBM97S/j/3mRIGbWq9cpmUhl+V0QCdJfHy2hePyuEVIy52/k7Pymd/hqzx3EwZtOcblaBn7LIs+7eMUrh1cuVOXg1vUN1b4yxwN92YCD9zTIAGLFdkrDzXWfAq78aovWpS0NtRxvy4I94aD5LzS9qgeIVSHoiQ0C+C5/L7QIDAQAB 5 | alipay.notifyUrl=http://dogwx.nat300.top/api/alipay/notify 6 | alipay.returnUrl=http://dogwx.nat300.top/api/alipay/notify 7 | alipay.signType=RSA2 8 | alipay.charset=utf-8 9 | alipay.gatewayUrl=https://openapi-sandbox.dl.alipaydev.com/gateway.do -------------------------------------------------------------------------------- /binapi-third-party/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #spring: 2 | # application: 3 | # name: binapi-third 4 | # cloud: 5 | # nacos: 6 | # discovery: 7 | # server-addr: localhost:8848 8 | # # DataSource Config 9 | # datasource: 10 | # driver-class-name: com.mysql.cj.jdbc.Driver 11 | # url: jdbc:mysql://localhost:3306/binapi 12 | # username: root 13 | # password: 123456 14 | # mvc: 15 | # pathmatch: 16 | # matching-strategy: ANT_PATH_MATCHER 17 | # # redis 18 | # redis: 19 | # port: 6379 20 | # host: localhost 21 | # database: 0 22 | # rabbitmq: 23 | # host: 127.0.0.1 24 | # port: 5672 25 | # publisher-confirm-type: correlated #开启发送端确认 26 | # publisher-returns: true #开启发送端消息抵达队列的确认 27 | # template: 28 | # mandatory: true #只要抵达队列,以异步发送优先回调我们这个returnsConfirm 29 | #server: 30 | # port: 8004 31 | # servlet: 32 | # context-path: /api/third 33 | #mybatis-plus: 34 | # configuration: 35 | # map-underscore-to-camel-case: false 36 | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 37 | # global-config: 38 | # db-config: 39 | # logic-delete-field: isDelete 40 | # logic-delete-value: 1 41 | # logic-not-delete-value: 0 42 | #dubbo: 43 | # application: 44 | # name: binapi-third-party-dubbo 45 | # protocol: 46 | # name: dubbo 47 | # port: -1 48 | # registry: 49 | # address: nacos://localhost:8848 50 | # # 配置namespace 51 | # parameters: 52 | # namespace: 16239c21-ac42-46bc-a4e7-690e64272f5a 53 | ##腾讯短信服务 54 | #tencent: 55 | # secretId: xxx 56 | # secretKey: xxx 57 | # sdkAppId: xxx 58 | # signName: xxx 59 | # templateId: xxx 60 | ##阿里云oss 61 | #aliyun: 62 | # oss: 63 | # file: 64 | # endpoint: oss-cn-guangzhou.aliyuncs.com 65 | # keyid: yourAccessKeyId 66 | # keysecret: yourSecret 67 | # bucketname: niumazlb -------------------------------------------------------------------------------- /binapi-third-party/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: binapi-third-party 4 | cloud: 5 | nacos: 6 | discovery: 7 | server-addr: localhost:8848 8 | config: 9 | file-extension: yaml 10 | namespace: 1ce6c2fb-611e-4d1e-834d-567340760462 11 | shared-configs[0]: 12 | dataId: db.yaml 13 | refresh: true 14 | shared-configs[1]: 15 | dataId: rabbitmq.yaml 16 | refresh: true 17 | shared-configs[2]: 18 | dataId: dubbo.yaml 19 | refresh: true 20 | shared-configs[3]: 21 | dataId: sentinel-dev.yaml 22 | refresh: true 23 | profiles: 24 | active: dev 25 | 26 | yuapi: 27 | client: 28 | access-key: xxx 29 | secret-key: xxx -------------------------------------------------------------------------------- /binapi-third-party/src/main/resources/mapper/AlipayInfoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | orderNumber,subject,totalAmount, 20 | buyerPayAmount,buyerId,tradeNo, 21 | tradeStatus,gmtPayment 22 | 23 | 24 | -------------------------------------------------------------------------------- /binapi-third-party/src/test/java/com/niuma/binapithirdparty/BinapiThirdPartyApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BinapiThirdPartyApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /binapi-third-party/src/test/java/com/niuma/binapithirdparty/YuCongMingTest.java: -------------------------------------------------------------------------------- 1 | package com.niuma.binapithirdparty; 2 | 3 | import com.yupi.yucongming.dev.client.YuCongMingClient; 4 | import com.yupi.yucongming.dev.common.BaseResponse; 5 | import com.yupi.yucongming.dev.model.DevChatRequest; 6 | import com.yupi.yucongming.dev.model.DevChatResponse; 7 | import org.junit.jupiter.api.Test; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | import javax.annotation.Resource; 11 | 12 | /** 13 | * @author niuma 14 | * @create 2023-05-29 22:06 15 | */ 16 | @SpringBootTest 17 | public class YuCongMingTest { 18 | @Resource 19 | YuCongMingClient yuCongMingClient; 20 | 21 | @Test 22 | public void testChat(){ 23 | DevChatRequest request = new DevChatRequest(); 24 | request.setModelId(1654785040361893889L); 25 | request.setMessage("你是?"); 26 | BaseResponse devChatResponseBaseResponse = 27 | yuCongMingClient.doChat(request); 28 | System.out.println(devChatResponseBaseResponse.getData().getContent()); 29 | //我是一个AI语言模型,可以热心地回答用户的各种问题。 30 | } 31 | 32 | } 33 | --------------------------------------------------------------------------------