@reglow/reglow 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/reglow/common/errors.d.ts +92 -0
- package/dist/reglow/common/errors.js +127 -0
- package/dist/reglow/common/errors.js.map +1 -0
- package/dist/reglow/common/exception_handler.d.ts +14 -0
- package/dist/reglow/common/exception_handler.js +135 -0
- package/dist/reglow/common/exception_handler.js.map +1 -0
- package/dist/reglow/common/i18n.d.ts +15 -0
- package/dist/reglow/common/i18n.js +61 -0
- package/dist/reglow/common/i18n.js.map +1 -0
- package/dist/reglow/common/middleware.d.ts +5 -0
- package/dist/reglow/common/middleware.js +131 -0
- package/dist/reglow/common/middleware.js.map +1 -0
- package/dist/reglow/common/response.d.ts +28 -0
- package/dist/reglow/common/response.js +42 -0
- package/dist/reglow/common/response.js.map +1 -0
- package/dist/reglow/common/serialize.d.ts +6 -0
- package/dist/reglow/common/serialize.js +39 -0
- package/dist/reglow/common/serialize.js.map +1 -0
- package/dist/reglow/common/utils/date_utils.d.ts +10 -0
- package/dist/reglow/common/utils/date_utils.js +30 -0
- package/dist/reglow/common/utils/date_utils.js.map +1 -0
- package/dist/reglow/common/utils/parse-user-agent.d.ts +11 -0
- package/dist/reglow/common/utils/parse-user-agent.js +80 -0
- package/dist/reglow/common/utils/parse-user-agent.js.map +1 -0
- package/dist/reglow/common/utils/string_utils.d.ts +14 -0
- package/dist/reglow/common/utils/string_utils.js +31 -0
- package/dist/reglow/common/utils/string_utils.js.map +1 -0
- package/dist/reglow/core/auth.d.ts +15 -0
- package/dist/reglow/core/auth.js +184 -0
- package/dist/reglow/core/auth.js.map +1 -0
- package/dist/reglow/core/cache.d.ts +6 -0
- package/dist/reglow/core/cache.js +15 -0
- package/dist/reglow/core/cache.js.map +1 -0
- package/dist/reglow/core/config.d.ts +45 -0
- package/dist/reglow/core/config.js +83 -0
- package/dist/reglow/core/config.js.map +1 -0
- package/dist/reglow/core/data_scope.d.ts +21 -0
- package/dist/reglow/core/data_scope.js +20 -0
- package/dist/reglow/core/data_scope.js.map +1 -0
- package/dist/reglow/core/database.d.ts +4 -0
- package/dist/reglow/core/database.js +43 -0
- package/dist/reglow/core/database.js.map +1 -0
- package/dist/reglow/core/email.d.ts +12 -0
- package/dist/reglow/core/email.js +277 -0
- package/dist/reglow/core/email.js.map +1 -0
- package/dist/reglow/core/entities.d.ts +462 -0
- package/dist/reglow/core/entities.js +6 -0
- package/dist/reglow/core/entities.js.map +1 -0
- package/dist/reglow/core/fastify.d.ts +21 -0
- package/dist/reglow/core/fastify.js +2 -0
- package/dist/reglow/core/fastify.js.map +1 -0
- package/dist/reglow/core/logging.d.ts +8 -0
- package/dist/reglow/core/logging.js +32 -0
- package/dist/reglow/core/logging.js.map +1 -0
- package/dist/reglow/core/models.d.ts +98 -0
- package/dist/reglow/core/models.js +57 -0
- package/dist/reglow/core/models.js.map +1 -0
- package/dist/reglow/core/observability.d.ts +17 -0
- package/dist/reglow/core/observability.js +92 -0
- package/dist/reglow/core/observability.js.map +1 -0
- package/dist/reglow/core/payment.d.ts +107 -0
- package/dist/reglow/core/payment.js +1177 -0
- package/dist/reglow/core/payment.js.map +1 -0
- package/dist/reglow/core/plugin.d.ts +19 -0
- package/dist/reglow/core/plugin.js +85 -0
- package/dist/reglow/core/plugin.js.map +1 -0
- package/dist/reglow/core/rate_limit.d.ts +2 -0
- package/dist/reglow/core/rate_limit.js +28 -0
- package/dist/reglow/core/rate_limit.js.map +1 -0
- package/dist/reglow/core/redis.d.ts +30 -0
- package/dist/reglow/core/redis.js +278 -0
- package/dist/reglow/core/redis.js.map +1 -0
- package/dist/reglow/core/redis_keys.d.ts +22 -0
- package/dist/reglow/core/redis_keys.js +59 -0
- package/dist/reglow/core/redis_keys.js.map +1 -0
- package/dist/reglow/core/security.d.ts +25 -0
- package/dist/reglow/core/security.js +64 -0
- package/dist/reglow/core/security.js.map +1 -0
- package/dist/reglow/core/session.d.ts +17 -0
- package/dist/reglow/core/session.js +194 -0
- package/dist/reglow/core/session.js.map +1 -0
- package/dist/reglow/core/sms.d.ts +19 -0
- package/dist/reglow/core/sms.js +33 -0
- package/dist/reglow/core/sms.js.map +1 -0
- package/dist/reglow/core/storage.d.ts +45 -0
- package/dist/reglow/core/storage.js +249 -0
- package/dist/reglow/core/storage.js.map +1 -0
- package/dist/reglow/modules/agreement/controller.d.ts +7 -0
- package/dist/reglow/modules/agreement/controller.js +242 -0
- package/dist/reglow/modules/agreement/controller.js.map +1 -0
- package/dist/reglow/modules/agreement/repository.d.ts +30 -0
- package/dist/reglow/modules/agreement/repository.js +160 -0
- package/dist/reglow/modules/agreement/repository.js.map +1 -0
- package/dist/reglow/modules/agreement/router.d.ts +13 -0
- package/dist/reglow/modules/agreement/router.js +10 -0
- package/dist/reglow/modules/agreement/router.js.map +1 -0
- package/dist/reglow/modules/agreement/schema.d.ts +30 -0
- package/dist/reglow/modules/agreement/schema.js +27 -0
- package/dist/reglow/modules/agreement/schema.js.map +1 -0
- package/dist/reglow/modules/agreement/service.d.ts +42 -0
- package/dist/reglow/modules/agreement/service.js +349 -0
- package/dist/reglow/modules/agreement/service.js.map +1 -0
- package/dist/reglow/modules/ai/controller.d.ts +25 -0
- package/dist/reglow/modules/ai/controller.js +1143 -0
- package/dist/reglow/modules/ai/controller.js.map +1 -0
- package/dist/reglow/modules/ai/router.d.ts +9 -0
- package/dist/reglow/modules/ai/router.js +7 -0
- package/dist/reglow/modules/ai/router.js.map +1 -0
- package/dist/reglow/modules/ai/schema.d.ts +48 -0
- package/dist/reglow/modules/ai/schema.js +40 -0
- package/dist/reglow/modules/ai/schema.js.map +1 -0
- package/dist/reglow/modules/ai/service.d.ts +8 -0
- package/dist/reglow/modules/ai/service.js +137 -0
- package/dist/reglow/modules/ai/service.js.map +1 -0
- package/dist/reglow/modules/article/controller.d.ts +6 -0
- package/dist/reglow/modules/article/controller.js +204 -0
- package/dist/reglow/modules/article/controller.js.map +1 -0
- package/dist/reglow/modules/article/repository.d.ts +37 -0
- package/dist/reglow/modules/article/repository.js +184 -0
- package/dist/reglow/modules/article/repository.js.map +1 -0
- package/dist/reglow/modules/article/router.d.ts +10 -0
- package/dist/reglow/modules/article/router.js +8 -0
- package/dist/reglow/modules/article/router.js.map +1 -0
- package/dist/reglow/modules/article/schema.d.ts +66 -0
- package/dist/reglow/modules/article/schema.js +66 -0
- package/dist/reglow/modules/article/schema.js.map +1 -0
- package/dist/reglow/modules/article/service.d.ts +81 -0
- package/dist/reglow/modules/article/service.js +254 -0
- package/dist/reglow/modules/article/service.js.map +1 -0
- package/dist/reglow/modules/auth/controller.d.ts +6 -0
- package/dist/reglow/modules/auth/controller.js +127 -0
- package/dist/reglow/modules/auth/controller.js.map +1 -0
- package/dist/reglow/modules/auth/router.d.ts +9 -0
- package/dist/reglow/modules/auth/router.js +7 -0
- package/dist/reglow/modules/auth/router.js.map +1 -0
- package/dist/reglow/modules/auth/schema.d.ts +59 -0
- package/dist/reglow/modules/auth/schema.js +56 -0
- package/dist/reglow/modules/auth/schema.js.map +1 -0
- package/dist/reglow/modules/auth/service.d.ts +69 -0
- package/dist/reglow/modules/auth/service.js +492 -0
- package/dist/reglow/modules/auth/service.js.map +1 -0
- package/dist/reglow/modules/config/controller.d.ts +7 -0
- package/dist/reglow/modules/config/controller.js +297 -0
- package/dist/reglow/modules/config/controller.js.map +1 -0
- package/dist/reglow/modules/config/repository.d.ts +17 -0
- package/dist/reglow/modules/config/repository.js +88 -0
- package/dist/reglow/modules/config/repository.js.map +1 -0
- package/dist/reglow/modules/config/router.d.ts +13 -0
- package/dist/reglow/modules/config/router.js +8 -0
- package/dist/reglow/modules/config/router.js.map +1 -0
- package/dist/reglow/modules/config/schema.d.ts +37 -0
- package/dist/reglow/modules/config/schema.js +25 -0
- package/dist/reglow/modules/config/schema.js.map +1 -0
- package/dist/reglow/modules/customer_service/controller.d.ts +3 -0
- package/dist/reglow/modules/customer_service/controller.js +443 -0
- package/dist/reglow/modules/customer_service/controller.js.map +1 -0
- package/dist/reglow/modules/customer_service/document_parser.d.ts +5 -0
- package/dist/reglow/modules/customer_service/document_parser.js +84 -0
- package/dist/reglow/modules/customer_service/document_parser.js.map +1 -0
- package/dist/reglow/modules/customer_service/repository.d.ts +72 -0
- package/dist/reglow/modules/customer_service/repository.js +376 -0
- package/dist/reglow/modules/customer_service/repository.js.map +1 -0
- package/dist/reglow/modules/customer_service/router.d.ts +14 -0
- package/dist/reglow/modules/customer_service/router.js +9 -0
- package/dist/reglow/modules/customer_service/router.js.map +1 -0
- package/dist/reglow/modules/customer_service/schema.d.ts +97 -0
- package/dist/reglow/modules/customer_service/schema.js +91 -0
- package/dist/reglow/modules/customer_service/schema.js.map +1 -0
- package/dist/reglow/modules/customer_service/sdk_template.html +666 -0
- package/dist/reglow/modules/customer_service/service.d.ts +92 -0
- package/dist/reglow/modules/customer_service/service.js +1642 -0
- package/dist/reglow/modules/customer_service/service.js.map +1 -0
- package/dist/reglow/modules/customer_service/ws.d.ts +29 -0
- package/dist/reglow/modules/customer_service/ws.js +182 -0
- package/dist/reglow/modules/customer_service/ws.js.map +1 -0
- package/dist/reglow/modules/dept/controller.d.ts +6 -0
- package/dist/reglow/modules/dept/controller.js +122 -0
- package/dist/reglow/modules/dept/controller.js.map +1 -0
- package/dist/reglow/modules/dept/repository.d.ts +24 -0
- package/dist/reglow/modules/dept/repository.js +140 -0
- package/dist/reglow/modules/dept/repository.js.map +1 -0
- package/dist/reglow/modules/dept/router.d.ts +9 -0
- package/dist/reglow/modules/dept/router.js +7 -0
- package/dist/reglow/modules/dept/router.js.map +1 -0
- package/dist/reglow/modules/dept/schema.d.ts +37 -0
- package/dist/reglow/modules/dept/schema.js +33 -0
- package/dist/reglow/modules/dept/schema.js.map +1 -0
- package/dist/reglow/modules/dept/service.d.ts +33 -0
- package/dist/reglow/modules/dept/service.js +88 -0
- package/dist/reglow/modules/dept/service.js.map +1 -0
- package/dist/reglow/modules/dict/controller.d.ts +5 -0
- package/dist/reglow/modules/dict/controller.js +87 -0
- package/dist/reglow/modules/dict/controller.js.map +1 -0
- package/dist/reglow/modules/dict/model.d.ts +7 -0
- package/dist/reglow/modules/dict/model.js +8 -0
- package/dist/reglow/modules/dict/model.js.map +1 -0
- package/dist/reglow/modules/dict/repository.d.ts +16 -0
- package/dist/reglow/modules/dict/repository.js +103 -0
- package/dist/reglow/modules/dict/repository.js.map +1 -0
- package/dist/reglow/modules/dict/router.d.ts +9 -0
- package/dist/reglow/modules/dict/router.js +7 -0
- package/dist/reglow/modules/dict/router.js.map +1 -0
- package/dist/reglow/modules/dict/schema.d.ts +38 -0
- package/dist/reglow/modules/dict/schema.js +37 -0
- package/dist/reglow/modules/dict/schema.js.map +1 -0
- package/dist/reglow/modules/dict/service.d.ts +15 -0
- package/dist/reglow/modules/dict/service.js +88 -0
- package/dist/reglow/modules/dict/service.js.map +1 -0
- package/dist/reglow/modules/employee/controller.d.ts +6 -0
- package/dist/reglow/modules/employee/controller.js +167 -0
- package/dist/reglow/modules/employee/controller.js.map +1 -0
- package/dist/reglow/modules/employee/repository.d.ts +22 -0
- package/dist/reglow/modules/employee/repository.js +129 -0
- package/dist/reglow/modules/employee/repository.js.map +1 -0
- package/dist/reglow/modules/employee/router.d.ts +9 -0
- package/dist/reglow/modules/employee/router.js +7 -0
- package/dist/reglow/modules/employee/router.js.map +1 -0
- package/dist/reglow/modules/employee/schema.d.ts +57 -0
- package/dist/reglow/modules/employee/schema.js +58 -0
- package/dist/reglow/modules/employee/schema.js.map +1 -0
- package/dist/reglow/modules/employee/service.d.ts +30 -0
- package/dist/reglow/modules/employee/service.js +193 -0
- package/dist/reglow/modules/employee/service.js.map +1 -0
- package/dist/reglow/modules/log/controller.d.ts +6 -0
- package/dist/reglow/modules/log/controller.js +137 -0
- package/dist/reglow/modules/log/controller.js.map +1 -0
- package/dist/reglow/modules/log/data-scope.d.ts +9 -0
- package/dist/reglow/modules/log/data-scope.js +108 -0
- package/dist/reglow/modules/log/data-scope.js.map +1 -0
- package/dist/reglow/modules/log/router.d.ts +9 -0
- package/dist/reglow/modules/log/router.js +7 -0
- package/dist/reglow/modules/log/router.js.map +1 -0
- package/dist/reglow/modules/material/controller.d.ts +3 -0
- package/dist/reglow/modules/material/controller.js +400 -0
- package/dist/reglow/modules/material/controller.js.map +1 -0
- package/dist/reglow/modules/material/repository.d.ts +37 -0
- package/dist/reglow/modules/material/repository.js +183 -0
- package/dist/reglow/modules/material/repository.js.map +1 -0
- package/dist/reglow/modules/material/router.d.ts +14 -0
- package/dist/reglow/modules/material/router.js +11 -0
- package/dist/reglow/modules/material/router.js.map +1 -0
- package/dist/reglow/modules/material/schema.d.ts +40 -0
- package/dist/reglow/modules/material/schema.js +34 -0
- package/dist/reglow/modules/material/schema.js.map +1 -0
- package/dist/reglow/modules/material/service.d.ts +85 -0
- package/dist/reglow/modules/material/service.js +292 -0
- package/dist/reglow/modules/material/service.js.map +1 -0
- package/dist/reglow/modules/menu/controller.d.ts +6 -0
- package/dist/reglow/modules/menu/controller.js +69 -0
- package/dist/reglow/modules/menu/controller.js.map +1 -0
- package/dist/reglow/modules/menu/repository.d.ts +14 -0
- package/dist/reglow/modules/menu/repository.js +37 -0
- package/dist/reglow/modules/menu/repository.js.map +1 -0
- package/dist/reglow/modules/menu/router.d.ts +9 -0
- package/dist/reglow/modules/menu/router.js +7 -0
- package/dist/reglow/modules/menu/router.js.map +1 -0
- package/dist/reglow/modules/menu/schema.d.ts +39 -0
- package/dist/reglow/modules/menu/schema.js +37 -0
- package/dist/reglow/modules/menu/schema.js.map +1 -0
- package/dist/reglow/modules/menu/service.d.ts +31 -0
- package/dist/reglow/modules/menu/service.js +89 -0
- package/dist/reglow/modules/menu/service.js.map +1 -0
- package/dist/reglow/modules/message/controller.d.ts +7 -0
- package/dist/reglow/modules/message/controller.js +260 -0
- package/dist/reglow/modules/message/controller.js.map +1 -0
- package/dist/reglow/modules/message/repository.d.ts +27 -0
- package/dist/reglow/modules/message/repository.js +145 -0
- package/dist/reglow/modules/message/repository.js.map +1 -0
- package/dist/reglow/modules/message/router.d.ts +13 -0
- package/dist/reglow/modules/message/router.js +8 -0
- package/dist/reglow/modules/message/router.js.map +1 -0
- package/dist/reglow/modules/message/schema.d.ts +39 -0
- package/dist/reglow/modules/message/schema.js +37 -0
- package/dist/reglow/modules/message/schema.js.map +1 -0
- package/dist/reglow/modules/message/service.d.ts +70 -0
- package/dist/reglow/modules/message/service.js +199 -0
- package/dist/reglow/modules/message/service.js.map +1 -0
- package/dist/reglow/modules/notice/controller.d.ts +6 -0
- package/dist/reglow/modules/notice/controller.js +123 -0
- package/dist/reglow/modules/notice/controller.js.map +1 -0
- package/dist/reglow/modules/notice/repository.d.ts +25 -0
- package/dist/reglow/modules/notice/repository.js +145 -0
- package/dist/reglow/modules/notice/repository.js.map +1 -0
- package/dist/reglow/modules/notice/router.d.ts +9 -0
- package/dist/reglow/modules/notice/router.js +7 -0
- package/dist/reglow/modules/notice/router.js.map +1 -0
- package/dist/reglow/modules/notice/schema.d.ts +23 -0
- package/dist/reglow/modules/notice/schema.js +22 -0
- package/dist/reglow/modules/notice/schema.js.map +1 -0
- package/dist/reglow/modules/notice/service.d.ts +45 -0
- package/dist/reglow/modules/notice/service.js +149 -0
- package/dist/reglow/modules/notice/service.js.map +1 -0
- package/dist/reglow/modules/payment/controller.d.ts +6 -0
- package/dist/reglow/modules/payment/controller.js +186 -0
- package/dist/reglow/modules/payment/controller.js.map +1 -0
- package/dist/reglow/modules/payment/router.d.ts +10 -0
- package/dist/reglow/modules/payment/router.js +8 -0
- package/dist/reglow/modules/payment/router.js.map +1 -0
- package/dist/reglow/modules/payment/schema.d.ts +52 -0
- package/dist/reglow/modules/payment/schema.js +43 -0
- package/dist/reglow/modules/payment/schema.js.map +1 -0
- package/dist/reglow/modules/payment/service.d.ts +28 -0
- package/dist/reglow/modules/payment/service.js +219 -0
- package/dist/reglow/modules/payment/service.js.map +1 -0
- package/dist/reglow/modules/photo/controller.d.ts +2 -0
- package/dist/reglow/modules/photo/controller.js +323 -0
- package/dist/reglow/modules/photo/controller.js.map +1 -0
- package/dist/reglow/modules/photo/controller_client.d.ts +2 -0
- package/dist/reglow/modules/photo/controller_client.js +293 -0
- package/dist/reglow/modules/photo/controller_client.js.map +1 -0
- package/dist/reglow/modules/photo/repository.d.ts +50 -0
- package/dist/reglow/modules/photo/repository.js +240 -0
- package/dist/reglow/modules/photo/repository.js.map +1 -0
- package/dist/reglow/modules/photo/router.d.ts +15 -0
- package/dist/reglow/modules/photo/router.js +10 -0
- package/dist/reglow/modules/photo/router.js.map +1 -0
- package/dist/reglow/modules/photo/schema.d.ts +69 -0
- package/dist/reglow/modules/photo/schema.js +66 -0
- package/dist/reglow/modules/photo/schema.js.map +1 -0
- package/dist/reglow/modules/photo/service.d.ts +98 -0
- package/dist/reglow/modules/photo/service.js +295 -0
- package/dist/reglow/modules/photo/service.js.map +1 -0
- package/dist/reglow/modules/post/controller.d.ts +6 -0
- package/dist/reglow/modules/post/controller.js +61 -0
- package/dist/reglow/modules/post/controller.js.map +1 -0
- package/dist/reglow/modules/post/repository.d.ts +12 -0
- package/dist/reglow/modules/post/repository.js +46 -0
- package/dist/reglow/modules/post/repository.js.map +1 -0
- package/dist/reglow/modules/post/router.d.ts +9 -0
- package/dist/reglow/modules/post/router.js +7 -0
- package/dist/reglow/modules/post/router.js.map +1 -0
- package/dist/reglow/modules/post/schema.d.ts +19 -0
- package/dist/reglow/modules/post/schema.js +18 -0
- package/dist/reglow/modules/post/schema.js.map +1 -0
- package/dist/reglow/modules/post/service.d.ts +18 -0
- package/dist/reglow/modules/post/service.js +44 -0
- package/dist/reglow/modules/post/service.js.map +1 -0
- package/dist/reglow/modules/role/controller.d.ts +6 -0
- package/dist/reglow/modules/role/controller.js +103 -0
- package/dist/reglow/modules/role/controller.js.map +1 -0
- package/dist/reglow/modules/role/repository.d.ts +22 -0
- package/dist/reglow/modules/role/repository.js +84 -0
- package/dist/reglow/modules/role/repository.js.map +1 -0
- package/dist/reglow/modules/role/router.d.ts +9 -0
- package/dist/reglow/modules/role/router.js +7 -0
- package/dist/reglow/modules/role/router.js.map +1 -0
- package/dist/reglow/modules/role/schema.d.ts +32 -0
- package/dist/reglow/modules/role/schema.js +29 -0
- package/dist/reglow/modules/role/schema.js.map +1 -0
- package/dist/reglow/modules/role/service.d.ts +22 -0
- package/dist/reglow/modules/role/service.js +72 -0
- package/dist/reglow/modules/role/service.js.map +1 -0
- package/dist/reglow/modules/user/controller.d.ts +6 -0
- package/dist/reglow/modules/user/controller.js +126 -0
- package/dist/reglow/modules/user/controller.js.map +1 -0
- package/dist/reglow/modules/user/controller_client.d.ts +2 -0
- package/dist/reglow/modules/user/controller_client.js +291 -0
- package/dist/reglow/modules/user/controller_client.js.map +1 -0
- package/dist/reglow/modules/user/repository.d.ts +12 -0
- package/dist/reglow/modules/user/repository.js +71 -0
- package/dist/reglow/modules/user/repository.js.map +1 -0
- package/dist/reglow/modules/user/router.d.ts +16 -0
- package/dist/reglow/modules/user/router.js +11 -0
- package/dist/reglow/modules/user/router.js.map +1 -0
- package/dist/reglow/modules/user/schema.d.ts +92 -0
- package/dist/reglow/modules/user/schema.js +82 -0
- package/dist/reglow/modules/user/schema.js.map +1 -0
- package/dist/reglow/modules/user/service.d.ts +43 -0
- package/dist/reglow/modules/user/service.js +311 -0
- package/dist/reglow/modules/user/service.js.map +1 -0
- package/dist/reglow/modules/video/controller.d.ts +2 -0
- package/dist/reglow/modules/video/controller.js +254 -0
- package/dist/reglow/modules/video/controller.js.map +1 -0
- package/dist/reglow/modules/video/repository.d.ts +38 -0
- package/dist/reglow/modules/video/repository.js +186 -0
- package/dist/reglow/modules/video/repository.js.map +1 -0
- package/dist/reglow/modules/video/router.d.ts +10 -0
- package/dist/reglow/modules/video/router.js +8 -0
- package/dist/reglow/modules/video/router.js.map +1 -0
- package/dist/reglow/modules/video/schema.d.ts +62 -0
- package/dist/reglow/modules/video/schema.js +61 -0
- package/dist/reglow/modules/video/schema.js.map +1 -0
- package/dist/reglow/modules/video/service.d.ts +80 -0
- package/dist/reglow/modules/video/service.js +251 -0
- package/dist/reglow/modules/video/service.js.map +1 -0
- package/dist/reglow/scripts/init-data.d.ts +44 -0
- package/dist/reglow/scripts/init-data.js +472 -0
- package/dist/reglow/scripts/init-data.js.map +1 -0
- package/dist/reglow/scripts/remove-business-menu.d.ts +1 -0
- package/dist/reglow/scripts/remove-business-menu.js +124 -0
- package/dist/reglow/scripts/remove-business-menu.js.map +1 -0
- package/dist/reglow/scripts/schema.d.ts +9 -0
- package/dist/reglow/scripts/schema.js +746 -0
- package/dist/reglow/scripts/schema.js.map +1 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.d.ts +1 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.js +304 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +162 -0
- package/dist/server.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,1177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 支付 Provider 抽象层
|
|
3
|
+
* 对应 backend-python 的 reglow/core/payment.py
|
|
4
|
+
*
|
|
5
|
+
* 支持: wechat(V3) / alipay(RSA2) / unionpay(ACP) / mock
|
|
6
|
+
* 基于 Node 内置 crypto(RSA-SHA256 / AES-256-GCM)与 fetch 实现,无外部 SDK 依赖。
|
|
7
|
+
*/
|
|
8
|
+
import { createPrivateKey, createPublicKey, sign as cryptoSign, verify as cryptoVerify, createDecipheriv, } from "node:crypto";
|
|
9
|
+
import { knex } from "./database.js";
|
|
10
|
+
import { ModelRegistry } from "./models.js";
|
|
11
|
+
function emptyResult() {
|
|
12
|
+
return {
|
|
13
|
+
success: false,
|
|
14
|
+
msg: "",
|
|
15
|
+
qrCode: "",
|
|
16
|
+
tradeNo: "",
|
|
17
|
+
outTradeNo: "",
|
|
18
|
+
payParams: {},
|
|
19
|
+
raw: {},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
// ─── RSA / 加解密工具 ───
|
|
23
|
+
function loadPrivateKey(keyStr) {
|
|
24
|
+
const s = keyStr.trim();
|
|
25
|
+
if (s.includes("BEGIN"))
|
|
26
|
+
return createPrivateKey(s);
|
|
27
|
+
for (const header of ["RSA PRIVATE KEY", "PRIVATE KEY"]) {
|
|
28
|
+
try {
|
|
29
|
+
return createPrivateKey(`-----BEGIN ${header}-----\n${s}\n-----END ${header}-----`);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
/* 继续尝试 */
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw new Error("私钥格式无法识别,请提供 PEM 格式或 PKCS#1/PKCS#8 base64");
|
|
36
|
+
}
|
|
37
|
+
function loadPublicKey(keyStr) {
|
|
38
|
+
const s = keyStr.trim();
|
|
39
|
+
if (s.includes("BEGIN"))
|
|
40
|
+
return createPublicKey(s);
|
|
41
|
+
return createPublicKey(`-----BEGIN PUBLIC KEY-----\n${s}\n-----END PUBLIC KEY-----`);
|
|
42
|
+
}
|
|
43
|
+
function rsaSign(privateKeyPem, data) {
|
|
44
|
+
return cryptoSign("RSA-SHA256", Buffer.from(data, "utf-8"), loadPrivateKey(privateKeyPem)).toString("base64");
|
|
45
|
+
}
|
|
46
|
+
function rsaVerify(publicKeyPem, data, signatureB64) {
|
|
47
|
+
try {
|
|
48
|
+
return cryptoVerify("RSA-SHA256", Buffer.from(data, "utf-8"), loadPublicKey(publicKeyPem), Buffer.from(signatureB64, "base64"));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function rsaSignWithKey(key, data) {
|
|
55
|
+
return cryptoSign("RSA-SHA256", Buffer.from(data, "utf-8"), key).toString("base64");
|
|
56
|
+
}
|
|
57
|
+
function rsaVerifyWithKey(key, data, signatureB64) {
|
|
58
|
+
try {
|
|
59
|
+
return cryptoVerify("RSA-SHA256", Buffer.from(data, "utf-8"), key, Buffer.from(signatureB64, "base64"));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function loadPkcs12PrivateKey(certBase64, _password) {
|
|
66
|
+
// node:crypto 不支持直接解析 PKCS12,需先转换为 PEM 私钥
|
|
67
|
+
const text = Buffer.from(certBase64, "base64").toString("utf-8");
|
|
68
|
+
if (text.includes("BEGIN"))
|
|
69
|
+
return createPrivateKey(text);
|
|
70
|
+
throw new Error("银联 PKCS12 证书需先转换为 PEM 私钥(node:crypto 不支持直接解析 PKCS12)");
|
|
71
|
+
}
|
|
72
|
+
function aesGcmDecrypt(key, nonce, ciphertextWithTag, aad) {
|
|
73
|
+
const tag = ciphertextWithTag.subarray(-16);
|
|
74
|
+
const ciphertext = ciphertextWithTag.subarray(0, -16);
|
|
75
|
+
const decipher = createDecipheriv("aes-256-gcm", key, nonce);
|
|
76
|
+
decipher.setAuthTag(tag);
|
|
77
|
+
if (aad && aad.length)
|
|
78
|
+
decipher.setAAD(aad);
|
|
79
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
80
|
+
}
|
|
81
|
+
function nonce() {
|
|
82
|
+
return Array.from({ length: 32 }, () => "abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random() * 36))).join("");
|
|
83
|
+
}
|
|
84
|
+
function ts() {
|
|
85
|
+
return String(Math.floor(Date.now() / 1000));
|
|
86
|
+
}
|
|
87
|
+
function parseForm(body) {
|
|
88
|
+
const params = new URLSearchParams(body);
|
|
89
|
+
const out = {};
|
|
90
|
+
for (const [k, v] of params.entries())
|
|
91
|
+
out[k] = v;
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
// ─── Provider 基类 ───
|
|
95
|
+
export class PaymentProvider {
|
|
96
|
+
provider_name = "base";
|
|
97
|
+
async createTradeByPlatform(outTradeNo, amountCents, subject, notifyUrl, _platform = "web", _openid = "", _buyerId = "", _payerIp = "") {
|
|
98
|
+
return this.createTrade(outTradeNo, amountCents, subject, notifyUrl);
|
|
99
|
+
}
|
|
100
|
+
successResponse() {
|
|
101
|
+
return "success";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// ─── Mock Provider ───
|
|
105
|
+
export class MockPaymentProvider extends PaymentProvider {
|
|
106
|
+
provider_name = "mock";
|
|
107
|
+
async createTrade(outTradeNo, amountCents, _subject, _notifyUrl) {
|
|
108
|
+
return {
|
|
109
|
+
success: true,
|
|
110
|
+
msg: "mock 支付订单已创建",
|
|
111
|
+
qrCode: `mock://pay?out_trade_no=${outTradeNo}&amount=${amountCents}`,
|
|
112
|
+
tradeNo: "",
|
|
113
|
+
outTradeNo,
|
|
114
|
+
payParams: {},
|
|
115
|
+
raw: {},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async createTradeByPlatform(outTradeNo, amountCents, subject, notifyUrl, platform = "web") {
|
|
119
|
+
if (platform === "web") {
|
|
120
|
+
return this.createTrade(outTradeNo, amountCents, subject, notifyUrl);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
msg: `mock ${platform} 订单已创建`,
|
|
125
|
+
qrCode: "",
|
|
126
|
+
tradeNo: "",
|
|
127
|
+
outTradeNo,
|
|
128
|
+
payParams: {
|
|
129
|
+
platform,
|
|
130
|
+
mock: true,
|
|
131
|
+
timeStamp: ts(),
|
|
132
|
+
nonceStr: "mock_nonce",
|
|
133
|
+
package: `prepay_id=mock_${outTradeNo}`,
|
|
134
|
+
signType: "RSA",
|
|
135
|
+
paySign: "mock_sign",
|
|
136
|
+
orderInfo: `mock_trade_string_${outTradeNo}`,
|
|
137
|
+
},
|
|
138
|
+
raw: {},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async queryTrade(outTradeNo) {
|
|
142
|
+
return {
|
|
143
|
+
success: true,
|
|
144
|
+
msg: "mock 订单已支付",
|
|
145
|
+
qrCode: "",
|
|
146
|
+
tradeNo: `mock_${outTradeNo}`,
|
|
147
|
+
outTradeNo,
|
|
148
|
+
payParams: {},
|
|
149
|
+
raw: {},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async verifyCallback(_headers, body) {
|
|
153
|
+
const data = body.length ? JSON.parse(body.toString("utf-8")) : {};
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
outTradeNo: data.out_trade_no || "",
|
|
157
|
+
tradeNo: data.trade_no || `mock_${data.out_trade_no || ""}`,
|
|
158
|
+
amount: data.amount || 0,
|
|
159
|
+
status: "paid",
|
|
160
|
+
msg: "",
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// ─── 支付宝 Provider ───
|
|
165
|
+
export class AlipayProvider extends PaymentProvider {
|
|
166
|
+
provider_name = "alipay";
|
|
167
|
+
appId;
|
|
168
|
+
appPrivateKey;
|
|
169
|
+
alipayPublicKey;
|
|
170
|
+
gateway;
|
|
171
|
+
notifyUrl;
|
|
172
|
+
returnUrl;
|
|
173
|
+
constructor(config) {
|
|
174
|
+
super();
|
|
175
|
+
this.appId = config["alipay_app_id"] || "";
|
|
176
|
+
this.appPrivateKey = config["alipay_app_private_key"] || "";
|
|
177
|
+
this.alipayPublicKey = config["alipay_alipay_public_key"] || "";
|
|
178
|
+
this.gateway =
|
|
179
|
+
config["alipay_gateway"] || "https://openapi.alipay.com/gateway.do";
|
|
180
|
+
this.notifyUrl = config["alipay_notify_url"] || "";
|
|
181
|
+
this.returnUrl = config["alipay_return_url"] || "";
|
|
182
|
+
if (!this.appId || !this.appPrivateKey || !this.alipayPublicKey) {
|
|
183
|
+
throw new Error("支付宝配置不完整:需要 app_id, app_private_key, alipay_public_key");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
signParams(params) {
|
|
187
|
+
const query = Object.entries(params)
|
|
188
|
+
.filter(([, v]) => v)
|
|
189
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
190
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
191
|
+
.join("&");
|
|
192
|
+
return rsaSign(this.appPrivateKey, query);
|
|
193
|
+
}
|
|
194
|
+
verifyParams(params, sign) {
|
|
195
|
+
const query = Object.entries(params)
|
|
196
|
+
.filter(([k, v]) => k !== "sign" && k !== "sign_type" && v)
|
|
197
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
198
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
199
|
+
.join("&");
|
|
200
|
+
return rsaVerify(this.alipayPublicKey, query, sign);
|
|
201
|
+
}
|
|
202
|
+
async alipayPost(params) {
|
|
203
|
+
const sendParams = Object.fromEntries(Object.entries(params).filter(([k]) => k !== "charset"));
|
|
204
|
+
const url = `${this.gateway}?charset=utf-8`;
|
|
205
|
+
const body = new URLSearchParams(sendParams);
|
|
206
|
+
const resp = await fetch(url, {
|
|
207
|
+
method: "POST",
|
|
208
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
209
|
+
body,
|
|
210
|
+
});
|
|
211
|
+
return resp.text();
|
|
212
|
+
}
|
|
213
|
+
async callAlipay(method, bizContent, notifyUrl = "") {
|
|
214
|
+
const params = {
|
|
215
|
+
app_id: this.appId,
|
|
216
|
+
method,
|
|
217
|
+
charset: "utf-8",
|
|
218
|
+
sign_type: "RSA2",
|
|
219
|
+
timestamp: new Date().toISOString().slice(0, 19).replace("T", " "),
|
|
220
|
+
version: "1.0",
|
|
221
|
+
biz_content: JSON.stringify(bizContent),
|
|
222
|
+
};
|
|
223
|
+
if (notifyUrl)
|
|
224
|
+
params["notify_url"] = notifyUrl;
|
|
225
|
+
params["sign"] = this.signParams(params);
|
|
226
|
+
return JSON.parse(await this.alipayPost(params));
|
|
227
|
+
}
|
|
228
|
+
async createTrade(outTradeNo, amountCents, subject, notifyUrl) {
|
|
229
|
+
const amountYuan = (amountCents / 100).toFixed(2);
|
|
230
|
+
const bizContent = JSON.stringify({
|
|
231
|
+
out_trade_no: outTradeNo,
|
|
232
|
+
total_amount: amountYuan,
|
|
233
|
+
subject,
|
|
234
|
+
product_code: "QR_CODE_OFFLINE",
|
|
235
|
+
});
|
|
236
|
+
const params = {
|
|
237
|
+
app_id: this.appId,
|
|
238
|
+
method: "alipay.trade.precreate",
|
|
239
|
+
charset: "utf-8",
|
|
240
|
+
sign_type: "RSA2",
|
|
241
|
+
timestamp: new Date().toISOString().slice(0, 19).replace("T", " "),
|
|
242
|
+
version: "1.0",
|
|
243
|
+
biz_content: bizContent,
|
|
244
|
+
};
|
|
245
|
+
if (notifyUrl)
|
|
246
|
+
params["notify_url"] = notifyUrl;
|
|
247
|
+
params["sign"] = this.signParams(params);
|
|
248
|
+
let result;
|
|
249
|
+
try {
|
|
250
|
+
result = JSON.parse(await this.alipayPost(params));
|
|
251
|
+
}
|
|
252
|
+
catch (e) {
|
|
253
|
+
return {
|
|
254
|
+
...emptyResult(),
|
|
255
|
+
msg: `支付宝请求失败: ${e.message}`,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const precreate = (result["alipay_trade_precreate_response"] ||
|
|
259
|
+
{});
|
|
260
|
+
if (precreate["code"] === "10000") {
|
|
261
|
+
return {
|
|
262
|
+
success: true,
|
|
263
|
+
msg: "支付宝订单创建成功",
|
|
264
|
+
qrCode: String(precreate["qr_code"] || ""),
|
|
265
|
+
tradeNo: "",
|
|
266
|
+
outTradeNo,
|
|
267
|
+
payParams: {},
|
|
268
|
+
raw: result,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const subCode = String(precreate["sub_code"] || "");
|
|
272
|
+
const subMsg = String(precreate["sub_msg"] || "");
|
|
273
|
+
const msg = String(precreate["msg"] || "未知错误");
|
|
274
|
+
const errDetail = subCode ? `${subMsg}(${subCode})` : msg;
|
|
275
|
+
return {
|
|
276
|
+
...emptyResult(),
|
|
277
|
+
msg: `支付宝下单失败: ${errDetail}`,
|
|
278
|
+
raw: result,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
async createTradeCreate(outTradeNo, amountCents, subject, notifyUrl, buyerId) {
|
|
282
|
+
try {
|
|
283
|
+
const result = await this.callAlipay("alipay.trade.create", {
|
|
284
|
+
out_trade_no: outTradeNo,
|
|
285
|
+
total_amount: (amountCents / 100).toFixed(2),
|
|
286
|
+
subject,
|
|
287
|
+
buyer_id: buyerId,
|
|
288
|
+
}, notifyUrl);
|
|
289
|
+
const resp = (result["alipay_trade_create_response"] || {});
|
|
290
|
+
if (resp["code"] === "10000") {
|
|
291
|
+
const tradeNo = String(resp["trade_no"] || "");
|
|
292
|
+
return {
|
|
293
|
+
success: true,
|
|
294
|
+
msg: "支付宝小程序订单创建成功",
|
|
295
|
+
qrCode: "",
|
|
296
|
+
tradeNo,
|
|
297
|
+
outTradeNo,
|
|
298
|
+
payParams: { tradeNO: tradeNo },
|
|
299
|
+
raw: result,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
...emptyResult(),
|
|
304
|
+
msg: `支付宝创建失败: ${resp["sub_msg"] || resp["msg"] || "未知错误"}`,
|
|
305
|
+
raw: result,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
catch (e) {
|
|
309
|
+
return {
|
|
310
|
+
...emptyResult(),
|
|
311
|
+
msg: `支付宝请求失败: ${e.message}`,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
async createAppTrade(outTradeNo, amountCents, subject, notifyUrl) {
|
|
316
|
+
const params = {
|
|
317
|
+
app_id: this.appId,
|
|
318
|
+
method: "alipay.trade.app.pay",
|
|
319
|
+
charset: "utf-8",
|
|
320
|
+
sign_type: "RSA2",
|
|
321
|
+
timestamp: new Date().toISOString().slice(0, 19).replace("T", " "),
|
|
322
|
+
version: "1.0",
|
|
323
|
+
biz_content: JSON.stringify({
|
|
324
|
+
out_trade_no: outTradeNo,
|
|
325
|
+
total_amount: (amountCents / 100).toFixed(2),
|
|
326
|
+
subject,
|
|
327
|
+
}),
|
|
328
|
+
};
|
|
329
|
+
if (notifyUrl)
|
|
330
|
+
params["notify_url"] = notifyUrl;
|
|
331
|
+
params["sign"] = this.signParams(params);
|
|
332
|
+
try {
|
|
333
|
+
const orderInfo = await this.alipayPost(params);
|
|
334
|
+
if (orderInfo.includes("trade_no")) {
|
|
335
|
+
return {
|
|
336
|
+
success: true,
|
|
337
|
+
msg: "支付宝APP订单创建成功",
|
|
338
|
+
qrCode: "",
|
|
339
|
+
tradeNo: "",
|
|
340
|
+
outTradeNo,
|
|
341
|
+
payParams: { orderInfo },
|
|
342
|
+
raw: { orderInfo: orderInfo.slice(0, 200) },
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
...emptyResult(),
|
|
347
|
+
msg: "支付宝APP下单失败",
|
|
348
|
+
raw: { response: orderInfo.slice(0, 500) },
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
catch (e) {
|
|
352
|
+
return {
|
|
353
|
+
...emptyResult(),
|
|
354
|
+
msg: `支付宝请求失败: ${e.message}`,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async createPageTrade(outTradeNo, amountCents, subject, notifyUrl, returnUrl = "") {
|
|
359
|
+
const params = {
|
|
360
|
+
app_id: this.appId,
|
|
361
|
+
method: "alipay.trade.page.pay",
|
|
362
|
+
charset: "utf-8",
|
|
363
|
+
sign_type: "RSA2",
|
|
364
|
+
timestamp: new Date().toISOString().slice(0, 19).replace("T", " "),
|
|
365
|
+
version: "1.0",
|
|
366
|
+
biz_content: JSON.stringify({
|
|
367
|
+
out_trade_no: outTradeNo,
|
|
368
|
+
total_amount: (amountCents / 100).toFixed(2),
|
|
369
|
+
subject,
|
|
370
|
+
product_code: "FAST_INSTANT_TRADE_PAY",
|
|
371
|
+
qr_pay_mode: "4",
|
|
372
|
+
qrcode_width: 320,
|
|
373
|
+
}),
|
|
374
|
+
};
|
|
375
|
+
if (notifyUrl)
|
|
376
|
+
params["notify_url"] = notifyUrl;
|
|
377
|
+
if (returnUrl)
|
|
378
|
+
params["return_url"] = returnUrl;
|
|
379
|
+
params["sign"] = this.signParams(params);
|
|
380
|
+
const query = Object.entries(params)
|
|
381
|
+
.filter(([, v]) => v)
|
|
382
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
383
|
+
.map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
|
|
384
|
+
.join("&");
|
|
385
|
+
const redirectUrl = `${this.gateway}?${query}`;
|
|
386
|
+
return {
|
|
387
|
+
success: true,
|
|
388
|
+
msg: "支付宝电脑网站支付订单创建成功",
|
|
389
|
+
qrCode: "",
|
|
390
|
+
tradeNo: "",
|
|
391
|
+
outTradeNo,
|
|
392
|
+
payParams: { redirect_url: redirectUrl },
|
|
393
|
+
raw: {},
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
async createWapTrade(outTradeNo, amountCents, subject, notifyUrl, returnUrl = "") {
|
|
397
|
+
// 支付宝 H5 移动网站支付(alipay.trade.wap.pay,手机浏览器拉起支付宝 App)
|
|
398
|
+
const params = {
|
|
399
|
+
app_id: this.appId,
|
|
400
|
+
method: "alipay.trade.wap.pay",
|
|
401
|
+
charset: "utf-8",
|
|
402
|
+
sign_type: "RSA2",
|
|
403
|
+
timestamp: new Date().toISOString().slice(0, 19).replace("T", " "),
|
|
404
|
+
version: "1.0",
|
|
405
|
+
biz_content: JSON.stringify({
|
|
406
|
+
out_trade_no: outTradeNo,
|
|
407
|
+
total_amount: (amountCents / 100).toFixed(2),
|
|
408
|
+
subject,
|
|
409
|
+
product_code: "QUICK_WAP_WAY",
|
|
410
|
+
}),
|
|
411
|
+
};
|
|
412
|
+
if (notifyUrl)
|
|
413
|
+
params["notify_url"] = notifyUrl;
|
|
414
|
+
if (returnUrl)
|
|
415
|
+
params["return_url"] = returnUrl;
|
|
416
|
+
params["sign"] = this.signParams(params);
|
|
417
|
+
const query = Object.entries(params)
|
|
418
|
+
.filter(([, v]) => v)
|
|
419
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
420
|
+
.map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
|
|
421
|
+
.join("&");
|
|
422
|
+
const redirectUrl = `${this.gateway}?${query}`;
|
|
423
|
+
return {
|
|
424
|
+
success: true,
|
|
425
|
+
msg: "支付宝H5订单创建成功",
|
|
426
|
+
qrCode: "",
|
|
427
|
+
tradeNo: "",
|
|
428
|
+
outTradeNo,
|
|
429
|
+
payParams: { redirect_url: redirectUrl, h5: true },
|
|
430
|
+
raw: {},
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
async createTradeByPlatform(outTradeNo, amountCents, subject, notifyUrl, platform = "web", _openid = "", buyerId = "") {
|
|
434
|
+
if (platform === "miniapp") {
|
|
435
|
+
if (!buyerId) {
|
|
436
|
+
return { ...emptyResult(), msg: "支付宝小程序支付需要 buyer_id" };
|
|
437
|
+
}
|
|
438
|
+
return this.createTradeCreate(outTradeNo, amountCents, subject, notifyUrl, buyerId);
|
|
439
|
+
}
|
|
440
|
+
if (platform === "app") {
|
|
441
|
+
return this.createAppTrade(outTradeNo, amountCents, subject, notifyUrl);
|
|
442
|
+
}
|
|
443
|
+
if (platform === "h5") {
|
|
444
|
+
return this.createWapTrade(outTradeNo, amountCents, subject, notifyUrl, this.returnUrl);
|
|
445
|
+
}
|
|
446
|
+
return this.createPageTrade(outTradeNo, amountCents, subject, notifyUrl, this.returnUrl);
|
|
447
|
+
}
|
|
448
|
+
async queryTrade(outTradeNo) {
|
|
449
|
+
const params = {
|
|
450
|
+
app_id: this.appId,
|
|
451
|
+
method: "alipay.trade.query",
|
|
452
|
+
charset: "utf-8",
|
|
453
|
+
sign_type: "RSA2",
|
|
454
|
+
timestamp: new Date().toISOString().slice(0, 19).replace("T", " "),
|
|
455
|
+
version: "1.0",
|
|
456
|
+
biz_content: JSON.stringify({ out_trade_no: outTradeNo }),
|
|
457
|
+
};
|
|
458
|
+
params["sign"] = this.signParams(params);
|
|
459
|
+
try {
|
|
460
|
+
const result = JSON.parse(await this.alipayPost(params));
|
|
461
|
+
const queryResp = (result["alipay_trade_query_response"] || {});
|
|
462
|
+
if (queryResp["trade_status"] === "TRADE_SUCCESS") {
|
|
463
|
+
return {
|
|
464
|
+
success: true,
|
|
465
|
+
msg: "支付成功",
|
|
466
|
+
qrCode: "",
|
|
467
|
+
tradeNo: String(queryResp["trade_no"] || ""),
|
|
468
|
+
outTradeNo,
|
|
469
|
+
payParams: {},
|
|
470
|
+
raw: result,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
...emptyResult(),
|
|
475
|
+
msg: `状态: ${queryResp["trade_status"] || ""}`,
|
|
476
|
+
raw: result,
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
catch (e) {
|
|
480
|
+
return { ...emptyResult(), msg: `查询失败: ${e.message}` };
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
async verifyCallback(_headers, body) {
|
|
484
|
+
const params = parseForm(body.toString("utf-8"));
|
|
485
|
+
const sign = params["sign"] || "";
|
|
486
|
+
if (!sign)
|
|
487
|
+
return {
|
|
488
|
+
success: false,
|
|
489
|
+
msg: "回调缺少签名",
|
|
490
|
+
outTradeNo: "",
|
|
491
|
+
tradeNo: "",
|
|
492
|
+
amount: 0,
|
|
493
|
+
status: "",
|
|
494
|
+
};
|
|
495
|
+
if (!this.verifyParams(params, sign)) {
|
|
496
|
+
return {
|
|
497
|
+
success: false,
|
|
498
|
+
msg: "签名验证失败",
|
|
499
|
+
outTradeNo: "",
|
|
500
|
+
tradeNo: "",
|
|
501
|
+
amount: 0,
|
|
502
|
+
status: "",
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
const tradeStatus = params["trade_status"] || "";
|
|
506
|
+
if (tradeStatus === "TRADE_SUCCESS" || tradeStatus === "TRADE_FINISHED") {
|
|
507
|
+
const amount = Math.round(parseFloat(params["total_amount"] || "0") * 100);
|
|
508
|
+
return {
|
|
509
|
+
success: true,
|
|
510
|
+
outTradeNo: params["out_trade_no"] || "",
|
|
511
|
+
tradeNo: params["trade_no"] || "",
|
|
512
|
+
amount,
|
|
513
|
+
status: "paid",
|
|
514
|
+
msg: "",
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
return {
|
|
518
|
+
success: false,
|
|
519
|
+
msg: `交易状态: ${tradeStatus}`,
|
|
520
|
+
outTradeNo: "",
|
|
521
|
+
tradeNo: "",
|
|
522
|
+
amount: 0,
|
|
523
|
+
status: "",
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
// ─── 银联云闪付 Provider ───
|
|
528
|
+
export class UnionPayProvider extends PaymentProvider {
|
|
529
|
+
provider_name = "unionpay";
|
|
530
|
+
static TEST_GATEWAY = "https://gateway.test.95516.com/gateway/api/backTransReq.do";
|
|
531
|
+
static PROD_GATEWAY = "https://gateway.95516.com/gateway/api/backTransReq.do";
|
|
532
|
+
merId;
|
|
533
|
+
gateway;
|
|
534
|
+
notifyUrl;
|
|
535
|
+
privateKey;
|
|
536
|
+
publicKey;
|
|
537
|
+
constructor(config) {
|
|
538
|
+
super();
|
|
539
|
+
this.merId = config["unionpay_mer_id"] || "";
|
|
540
|
+
const certBase64 = config["unionpay_cert_base64"] || "";
|
|
541
|
+
const certPassword = config["unionpay_cert_password"] || "";
|
|
542
|
+
const publicKey = config["unionpay_public_key"] || "";
|
|
543
|
+
this.notifyUrl = config["unionpay_notify_url"] || "";
|
|
544
|
+
this.gateway = config["unionpay_gateway"] || UnionPayProvider.TEST_GATEWAY;
|
|
545
|
+
if (!this.merId || !certBase64 || !publicKey) {
|
|
546
|
+
throw new Error("银联配置不完整:需要 mer_id, cert_base64, public_key");
|
|
547
|
+
}
|
|
548
|
+
this.privateKey = loadPkcs12PrivateKey(certBase64, certPassword);
|
|
549
|
+
this.publicKey = loadPublicKey(publicKey);
|
|
550
|
+
}
|
|
551
|
+
signParams(params) {
|
|
552
|
+
const query = Object.entries(params)
|
|
553
|
+
.filter(([k, v]) => v && k !== "signature")
|
|
554
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
555
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
556
|
+
.join("&");
|
|
557
|
+
return rsaSignWithKey(this.privateKey, query);
|
|
558
|
+
}
|
|
559
|
+
verifyParams(params, sign) {
|
|
560
|
+
const query = Object.entries(params)
|
|
561
|
+
.filter(([k, v]) => v && k !== "signature")
|
|
562
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
563
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
564
|
+
.join("&");
|
|
565
|
+
return rsaVerifyWithKey(this.publicKey, query, sign);
|
|
566
|
+
}
|
|
567
|
+
async post(params) {
|
|
568
|
+
const resp = await fetch(this.gateway, {
|
|
569
|
+
method: "POST",
|
|
570
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
571
|
+
body: new URLSearchParams(params),
|
|
572
|
+
});
|
|
573
|
+
return parseForm(await resp.text());
|
|
574
|
+
}
|
|
575
|
+
async createTrade(outTradeNo, amountCents, _subject, notifyUrl) {
|
|
576
|
+
const params = {
|
|
577
|
+
version: "5.1.0",
|
|
578
|
+
encoding: "utf-8",
|
|
579
|
+
txnType: "01",
|
|
580
|
+
txnSubType: "07",
|
|
581
|
+
bizType: "000000",
|
|
582
|
+
channelType: "08",
|
|
583
|
+
merId: this.merId,
|
|
584
|
+
orderId: outTradeNo,
|
|
585
|
+
txnAmt: String(amountCents),
|
|
586
|
+
txnTime: new Date().toISOString().slice(0, 19).replace(/[-:T]/g, ""),
|
|
587
|
+
backUrl: notifyUrl || this.notifyUrl,
|
|
588
|
+
certId: "",
|
|
589
|
+
signatureMethod: "SHA256",
|
|
590
|
+
signature: "",
|
|
591
|
+
};
|
|
592
|
+
params["signature"] = this.signParams(params);
|
|
593
|
+
let result;
|
|
594
|
+
try {
|
|
595
|
+
result = await this.post(params);
|
|
596
|
+
}
|
|
597
|
+
catch (e) {
|
|
598
|
+
return { ...emptyResult(), msg: `银联请求失败: ${e.message}` };
|
|
599
|
+
}
|
|
600
|
+
const respCode = result["respCode"] || "";
|
|
601
|
+
const qrCode = result["qrCode"] || "";
|
|
602
|
+
if (respCode === "00" && qrCode) {
|
|
603
|
+
return {
|
|
604
|
+
success: true,
|
|
605
|
+
msg: "银联扫码订单创建成功",
|
|
606
|
+
qrCode,
|
|
607
|
+
tradeNo: "",
|
|
608
|
+
outTradeNo,
|
|
609
|
+
payParams: {},
|
|
610
|
+
raw: result,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
return {
|
|
614
|
+
...emptyResult(),
|
|
615
|
+
msg: `银联下单失败: ${result["respMsg"] || "未知错误"} (code=${respCode})`,
|
|
616
|
+
raw: result,
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
async createAppTrade(outTradeNo, amountCents, _subject, notifyUrl) {
|
|
620
|
+
const params = {
|
|
621
|
+
version: "5.1.0",
|
|
622
|
+
encoding: "utf-8",
|
|
623
|
+
txnType: "01",
|
|
624
|
+
txnSubType: "01",
|
|
625
|
+
bizType: "000201",
|
|
626
|
+
channelType: "08",
|
|
627
|
+
merId: this.merId,
|
|
628
|
+
orderId: outTradeNo,
|
|
629
|
+
txnAmt: String(amountCents),
|
|
630
|
+
txnTime: new Date().toISOString().slice(0, 19).replace(/[-:T]/g, ""),
|
|
631
|
+
backUrl: notifyUrl || this.notifyUrl,
|
|
632
|
+
signatureMethod: "SHA256",
|
|
633
|
+
signature: "",
|
|
634
|
+
};
|
|
635
|
+
params["signature"] = this.signParams(params);
|
|
636
|
+
let result;
|
|
637
|
+
try {
|
|
638
|
+
result = await this.post(params);
|
|
639
|
+
}
|
|
640
|
+
catch (e) {
|
|
641
|
+
return { ...emptyResult(), msg: `银联请求失败: ${e.message}` };
|
|
642
|
+
}
|
|
643
|
+
const respCode = result["respCode"] || "";
|
|
644
|
+
const tn = result["tn"] || "";
|
|
645
|
+
if (respCode === "00" && tn) {
|
|
646
|
+
return {
|
|
647
|
+
success: true,
|
|
648
|
+
msg: "银联APP订单创建成功",
|
|
649
|
+
qrCode: "",
|
|
650
|
+
tradeNo: "",
|
|
651
|
+
outTradeNo,
|
|
652
|
+
payParams: { tn },
|
|
653
|
+
raw: result,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
return {
|
|
657
|
+
...emptyResult(),
|
|
658
|
+
msg: `银联APP下单失败: ${result["respMsg"] || "未知错误"}`,
|
|
659
|
+
raw: result,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
async createTradeByPlatform(outTradeNo, amountCents, subject, notifyUrl, platform = "web") {
|
|
663
|
+
if (platform === "app") {
|
|
664
|
+
return this.createAppTrade(outTradeNo, amountCents, subject, notifyUrl);
|
|
665
|
+
}
|
|
666
|
+
return this.createTrade(outTradeNo, amountCents, subject, notifyUrl);
|
|
667
|
+
}
|
|
668
|
+
async queryTrade(outTradeNo) {
|
|
669
|
+
const params = {
|
|
670
|
+
version: "5.1.0",
|
|
671
|
+
encoding: "utf-8",
|
|
672
|
+
txnType: "00",
|
|
673
|
+
txnSubType: "00",
|
|
674
|
+
bizType: "000000",
|
|
675
|
+
channelType: "08",
|
|
676
|
+
merId: this.merId,
|
|
677
|
+
orderId: outTradeNo,
|
|
678
|
+
txnTime: new Date().toISOString().slice(0, 19).replace(/[-:T]/g, ""),
|
|
679
|
+
signatureMethod: "SHA256",
|
|
680
|
+
signature: "",
|
|
681
|
+
};
|
|
682
|
+
params["signature"] = this.signParams(params);
|
|
683
|
+
let result;
|
|
684
|
+
try {
|
|
685
|
+
result = await this.post(params);
|
|
686
|
+
}
|
|
687
|
+
catch (e) {
|
|
688
|
+
return { ...emptyResult(), msg: `查询失败: ${e.message}` };
|
|
689
|
+
}
|
|
690
|
+
const origRespCode = result["origRespCode"] || "";
|
|
691
|
+
if (origRespCode === "00") {
|
|
692
|
+
return {
|
|
693
|
+
success: true,
|
|
694
|
+
msg: "支付成功",
|
|
695
|
+
qrCode: "",
|
|
696
|
+
tradeNo: result["queryId"] || "",
|
|
697
|
+
outTradeNo,
|
|
698
|
+
payParams: {},
|
|
699
|
+
raw: result,
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
return { ...emptyResult(), msg: `状态: ${origRespCode}`, raw: result };
|
|
703
|
+
}
|
|
704
|
+
async verifyCallback(_headers, body) {
|
|
705
|
+
const params = parseForm(body.toString("utf-8"));
|
|
706
|
+
const sign = params["signature"] || "";
|
|
707
|
+
if (!sign)
|
|
708
|
+
return {
|
|
709
|
+
success: false,
|
|
710
|
+
msg: "回调缺少签名",
|
|
711
|
+
outTradeNo: "",
|
|
712
|
+
tradeNo: "",
|
|
713
|
+
amount: 0,
|
|
714
|
+
status: "",
|
|
715
|
+
};
|
|
716
|
+
if (!this.verifyParams(params, sign)) {
|
|
717
|
+
return {
|
|
718
|
+
success: false,
|
|
719
|
+
msg: "签名验证失败",
|
|
720
|
+
outTradeNo: "",
|
|
721
|
+
tradeNo: "",
|
|
722
|
+
amount: 0,
|
|
723
|
+
status: "",
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
const respCode = params["respCode"] || "";
|
|
727
|
+
if (respCode === "00") {
|
|
728
|
+
return {
|
|
729
|
+
success: true,
|
|
730
|
+
outTradeNo: params["orderId"] || "",
|
|
731
|
+
tradeNo: params["queryId"] || "",
|
|
732
|
+
amount: parseInt(params["txnAmt"] || "0", 10),
|
|
733
|
+
status: "paid",
|
|
734
|
+
msg: "",
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
return {
|
|
738
|
+
success: false,
|
|
739
|
+
msg: `交易状态: ${respCode}`,
|
|
740
|
+
outTradeNo: "",
|
|
741
|
+
tradeNo: "",
|
|
742
|
+
amount: 0,
|
|
743
|
+
status: "",
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
successResponse() {
|
|
747
|
+
return "ok";
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
// ─── 微信支付 V3 Provider ───
|
|
751
|
+
export class WeChatPayProvider extends PaymentProvider {
|
|
752
|
+
provider_name = "wechat";
|
|
753
|
+
static BASE_URL = "https://api.mch.weixin.qq.com";
|
|
754
|
+
appid;
|
|
755
|
+
miniAppId;
|
|
756
|
+
appAppId;
|
|
757
|
+
appSecret;
|
|
758
|
+
mchid;
|
|
759
|
+
serialNo;
|
|
760
|
+
privateKey;
|
|
761
|
+
apiV3Key;
|
|
762
|
+
notifyUrl;
|
|
763
|
+
constructor(config) {
|
|
764
|
+
super();
|
|
765
|
+
this.miniAppId = config["wechat_mini_app_id"] || "";
|
|
766
|
+
this.appAppId = config["wechat_app_app_id"] || "";
|
|
767
|
+
this.appid = config["wechat_app_id"] || this.miniAppId;
|
|
768
|
+
// 公众号 AppSecret(网页授权 snsapi_base 换取 openid,公众号JSAPI支付必需)
|
|
769
|
+
this.appSecret = config["wechat_app_secret"] || "";
|
|
770
|
+
this.mchid = config["wechat_mch_id"] || "";
|
|
771
|
+
this.serialNo = config["wechat_serial_no"] || "";
|
|
772
|
+
this.privateKey = config["wechat_private_key"] || "";
|
|
773
|
+
this.apiV3Key = config["wechat_api_v3_key"] || "";
|
|
774
|
+
this.notifyUrl = config["wechat_notify_url"] || "";
|
|
775
|
+
if (!this.appid ||
|
|
776
|
+
!this.mchid ||
|
|
777
|
+
!this.serialNo ||
|
|
778
|
+
!this.privateKey ||
|
|
779
|
+
!this.apiV3Key) {
|
|
780
|
+
throw new Error("微信支付配置不完整:需要 app_id(或mini_app_id), mch_id, serial_no, private_key, api_v3_key");
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
buildAuth(method, urlPath, body = "") {
|
|
784
|
+
const timestamp = ts();
|
|
785
|
+
const nonceStr = nonce();
|
|
786
|
+
const message = `${method}\n${urlPath}\n${timestamp}\n${nonceStr}\n${body}\n`;
|
|
787
|
+
const signature = rsaSign(this.privateKey, message);
|
|
788
|
+
return (`WECHATPAY2-SHA256-RSA2048 ` +
|
|
789
|
+
`mchid="${this.mchid}",nonce_str="${nonceStr}",timestamp="${timestamp}",` +
|
|
790
|
+
`serial_no="${this.serialNo}",signature="${signature}"`);
|
|
791
|
+
}
|
|
792
|
+
async v3Post(urlPath, bodyDict) {
|
|
793
|
+
const body = JSON.stringify(bodyDict);
|
|
794
|
+
const auth = this.buildAuth("POST", urlPath, body);
|
|
795
|
+
const resp = await fetch(`${WeChatPayProvider.BASE_URL}${urlPath}`, {
|
|
796
|
+
method: "POST",
|
|
797
|
+
headers: {
|
|
798
|
+
Authorization: auth,
|
|
799
|
+
"Content-Type": "application/json",
|
|
800
|
+
Accept: "application/json",
|
|
801
|
+
},
|
|
802
|
+
body,
|
|
803
|
+
});
|
|
804
|
+
return resp.json();
|
|
805
|
+
}
|
|
806
|
+
async createTrade(outTradeNo, amountCents, subject, notifyUrl) {
|
|
807
|
+
const urlPath = "/v3/pay/transactions/native";
|
|
808
|
+
const body = JSON.stringify({
|
|
809
|
+
appid: this.appid,
|
|
810
|
+
mchid: this.mchid,
|
|
811
|
+
description: subject,
|
|
812
|
+
out_trade_no: outTradeNo,
|
|
813
|
+
notify_url: notifyUrl || this.notifyUrl,
|
|
814
|
+
amount: { total: amountCents, currency: "CNY" },
|
|
815
|
+
});
|
|
816
|
+
const auth = this.buildAuth("POST", urlPath, body);
|
|
817
|
+
let result;
|
|
818
|
+
try {
|
|
819
|
+
const resp = await fetch(`${WeChatPayProvider.BASE_URL}${urlPath}`, {
|
|
820
|
+
method: "POST",
|
|
821
|
+
headers: {
|
|
822
|
+
Authorization: auth,
|
|
823
|
+
"Content-Type": "application/json",
|
|
824
|
+
Accept: "application/json",
|
|
825
|
+
},
|
|
826
|
+
body,
|
|
827
|
+
});
|
|
828
|
+
result = (await resp.json());
|
|
829
|
+
if (resp.status === 200 && "code_url" in result) {
|
|
830
|
+
return {
|
|
831
|
+
success: true,
|
|
832
|
+
msg: "微信支付订单创建成功",
|
|
833
|
+
qrCode: String(result["code_url"]),
|
|
834
|
+
tradeNo: "",
|
|
835
|
+
outTradeNo,
|
|
836
|
+
payParams: {},
|
|
837
|
+
raw: result,
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
catch (e) {
|
|
842
|
+
return {
|
|
843
|
+
...emptyResult(),
|
|
844
|
+
msg: `微信支付请求失败: ${e.message}`,
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
return {
|
|
848
|
+
...emptyResult(),
|
|
849
|
+
msg: `微信下单失败: ${result["message"] || "未知错误"} (code=${result["code"] || ""})`,
|
|
850
|
+
raw: result,
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
generateJsapiParams(prepayId, appid = "") {
|
|
854
|
+
const finalAppid = appid || this.miniAppId || this.appid;
|
|
855
|
+
const timestamp = ts();
|
|
856
|
+
const nonceStr = nonce();
|
|
857
|
+
const pkg = `prepay_id=${prepayId}`;
|
|
858
|
+
const message = `${finalAppid}\n${timestamp}\n${nonceStr}\n${pkg}\n`;
|
|
859
|
+
const paySign = rsaSign(this.privateKey, message);
|
|
860
|
+
return {
|
|
861
|
+
appId: finalAppid,
|
|
862
|
+
timeStamp: timestamp,
|
|
863
|
+
nonceStr,
|
|
864
|
+
package: pkg,
|
|
865
|
+
signType: "RSA",
|
|
866
|
+
paySign,
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
generateAppParams(prepayId) {
|
|
870
|
+
const appid = this.appAppId || this.appid;
|
|
871
|
+
const timestamp = ts();
|
|
872
|
+
const nonceStr = nonce();
|
|
873
|
+
const pkg = "Sign=WXPay";
|
|
874
|
+
const message = `${appid}\n${this.mchid}\n${prepayId}\n${pkg}\n${timestamp}\n${nonceStr}\n`;
|
|
875
|
+
const sign = rsaSign(this.privateKey, message);
|
|
876
|
+
return {
|
|
877
|
+
appid,
|
|
878
|
+
partnerid: this.mchid,
|
|
879
|
+
prepayid: prepayId,
|
|
880
|
+
package: pkg,
|
|
881
|
+
noncestr: nonceStr,
|
|
882
|
+
timestamp,
|
|
883
|
+
sign,
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
async createJsapiTrade(outTradeNo, amountCents, subject, notifyUrl, openid) {
|
|
887
|
+
// 公众号/小程序 JSAPI 通用;appid 优先公众号(与 OAuth 拿到的 openid 对应)
|
|
888
|
+
const appid = this.appid;
|
|
889
|
+
let result;
|
|
890
|
+
try {
|
|
891
|
+
result = await this.v3Post("/v3/pay/transactions/jsapi", {
|
|
892
|
+
appid,
|
|
893
|
+
mchid: this.mchid,
|
|
894
|
+
description: subject,
|
|
895
|
+
out_trade_no: outTradeNo,
|
|
896
|
+
notify_url: notifyUrl || this.notifyUrl,
|
|
897
|
+
amount: { total: amountCents, currency: "CNY" },
|
|
898
|
+
payer: { openid },
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
catch (e) {
|
|
902
|
+
return {
|
|
903
|
+
...emptyResult(),
|
|
904
|
+
msg: `微信JSAPI请求失败: ${e.message}`,
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
if ("prepay_id" in result) {
|
|
908
|
+
return {
|
|
909
|
+
success: true,
|
|
910
|
+
msg: "微信小程序订单创建成功",
|
|
911
|
+
qrCode: "",
|
|
912
|
+
tradeNo: "",
|
|
913
|
+
outTradeNo,
|
|
914
|
+
payParams: this.generateJsapiParams(String(result["prepay_id"]), appid),
|
|
915
|
+
raw: result,
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
return {
|
|
919
|
+
...emptyResult(),
|
|
920
|
+
msg: `微信JSAPI下单失败: ${result["message"] || "未知错误"}`,
|
|
921
|
+
raw: result,
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
async createH5Trade(outTradeNo, amountCents, subject, notifyUrl, payerIp) {
|
|
925
|
+
let result;
|
|
926
|
+
try {
|
|
927
|
+
result = await this.v3Post("/v3/pay/transactions/h5", {
|
|
928
|
+
appid: this.appid,
|
|
929
|
+
mchid: this.mchid,
|
|
930
|
+
description: subject,
|
|
931
|
+
out_trade_no: outTradeNo,
|
|
932
|
+
notify_url: notifyUrl || this.notifyUrl,
|
|
933
|
+
amount: { total: amountCents, currency: "CNY" },
|
|
934
|
+
scene_info: {
|
|
935
|
+
payer_client_ip: payerIp || "127.0.0.1",
|
|
936
|
+
h5_info: { type: "Wap" },
|
|
937
|
+
},
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
catch (e) {
|
|
941
|
+
return {
|
|
942
|
+
...emptyResult(),
|
|
943
|
+
msg: `微信H5请求失败: ${e.message}`,
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
if ("h5_url" in result) {
|
|
947
|
+
return {
|
|
948
|
+
success: true,
|
|
949
|
+
msg: "微信H5订单创建成功",
|
|
950
|
+
qrCode: "",
|
|
951
|
+
tradeNo: "",
|
|
952
|
+
outTradeNo,
|
|
953
|
+
payParams: { h5_url: result["h5_url"] },
|
|
954
|
+
raw: result,
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
return {
|
|
958
|
+
...emptyResult(),
|
|
959
|
+
msg: `微信H5下单失败: ${result["message"] || "未知错误"}`,
|
|
960
|
+
raw: result,
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
async createAppTrade(outTradeNo, amountCents, subject, notifyUrl) {
|
|
964
|
+
const appid = this.appAppId || this.appid;
|
|
965
|
+
let result;
|
|
966
|
+
try {
|
|
967
|
+
result = await this.v3Post("/v3/pay/transactions/app", {
|
|
968
|
+
appid,
|
|
969
|
+
mchid: this.mchid,
|
|
970
|
+
description: subject,
|
|
971
|
+
out_trade_no: outTradeNo,
|
|
972
|
+
notify_url: notifyUrl || this.notifyUrl,
|
|
973
|
+
amount: { total: amountCents, currency: "CNY" },
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
catch (e) {
|
|
977
|
+
return {
|
|
978
|
+
...emptyResult(),
|
|
979
|
+
msg: `微信APP请求失败: ${e.message}`,
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
if ("prepay_id" in result) {
|
|
983
|
+
return {
|
|
984
|
+
success: true,
|
|
985
|
+
msg: "微信APP订单创建成功",
|
|
986
|
+
qrCode: "",
|
|
987
|
+
tradeNo: "",
|
|
988
|
+
outTradeNo,
|
|
989
|
+
payParams: this.generateAppParams(String(result["prepay_id"])),
|
|
990
|
+
raw: result,
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
return {
|
|
994
|
+
...emptyResult(),
|
|
995
|
+
msg: `微信APP下单失败: ${result["message"] || "未知错误"}`,
|
|
996
|
+
raw: result,
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
/** 构造微信公众号网页授权跳转 URL(默认 snsapi_base 静默授权,仅拿 openid) */
|
|
1000
|
+
buildOauthUrl(redirectUri, scope = "snsapi_base", state = "") {
|
|
1001
|
+
const params = new URLSearchParams();
|
|
1002
|
+
params.set("appid", this.appid);
|
|
1003
|
+
params.set("redirect_uri", redirectUri);
|
|
1004
|
+
params.set("response_type", "code");
|
|
1005
|
+
params.set("scope", scope);
|
|
1006
|
+
if (state)
|
|
1007
|
+
params.set("state", state);
|
|
1008
|
+
return `https://open.weixin.qq.com/connect/oauth2/authorize?${params.toString()}#wechat_redirect`;
|
|
1009
|
+
}
|
|
1010
|
+
/** 用网页授权 code 换取 openid(snsapi_base 静默授权) */
|
|
1011
|
+
async getOpenidByCode(code) {
|
|
1012
|
+
if (!this.appSecret) {
|
|
1013
|
+
throw new Error("微信网页授权未配置:缺少 wechat_app_secret(公众号 AppSecret)");
|
|
1014
|
+
}
|
|
1015
|
+
if (!code)
|
|
1016
|
+
throw new Error("缺少微信授权 code");
|
|
1017
|
+
const params = new URLSearchParams({
|
|
1018
|
+
appid: this.appid,
|
|
1019
|
+
secret: this.appSecret,
|
|
1020
|
+
code,
|
|
1021
|
+
grant_type: "authorization_code",
|
|
1022
|
+
});
|
|
1023
|
+
let data;
|
|
1024
|
+
try {
|
|
1025
|
+
const resp = await fetch(`https://api.weixin.qq.com/sns/oauth2/access_token?${params.toString()}`);
|
|
1026
|
+
data = (await resp.json());
|
|
1027
|
+
}
|
|
1028
|
+
catch (e) {
|
|
1029
|
+
throw new Error(`微信授权请求失败: ${e.message}`);
|
|
1030
|
+
}
|
|
1031
|
+
if (!("openid" in data)) {
|
|
1032
|
+
throw new Error(`微信授权失败: ${data["errmsg"] || "未知错误"}`);
|
|
1033
|
+
}
|
|
1034
|
+
return String(data["openid"]);
|
|
1035
|
+
}
|
|
1036
|
+
async createTradeByPlatform(outTradeNo, amountCents, subject, notifyUrl, platform = "web", openid = "", _buyerId = "", payerIp = "") {
|
|
1037
|
+
if (platform === "miniapp") {
|
|
1038
|
+
if (!openid)
|
|
1039
|
+
return { ...emptyResult(), msg: "小程序支付需要 openid" };
|
|
1040
|
+
return this.createJsapiTrade(outTradeNo, amountCents, subject, notifyUrl, openid);
|
|
1041
|
+
}
|
|
1042
|
+
if (platform === "h5") {
|
|
1043
|
+
return this.createH5Trade(outTradeNo, amountCents, subject, notifyUrl, payerIp);
|
|
1044
|
+
}
|
|
1045
|
+
if (platform === "app") {
|
|
1046
|
+
return this.createAppTrade(outTradeNo, amountCents, subject, notifyUrl);
|
|
1047
|
+
}
|
|
1048
|
+
return this.createTrade(outTradeNo, amountCents, subject, notifyUrl);
|
|
1049
|
+
}
|
|
1050
|
+
async queryTrade(outTradeNo) {
|
|
1051
|
+
const urlPath = `/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=${this.mchid}`;
|
|
1052
|
+
const auth = this.buildAuth("GET", urlPath, "");
|
|
1053
|
+
let result;
|
|
1054
|
+
try {
|
|
1055
|
+
const resp = await fetch(`${WeChatPayProvider.BASE_URL}${urlPath}`, {
|
|
1056
|
+
method: "GET",
|
|
1057
|
+
headers: { Authorization: auth, Accept: "application/json" },
|
|
1058
|
+
});
|
|
1059
|
+
result = (await resp.json());
|
|
1060
|
+
}
|
|
1061
|
+
catch (e) {
|
|
1062
|
+
return { ...emptyResult(), msg: `查询失败: ${e.message}` };
|
|
1063
|
+
}
|
|
1064
|
+
const tradeState = result["trade_state"] || "";
|
|
1065
|
+
if (tradeState === "SUCCESS") {
|
|
1066
|
+
return {
|
|
1067
|
+
success: true,
|
|
1068
|
+
msg: "支付成功",
|
|
1069
|
+
qrCode: "",
|
|
1070
|
+
tradeNo: String(result["transaction_id"] || ""),
|
|
1071
|
+
outTradeNo,
|
|
1072
|
+
payParams: {},
|
|
1073
|
+
raw: result,
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
return { ...emptyResult(), msg: `状态: ${tradeState}`, raw: result };
|
|
1077
|
+
}
|
|
1078
|
+
async verifyCallback(_headers, body) {
|
|
1079
|
+
let bodyJson;
|
|
1080
|
+
try {
|
|
1081
|
+
bodyJson = JSON.parse(body.toString("utf-8"));
|
|
1082
|
+
}
|
|
1083
|
+
catch {
|
|
1084
|
+
return {
|
|
1085
|
+
success: false,
|
|
1086
|
+
msg: "回调 body 解析失败",
|
|
1087
|
+
outTradeNo: "",
|
|
1088
|
+
tradeNo: "",
|
|
1089
|
+
amount: 0,
|
|
1090
|
+
status: "",
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
const resource = (bodyJson["resource"] || {});
|
|
1094
|
+
const ciphertext = resource["ciphertext"] || "";
|
|
1095
|
+
const nonceStr = resource["nonce"] || "";
|
|
1096
|
+
const associatedData = resource["associated_data"] || "";
|
|
1097
|
+
if (!ciphertext) {
|
|
1098
|
+
return {
|
|
1099
|
+
success: false,
|
|
1100
|
+
msg: "回调缺少加密数据",
|
|
1101
|
+
outTradeNo: "",
|
|
1102
|
+
tradeNo: "",
|
|
1103
|
+
amount: 0,
|
|
1104
|
+
status: "",
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
let data;
|
|
1108
|
+
try {
|
|
1109
|
+
const plaintext = aesGcmDecrypt(Buffer.from(this.apiV3Key, "utf-8"), Buffer.from(nonceStr, "utf-8"), Buffer.from(ciphertext, "base64"), associatedData ? Buffer.from(associatedData, "utf-8") : null);
|
|
1110
|
+
data = JSON.parse(plaintext.toString("utf-8"));
|
|
1111
|
+
}
|
|
1112
|
+
catch (e) {
|
|
1113
|
+
return {
|
|
1114
|
+
success: false,
|
|
1115
|
+
msg: `解密失败: ${e.message}`,
|
|
1116
|
+
outTradeNo: "",
|
|
1117
|
+
tradeNo: "",
|
|
1118
|
+
amount: 0,
|
|
1119
|
+
status: "",
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
const tradeState = data["trade_state"] || "";
|
|
1123
|
+
if (tradeState === "SUCCESS") {
|
|
1124
|
+
const amount = data["amount"]?.total || 0;
|
|
1125
|
+
return {
|
|
1126
|
+
success: true,
|
|
1127
|
+
outTradeNo: String(data["out_trade_no"] || ""),
|
|
1128
|
+
tradeNo: String(data["transaction_id"] || ""),
|
|
1129
|
+
amount: Number(amount),
|
|
1130
|
+
status: "paid",
|
|
1131
|
+
msg: "",
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
return {
|
|
1135
|
+
success: false,
|
|
1136
|
+
msg: `交易状态: ${tradeState}`,
|
|
1137
|
+
outTradeNo: "",
|
|
1138
|
+
tradeNo: "",
|
|
1139
|
+
amount: 0,
|
|
1140
|
+
status: "",
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
successResponse() {
|
|
1144
|
+
return JSON.stringify({ code: "SUCCESS", message: "成功" });
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
// ─── 工厂函数 ───
|
|
1148
|
+
export function createPaymentProvider(providerName, config) {
|
|
1149
|
+
if (providerName === "mock")
|
|
1150
|
+
return new MockPaymentProvider();
|
|
1151
|
+
if (providerName === "alipay")
|
|
1152
|
+
return new AlipayProvider(config);
|
|
1153
|
+
if (providerName === "wechat")
|
|
1154
|
+
return new WeChatPayProvider(config);
|
|
1155
|
+
if (providerName === "unionpay")
|
|
1156
|
+
return new UnionPayProvider(config);
|
|
1157
|
+
throw new Error(`不支持的支付服务商: ${providerName}`);
|
|
1158
|
+
}
|
|
1159
|
+
export async function getPaymentSettings() {
|
|
1160
|
+
const rows = (await knex(ModelRegistry.get("SysSetting"))
|
|
1161
|
+
.where("group_key", "payment")
|
|
1162
|
+
.select("key", "value"));
|
|
1163
|
+
const map = {};
|
|
1164
|
+
for (const r of rows)
|
|
1165
|
+
map[r.key] = r.value ?? "";
|
|
1166
|
+
return map;
|
|
1167
|
+
}
|
|
1168
|
+
export function getActiveProvider(config) {
|
|
1169
|
+
if (config["wechat_enabled"] === "true")
|
|
1170
|
+
return "wechat";
|
|
1171
|
+
if (config["alipay_enabled"] === "true")
|
|
1172
|
+
return "alipay";
|
|
1173
|
+
if (config["unionpay_enabled"] === "true")
|
|
1174
|
+
return "unionpay";
|
|
1175
|
+
return "mock";
|
|
1176
|
+
}
|
|
1177
|
+
//# sourceMappingURL=payment.js.map
|