@@ -64,4 +64,9 @@ public class BaseController { | |||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||
return IPUtil.getIpAddr(request); | |||
} | |||
public Long getServiceId() { | |||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||
return (Long) request.getAttribute(Constant.SERVICE_ID); | |||
} | |||
} |
@@ -1,13 +1,11 @@ | |||
package com.iformall.controller.ai; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.domain.po.sm.UserMouldVideo; | |||
import com.iformall.controller.BaseController; | |||
import com.iformall.dto.GenerateVideoDTO; | |||
import com.iformall.dto.PreviewVideoDTO; | |||
import com.iformall.service.AiVideoService; | |||
import com.iformall.sm.AiPreviewParam; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
@@ -18,13 +16,13 @@ import org.springframework.web.bind.annotation.RestController; | |||
@Api(tags = "视频相关api") | |||
@RestController | |||
@RequestMapping("/ai/video") | |||
public class AiVideoController { | |||
public class AiVideoController extends BaseController { | |||
@Autowired | |||
private AiVideoService aiVideoService; | |||
@ApiOperation("预览") | |||
@PostMapping("/preview") | |||
@PostMapping("/previewVideo") | |||
public ResultData previewVideo(@RequestBody PreviewVideoDTO dto) { | |||
return new ResultData(aiVideoService.previewVideo(PreviewVideoDTO.mappingParam(dto))); | |||
} | |||
@@ -32,6 +30,6 @@ public class AiVideoController { | |||
@ApiOperation("生成视频") | |||
@PostMapping("generateVideo") | |||
public ResultData generateVideo(@RequestBody GenerateVideoDTO dto) { | |||
return new ResultData(aiVideoService.generateVideo(dto.getAiVideoParam(), dto.getId())); | |||
return new ResultData(aiVideoService.generateVideo(dto.getAiVideoParam(), dto.getId(), getServiceId())); | |||
} | |||
} |
@@ -50,6 +50,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
if(apiConfig == null){ | |||
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"非法请求"); | |||
} | |||
request.setAttribute(Constant.SERVICE_ID, apiConfig.getServiceId()); | |||
request.setAttribute(Constant.APP_Id, apiConfig.getAppId()); | |||
request.setAttribute(Constant.TENANT_ID, apiConfig.getTenantId()); | |||
request.setAttribute(Constant.PARENT_TENANT_ID, apiConfig.getParentTenantId()); | |||
@@ -77,7 +78,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
if(StringUtils.isBlank(timeStamp)){ | |||
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"缺少timeStamp"); | |||
} | |||
long timestampDate = Long.valueOf(timeStamp) + 1000*60*5;//五分钟有效 | |||
long timestampDate = Long.parseLong(timeStamp) + 1000*60*5;//五分钟有效 | |||
long currDate = System.currentTimeMillis(); | |||
// 请求过期 | |||
if (timestampDate < currDate) { | |||
@@ -85,9 +86,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
} | |||
for (String key:notKeys) { | |||
if(parameterMap.containsKey(key)){ | |||
parameterMap.remove(key); | |||
} | |||
parameterMap.remove(key); | |||
} | |||
String newSignature = SignUtils.getSign(apiConfig.getSignKey(), parameterMap, "MD5"); | |||
@@ -23,5 +23,5 @@ public interface AiVideoService { | |||
* @param aiVideoParam | |||
* @return {@link AiVideoResult} | |||
*/ | |||
AiVideoResult generateVideo(AiVideoParam aiVideoParam, Long taskId); | |||
AiVideoResult generateVideo(AiVideoParam aiVideoParam, Long taskId, Long serviceId); | |||
} |
@@ -1,12 +1,14 @@ | |||
package com.iformall.service.impl; | |||
import com.iformall.common.ErrorCode; | |||
import com.iformall.domain.dto.neuver.SaveServiceVideoRecordDTO; | |||
import com.iformall.domain.po.sm.UserMouldVideo; | |||
import com.iformall.dto.GenerateVideoDTO; | |||
import com.iformall.dto.PreviewVideoDTO; | |||
import com.iformall.enums.EnumVideoStatus; | |||
import com.iformall.exception.BizException; | |||
import com.iformall.service.AiVideoService; | |||
import com.iformall.service.sm.ServiceVideoRecordService; | |||
import com.iformall.service.sm.UserMouldVideoService; | |||
import com.iformall.service.sm.VoiceInfoService; | |||
import com.iformall.sm.*; | |||
@@ -26,10 +28,10 @@ import java.util.Optional; | |||
@Service | |||
public class AiVideoServiceImpl implements AiVideoService { | |||
@Autowired | |||
private VoiceInfoService voiceInfoService; | |||
@Autowired | |||
private UserMouldVideoService userMouldVideoService; | |||
@Autowired | |||
private ServiceVideoRecordService serviceVideoRecordService; | |||
@Override | |||
public AiPreviewResult previewVideo(AiPreviewParam aiPreviewParam) { | |||
@@ -37,7 +39,7 @@ public class AiVideoServiceImpl implements AiVideoService { | |||
} | |||
@Override | |||
public AiVideoResult generateVideo(AiVideoParam aiVideoParam, Long taskId) { | |||
public AiVideoResult generateVideo(AiVideoParam aiVideoParam, Long taskId, Long serviceId) { | |||
// // 参数校验 | |||
// UserMouldVideo userMouldVideo = Optional.ofNullable(userMouldVideoService.getById(dto.getId())).orElseThrow(() -> new BizException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "未找到用户数据")); | |||
// if (StringUtils.isBlank(userMouldVideo.getPaperwork())) { | |||
@@ -60,6 +62,11 @@ public class AiVideoServiceImpl implements AiVideoService { | |||
AiVideoResult video = AiVideoHelper.createVideo(aiVideoParam, taskId); | |||
if (video.isSuccess()) { | |||
// 记录时长 | |||
SaveServiceVideoRecordDTO dto = SaveServiceVideoRecordDTO.builder() | |||
.serviceId(serviceId) | |||
.videoTime(String.valueOf(video.getDuration())) | |||
.build(); | |||
serviceVideoRecordService.saveServiceVideoRecord(dto); | |||
} | |||
return video; | |||
} | |||
@@ -9,7 +9,7 @@ import lombok.Data; | |||
import java.util.Date; | |||
@ApiModel(value = "获取语种") | |||
@ApiModel(value = "新增接入商") | |||
@Data | |||
public class SaveServiceInfoDTO { | |||
@ApiModelProperty("客户名称") | |||
@@ -0,0 +1,30 @@ | |||
package com.iformall.domain.dto.neuver; | |||
import com.iformall.common.IdWorker; | |||
import com.iformall.domain.po.sm.ServiceVideoRecord; | |||
import io.swagger.annotations.ApiModel; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import java.util.Date; | |||
@ApiModel(value = "新增生成视频时长记录") | |||
@Data | |||
@Builder | |||
public class SaveServiceVideoRecordDTO { | |||
@ApiModelProperty("接入商标识") | |||
private Long serviceId; | |||
@ApiModelProperty("视频时长") | |||
private String videoTime; | |||
public static ServiceVideoRecord mapping(SaveServiceVideoRecordDTO dto) { | |||
ServiceVideoRecord serviceVideoRecord = new ServiceVideoRecord(); | |||
serviceVideoRecord.setId(IdWorker.get().nextId()); | |||
serviceVideoRecord.setCreateTime(new Date()); | |||
serviceVideoRecord.setUpdateTime(new Date()); | |||
serviceVideoRecord.setServiceId(dto.getServiceId()); | |||
serviceVideoRecord.setVideoTime(dto.getVideoTime()); | |||
return serviceVideoRecord; | |||
} | |||
} |
@@ -2,6 +2,7 @@ package com.iformall.domain.po; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.iformall.domain.po.base.TenantEntity; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
@@ -52,5 +53,8 @@ public class WxThirdPartyApi extends TenantEntity { | |||
@io.swagger.annotations.ApiModelProperty(value="",name="tpId") | |||
private String tpId; | |||
@ApiModelProperty("接入商id") | |||
private Long serviceId; | |||
} |
@@ -8,7 +8,7 @@ public enum EnumProductOrderPayVendor { | |||
PAY_WAY_WECHAT(1, "微信小程序",EnumAppPlat.WX.getCode(),EnumProfitSharing.PROFIT_SHARING_NO.getCode()), | |||
PAY_WAY_WECHAT_NATIVE(2, "微信Native",EnumAppPlat.WX.getCode(),EnumProfitSharing.PROFIT_SHARING_NO.getCode()), | |||
PAY_WAY_ALIPAY(3, "支付宝小程序",null,null), | |||
PAY_WAY_ALIPAY_WAP(4, "支付宝H5",null,null), | |||
PAY_WAY_ALIPAY_WAP(4, "支付宝H5",EnumAppPlat.ALI.getCode(),EnumProfitSharing.PROFIT_SHARING_NO.getCode()), | |||
PAY_WAY_TT(5, "抖音小程序",EnumAppPlat.TOUTIAO.getCode(),EnumProfitSharing.PROFIT_SHARING_NO.getCode()), | |||
; | |||
public static EnumProductOrderPayVendor getEnum(Integer code) { | |||
@@ -159,7 +159,7 @@ public class ProductOrderPayServiceImpl implements ProductOrderPayService { | |||
PayAdapterResult payResult = payAdapterService.createPay(productOrderPay, appinfo, payAccount); | |||
if(payResult.isSuccess()){ | |||
ProductOrderPay updPay = new ProductOrderPay(); | |||
updPay.setId(productOrder.getId()); | |||
updPay.setId(productOrderPay.getId()); | |||
updPay.setTransactionId(payResult.getTransactionId()); | |||
updPay.setUpdateDate(new Date()); | |||
productOrderPayMapper.updateById(updPay); | |||
@@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentHashMap; | |||
import com.iformall.enums.EnumAppPlat; | |||
import com.iformall.enums.EnumPayVersion; | |||
import com.iformall.enums.EnumProductOrderPayVendor; | |||
import com.iformall.service.pay.service.pay.ali.page.AliPagePayAdapterService; | |||
import com.iformall.service.pay.service.pay.wx.v3.nativePay.WxNativePayV3AdapterService; | |||
import com.iformall.service.pay.service.refund.ali.AliRefundAdapterService; | |||
import com.iformall.service.pay.service.refund.douyin.TtRefundAdapterService; | |||
@@ -65,6 +66,8 @@ public class PayServiceFactory { | |||
@Autowired | |||
WxNativePayV3AdapterService wxNativePayV3AdapterService; | |||
@Autowired | |||
AliPagePayAdapterService aliPagePayAdapterService; | |||
@Autowired | |||
WxMiniMaPayAdapterService wxMiniAppMaPayService; | |||
@@ -158,7 +161,7 @@ public class PayServiceFactory { | |||
payVendorServiceMap.put(EnumProductOrderPayVendor.PAY_WAY_WECHAT.getCode()+"_", wxMiniAppPayV3AdapterService); | |||
payVendorServiceMap.put(EnumProductOrderPayVendor.PAY_WAY_WECHAT_NATIVE.getCode()+"_", wxNativePayV3AdapterService); | |||
// payVendorServiceMap.put(EnumProductOrderPayVendor.PAY_WAY_ALIPAY.getCode()+"_", ); | |||
// payVendorServiceMap.put(EnumProductOrderPayVendor.PAY_WAY_ALIPAY_WAP.getCode()+"_",); | |||
payVendorServiceMap.put(EnumProductOrderPayVendor.PAY_WAY_ALIPAY_WAP.getCode()+"_",aliPagePayAdapterService); | |||
payVendorServiceMap.put(EnumProductOrderPayVendor.PAY_WAY_TT.getCode()+"_",ttMiniAppPayService); | |||
} | |||
return payVendorServiceMap; | |||
@@ -2,6 +2,7 @@ package com.iformall.service.pay.service.pay.ali; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.alipay.api.AlipayApiException; | |||
import com.alipay.api.AlipayClient; | |||
import com.alipay.api.request.AlipayTradeQueryRequest; | |||
import com.alipay.api.response.AlipayTradeQueryResponse; | |||
@@ -48,22 +49,28 @@ public class BaseAliPayAdapterService { | |||
bizContent.put("out_trade_no", orderPay.getOrderNumber()); | |||
request.setBizContent(bizContent.toString()); | |||
AlipayTradeQueryResponse response = alipayClient.execute(request); | |||
try{ | |||
AlipayTradeQueryResponse response = alipayClient.execute(request); | |||
if(response.isSuccess()){ | |||
if("10000".equals(response.getCode())){ | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(getPayStatusFrom(response.getTradeStatus())); | |||
result.setTransactionId(response.getTradeNo()); | |||
return result; | |||
} | |||
if("ACQ.TRADE_NOT_EXIST".equals(response.getSubCode())){ | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
result.setMsg(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getMessage()); | |||
return result; | |||
if(response.isSuccess()){ | |||
if("10000".equals(response.getCode())){ | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(getPayStatusFrom(response.getTradeStatus())); | |||
result.setTransactionId(response.getTradeNo()); | |||
return result; | |||
} | |||
if("ACQ.TRADE_NOT_EXIST".equals(response.getSubCode())){ | |||
PayQueryAdapterResult result = new PayQueryAdapterResult(); | |||
result.setCode(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
result.setMsg(EnumPayOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getMessage()); | |||
return result; | |||
} | |||
} | |||
}catch(AlipayApiException e){ | |||
log.error("ali pay query error",e); | |||
} | |||
throw new MallinkException(ErrorCode.PAY_ORDER_QUERY_ERROR); | |||
} | |||
@@ -1,11 +1,14 @@ | |||
package com.iformall.service.pay.service.pay.ali.page; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.alipay.api.AlipayApiException; | |||
import com.alipay.api.AlipayClient; | |||
import com.alipay.api.request.AlipayTradePagePayRequest; | |||
import com.alipay.api.response.AlipayTradePagePayResponse; | |||
import com.iformall.common.ErrorCode; | |||
import com.iformall.domain.po.*; | |||
import com.iformall.enums.*; | |||
import com.iformall.exception.MallinkException; | |||
import com.iformall.service.order.OrderFactory; | |||
import com.iformall.service.order.entity.WxComposeOrder; | |||
import com.iformall.service.pay.entity.PayExtraParam; | |||
@@ -66,21 +69,25 @@ public class AliPagePayAdapterService extends BaseAliPayAdapterService implement | |||
bizContent.put("time_expire", after15); | |||
request.setBizContent(bizContent.toString()); | |||
AlipayTradePagePayResponse response = alipayClient.pageExecute(request); | |||
PayAdapterResult par = new PayAdapterResult(); | |||
if(response.isSuccess()){ | |||
if("10000".equals(response.getCode())){ | |||
par.setSuccess(true); | |||
par.setTransactionId(response.getTradeNo()); | |||
par.setData(response); | |||
}else{ | |||
par.setSuccess(false); | |||
par.setMsg(response.getMsg()); | |||
try{ | |||
AlipayTradePagePayResponse response = alipayClient.pageExecute(request); | |||
PayAdapterResult par = new PayAdapterResult(); | |||
if(response.isSuccess()){ | |||
if("10000".equals(response.getCode())){ | |||
par.setSuccess(true); | |||
par.setTransactionId(response.getTradeNo()); | |||
par.setData(response); | |||
} | |||
} | |||
} else { | |||
par.setSuccess(false); | |||
par.setMsg(response.getMsg()); | |||
return par; | |||
}catch(AlipayApiException e){ | |||
log.error("ali pay error",e); | |||
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(),e.getMessage()); | |||
} | |||
return par; | |||
} | |||
@Override | |||
@@ -107,7 +107,7 @@ public class WxNativePayV3AdapterService extends BaseWxPayV3AdapterService imple | |||
return getOrderPResult(response,payService,appInfo,payAccount,orderPay.getOrderNumber()); | |||
}catch(WxPayException e) { | |||
log.error("wexin pay v3 error",e); | |||
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); | |||
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(),e.getCustomErrorMsg()); | |||
} | |||
} | |||
@@ -1,4 +1,15 @@ | |||
package com.iformall.service.sm; | |||
import com.iformall.domain.dto.neuver.SaveServiceVideoRecordDTO; | |||
/** | |||
* @author xmzhao71 | |||
* @date 2023-10-20 | |||
*/ | |||
public interface ServiceVideoRecordService { | |||
/** | |||
* @param dto | |||
*/ | |||
void saveServiceVideoRecord(SaveServiceVideoRecordDTO dto); | |||
} |
@@ -1,8 +1,20 @@ | |||
package com.iformall.service.sm.impl; | |||
import com.iformall.domain.dto.neuver.SaveServiceVideoRecordDTO; | |||
import com.iformall.domain.po.sm.ServiceVideoRecord; | |||
import com.iformall.mapper.ServiceVideoRecordMapper; | |||
import com.iformall.service.sm.ServiceVideoRecordService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@Service | |||
public class ServiceVideoRecordServiceImpl implements ServiceVideoRecordService { | |||
@Autowired | |||
private ServiceVideoRecordMapper serviceVideoRecordMapper; | |||
@Override | |||
public void saveServiceVideoRecord(SaveServiceVideoRecordDTO dto) { | |||
serviceVideoRecordMapper.insert(SaveServiceVideoRecordDTO.mapping(dto)); | |||
} | |||
} |
@@ -69,7 +69,8 @@ public class Constant { | |||
public static final String APP_Id = "APP_Id"; | |||
public static final String APP_NAME = "APP_NAME"; | |||
public static final String APP_INFO = "APPINFO"; | |||
public static final String SERVICE_ID = "SERVICE_ID"; | |||
public static final String LOGIN_B_USER_KEY = "LOGIN_B_USER_KEY"; | |||