1.0.0 • Published 3 years ago

@yidun/tt-ne-captcha v1.0.0

Weekly downloads
3
License
MIT
Repository
-
Last release
3 years ago

易盾验证码用户使用文档--字节跳动小程序版

引入

在根目录执行下述命令

  npm install @yidun/tt-ne-captcha

使用

  1. 引用声明组件,在页面或组件的json文件中声明
{
  "usingComponents": {
    "ne-captcha": "path-to-component/ne-captcha/index"
  }
}
  1. 使用组件
<view>
  <ne-captcha
    id="neCaptcha"
    captcha-id="yourCaptchaID"
    width="640rpx"
    bindverify="handleVerify"></ne-captcha>
  <view>
    <button bindtap="openCaptcha">点击验证</button>
  </view>
</view>
Page({
  handleVerify (ev) {
    if (ev.detail[0]) {
      // 验证失败
      return
    }
    
    // TODO: 验证成功
    console.log(ev.detail[1])
  },
  openCaptcha () {
    this.selectComponent('#neCaptcha', res => {
      res && res.popup()
      // 智能无感知请调用 res.verify()
    })
  }
})

属性

可配项类型默认值描述
captchaIdString验证码ID
langString'zh-CN'语言
widthString'auto'验证码弹框宽度,接受单位'rpx'/'px'/'rem'/'%'
captchaTypeString配置验证码类型
customStylesObjectnull自定义验证码样式,包含imagePanel/controlBar/gap/popTitle/popPadding,详情查看下面

注意:小程序的超时设置可在app.json全局配置

customStyles

  • imagePanel
    • borderRadius(String): imagePanel的圆角大小
  • controlBar
    • borderRadius(String): controlBar的圆角大小
    • height(String): controlBar的高度
  • gap: imagePanel和controlBar的间隔
  • popTitle
    • height(String): 弹框头部高度
  • popPadding(String): 弹框体内边距

事件

事件名参数描述
error验证码配置失败
init验证码配置成功(初始化)
ready验证码准备就绪
verifyerr,validate验证码验证完成
close验证码弹框准备关闭

组件方法

popup: 展示验证码 reset: 重置验证码,获取新的验证信息 verify: 智能无感知验证码进行验证 getCaptchaType: 获取验证码类型

域名

  1. 服务器域名:c.dun.163yun.com、c.dun.163.com
  2. 图片域名:necaptcha.nosdn.127.net、nos.netease.com