feat
This commit is contained in:
parent
52eccfa394
commit
43d2da77bf
@ -6,7 +6,7 @@ WORKDIR /app
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# 2. 使用 Maven 在容器中进行编译和打包(如果需要测试可去掉 -DskipTests)
|
# 2. 使用 Maven 在容器中进行编译和打包(如果需要测试可去掉 -DskipTests)
|
||||||
RUN mvn clean package -DskipTests
|
RUN mvn clean package -DskipTests=true
|
||||||
|
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
# 第二阶段:使用精简的 OpenJDK 11 镜像作为运行时环境
|
# 第二阶段:使用精简的 OpenJDK 11 镜像作为运行时环境
|
||||||
|
|||||||
@ -41,12 +41,11 @@ public abstract class AbstractOrderClient {
|
|||||||
OrderEntity order = orderService.createOrder(userId, getPayChannel(), getAmount());
|
OrderEntity order = orderService.createOrder(userId, getPayChannel(), getAmount());
|
||||||
// 2.支付
|
// 2.支付
|
||||||
AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();
|
AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();
|
||||||
model.setSubject("BAOGUTANGMUSIC");
|
model.setSubject("N1KO MUSIC 会员");
|
||||||
model.setTotalAmount(order.getAmount().toString());
|
model.setTotalAmount(order.getAmount().toString());
|
||||||
model.setStoreId("BAOGUTANGMUSIC");
|
|
||||||
model.setTimeoutExpress("10m");
|
model.setTimeoutExpress("10m");
|
||||||
model.setOutTradeNo(order.getOrderNo());
|
model.setOutTradeNo(order.getOrderNo());
|
||||||
model.setProductCode("QR_CODE_OFFLINE");
|
model.setProductCode("FACE_TO_FACE_PAYMENT");
|
||||||
String qrCode;
|
String qrCode;
|
||||||
try {
|
try {
|
||||||
String resultStr = AliPayApi.tradePrecreatePayToResponse(model, getNotifyUrl())
|
String resultStr = AliPayApi.tradePrecreatePayToResponse(model, getNotifyUrl())
|
||||||
@ -62,6 +61,8 @@ public abstract class AbstractOrderClient {
|
|||||||
orderRes.setUserId(userId);
|
orderRes.setUserId(userId);
|
||||||
orderRes.setOrderId(order.getId());
|
orderRes.setOrderId(order.getId());
|
||||||
orderRes.setOrderNo(order.getOrderNo());
|
orderRes.setOrderNo(order.getOrderNo());
|
||||||
|
orderRes.setAmount(order.getAmount());
|
||||||
|
orderRes.setStatus(order.getStatus());
|
||||||
return orderRes;
|
return orderRes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,58 @@
|
|||||||
|
package top.baogutang.music.controller;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import top.baogutang.music.annos.Login;
|
||||||
|
import top.baogutang.music.domain.Results;
|
||||||
|
import top.baogutang.music.service.ILicenseService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码管理接口(需要登录,且需要 ADMIN 角色)
|
||||||
|
* 用于批量生成激活码、撤销激活码
|
||||||
|
*
|
||||||
|
* @author N1KO
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/admin/license")
|
||||||
|
public class AdminLicenseController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ILicenseService licenseService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量生成激活码
|
||||||
|
* POST /api/v1/admin/license/generate
|
||||||
|
* Body: { "count": 10, "durationDays": -1, "maxActivations": 3, "remark": "首批用户" }
|
||||||
|
*/
|
||||||
|
@Login
|
||||||
|
@PostMapping("/generate")
|
||||||
|
public Results<List<String>> generate(@RequestBody Map<String, Object> body) {
|
||||||
|
int count = Integer.parseInt(String.valueOf(body.getOrDefault("count", 1)));
|
||||||
|
int durationDays = Integer.parseInt(String.valueOf(body.getOrDefault("durationDays", -1)));
|
||||||
|
int maxActivations = Integer.parseInt(String.valueOf(body.getOrDefault("maxActivations", 3)));
|
||||||
|
String remark = (String) body.getOrDefault("remark", "");
|
||||||
|
List<String> codes = licenseService.generate(count, durationDays, maxActivations, remark);
|
||||||
|
return Results.ok(codes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 撤销激活码
|
||||||
|
* POST /api/v1/admin/license/revoke
|
||||||
|
* Body: { "code": "XXXX-XXXX-XXXX-XXXX" }
|
||||||
|
*/
|
||||||
|
@Login
|
||||||
|
@PostMapping("/revoke")
|
||||||
|
public Results<Void> revoke(@RequestBody Map<String, String> body) {
|
||||||
|
String code = body.getOrDefault("code", "");
|
||||||
|
boolean result = licenseService.revoke(code);
|
||||||
|
if (result) {
|
||||||
|
return Results.ok();
|
||||||
|
}
|
||||||
|
return Results.failed("激活码不存在或已撤销");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package top.baogutang.music.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import top.baogutang.music.properties.AliPayConfigProperties;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购买落地页
|
||||||
|
* GET /buy → buy.html
|
||||||
|
*
|
||||||
|
* @author N1KO
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/buy")
|
||||||
|
public class BuyPageController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AliPayConfigProperties aliPayConfigProperties;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public String buy(Model model) {
|
||||||
|
model.addAttribute("payAmount", aliPayConfigProperties.getPayAmount());
|
||||||
|
return "buy";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,24 +2,34 @@ package top.baogutang.music.controller;
|
|||||||
|
|
||||||
import com.alipay.api.AlipayApiException;
|
import com.alipay.api.AlipayApiException;
|
||||||
import com.alipay.api.internal.util.AlipaySignature;
|
import com.alipay.api.internal.util.AlipaySignature;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||||
import com.ijpay.alipay.AliPayApi;
|
import com.ijpay.alipay.AliPayApi;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import top.baogutang.music.dao.entity.OrderEntity;
|
||||||
|
import top.baogutang.music.dao.entity.UserEntity;
|
||||||
|
import top.baogutang.music.dao.mapper.OrderMapper;
|
||||||
|
import top.baogutang.music.dao.mapper.UserMapper;
|
||||||
|
import top.baogutang.music.enums.OrderStatus;
|
||||||
|
import top.baogutang.music.enums.UserLevel;
|
||||||
import top.baogutang.music.properties.AliPayConfigProperties;
|
import top.baogutang.music.properties.AliPayConfigProperties;
|
||||||
|
import top.baogutang.music.service.ILicenseService;
|
||||||
import top.baogutang.music.utils.JacksonUtil;
|
import top.baogutang.music.utils.JacksonUtil;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 支付回调处理器
|
||||||
|
* 支付宝异步通知入口:支付成功后自动升级用户等级并颁发激活码
|
||||||
*
|
*
|
||||||
* @description:
|
* @author N1KO
|
||||||
*
|
|
||||||
* @author: N1KO
|
|
||||||
* @date: 2024/12/26 : 14:36
|
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Controller
|
@Controller
|
||||||
@ -29,22 +39,110 @@ public class CallbackController {
|
|||||||
@Resource
|
@Resource
|
||||||
private AliPayConfigProperties aliPayConfigProperties;
|
private AliPayConfigProperties aliPayConfigProperties;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ILicenseService licenseService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝异步通知回调
|
||||||
|
* 支付成功后:
|
||||||
|
* 1. 验签
|
||||||
|
* 2. 更新订单状态为 PAYED
|
||||||
|
* 3. 升级用户等级为 VIP
|
||||||
|
* 4. 自动生成一枚激活码并绑定到该用户/订单
|
||||||
|
*/
|
||||||
@RequestMapping("/alipay")
|
@RequestMapping("/alipay")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String certNotifyUrl(HttpServletRequest request) {
|
public String certNotifyUrl(HttpServletRequest request) {
|
||||||
try {
|
try {
|
||||||
// 获取支付宝POST过来反馈信息
|
// 获取支付宝 POST 回调参数
|
||||||
Map<String, String> params = AliPayApi.toMap(request);
|
Map<String, String> params = AliPayApi.toMap(request);
|
||||||
log.info(">>>>>>>>>>>received callback from alipay:{}<<<<<<<<<<", JacksonUtil.toJson(params));
|
log.info("[Callback] received alipay notify: {}", JacksonUtil.toJson(params));
|
||||||
boolean verifyResult = AlipaySignature.rsaCertCheckV1(params, aliPayConfigProperties.getAliPayCertPath(), "UTF-8", "RSA2");
|
|
||||||
|
// 验签
|
||||||
|
boolean verifyResult = AlipaySignature.rsaCertCheckV1(
|
||||||
|
params, aliPayConfigProperties.getAliPayCertPath(), "UTF-8", "RSA2");
|
||||||
if (!verifyResult) {
|
if (!verifyResult) {
|
||||||
log.error(">>>>>>>>>>certNotifyUrl sign check failed<<<<<<<<<<");
|
log.error("[Callback] alipay sign verify failed");
|
||||||
return "failure";
|
return "failure";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 只处理 TRADE_SUCCESS 状态
|
||||||
|
String tradeStatus = params.getOrDefault("trade_status", "");
|
||||||
|
if (!"TRADE_SUCCESS".equals(tradeStatus)) {
|
||||||
|
log.info("[Callback] trade_status={}, skip", tradeStatus);
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
String outTradeNo = params.get("out_trade_no");
|
||||||
|
if (StringUtils.isBlank(outTradeNo)) {
|
||||||
|
log.error("[Callback] out_trade_no is blank");
|
||||||
|
return "failure";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询订单
|
||||||
|
OrderEntity order = new LambdaQueryChainWrapper<>(orderMapper)
|
||||||
|
.eq(OrderEntity::getOrderNo, outTradeNo)
|
||||||
|
.eq(OrderEntity::getDeleted, Boolean.FALSE)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
|
||||||
|
if (Objects.isNull(order)) {
|
||||||
|
log.error("[Callback] order not found: {}", outTradeNo);
|
||||||
|
return "failure";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 幂等:已支付则直接返回成功
|
||||||
|
if (OrderStatus.PAYED.equals(order.getStatus())) {
|
||||||
|
log.info("[Callback] order already payed: {}", outTradeNo);
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 更新订单状态
|
||||||
|
order.setStatus(OrderStatus.PAYED);
|
||||||
|
order.setThirdOrderNo(params.getOrDefault("trade_no", ""));
|
||||||
|
orderMapper.updateById(order);
|
||||||
|
log.info("[Callback] order payed: {}", outTradeNo);
|
||||||
|
|
||||||
|
// 2. 升级用户等级为 VIP(匿名订单 userId=0 时跳过)
|
||||||
|
Long userId = order.getUserId();
|
||||||
|
if (Objects.nonNull(userId) && userId != 0L) {
|
||||||
|
UserEntity user = userMapper.selectById(userId);
|
||||||
|
if (Objects.nonNull(user) && !UserLevel.VIP.equals(user.getLevel())) {
|
||||||
|
user.setLevel(UserLevel.VIP);
|
||||||
|
userMapper.updateById(user);
|
||||||
|
log.info("[Callback] user {} upgraded to VIP", userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 自动生成激活码并绑定到该用户/订单
|
||||||
|
try {
|
||||||
|
String licenseCode = licenseService.generateForOrder(userId, outTradeNo);
|
||||||
|
log.info("[Callback] license code generated for user={} order={} code={}",
|
||||||
|
userId, outTradeNo, licenseCode);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 激活码生成失败不影响主流程
|
||||||
|
log.error("[Callback] failed to generate license code for order: {}", outTradeNo, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 匿名订单:直接生成激活码,不绑定用户
|
||||||
|
try {
|
||||||
|
String licenseCode = licenseService.generateForOrder(0L, outTradeNo);
|
||||||
|
log.info("[Callback] anonymous license code generated for order={} code={}", outTradeNo, licenseCode);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[Callback] failed to generate license code for anonymous order: {}", outTradeNo, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return "success";
|
return "success";
|
||||||
} catch (AlipayApiException e) {
|
} catch (AlipayApiException e) {
|
||||||
log.error(">>>>>>>>>>process alipay callback failed:{}<<<<<<<<<<", e.getErrMsg(), e);
|
log.error("[Callback] process alipay callback failed: {}", e.getErrMsg(), e);
|
||||||
return "failure";
|
return "failure";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,40 @@
|
|||||||
|
package top.baogutang.music.controller;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import top.baogutang.music.domain.Results;
|
||||||
|
import top.baogutang.music.domain.res.license.ActivateRes;
|
||||||
|
import top.baogutang.music.service.ILicenseService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码公开接口(无需登录)
|
||||||
|
* N1KO MUSIC 客户端调用此接口验证激活码
|
||||||
|
*
|
||||||
|
* @author N1KO
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/license")
|
||||||
|
public class LicenseController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ILicenseService licenseService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活会员
|
||||||
|
* POST /api/v1/license/activate
|
||||||
|
* Body: { "code": "XXXX-XXXX-XXXX-XXXX" }
|
||||||
|
*/
|
||||||
|
@PostMapping("/activate")
|
||||||
|
public Results<ActivateRes> activate(@RequestBody Map<String, String> body) {
|
||||||
|
String code = body.getOrDefault("code", "");
|
||||||
|
ActivateRes res = licenseService.activate(code);
|
||||||
|
if (Boolean.TRUE.equals(res.getSuccess())) {
|
||||||
|
return Results.ok(res);
|
||||||
|
}
|
||||||
|
return Results.failed(res, res.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,42 +2,88 @@ package top.baogutang.music.controller;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import top.baogutang.music.annos.Login;
|
import top.baogutang.music.dao.entity.LicenseCodeEntity;
|
||||||
|
import top.baogutang.music.dao.entity.OrderEntity;
|
||||||
import top.baogutang.music.domain.Results;
|
import top.baogutang.music.domain.Results;
|
||||||
import top.baogutang.music.domain.res.pay.OrderRes;
|
import top.baogutang.music.domain.res.pay.OrderRes;
|
||||||
|
import top.baogutang.music.enums.OrderStatus;
|
||||||
import top.baogutang.music.enums.PayChannel;
|
import top.baogutang.music.enums.PayChannel;
|
||||||
import top.baogutang.music.factory.PayClientFactory;
|
import top.baogutang.music.factory.PayClientFactory;
|
||||||
import top.baogutang.music.utils.UserThreadLocal;
|
import top.baogutang.music.service.ILicenseService;
|
||||||
|
import top.baogutang.music.service.IOrderService;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 订单接口(无需登录,支持匿名购买)
|
||||||
|
* - GET /api/v1/music/order 下单(生成支付二维码)
|
||||||
|
* - GET /api/v1/music/order/query 查询订单状态(前端轮询)
|
||||||
*
|
*
|
||||||
* @description:
|
* @author N1KO
|
||||||
*
|
|
||||||
* @author: N1KO
|
|
||||||
* @date: 2024/12/25 : 13:37
|
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/music/order")
|
@RequestMapping("/api/v1/music/order")
|
||||||
public class OrderController {
|
public class OrderController {
|
||||||
|
|
||||||
|
/** 匿名用户 userId,用于无登录态下单 */
|
||||||
|
private static final Long ANONYMOUS_USER_ID = 0L;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PayClientFactory payClientFactory;
|
private PayClientFactory payClientFactory;
|
||||||
|
|
||||||
@Login
|
@Resource
|
||||||
|
private IOrderService orderService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ILicenseService licenseService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 匿名下单,返回支付二维码
|
||||||
|
* GET /api/v1/music/order?payChannel=ALI_PAY
|
||||||
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public Results<OrderRes> order(@RequestParam(name = "payChannel") PayChannel payChannel) {
|
public Results<OrderRes> order(@RequestParam(name = "payChannel") PayChannel payChannel) {
|
||||||
return Results.ok(payClientFactory.getClient(payChannel).order(UserThreadLocal.get()));
|
return Results.ok(payClientFactory.getClient(payChannel).order(ANONYMOUS_USER_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Login
|
/**
|
||||||
// @PostMapping("/pcPay")
|
* 查询订单状态(前端每 3 秒轮询一次,检测是否支付成功)
|
||||||
// public void webPay(@RequestParam(name = "payChannel") PayChannel payChannel,
|
* GET /api/v1/music/order/query?orderId=123
|
||||||
// @RequestParam(name = "orderId") Long orderId,
|
*
|
||||||
// HttpServletResponse response) {
|
* 支付成功时响应额外携带 licenseCode,前端可直接激活
|
||||||
// payClientFactory.getClient(payChannel).pcPay(UserThreadLocal.get(), orderId, response);
|
*/
|
||||||
// }
|
@GetMapping("/query")
|
||||||
|
public Results<OrderRes> query(@RequestParam(name = "orderId") Long orderId) {
|
||||||
|
// 匿名订单直接按 orderId 查,不校验 userId
|
||||||
|
OrderEntity order = orderService.lambdaQuery()
|
||||||
|
.eq(OrderEntity::getId, orderId)
|
||||||
|
.eq(OrderEntity::getDeleted, Boolean.FALSE)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
if (Objects.isNull(order)) {
|
||||||
|
return Results.failed("订单不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
OrderRes res = new OrderRes();
|
||||||
|
res.setOrderId(order.getId());
|
||||||
|
res.setOrderNo(order.getOrderNo());
|
||||||
|
res.setAmount(order.getAmount());
|
||||||
|
res.setStatus(order.getStatus());
|
||||||
|
|
||||||
|
// 支付成功时,查询并返回该订单绑定的激活码
|
||||||
|
if (OrderStatus.PAYED.equals(order.getStatus())) {
|
||||||
|
LicenseCodeEntity license = licenseService.lambdaQuery()
|
||||||
|
.eq(LicenseCodeEntity::getOrderNo, order.getOrderNo())
|
||||||
|
.eq(LicenseCodeEntity::getDeleted, Boolean.FALSE)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
if (Objects.nonNull(license)) {
|
||||||
|
res.setLicenseCode(license.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Results.ok(res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,72 @@
|
|||||||
|
package top.baogutang.music.dao.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码实体
|
||||||
|
* 用于 N1KO MUSIC 客户端会员功能激活
|
||||||
|
*
|
||||||
|
* @author N1KO
|
||||||
|
* @date 2025/01
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@TableName("t_license_code")
|
||||||
|
public class LicenseCodeEntity extends BaseEntity {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码(格式:XXXX-XXXX-XXXX-XXXX)
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员等级(premium)
|
||||||
|
*/
|
||||||
|
private String tier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有效期天数,-1 表示永久
|
||||||
|
*/
|
||||||
|
private Integer durationDays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已激活次数
|
||||||
|
*/
|
||||||
|
private Integer activationCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大可激活次数(默认3台设备)
|
||||||
|
*/
|
||||||
|
private Integer maxActivations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已撤销
|
||||||
|
*/
|
||||||
|
private Boolean revoked;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联的订单号(支付后自动生成时填充)
|
||||||
|
*/
|
||||||
|
private String orderNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联的用户ID(支付后自动生成时填充)
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注(批次标识等)
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后激活时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime lastActivatedAt;
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package top.baogutang.music.dao.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import top.baogutang.music.dao.entity.LicenseCodeEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码 Mapper
|
||||||
|
*
|
||||||
|
* @author N1KO
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface LicenseCodeMapper extends BaseMapper<LicenseCodeEntity> {
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package top.baogutang.music.domain.res.license;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码激活响应
|
||||||
|
*
|
||||||
|
* @author N1KO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ActivateRes {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否激活成功
|
||||||
|
*/
|
||||||
|
private Boolean success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示信息
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过期时间戳(毫秒),-1 表示永久,null 表示未激活
|
||||||
|
*/
|
||||||
|
private Long expireAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员等级
|
||||||
|
*/
|
||||||
|
private String tier;
|
||||||
|
|
||||||
|
public static ActivateRes success(String message, Long expireAt, String tier) {
|
||||||
|
ActivateRes res = new ActivateRes();
|
||||||
|
res.setSuccess(Boolean.TRUE);
|
||||||
|
res.setMessage(message);
|
||||||
|
res.setExpireAt(expireAt);
|
||||||
|
res.setTier(tier);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ActivateRes fail(String message) {
|
||||||
|
ActivateRes res = new ActivateRes();
|
||||||
|
res.setSuccess(Boolean.FALSE);
|
||||||
|
res.setMessage(message);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,15 +1,15 @@
|
|||||||
package top.baogutang.music.domain.res.pay;
|
package top.baogutang.music.domain.res.pay;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import top.baogutang.music.enums.OrderStatus;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 下单 / 查询订单响应
|
||||||
*
|
*
|
||||||
* @description:
|
* @author N1KO
|
||||||
*
|
|
||||||
* @author: N1KO
|
|
||||||
* @date: 2024/12/25 : 15:14
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class OrderRes implements Serializable {
|
public class OrderRes implements Serializable {
|
||||||
@ -22,6 +22,15 @@ public class OrderRes implements Serializable {
|
|||||||
|
|
||||||
private String orderNo;
|
private String orderNo;
|
||||||
|
|
||||||
|
/** 支付宝订单码二维码 URL,前端展示扫码 */
|
||||||
private String qrCode;
|
private String qrCode;
|
||||||
|
|
||||||
|
/** 订单金额 */
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
/** 订单状态:CREATED / PAYED / CANCELED */
|
||||||
|
private OrderStatus status;
|
||||||
|
|
||||||
|
/** 支付成功后自动生成的激活码(只在 PAYED 时返回,方便前端直接激活)*/
|
||||||
|
private String licenseCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,51 @@
|
|||||||
|
package top.baogutang.music.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import top.baogutang.music.dao.entity.LicenseCodeEntity;
|
||||||
|
import top.baogutang.music.domain.res.license.ActivateRes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码 Service 接口
|
||||||
|
*
|
||||||
|
* @author N1KO
|
||||||
|
*/
|
||||||
|
public interface ILicenseService extends IService<LicenseCodeEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活激活码(前端调用)
|
||||||
|
*
|
||||||
|
* @param code 激活码
|
||||||
|
* @return 激活结果
|
||||||
|
*/
|
||||||
|
ActivateRes activate(String code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量生成激活码(管理员调用)
|
||||||
|
*
|
||||||
|
* @param count 数量
|
||||||
|
* @param durationDays 有效期天数(-1 永久)
|
||||||
|
* @param maxActivations 最大激活次数
|
||||||
|
* @param remark 备注
|
||||||
|
* @return 生成的激活码列表
|
||||||
|
*/
|
||||||
|
List<String> generate(int count, int durationDays, int maxActivations, String remark);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功后为指定用户自动生成并绑定激活码
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param orderNo 订单号
|
||||||
|
* @return 生成的激活码
|
||||||
|
*/
|
||||||
|
String generateForOrder(Long userId, String orderNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 撤销激活码(管理员调用)
|
||||||
|
*
|
||||||
|
* @param code 激活码
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean revoke(String code);
|
||||||
|
}
|
||||||
@ -16,4 +16,13 @@ import java.math.BigDecimal;
|
|||||||
public interface IOrderService extends IService<OrderEntity> {
|
public interface IOrderService extends IService<OrderEntity> {
|
||||||
|
|
||||||
OrderEntity createOrder(Long userId, PayChannel payChannel, BigDecimal amount);
|
OrderEntity createOrder(Long userId, PayChannel payChannel, BigDecimal amount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户当前最新一笔订单
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param orderId 订单ID(精确查询,可为 null 则查最新一笔)
|
||||||
|
* @return 订单实体,不存在返回 null
|
||||||
|
*/
|
||||||
|
OrderEntity queryOrder(Long userId, Long orderId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,172 @@
|
|||||||
|
package top.baogutang.music.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import top.baogutang.music.dao.entity.LicenseCodeEntity;
|
||||||
|
import top.baogutang.music.dao.mapper.LicenseCodeMapper;
|
||||||
|
import top.baogutang.music.domain.res.license.ActivateRes;
|
||||||
|
import top.baogutang.music.service.ILicenseService;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码 Service 实现
|
||||||
|
*
|
||||||
|
* @author N1KO
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class LicenseServiceImpl extends ServiceImpl<LicenseCodeMapper, LicenseCodeEntity> implements ILicenseService {
|
||||||
|
|
||||||
|
// 去掉易混淆字符 0/O/1/I
|
||||||
|
private static final String CODE_CHARS = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
||||||
|
private static final SecureRandom RANDOM = new SecureRandom();
|
||||||
|
private static final int DEFAULT_MAX_ACTIVATIONS = 3;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ActivateRes activate(String code) {
|
||||||
|
if (StringUtils.isBlank(code)) {
|
||||||
|
return ActivateRes.fail("激活码不能为空");
|
||||||
|
}
|
||||||
|
String trimCode = code.trim().toUpperCase();
|
||||||
|
|
||||||
|
LicenseCodeEntity license = new LambdaQueryChainWrapper<>(baseMapper)
|
||||||
|
.eq(LicenseCodeEntity::getCode, trimCode)
|
||||||
|
.eq(LicenseCodeEntity::getDeleted, Boolean.FALSE)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
|
||||||
|
if (Objects.isNull(license)) {
|
||||||
|
log.warn("[License] activate failed - not found: {}", trimCode);
|
||||||
|
return ActivateRes.fail("激活码无效,请检查后重试");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Boolean.TRUE.equals(license.getRevoked())) {
|
||||||
|
log.warn("[License] activate failed - revoked: {}", trimCode);
|
||||||
|
return ActivateRes.fail("该激活码已被撤销");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (license.getActivationCount() >= license.getMaxActivations()) {
|
||||||
|
log.warn("[License] activate failed - max activations reached: {}", trimCode);
|
||||||
|
return ActivateRes.fail("该激活码已达到最大激活设备数(" + license.getMaxActivations() + " 台)");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算过期时间
|
||||||
|
long expireAt;
|
||||||
|
if (license.getDurationDays() == null || license.getDurationDays() == -1) {
|
||||||
|
expireAt = -1L; // 永久
|
||||||
|
} else {
|
||||||
|
expireAt = LocalDateTime.now()
|
||||||
|
.plusDays(license.getDurationDays())
|
||||||
|
.toInstant(ZoneOffset.UTC)
|
||||||
|
.toEpochMilli();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新激活次数
|
||||||
|
license.setActivationCount(license.getActivationCount() + 1);
|
||||||
|
license.setLastActivatedAt(LocalDateTime.now());
|
||||||
|
updateById(license);
|
||||||
|
|
||||||
|
log.info("[License] activated: {} ({}/{})", trimCode, license.getActivationCount(), license.getMaxActivations());
|
||||||
|
return ActivateRes.success("激活成功!欢迎成为 N1KO MUSIC 会员 🎵", expireAt, license.getTier());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public List<String> generate(int count, int durationDays, int maxActivations, String remark) {
|
||||||
|
int safeCount = Math.min(count, 1000);
|
||||||
|
int safeMaxAct = maxActivations > 0 ? maxActivations : DEFAULT_MAX_ACTIVATIONS;
|
||||||
|
List<String> codes = new ArrayList<>(safeCount);
|
||||||
|
|
||||||
|
for (int i = 0; i < safeCount; i++) {
|
||||||
|
String code = generateUniqueCode();
|
||||||
|
LicenseCodeEntity entity = buildLicense(code, durationDays, safeMaxAct, remark, null, null);
|
||||||
|
save(entity);
|
||||||
|
codes.add(code);
|
||||||
|
}
|
||||||
|
log.info("[License] generated {} codes, remark: {}", safeCount, remark);
|
||||||
|
return codes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public String generateForOrder(Long userId, String orderNo) {
|
||||||
|
String code = generateUniqueCode();
|
||||||
|
// 订单付款对应永久会员,可在此按需修改 durationDays
|
||||||
|
LicenseCodeEntity entity = buildLicense(code, -1, DEFAULT_MAX_ACTIVATIONS, "支付宝支付-自动生成", orderNo, userId);
|
||||||
|
save(entity);
|
||||||
|
log.info("[License] generated for order: {} user: {} code: {}", orderNo, userId, code);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean revoke(String code) {
|
||||||
|
if (StringUtils.isBlank(code)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LicenseCodeEntity license = new LambdaQueryChainWrapper<>(baseMapper)
|
||||||
|
.eq(LicenseCodeEntity::getCode, code.trim().toUpperCase())
|
||||||
|
.eq(LicenseCodeEntity::getDeleted, Boolean.FALSE)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
if (Objects.isNull(license)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
license.setRevoked(Boolean.TRUE);
|
||||||
|
updateById(license);
|
||||||
|
log.info("[License] revoked: {}", code);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================== private =====================
|
||||||
|
|
||||||
|
private LicenseCodeEntity buildLicense(String code, int durationDays, int maxActivations,
|
||||||
|
String remark, String orderNo, Long userId) {
|
||||||
|
LicenseCodeEntity entity = new LicenseCodeEntity();
|
||||||
|
entity.setCode(code);
|
||||||
|
entity.setTier("premium");
|
||||||
|
entity.setDurationDays(durationDays);
|
||||||
|
entity.setActivationCount(0);
|
||||||
|
entity.setMaxActivations(maxActivations);
|
||||||
|
entity.setRevoked(Boolean.FALSE);
|
||||||
|
entity.setRemark(remark);
|
||||||
|
entity.setOrderNo(orderNo);
|
||||||
|
entity.setUserId(userId);
|
||||||
|
entity.setDeleted(Boolean.FALSE);
|
||||||
|
entity.setCreateTime(LocalDateTime.now());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateUniqueCode() {
|
||||||
|
String code;
|
||||||
|
do {
|
||||||
|
code = buildCodeString();
|
||||||
|
} while (lambdaQuery()
|
||||||
|
.eq(LicenseCodeEntity::getCode, code)
|
||||||
|
.eq(LicenseCodeEntity::getDeleted, Boolean.FALSE)
|
||||||
|
.exists());
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildCodeString() {
|
||||||
|
StringBuilder sb = new StringBuilder(19);
|
||||||
|
for (int seg = 0; seg < 4; seg++) {
|
||||||
|
if (seg > 0) sb.append('-');
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
sb.append(CODE_CHARS.charAt(RANDOM.nextInt(CODE_CHARS.length())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -50,4 +50,17 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderEntity> impl
|
|||||||
// 3.返回订单
|
// 3.返回订单
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderEntity queryOrder(Long userId, Long orderId) {
|
||||||
|
LambdaQueryChainWrapper<OrderEntity> wrapper = new LambdaQueryChainWrapper<>(baseMapper)
|
||||||
|
.eq(OrderEntity::getUserId, userId)
|
||||||
|
.eq(OrderEntity::getDeleted, false);
|
||||||
|
if (Objects.nonNull(orderId)) {
|
||||||
|
wrapper.eq(OrderEntity::getId, orderId);
|
||||||
|
}
|
||||||
|
return wrapper.orderByDesc(OrderEntity::getCreateTime)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/main/resources/sql/t_license_code.sql
Normal file
23
src/main/resources/sql/t_license_code.sql
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
-- N1KO MUSIC 激活码表
|
||||||
|
-- 支付完成后自动生成激活码,前端通过 POST /api/v1/license/activate 验证
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `t_license_code` (
|
||||||
|
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||||
|
`code` VARCHAR(64) NOT NULL COMMENT '激活码,格式:XXXX-XXXX-XXXX-XXXX',
|
||||||
|
`tier` VARCHAR(32) NOT NULL DEFAULT 'premium' COMMENT '会员等级',
|
||||||
|
`duration_days` INT NOT NULL DEFAULT -1 COMMENT '有效期天数,-1 表示永久',
|
||||||
|
`activation_count` INT NOT NULL DEFAULT 0 COMMENT '已激活次数',
|
||||||
|
`max_activations` INT NOT NULL DEFAULT 3 COMMENT '最大可激活次数(设备数)',
|
||||||
|
`revoked` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否已撤销',
|
||||||
|
`order_no` VARCHAR(64) COMMENT '关联订单号(支付后自动生成时填充)',
|
||||||
|
`user_id` BIGINT COMMENT '关联用户ID(支付后自动生成时填充)',
|
||||||
|
`remark` VARCHAR(255) COMMENT '备注(批次名称等)',
|
||||||
|
`last_activated_at` DATETIME COMMENT '最后激活时间',
|
||||||
|
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除(0-未删除,1-已删除)',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `uk_code` (`code`),
|
||||||
|
KEY `idx_user_id` (`user_id`),
|
||||||
|
KEY `idx_order_no` (`order_no`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='N1KO MUSIC 激活码表';
|
||||||
446
src/main/resources/templates/buy.html
Normal file
446
src/main/resources/templates/buy.html
Normal file
@ -0,0 +1,446 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<link rel="icon" type="image/png" th:href="@{/NIKO.png}">
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>N1KO MUSIC - 购买会员</title>
|
||||||
|
<style>
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||||
|
min-height: 100vh;
|
||||||
|
background: #0f0f13;
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── 左侧品牌区 ─── */
|
||||||
|
.left {
|
||||||
|
display: none;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
background: linear-gradient(135deg, #f59e0b 0%, #ea580c 60%, #c2410c 100%);
|
||||||
|
padding: 48px;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
@media (min-width: 960px) { .left { display: flex; } }
|
||||||
|
|
||||||
|
.left::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Ccircle cx='30' cy='30' r='20'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-logo {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
position: absolute;
|
||||||
|
top: 40px; left: 40px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
.brand-logo-icon {
|
||||||
|
width: 40px; height: 40px;
|
||||||
|
background: rgba(255,255,255,0.2);
|
||||||
|
border-radius: 10px;
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
.brand-logo-text { font-size: 1.2rem; font-weight: 700; }
|
||||||
|
|
||||||
|
.brand-content { position: relative; z-index: 2; }
|
||||||
|
.brand-title { font-size: 2.2rem; font-weight: 800; line-height: 1.2; margin-bottom: 16px; }
|
||||||
|
.brand-subtitle { font-size: 1rem; opacity: 0.85; line-height: 1.6; margin-bottom: 36px; }
|
||||||
|
|
||||||
|
.features { display: flex; flex-direction: column; gap: 14px; }
|
||||||
|
.feature-item {
|
||||||
|
display: flex; align-items: center; gap: 12px;
|
||||||
|
background: rgba(255,255,255,0.12);
|
||||||
|
border-radius: 12px; padding: 12px 16px;
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
}
|
||||||
|
.feature-icon {
|
||||||
|
width: 36px; height: 36px; border-radius: 8px;
|
||||||
|
background: rgba(255,255,255,0.2);
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
font-size: 16px; flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.feature-text { font-size: 0.88rem; }
|
||||||
|
.feature-text strong { display: block; font-weight: 600; margin-bottom: 2px; }
|
||||||
|
.feature-text span { opacity: 0.75; font-size: 0.78rem; }
|
||||||
|
|
||||||
|
/* ─── 右侧支付区 ─── */
|
||||||
|
.right {
|
||||||
|
display: flex; flex-direction: column;
|
||||||
|
align-items: center; justify-content: center;
|
||||||
|
padding: 40px 32px;
|
||||||
|
background: #0f0f13;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
width: 100%; max-width: 400px;
|
||||||
|
background: #1a1a22;
|
||||||
|
border: 1px solid rgba(255,255,255,0.08);
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 36px 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header { text-align: center; margin-bottom: 28px; }
|
||||||
|
.crown-icon {
|
||||||
|
width: 56px; height: 56px; border-radius: 16px;
|
||||||
|
background: linear-gradient(135deg, #f59e0b, #ea580c);
|
||||||
|
display: inline-flex; align-items: center; justify-content: center;
|
||||||
|
font-size: 28px; margin-bottom: 14px;
|
||||||
|
box-shadow: 0 8px 24px rgba(245,158,11,0.35);
|
||||||
|
}
|
||||||
|
.card-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 6px; }
|
||||||
|
.card-subtitle { font-size: 0.85rem; color: rgba(255,255,255,0.45); }
|
||||||
|
|
||||||
|
.price-block {
|
||||||
|
text-align: center;
|
||||||
|
margin: 20px 0 24px;
|
||||||
|
padding: 16px;
|
||||||
|
background: rgba(245,158,11,0.06);
|
||||||
|
border: 1px solid rgba(245,158,11,0.2);
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
.price-amount { font-size: 2.6rem; font-weight: 800; color: #f59e0b; }
|
||||||
|
.price-label { font-size: 0.8rem; color: rgba(255,255,255,0.4); margin-top: 4px; }
|
||||||
|
|
||||||
|
/* ─── 状态区 ─── */
|
||||||
|
#state-idle { display: block; }
|
||||||
|
#state-loading { display: none; text-align: center; padding: 24px 0; }
|
||||||
|
#state-qr { display: none; text-align: center; }
|
||||||
|
#state-success { display: none; text-align: center; padding: 24px 0; }
|
||||||
|
#state-error { display: none; }
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
width: 100%; height: 48px; border: none; border-radius: 12px; cursor: pointer;
|
||||||
|
font-size: 1rem; font-weight: 600;
|
||||||
|
background: linear-gradient(135deg, #f59e0b, #ea580c);
|
||||||
|
color: #fff;
|
||||||
|
transition: opacity .2s, transform .1s;
|
||||||
|
}
|
||||||
|
.btn:hover { opacity: 0.9; }
|
||||||
|
.btn:active { transform: scale(0.98); }
|
||||||
|
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||||
|
|
||||||
|
.btn-ghost {
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid rgba(255,255,255,0.12);
|
||||||
|
color: rgba(255,255,255,0.5);
|
||||||
|
font-size: 0.82rem;
|
||||||
|
height: 36px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.btn-ghost:hover { color: rgba(255,255,255,0.8); border-color: rgba(255,255,255,0.25); opacity: 1; }
|
||||||
|
|
||||||
|
.qr-wrapper {
|
||||||
|
width: 192px; height: 192px; border-radius: 16px;
|
||||||
|
background: #fff; margin: 0 auto 16px;
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.qr-wrapper img { width: 100%; height: 100%; object-fit: contain; }
|
||||||
|
|
||||||
|
.countdown {
|
||||||
|
font-size: 0.78rem; color: rgba(255,255,255,0.35);
|
||||||
|
display: flex; align-items: center; gap-6: 6px; justify-content: center;
|
||||||
|
gap: 6px; margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.dot-pulse {
|
||||||
|
width: 7px; height: 7px; border-radius: 50%;
|
||||||
|
background: #4ade80; animation: pulse 1.2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
|
||||||
|
|
||||||
|
.success-icon {
|
||||||
|
width: 64px; height: 64px; border-radius: 50%;
|
||||||
|
background: rgba(74,222,128,0.15);
|
||||||
|
display: inline-flex; align-items: center; justify-content: center;
|
||||||
|
font-size: 32px; margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
.success-title { font-size: 1.2rem; font-weight: 700; color: #4ade80; margin-bottom: 8px; }
|
||||||
|
.success-sub { font-size: 0.82rem; color: rgba(255,255,255,0.45); margin-bottom: 20px; }
|
||||||
|
|
||||||
|
.license-box {
|
||||||
|
background: rgba(255,255,255,0.05);
|
||||||
|
border: 1px solid rgba(255,255,255,0.1);
|
||||||
|
border-radius: 10px; padding: 14px 16px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
.license-label { font-size: 0.72rem; color: rgba(255,255,255,0.35); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em; }
|
||||||
|
.license-code {
|
||||||
|
font-family: 'Courier New', monospace; font-size: 1.1rem;
|
||||||
|
font-weight: 700; letter-spacing: .2em; color: #f59e0b;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-btn {
|
||||||
|
width: 100%; height: 40px; border: none; border-radius: 10px; cursor: pointer;
|
||||||
|
background: rgba(245,158,11,0.15); color: #f59e0b;
|
||||||
|
font-size: 0.88rem; font-weight: 600;
|
||||||
|
transition: background .2s;
|
||||||
|
}
|
||||||
|
.copy-btn:hover { background: rgba(245,158,11,0.25); }
|
||||||
|
|
||||||
|
.hint {
|
||||||
|
font-size: 0.75rem; color: rgba(255,255,255,0.25);
|
||||||
|
text-align: center; margin-top: 20px; line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-box {
|
||||||
|
background: rgba(239,68,68,0.1);
|
||||||
|
border: 1px solid rgba(239,68,68,0.25);
|
||||||
|
border-radius: 10px; padding: 12px 14px;
|
||||||
|
font-size: 0.84rem; color: #f87171;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.1);
|
||||||
|
border-top-color: #f59e0b; border-radius: 50%;
|
||||||
|
animation: spin .8s linear infinite; margin: 0 auto 14px;
|
||||||
|
}
|
||||||
|
@keyframes spin { to { transform: rotate(360deg); } }
|
||||||
|
|
||||||
|
.loading-text { font-size: 0.88rem; color: rgba(255,255,255,0.45); }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="page">
|
||||||
|
|
||||||
|
<!-- ─── 左侧品牌区 ─── -->
|
||||||
|
<div class="left">
|
||||||
|
<div class="brand-logo">
|
||||||
|
<div class="brand-logo-icon">🎵</div>
|
||||||
|
<span class="brand-logo-text">N1KO MUSIC</span>
|
||||||
|
</div>
|
||||||
|
<div class="brand-content">
|
||||||
|
<h1 class="brand-title">解锁完整<br>音乐体验</h1>
|
||||||
|
<p class="brand-subtitle">一次性永久会员,享受所有高级功能</p>
|
||||||
|
<div class="features">
|
||||||
|
<div class="feature-item">
|
||||||
|
<div class="feature-icon">🎧</div>
|
||||||
|
<div class="feature-text">
|
||||||
|
<strong>无损原码音质</strong>
|
||||||
|
<span>支持 FLAC、无损原码等高品质格式</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="feature-item">
|
||||||
|
<div class="feature-icon">⚡</div>
|
||||||
|
<div class="feature-text">
|
||||||
|
<strong>智能推荐</strong>
|
||||||
|
<span>根据你的口味精选个性化歌单</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="feature-item">
|
||||||
|
<div class="feature-icon">⭐</div>
|
||||||
|
<div class="feature-text">
|
||||||
|
<strong>我的收藏</strong>
|
||||||
|
<span>跨设备同步收藏夹,随时随地听</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="feature-item">
|
||||||
|
<div class="feature-icon">📊</div>
|
||||||
|
<div class="feature-text">
|
||||||
|
<strong>听歌统计</strong>
|
||||||
|
<span>详细播放数据,了解你的音乐偏好</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ─── 右侧支付区 ─── -->
|
||||||
|
<div class="right">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="crown-icon">👑</div>
|
||||||
|
<div class="card-title">开通永久会员</div>
|
||||||
|
<div class="card-subtitle">扫码支付宝完成购买,立即获得激活码</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="price-block">
|
||||||
|
<div class="price-amount">¥<span th:text="${payAmount}">29.9</span></div>
|
||||||
|
<div class="price-label">永久会员 · 一次付清</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 初始状态 -->
|
||||||
|
<div id="state-idle">
|
||||||
|
<button class="btn" onclick="createOrder()">立即扫码购买</button>
|
||||||
|
<div class="hint">点击后生成支付宝二维码,有效期 10 分钟</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 加载中 -->
|
||||||
|
<div id="state-loading">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<div class="loading-text">正在生成支付二维码…</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 二维码展示 -->
|
||||||
|
<div id="state-qr">
|
||||||
|
<div class="qr-wrapper">
|
||||||
|
<img id="qr-img" src="" alt="支付宝二维码"/>
|
||||||
|
</div>
|
||||||
|
<div class="countdown">
|
||||||
|
<div class="dot-pulse"></div>
|
||||||
|
<span>等待支付 · 二维码 <span id="cd-text">10:00</span> 后过期</span>
|
||||||
|
</div>
|
||||||
|
<button class="btn" onclick="refreshOrder()">刷新二维码</button>
|
||||||
|
<button class="btn btn-ghost" onclick="resetState()">取消</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 支付成功 -->
|
||||||
|
<div id="state-success">
|
||||||
|
<div class="success-icon">✅</div>
|
||||||
|
<div class="success-title">支付成功!</div>
|
||||||
|
<div class="success-sub">请复制下方激活码,回到 N1KO MUSIC 填入</div>
|
||||||
|
<div class="license-box">
|
||||||
|
<div class="license-label">你的激活码</div>
|
||||||
|
<div class="license-code" id="license-code-text">—</div>
|
||||||
|
</div>
|
||||||
|
<button class="copy-btn" onclick="copyCode()">📋 复制激活码</button>
|
||||||
|
<div class="hint">激活码可重复使用,请妥善保管</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 错误状态 -->
|
||||||
|
<div id="state-error">
|
||||||
|
<div class="error-box" id="error-msg">下单失败,请稍后重试</div>
|
||||||
|
<button class="btn" onclick="createOrder()">重新尝试</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const API_BASE = ''; // 同域,无需前缀
|
||||||
|
let orderId = null;
|
||||||
|
let pollTimer = null;
|
||||||
|
let cdTimer = null;
|
||||||
|
let countdown = 0;
|
||||||
|
|
||||||
|
function show(state) {
|
||||||
|
['idle','loading','qr','success','error'].forEach(s => {
|
||||||
|
document.getElementById('state-' + s).style.display = (s === state ? (s === 'idle' ? 'block' : 'block') : 'none');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopTimers() {
|
||||||
|
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
|
||||||
|
if (cdTimer) { clearInterval(cdTimer); cdTimer = null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
function startCountdown(seconds) {
|
||||||
|
countdown = seconds;
|
||||||
|
updateCd();
|
||||||
|
cdTimer = setInterval(() => {
|
||||||
|
countdown--;
|
||||||
|
updateCd();
|
||||||
|
if (countdown <= 0) {
|
||||||
|
stopTimers();
|
||||||
|
showError('二维码已过期,请刷新重新获取');
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateCd() {
|
||||||
|
const m = String(Math.floor(countdown / 60)).padStart(2, '0');
|
||||||
|
const s = String(countdown % 60).padStart(2, '0');
|
||||||
|
document.getElementById('cd-text').textContent = m + ':' + s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function startPolling() {
|
||||||
|
pollTimer = setInterval(async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(API_BASE + '/api/v1/music/order/query?orderId=' + orderId);
|
||||||
|
const json = await res.json();
|
||||||
|
if (json.code !== 200 || !json.data) return;
|
||||||
|
const data = json.data;
|
||||||
|
if (data.status === 'PAYED') {
|
||||||
|
stopTimers();
|
||||||
|
showSuccess(data.licenseCode || '');
|
||||||
|
} else if (data.status === 'CANCELED') {
|
||||||
|
stopTimers();
|
||||||
|
showError('订单已取消,请重新下单');
|
||||||
|
}
|
||||||
|
} catch (e) { /* 静默忽略轮询异常 */ }
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createOrder() {
|
||||||
|
stopTimers();
|
||||||
|
show('loading');
|
||||||
|
try {
|
||||||
|
const res = await fetch(API_BASE + '/api/v1/music/order?payChannel=ALI_PAY');
|
||||||
|
const json = await res.json();
|
||||||
|
if (json.code !== 200 || !json.data || !json.data.qrCode) {
|
||||||
|
showError(json.msg || json.message || '下单失败,请稍后重试');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = json.data;
|
||||||
|
orderId = data.orderId;
|
||||||
|
const qrUrl = 'https://api.qrserver.com/v1/create-qr-code/?size=192x192&data=' + encodeURIComponent(data.qrCode);
|
||||||
|
document.getElementById('qr-img').src = qrUrl;
|
||||||
|
show('qr');
|
||||||
|
startCountdown(600);
|
||||||
|
startPolling();
|
||||||
|
} catch (e) {
|
||||||
|
showError('网络异常,请检查连接后重试');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshOrder() {
|
||||||
|
createOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetState() {
|
||||||
|
stopTimers();
|
||||||
|
orderId = null;
|
||||||
|
show('idle');
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSuccess(code) {
|
||||||
|
document.getElementById('license-code-text').textContent = code || '(激活码生成中,请稍候查看邮件)';
|
||||||
|
show('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
function showError(msg) {
|
||||||
|
document.getElementById('error-msg').textContent = msg;
|
||||||
|
show('error');
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyCode() {
|
||||||
|
const code = document.getElementById('license-code-text').textContent;
|
||||||
|
if (!code || code === '—') return;
|
||||||
|
navigator.clipboard.writeText(code).then(() => {
|
||||||
|
const btn = document.querySelector('.copy-btn');
|
||||||
|
const orig = btn.textContent;
|
||||||
|
btn.textContent = '✅ 已复制!';
|
||||||
|
setTimeout(() => { btn.textContent = orig; }, 2000);
|
||||||
|
}).catch(() => {
|
||||||
|
// fallback
|
||||||
|
const ta = document.createElement('textarea');
|
||||||
|
ta.value = code;
|
||||||
|
document.body.appendChild(ta);
|
||||||
|
ta.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(ta);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user