Bladeren bron

gpt推广小程序schema

zoujiajian 1 jaar geleden
bovenliggende
commit
13ee3069b6

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/mini/MiniService.java

@@ -29,4 +29,6 @@ public interface MiniService {
 	String generateSchema(MiniSchemaReq req) throws Exception;
 
 	byte[] generateCode(MiniSchemaReq req) throws Exception;
+
+	String generateGptMiniSchema(MiniSchemaReq req) throws Exception;
 }

+ 22 - 0
netflix-service/src/main/java/com/cyksj/service/mini/impl/MiniServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Times;
 import com.cyksj.config.TgMiniConfig;
 import com.cyksj.config.YhCertMiniConfig;
@@ -204,6 +205,27 @@ public class MiniServiceImpl implements MiniService {
 		return weChatService.generateCode(accessToken, req.getPath());
 	}
 
+	@Override
+	public String generateGptMiniSchema(MiniSchemaReq req) throws Exception {
+		if (StrUtil.isEmpty(req.getPath())) {
+			throw BusinessRuntimeException.getInstance("请传入小程序跳转路径");
+		}
+		String query = StrUtil.EMPTY;
+		if (StrUtil.isNotBlank(req.getDsCode())) {
+			query = "dsCode=" + req.getDsCode();
+		}
+		//调用微信小程序接口
+		String accessToken = weChatService.getAccessToken(tgMiniConfig.getAppId());
+		TargetAppletSchemeReq targetAppletSchemeReq = new TargetAppletSchemeReq();
+		targetAppletSchemeReq.setExpireType(0l);
+		targetAppletSchemeReq.setExpireTime((System.currentTimeMillis() / 1000) + Times.second_per_day);
+		targetAppletSchemeReq.setIsExpired(false);
+		TargetAppletSchemeReq.JumpWxa jumpWxa = new TargetAppletSchemeReq.JumpWxa(req.getPath(), query);
+		targetAppletSchemeReq.setJumpWxa(jumpWxa);
+		String miniSchema = weChatService.generateSchema(accessToken, targetAppletSchemeReq);
+		return miniSchema;
+	}
+
 	public void updateArticleMarkNum(Integer type, Long articleId, Integer offset) {
 		Integer success = 0;
 		while (success != 1) {

+ 9 - 0
netflix-web/src/main/java/com/cyksj/web/controller/mini/MiniController.java

@@ -108,6 +108,15 @@ public class MiniController {
 		return GatewayResponse.SUCCESS.newBuilder().toResult(StpUserUtil.getTokenValue());
 	}
 
+	/**
+	 * 生成GPT小程序schema
+	 */
+	@PostMapping("/generate/gpt/schema")
+	public Result<String> generateGptMiniSchema(@RequestBody MiniSchemaReq req) throws Exception {
+		String url = miniService.generateGptMiniSchema(req);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(url);
+	}
+
 
 	/**
 	 * 文章列表