# realname 实名认证能力
# 介绍
出行服务用户实名认证能力,用于票务、ETC等业务身份校验。
# 使用指南
# 一般用法
<tms-realname
id="realname-cop"
bindauthStart="onAuthStart"
bindauthEnd="onAuthEnd"
bindrendering="onRendering"
bindrendered="onRendered"
bindobtain="onObtainAuthInfo"
/>
Page({
// 开始认证回调
onAuthStart() {
console.log('onAuthStart:');
wx.showLoading({ title: '认证中...', mask: true });
},
// 认证完成回调
onAuthEnd({ detail }) {
console.log('onAuthEnd:', detail);
wx.hideLoading();
const { msg } = detail; // { status, msg }
wx.showToast({ title: msg, icon: 'none', duration: 2000 });
},
// 加载数据回调
onRendering() {
console.log('onRendering:');
wx.showLoading({ title: '加载中...', mask: true });
},
// 加载完成回调
onRendered({ detail }) {
console.log('onRendered:', detail);
wx.hideLoading();
},
// 已实名认证,返回认证信息
async onObtainAuthInfo({ detail }) {
const { errMsg, auth, realName, credId } = detail;
// todo
},
});
# 自定义视觉用法
<tms-realname
id="realname-cop"
visible="{{flase}}"
bindauthStart="onAuthStart"
bindauthEnd="onAuthEnd"
bindrendering="onRendering"
bindrendered="onRendered"
bindobtain="onObtainAuthInfo"
/>
<input placeholder="请输入姓名" type="text" bindinput="nameInput" />
<input placeholder="请输入证件号" type="idcard" bindinput="credidInput" />
<view bindtap="callRealName">去认证</view>
Page({
onLoad() {
this.realnameCop = this.selectComponent('#realname-cop');;
},
// 姓名input
nameInput(e) {
const checkRs = this.realnameCop.checkName(e.detail.value);
if (checkRs) this.realName = e.detail.value;
},
// 证件号input
credidInput(e) {
const checkRs = this.realnameCop.checkCredId(e.detail.value);
if (checkRs) this.credId = e.detail.value;
},
// 手动触发
callRealName() {
const { realName, credId } = this;
realnameCop.callRealNameAuth({
realName, // 姓名
credId, // 身份证号
credType: 0, // 类型 0 身份证
});
},
});
# realname 方法说明
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| onAuthStart | Function | 否 | 开始认证回调函数 | |
| onAuthEnd | Function | 否 | 认证结束回调函数 | |
| onRendering | Function | 否 | 初始获取实名认证信息开始 | |
| onRendered | Function | 否 | 初始获取实名认证信息完成 | |
| onObtainAuthInfo | Function | 否 | 已实名认证,点击“确认”返回认证信息 | |
| checkName | Function | 否 | 姓名检查函数 | |
| checkCredId | Function | 否 | 身份证检查函数 | |
| callRealNameAuth | Function | 否 | 调起实名认证 | |
| visible | Boolean | true | 否 | 默认视觉是否可见 |
