当前位置: 首页 > news >正文

潍坊网站建设公司电话电商网站竞价推广的策略

潍坊网站建设公司电话,电商网站竞价推广的策略,软文营销网站,2023年楼市将迎来抛售潮一、实现效果 springboot使用EasyCaptcha实现简单验证码&#xff0c;更多api和用法可以去github上查看EasyCaptcha: Java图形验证码&#xff0c;支持gif、中文、算术等类型&#xff0c;可用于Java Web、JavaSE等项目。 二、实现步骤 1、导入依赖 <!-- easy-captcha --&g…

一、实现效果

springboot使用EasyCaptcha实现简单验证码,更多api和用法可以去github上查看EasyCaptcha: Java图形验证码,支持gif、中文、算术等类型,可用于Java Web、JavaSE等项目。

二、实现步骤 

1、导入依赖

<!-- easy-captcha -->
<dependency><groupId>com.github.whvcse</groupId><artifactId>easy-captcha</artifactId><version>1.6.2</version>
</dependency><!--    解决easy-captcha算术验证码报错问题    -->
<dependency><groupId>org.openjdk.nashorn</groupId><artifactId>nashorn-core</artifactId><version>15.4</version>
</dependency>

我使用的JDK版本是Java21,SpringBoot版本是3.2.0,如果不引入nashorn-core,生成验证码时会报错java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.eval(String)" because "engine" is null。有开发者反馈使用Java 17时也遇到了同样的问题,手动引入nashorn-core后即可解决该问题。

详细堆栈和截图如下:

 java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.eval(String)" because "engine" is nullat com.wf.captcha.base.ArithmeticCaptchaAbstract.alphas(ArithmeticCaptchaAbstract.java:42) ~[easy-captcha-1.6.2.jar:na]at com.wf.captcha.base.Captcha.checkAlpha(Captcha.java:156) ~[easy-captcha-1.6.2.jar:na]at com.wf.captcha.base.Captcha.text(Captcha.java:137) ~[easy-captcha-1.6.2.jar:na]at com.fast.alden.admin.service.impl.AuthServiceImpl.generateVerifyCode(AuthServiceImpl.java:72) ~[classes/:na]......

 2、后端代码

@RestController
@RequestMapping()
public class EasyCaptchaController {@GetMapping("/specCaptcha")public Result createSpecCaptcha() throws Exception {// png类型SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);//设置验证码字符类型,只有SpecCaptcha和GifCaptcha设置才有效果。//specCaptcha.setCharType(Captcha.TYPE_ONLY_NUMBER);// 设置内置字体//specCaptcha.setFont(Captcha.FONT_1);// 获取验证码字符串,并转为小写,后续可以存储到redis中方便校验String verCode = specCaptcha.text().toLowerCase();String specCaptchaBase64 = specCaptcha.toBase64();return Result.success(specCaptchaBase64);}@GetMapping("/gifsCaptcha")public Result createGifCaptcha() throws Exception {// gif类型GifCaptcha gifCaptcha = new GifCaptcha(130, 48, 5);// 获取验证码字符串,并转为小写,后续可以存储到redis中方便校验String verCode = gifCaptcha.text().toLowerCase();String specCaptchaBase64 = gifCaptcha.toBase64();return Result.success(specCaptchaBase64);}@GetMapping("/chineseCaptcha")public Result createChineseCaptcha() throws Exception {// 中文类型ChineseCaptcha chineseCaptcha = new ChineseCaptcha(130, 48, 5);// 获取验证码字符串,后续可以存储到redis中方便校验String verCode = chineseCaptcha.text();String specCaptchaBase64 = chineseCaptcha.toBase64();return Result.success(specCaptchaBase64);}@GetMapping("/chineseGifCaptcha")public Result createChineseGifCaptcha() throws Exception {// 中文gif类型ChineseGifCaptcha chineseGifCaptcha = new ChineseGifCaptcha(130, 48,5);// 获取验证码字符串,后续可以存储到redis中方便校验String verCode = chineseGifCaptcha.text().toLowerCase();String specCaptchaBase64 = chineseGifCaptcha.toBase64();return Result.success(specCaptchaBase64);}@GetMapping("/arithmeticCaptcha")public Result createArithmeticCaptcha() throws Exception {// 算术类型ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);captcha.setLen(3);  // 几位数运算,默认是两位captcha.getArithmeticString();  // 获取运算的公式:3+2=?String text = captcha.text();// 获取运算的结果:5String arithmeticCaptchaBase64 = captcha.toBase64();return Result.success(arithmeticCaptchaBase64);}}

3、前端代码

api

import request from "@/utils/request";
export const getSpecCaptcha = () => {return request({url: "/specCaptcha",method: "get",});
};
export const getGifsCaptcha = () => {return request({url: "/gifsCaptcha",method: "get",});
};
export const getChineseCaptcha = () => {return request({url: "/chineseCaptcha",method: "get",});
};
export const getChineseGifCaptcha = () => {return request({url: "/chineseGifCaptcha",method: "get",});
};
export const getArithmeticCaptcha = () => {return request({url: "/arithmeticCaptcha",method: "get",});
};

