Commit f8f933ae by 叶立庆

Merge branch 'v5.7.1' into 'master'

上线合并

See merge request !1
2 parents f227fb5d 5bf38f50
Showing 20 changed files with 1150 additions and 0 deletions
# IntelliJ / IDEA
*.iml
.idea/
out/
# Maven 构建物
target/
# Maven Flatten 插件的产物
.flattened-pom.xml
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.stoassistant.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
/**
* GSC 服务池配置
*
* @author system
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "gsc.common")
public class GSCServicePoolConfig {
/**
* GSC 服务池配置
* key: 服务名称(如 gsc-vcp-web-facade)
* value: 服务配置参数
*/
private Map<String, GSCServiceParam> gscPool = new HashMap<>();
/**
* 获取指定服务的配置
*
* @param serviceName 服务名称
* @return 服务配置参数
*/
public GSCServiceParam getServiceParam(String serviceName) {
GSCServiceParam param = gscPool.get(serviceName);
if (param == null) {
throw new IllegalArgumentException("未找到服务配置:" + serviceName);
}
return param;
}
/**
* GSC 服务配置参数
*/
@Data
public static class GSCServiceParam {
/**
* 服务基础URL
*/
private String baseurl;
/**
* 应用ID
*/
private String appId;
/**
* 随机字符串
*/
private String nonce;
/**
* 密钥
*/
private String secret;
}
}
package cn.com.glsx.stoassistant.constans;
/**
* GSC 服务名称常量
*
* @author system
*/
public class GSCServiceConstants {
/**
* GSC VCP Web Facade 服务
*/
public static final String GSC_VCP_WEB_FACADE = "gsc-vcp-web-facade";
/**
* GSC VCP Pad Facade 服务
*/
public static final String GSC_VCP_PAD_FACADE = "gsc-vcp-pad-facade";
private GSCServiceConstants() {
// 私有构造函数,防止实例化
}
}
package cn.com.glsx.stoassistant.controller;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.stoassistant.request.GroupAllocRequest;
import cn.com.glsx.stoassistant.request.LiveCodeRequest;
import cn.com.glsx.stoassistant.response.GroupAllocResponse;
import cn.com.glsx.stoassistant.response.LiveCodeResponse;
import cn.com.glsx.stoassistant.service.LiveCodeService;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 活码管理
*/
@Slf4j
@Api("活码管理")
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
//@RestController
public class LiveCodeController {
@Autowired
private LiveCodeService liveCodeService;
/**
* 获取群活码(车主扫码分配真实企微群)
*/
@ServiceMethod(method = "scrm.api.stoassistant.livecode.get", needInSession = NeedInSessionType.YES)
@ApiOperation("获取群活码")
// @PostMapping("/scrm.api.stoassistant.livecode.get/1.0.0")
public RopResponse<LiveCodeResponse> getLiveCode(LiveCodeRequest request) {
try {
if (request == null || request.getReportUuidId() == null || request.getReportUuidId().trim().isEmpty()) {
return RopResponse.error("AI收车报告唯一ID不能为空");
}
LiveCodeResponse response = liveCodeService.getLiveCode(request);
return RopResponse.success(response);
} catch (Exception e) {
log.error("获取群活码失败", e);
return RopResponse.error(e.getMessage());
}
}
/**
* 扫码分配空闲企微群
*/
@ServiceMethod(method = "scrm.api.stoassistant.livecode.allocate", needInSession = NeedInSessionType.YES)
@ApiOperation("扫码分配空闲企微群")
// @PostMapping("/scrm.api.stoassistant.livecode.allocate/1.0.0")
public RopResponse<GroupAllocResponse> allocateGroup(GroupAllocRequest request) {
try {
if (request == null) {
return RopResponse.error("请求参数不能为空");
}
if (request.getLiveCode() == null || request.getLiveCode().trim().isEmpty()) {
return RopResponse.error("活码编码不能为空");
}
if (request.getOpenid() == null || request.getOpenid().trim().isEmpty()) {
return RopResponse.error("微信openid不能为空");
}
if (request.getSignature() == null || request.getSignature().trim().isEmpty()) {
return RopResponse.error("签名不能为空");
}
if (request.getNonce() == null || request.getNonce().trim().isEmpty()) {
return RopResponse.error("随机字符串不能为空");
}
if (request.getSaUserId() == null || request.getSaUserId().trim().isEmpty()) {
return RopResponse.error("销售顾问ID不能为空");
}
GroupAllocResponse response = liveCodeService.allocateGroup(request);
return RopResponse.success(response);
} catch (Exception e) {
log.error("扫码分配群失败", e);
return RopResponse.error(e.getMessage());
}
}
}
package cn.com.glsx.stoassistant.controller.carcondition;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.scrm.system.model.wechatapplets.LoginUserInfoResponse;
import cn.com.glsx.stoassistant.request.carcondition.CarConditionPadPageRequest;
import cn.com.glsx.stoassistant.response.carcondition.CarConditionPageVO;
import cn.com.glsx.stoassistant.service.cardition.CarConditionService;
import cn.com.glsx.stoassistant.utils.Pagination;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.boot.autoconfigure.rop.util.RopThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@Api("车况管理")
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
//@RestController
public class CarConditionController {
@Autowired
private CarConditionService carConditionService;
@ApiOperation("PAD端车况分页查询")
@ServiceMethod(method = "scrm.api.stoassistant.carCondition.page", needInSession = NeedInSessionType.YES)
// @PostMapping("/scrm.api.stoassistant.carCondition.page/1.0.0")
public RopResponse<Pagination<CarConditionPageVO>> page(CarConditionPadPageRequest request) {
try {
if (request == null) {
return RopResponse.error("参数不能为空");
}
if (StringUtils.isBlank(request.getOperatorId())) {
LoginUserInfoResponse loginUser = RopThreadLocal.getLoginUser(LoginUserInfoResponse.class);
request.setOperatorId(loginUser.getUuid());
}
return carConditionService.page(request);
} catch (Exception e) {
log.error("PAD端车况分页查询失败", e);
return RopResponse.error(e.getMessage());
}
}
// @ApiOperation("PAD端车况详情接口")
// @ServiceMethod(method = "scrm.api.stoassistant.carCondition.detail", needInSession = NeedInSessionType.YES)
// @PostMapping("/scrm.api.stoassistant.carCondition.detail/1.0.0")
// public RopResponse<CarConditionPadDetailVO> detail(CarConditionDetailRequest request) {
// try {
// if (request == null || request.getId() == null) {
// return RopResponse.error("车况唯一ID不能为空");
// }
// return carConditionService.detail(request);
// } catch (Exception e) {
// log.error("PAD端车况详情接口失败", e);
// return RopResponse.error(e.getMessage());
// }
// }
//
//
// @ApiOperation("新增车况录入")
// @ServiceMethod(method = "scrm.api.stoassistant.carCondition.add", needInSession = NeedInSessionType.YES)
// public RopResponse<Integer> add(CarConditionAddRequest request) {
// try {
// if (request == null || request.getSource() == null) {
// return RopResponse.error("车况来源不能为空");
// }
// return carConditionService.add(request);
// } catch (Exception e) {
// log.error("新增车况录入失败", e);
// return RopResponse.error(e.getMessage());
// }
//
// }
//
// @ApiOperation("编辑车况录入")
// @ServiceMethod(method = "scrm.api.stoassistant.carCondition.edit", needInSession = NeedInSessionType.YES)
// public RopResponse<Integer> edit(CarConditionEditRequest request) {
// try {
// if (request == null || request.getId() == null) {
// return RopResponse.error("车况唯一ID不能为空");
// }
// if (request.getSource() == null) {
// return RopResponse.error("车况来源不能为空");
// }
// return carConditionService.edit(request);
// } catch (Exception e) {
// log.error("编辑车况录入失败", e);
// return RopResponse.error(e.getMessage());
// }
// }
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.stoassistant.request;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* 扫码分配群请求
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("扫码分配群请求")
public class GroupAllocRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 活码编码
*/
@ApiModelProperty("活码编码")
private String liveCode;
/**
* 微信openid
*/
@ApiModelProperty("微信openid")
private String openid;
/**
* 签名
*/
@ApiModelProperty("签名")
private String signature;
/**
* 过期时间戳
*/
@ApiModelProperty("过期时间戳")
private String exp;
/**
* 随机字符串
*/
@ApiModelProperty("随机字符串")
private String nonce;
/**
* 销售顾问系统用户ID
*/
@ApiModelProperty("销售顾问系统用户ID")
private String saUserId;
/**
* 车况编码
*/
@ApiModelProperty("车况编码")
private String carConditionCode;
}
package cn.com.glsx.stoassistant.request;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 获取群活码请求
*/
@Data
@ApiModel("获取群活码请求")
public class LiveCodeRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = 1L;
/**
* AI收车报告唯一ID
*/
@ApiModelProperty(value = "AI收车报告唯一ID", required = true)
private String reportUuidId;
}
package cn.com.glsx.stoassistant.request.carcondition;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* PAD端车况新增请求
*/
@Data
public class CarConditionAddRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "车主姓名")
private String ownerName;
@ApiModelProperty(notes = "车牌号")
private String licensePlate;
@ApiModelProperty(notes = "车架号")
private String vin;
@ApiModelProperty(notes = "上牌时间(注册日期)")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date registrationDate;
@ApiModelProperty(notes = "销售用户id(4S店)")
private String sellerUserId;
@ApiModelProperty(notes = "销售姓名(4S店)")
private String sellerName;
@ApiModelProperty(notes = "销售商户号(4S店)")
private Integer sellerMerchantId;
@ApiModelProperty(notes = "销售(4S店)商户名称")
private String sellerMerchantName;
@ApiModelProperty(notes = "转化用户id(园区店)")
private String conversionUserId;
@ApiModelProperty(notes = "转化姓名(园区店)")
private String conversionName;
@ApiModelProperty(notes = "转化商户号(园区店)")
private Integer conversionMerchantId;
@ApiModelProperty(notes = "转化(园区店)商户名称")
private String conversionMerchantName;
@ApiModelProperty(notes = "行驶证图片URL")
private String drivingLicenseImgUrl;
@ApiModelProperty(notes = "铭牌图片URL")
private String nameplateImgUrl;
@ApiModelProperty(notes = "左前45度图片URL")
private String leftFrontImgUrl;
@ApiModelProperty(notes = "右前45度图片URL")
private String rightFrontImgUrl;
@ApiModelProperty(notes = "仪表公里数图片URL")
private String mileageImgUrl;
@ApiModelProperty(notes = "中控台全景图片URL")
private String centerConsoleImgUrl;
@ApiModelProperty(notes = "主驾全景图片URL")
private String driverSeatImgUrl;
@ApiModelProperty(notes = "后排全景图片URL")
private String rearSeatImgUrl;
@ApiModelProperty(notes = "其他细节图片URL")
private String otherDetailImgUrl;
@ApiModelProperty(notes = "车况描述")
private String conditionDescription;
@ApiModelProperty(notes = "录入状态:0-草稿(信息待补全),1-已提交(已录入)")
private Integer entryStatus;
@ApiModelProperty(notes = "车况单来源 1-展业助手app 2-生意助手员工版小程序 3-车生活助手小程序")
private Integer source;
@ApiModelProperty(notes = "小程序openId")
private String openId;
@ApiModelProperty(notes = "操作人手机号")
private String phone;
@ApiModelProperty(notes = "操作人姓名")
private String operator;
@ApiModelProperty(notes = "操作人id")
private String operatorId;
@ApiModelProperty(notes = "操作人所在门店id")
private Integer merchantId;
@ApiModelProperty(notes = "操作人所在门店名称")
private String merchantName;
}
package cn.com.glsx.stoassistant.request.carcondition;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
@Data
@Schema(description = "车况详情查询请求")
public class CarConditionDetailRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(name = "id",notes = "主键id")
private Integer id;
}
package cn.com.glsx.stoassistant.request.carcondition;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* PAD端车况编辑请求
*/
@Data
public class CarConditionEditRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "主键id")
private Integer id;
@ApiModelProperty(notes = "车主姓名")
private String ownerName;
@ApiModelProperty(notes = "车牌号")
private String licensePlate;
@ApiModelProperty(notes = "车架号")
private String vin;
@ApiModelProperty(notes = "上牌时间(注册日期)")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date registrationDate;
@ApiModelProperty(notes = "销售用户id(4S店)")
private String sellerUserId;
@ApiModelProperty(notes = "销售姓名(4S店)")
private String sellerName;
@ApiModelProperty(notes = "销售商户号(4S店)")
private Integer sellerMerchantId;
@ApiModelProperty(notes = "销售(4S店)商户名称")
private String sellerMerchantName;
@ApiModelProperty(notes = "转化用户id(园区店)")
private String conversionUserId;
@ApiModelProperty(notes = "转化姓名(园区店)")
private String conversionName;
@ApiModelProperty(notes = "转化商户号(园区店)")
private Integer conversionMerchantId;
@ApiModelProperty(notes = "转化(园区店)商户名称")
private String conversionMerchantName;
@ApiModelProperty(notes = "行驶证图片URL")
private String drivingLicenseImgUrl;
@ApiModelProperty(notes = "铭牌图片URL")
private String nameplateImgUrl;
@ApiModelProperty(notes = "左前45度图片URL")
private String leftFrontImgUrl;
@ApiModelProperty(notes = "右前45度图片URL")
private String rightFrontImgUrl;
@ApiModelProperty(notes = "仪表公里数图片URL")
private String mileageImgUrl;
@ApiModelProperty(notes = "中控台全景图片URL")
private String centerConsoleImgUrl;
@ApiModelProperty(notes = "主驾全景图片URL")
private String driverSeatImgUrl;
@ApiModelProperty(notes = "后排全景图片URL")
private String rearSeatImgUrl;
@ApiModelProperty(notes = "其他细节图片URL")
private String otherDetailImgUrl;
@ApiModelProperty(notes = "车况描述")
private String conditionDescription;
@ApiModelProperty(notes = "录入状态:0-草稿(信息待补全),1-已提交(已录入)")
private Integer entryStatus;
@ApiModelProperty(notes = "操作人姓名")
private String operator;
@ApiModelProperty(notes = "操作人id")
private String operatorId;
@ApiModelProperty(notes = "操作人所在门店id")
private Integer merchantId;
@ApiModelProperty(notes = "操作人所在门店名称")
private String merchantName;
@ApiModelProperty(notes = "车况单来源 1-展业助手app 2-生意助手员工版小程序 3-车生活助手小程序")
private Integer source;
@ApiModelProperty(notes = "小程序openId")
private String openId;
}
package cn.com.glsx.stoassistant.request.carcondition;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
/**
* PAD端车况分页查询请求
*/
@Data
public class CarConditionPadPageRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "录入状态:0-草稿(信息待补全),1-已提交(已录入)")
private Integer entryStatus;
@Schema(description = "操作人id")
private String operatorId;
@ApiModelProperty(notes = "当前页")
private long currentPage = 1;
@ApiModelProperty(notes = "每页数量")
private long pageSize = 10;
}
package cn.com.glsx.stoassistant.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 扫码分配群响应
*/
@Data
@ApiModel("扫码分配群响应")
public class GroupAllocResponse implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 群二维码URL
*/
@ApiModelProperty("群二维码URL")
private String qrCodeUrl;
/**
* 群名称
*/
@ApiModelProperty("群名称")
private String groupName;
/**
* 锁定过期时间
*/
@ApiModelProperty("锁定过期时间")
private String lockExpireTime;
}
package cn.com.glsx.stoassistant.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 获取群活码响应
*/
@Data
@ApiModel("获取群活码响应")
public class LiveCodeResponse implements Serializable {
private static final long serialVersionUID = 1L;
/**
* H5引流链接
*/
@ApiModelProperty("H5引流链接")
private String h5Url;
/**
* 二维码图片URL
*/
@ApiModelProperty("二维码图片URL")
private String qrCodeUrl;
}
package cn.com.glsx.stoassistant.response.carcondition;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
/**
* PAD端车况详情VO
*/
@Data
@Schema(description = "PAD端车况详情VO")
public class CarConditionPadDetailVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "主键id")
private Integer id;
@Schema(description = "车况编码")
private String carConditionCode;
@Schema(description = "车主姓名")
private String ownerName;
@Schema(description = "销售用户id(4S店)")
private String sellerUserId;
@Schema(description = "销售姓名(4S店)")
private String sellerName;
@Schema(description = "行驶证图片URL")
private String drivingLicenseImgUrl;
@Schema(description = "铭牌图片URL")
private String nameplateImgUrl;
@Schema(description = "左前45度图片URL")
private String leftFrontImgUrl;
@Schema(description = "右前45度图片URL")
private String rightFrontImgUrl;
@Schema(description = "仪表公里数图片URL")
private String mileageImgUrl;
@Schema(description = "中控台全景图片URL")
private String centerConsoleImgUrl;
@Schema(description = "主驾全景图片URL")
private String driverSeatImgUrl;
@Schema(description = "后排全景图片URL")
private String rearSeatImgUrl;
@Schema(description = "其他细节图片URL")
private String otherDetailImgUrl;
@Schema(description = "车况描述")
private String conditionDescription;
@Schema(description = "录入状态:0-草稿(信息待补全),1-已提交(已录入)")
private Integer entryStatus;
}
package cn.com.glsx.stoassistant.response.carcondition;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@Schema(description = "PAD端车况分页查询返回结果")
public class CarConditionPageVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "主键id")
private Integer id;
@Schema(description = "车主姓名")
private String ownerName;
@Schema(description = "车牌号")
private String licensePlate;
@Schema(description = "录入时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date entryTime;
@Schema(description = "录入状态:0-草稿(信息待补全),1-已提交(已录入)")
private Integer entryStatus;
@Schema(description = "左前45度图片URL")
private String leftFrontImgUrl;
}
package cn.com.glsx.stoassistant.service;
import cn.com.glsx.stoassistant.config.GSCServicePoolConfig;
import cn.com.glsx.stoassistant.constans.GSCServiceConstants;
import cn.com.glsx.stoassistant.request.GroupAllocRequest;
import cn.com.glsx.stoassistant.request.LiveCodeRequest;
import cn.com.glsx.stoassistant.response.GroupAllocResponse;
import cn.com.glsx.stoassistant.response.LiveCodeResponse;
import cn.com.glsx.stoassistant.utils.SpringCloudHttpUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* 活码服务
*/
@Slf4j
@Service
public class LiveCodeService {
@Autowired
private GSCServicePoolConfig gscServicePoolConfig;
/**
* 获取群活码
*/
public LiveCodeResponse getLiveCode(LiveCodeRequest request) {
// 默认调用 gsc-vcp-pad-facade 服务
return getLiveCode(request, GSCServiceConstants.GSC_VCP_PAD_FACADE);
}
/**
* 获取群活码(支持指定服务)
*
* @param request 请求参数
* @param serviceName 服务名称(如 gsc-vcp-pad-facade、gsc-vcp-web-facade)
* @return 活码响应
*/
public LiveCodeResponse getLiveCode(LiveCodeRequest request, String serviceName) {
try {
// 获取指定服务的配置
GSCServicePoolConfig.GSCServiceParam serviceParam = gscServicePoolConfig.getServiceParam(serviceName);
// 构建请求参数
Map<String, Object> params = new HashMap<>();
params.put("reportUuidId", request.getReportUuidId());
log.info("调用服务:{},请求参数:{}", serviceName, params);
// 调用指定服务的接口
String result = SpringCloudHttpUtil.post(
serviceParam,
params,
String.class,
"/liveCode/generate",
null
);
log.info("调用服务:{} 返回结果:{}", serviceName, result);
// 解析返回结果
Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
if (resultMap == null) {
throw new RuntimeException("调用服务失败:返回结果为空");
}
Integer code = (Integer) resultMap.get("code");
if (code == null || code != 0) {
String msg = (String) resultMap.get("msg");
throw new RuntimeException("调用服务失败:" + msg);
}
Map<String, Object> data = (Map<String, Object>) resultMap.get("data");
if (data == null) {
throw new RuntimeException("调用服务失败:data为空");
}
LiveCodeResponse response = new LiveCodeResponse();
response.setH5Url((String) data.get("h5Url"));
response.setQrCodeUrl((String) data.get("qrCodeUrl"));
return response;
} catch (Exception e) {
log.error("获取群活码失败,服务:{}", serviceName, e);
throw new RuntimeException("获取群活码失败:" + e.getMessage(), e);
}
}
/**
* 扫码分配空闲企微群
*/
public GroupAllocResponse allocateGroup(GroupAllocRequest request) {
return allocateGroup(request, GSCServiceConstants.GSC_VCP_PAD_FACADE);
}
/**
* 扫码分配空闲企微群(支持指定服务)
*/
public GroupAllocResponse allocateGroup(GroupAllocRequest request, String serviceName) {
try {
GSCServicePoolConfig.GSCServiceParam serviceParam = gscServicePoolConfig.getServiceParam(serviceName);
Map<String, Object> params = new HashMap<>();
params.put("liveCode", request.getLiveCode());
params.put("openid", request.getOpenid());
params.put("signature", request.getSignature());
params.put("exp", request.getExp());
params.put("nonce", request.getNonce());
params.put("saUserId", request.getSaUserId());
params.put("carConditionCode", request.getCarConditionCode());
log.info("调用服务:{},扫码分配群,请求参数:{}", serviceName, params);
String result = SpringCloudHttpUtil.post(
serviceParam,
params,
String.class,
"/liveCode/allocate",
null
);
log.info("调用服务:{} 扫码分配群返回结果:{}", serviceName, result);
Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
if (resultMap == null) {
throw new RuntimeException("调用服务失败:返回结果为空");
}
Integer code = (Integer) resultMap.get("code");
if (code == null || code != 0) {
String msg = (String) resultMap.get("msg");
throw new RuntimeException("调用服务失败:" + msg);
}
Map<String, Object> data = (Map<String, Object>) resultMap.get("data");
if (data == null) {
throw new RuntimeException("调用服务失败:data为空");
}
GroupAllocResponse response = new GroupAllocResponse();
response.setQrCodeUrl((String) data.get("qrCodeUrl"));
response.setGroupName((String) data.get("groupName"));
response.setLockExpireTime((String) data.get("lockExpireTime"));
return response;
} catch (Exception e) {
log.error("扫码分配群失败,服务:{}", serviceName, e);
throw new RuntimeException("扫码分配群失败:" + e.getMessage(), e);
}
}
}
package cn.com.glsx.stoassistant.utils;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
/**
* 签名工具类
*/
public class SignUtil {
private static final String HMAC_SHA256_ALGORITHM = "HmacSHA256";
private static final String SIGN_KEY = "X-Sign";
private static final String SECRET_PARAM = "secret=";
/**
* 生成签名
*/
public static String generateSign(Map<String, Object> params, String secret) {
// 1. 参数排序
List<String> keys = new ArrayList<>(params.keySet());
Collections.sort(keys);
// 2. 拼接参数
StringBuilder sb = new StringBuilder();
for (String key : keys) {
if (SIGN_KEY.equals(key) || params.get(key) == null || "".equals(params.get(key))) {
continue;
}
sb.append(key).append("=").append(params.get(key)).append("&");
}
String stringToSign = sb.toString();
stringToSign = stringToSign + SECRET_PARAM + secret;
// 3. 计算HMAC-SHA256签名
return calculateHmacSha256(secret, stringToSign);
}
/**
* 计算 HMAC-SHA256 签名
*/
private static String calculateHmacSha256(String secret, String data) {
try {
Mac sha256_HMAC = Mac.getInstance(HMAC_SHA256_ALGORITHM);
SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), HMAC_SHA256_ALGORITHM);
sha256_HMAC.init(secretKey);
byte[] hashBytes = sha256_HMAC.doFinal(data.getBytes(StandardCharsets.UTF_8));
return bytesToHex(hashBytes);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("HMAC-SHA256 algorithm not available", e);
} catch (InvalidKeyException e) {
throw new RuntimeException("Invalid secret key", e);
}
}
/**
* 将字节数组转换为16进制字符串
*/
private static String bytesToHex(byte[] bytes) {
StringBuilder hexString = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}
package cn.com.glsx.stoassistant.utils;
import cn.com.glsx.stoassistant.config.GSCServicePoolConfig;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
/**
* Spring Cloud HTTP 工具类
*/
@Slf4j
public class SpringCloudHttpUtil {
private final static RestTemplate restTemplate;
static {
restTemplate = new RestTemplate();
// 关键点:找到 StringHttpMessageConverter 并将其编码设为 UTF-8
restTemplate.getMessageConverters()
.stream()
.filter(converter -> converter instanceof StringHttpMessageConverter)
.map(converter -> (StringHttpMessageConverter) converter)
.forEach(converter -> converter.setDefaultCharset(StandardCharsets.UTF_8));
}
// private final static RestTemplate restTemplate = new RestTemplate();
private static final ObjectMapper objectMapper = new ObjectMapper();
/**
* POST 请求
*/
public static <T> T post(GSCServicePoolConfig.GSCServiceParam serviceParam, Object obj, Class<T> responseType, String method, String sessionId) throws Exception {
long timestamp = System.currentTimeMillis();
if (sessionId != null) {
method = method + "?sessionId=" + sessionId;
}
String url = serviceParam.getBaseurl() + method;
// 创建请求头
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Content-Type", "application/json");
httpHeaders.add("X-App-Id", serviceParam.getAppId());
httpHeaders.add("X-Timestamp", timestamp + "");
httpHeaders.add("X-Nonce", serviceParam.getNonce());
// 构建参数
Map<String, Object> params = new HashMap<>();
params.put("X-App-Id", serviceParam.getAppId());
params.put("X-Timestamp", timestamp);
params.put("X-Nonce", serviceParam.getNonce());
Map<String, Object> objectMap = getOuterKeyValues(obj);
params.putAll(objectMap);
if (sessionId != null) {
params.put("sessionId", sessionId);
}
// 生成签名
String sign = SignUtil.generateSign(params, serviceParam.getSecret());
httpHeaders.add("X-Sign", sign);
HttpEntity<Object> httpEntity = new HttpEntity<>(objectMap, httpHeaders);
// 远程调用
log.info("请求地址:{},请求参数:{},请求头:{}", url, JSON.toJSON(obj), httpHeaders);
T result = restTemplate.postForObject(url, httpEntity, responseType);
log.info("返回结果:{}", JSON.toJSON(result));
return result;
}
/**
* 获取对象的外层键值对
*/
public static Map<String, Object> getOuterKeyValues(Object obj) {
try {
JsonNode jsonNode = objectMapper.valueToTree(obj);
Map<String, Object> result = new HashMap<>();
jsonNode.fields().forEachRemaining(entry -> {
// 非空才封装
if (entry.getValue().isNull() || entry.getValue().isMissingNode()) {
return;
}
result.put(entry.getKey(), entry.getValue());
});
return result;
} catch (Exception e) {
throw new RuntimeException("JSON转换失败", e);
}
}
}
package cn.com.glsx.stoassistant.service;
import cn.com.glsx.stoassistant.request.LiveCodeRequest;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
public class LiveCodeServiceTest extends BaseServiceTest {
@Autowired
private LiveCodeService liveCodeService;
@Test
public void testGetLiveCode() {
LiveCodeRequest request = new LiveCodeRequest();
request.setReportUuidId("919220012001jjjka");
liveCodeService.getLiveCode(request);
}
@Test
public void testAllocateGroup() {
}
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!