 vue

<template><div class="captcha"><h1>验证码</h1><div class="easy-captcha"><h3>easy-captcha</h3><span>SpecCaptcha:<img :src="SpecCaptcha" alt="验证码" @click="changeCaptchaImg('Spec')"/></span><span>GifsCaptcha:<img :src="GifsCaptcha" alt="验证码" @click="changeCaptchaImg('Gifs')"/></span><span>ChineseCaptcha:<img:src="ChineseCaptcha"alt="验证码"@click="changeCaptchaImg('Chinese')"/></span><span>ChineseGifCaptcha:<img:src="ChineseGifCaptcha"alt="验证码"@click="changeCaptchaImg('ChineseGif')"/></span><span>ArithmeticCaptcha:<img:src="ArithmeticCaptcha"alt="验证码"@click="changeCaptchaImg('Arithmetic')"/></span></div></div>
</template><script setup>
import { ref, onMounted, onBeforeUnmount } from "vue";
import {getSpecCaptcha,getGifsCaptcha,getChineseCaptcha,getChineseGifCaptcha,getArithmeticCaptcha,
} from "@/api/captcha/index";
import { ElMessage } from "element-plus";const SpecCaptcha = ref("");
const GifsCaptcha = ref("");
const ChineseCaptcha = ref("");
const ChineseGifCaptcha = ref("");
const ArithmeticCaptcha = ref("");const captchaRefs = {Spec: SpecCaptcha,Gifs: GifsCaptcha,Chinese: ChineseCaptcha,ChineseGif: ChineseGifCaptcha,Arithmetic: ArithmeticCaptcha,
};const getCaptcha = async (captchaType) => {try {let res;switch (captchaType) {case "Spec":res = await getSpecCaptcha();break;case "Gifs":res = await getGifsCaptcha();break;case "Chinese":res = await getChineseCaptcha();break;case "ChineseGif":res = await getChineseGifCaptcha();break;case "Arithmetic":res = await getArithmeticCaptcha();break;default:throw new Error("Invalid captcha type");}captchaRefs[captchaType].value = res.data;} catch (error) {console.error(`获取 ${captchaType} 验证码时出错:`, error);ElMessage.error(`获取 ${captchaType} 验证码时出错,请稍后再试`);}
};const changeCaptchaImg = async (captchaType) => {await getCaptcha(captchaType);
};const revokeCaptchaUrls = () => {for (const captchaType in captchaRefs) {if (captchaRefs[captchaType].value) {URL.revokeObjectURL(captchaRefs[captchaType].value);}}
};onMounted(async () => {await Promise.all([getCaptcha("Spec"),getCaptcha("Gifs"),getCaptcha("Chinese"),getCaptcha("ChineseGif"),getCaptcha("Arithmetic"),]);
});onBeforeUnmount(() => {revokeCaptchaUrls();
});
</script><style lang="scss" scoped></style>

http://www.yayakq.cn/news/579054/

相关文章:

  • 沈阳seo网站关键词优化查找手机网站
  • 正保建设工程网站大丰哪家专业做网站
  • 上海培训网站建设网站服务器如何更改解析
  • google建设网站赚钱h5case什么网站
  • 晋江网站建设加强和改进网站建设建设方案
  • 建设厅安全员证书查询网站网络设计教程
  • 北京家装公司排名前十强快速排名优化推广排名
  • 微站网wordpress木马检测
  • 如皋市建设局网站在哪里太原的网站建设公司
  • 网站开发可选择的方案有哪些wordpress mp4 插件下载
  • 全国感染的最新数据统计手机优化如何弄到100
  • 怎样在国外网站购买新鲜橙花做纯露北京网页设计工资
  • 一个新网站要怎么优化门户网站设计技巧
  • 软文推广网站做网站 人员
  • 为什么推荐企业做网站中学网站建设方案计划
  • 个人房屋做民宿在哪个网站工作不好找怎么办
  • 1206家校互联深圳防疫措施优化调整
  • 网站服务器最好的中小企业网站建设与推广
  • 怎么在百度制作自己的网站化妆品网站建设实施方案
  • 网站建设如何在宣传部备案网站建设论文 优帮云
  • 国外画册设计欣赏网站网站手机页面如何做
  • 泰安网站建设流程如何用wordpress插件
  • 房山企业网站建设公司网站备案是在哪里的
  • 旅游网站建设论文题目wordpress如何使用
  • 郑州网站设计排行学校网站建设问卷调查
  • 网站社区建设微网站的建设
  • 网站建设系统优势网站开发税率是多少
  • 上海网站备案拍照地点网站制作接单
  • 企业网站的页面信息该如何排放网站建设需求文档模板
  • 增城住房和建设局网站电子商务怎样建立网站的