观看条件 - 登记观看
更新时间:2024-10-10 17:27:10
一、设置信息
1.1 登记观看条件设置信息
Interface 接口: AuthSettingItemInfo
| 属性名 | 说明 | 类型 |
|---|---|---|
authType |
条件类型 | Info |
privacyContent |
隐私声明内容 | string |
privacyStatus |
是否开启隐私声明 | YN |
infoAuthTips |
欢迎标题 | string |
infoDesc |
提示信息 | string |
infoEntryText |
入口文本 | null | string |
1.2 登记观看的表单选项
Interface 接口: AuthInfoItem
| 属性名 | 说明 | 类型 |
|---|---|---|
type |
表单类型 | AuthInfoType |
name |
信息标题 | string |
placeholder |
信息描述 | string |
sms |
是否需要短信验证 | YN |
options |
下拉选项列表,用英文逗号隔开 | string |
1.3 登记观看的选项类型
Enum 枚举: AuthInfoType
| 常量 | 枚举成员 | 说明 |
|---|---|---|
'name' |
AuthInfoType.Name |
姓名 |
'text' |
AuthInfoType.Text |
文本 |
'mobile' |
AuthInfoType.Mobile |
手机号码 |
'option' |
AuthInfoType.Option |
下拉选项 |
'number' |
AuthInfoType.Number |
数值 |
二、使用方式
2.1 获取登记观看表单设置列表
Api 方法: getAuthInfoFields(): AuthInfoItem[]
返回值说明: 表单设置列表,AuthInfoItem[] 类型
示例:
const formFields = watchCore.auth.getAuthInfoFields();
formFields.forEach(fieldItem => {
console.log('表单项信息', fieldItem);
console.log('表单类型', fieldItem.type);
});
2.2 验证登记观看
通过 verifyInfoAuth 传入 formValues 进行验证登记观看,如果后台设置了手机号码的登记选项,需要另外传入 phoneNumber、areaCode、smsCore 这三个字段。
Api 方法: verifyInfoAuth(params: VerifyInfoAuthParam): Promise<VerifyInfoAuthResult>
参数说明:
- params:调用参数,
VerifyInfoAuthParam类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
phoneNumber |
手机号 | string |
否 | - |
areaCode |
手机区号 | string |
否 | - |
smsCode |
短信验证码 | string |
否 | - |
formValues |
登记填写信息 | string[] |
是 | - |
返回值说明: 授权结果,Promise<VerifyInfoAuthResult> 类型
示例:
// 登记观看表单列表结构示例:
// [mobile(手机号码), name(姓名), text(职业), number(年龄), option(城市->广州,深圳,佛山,惠州)]
// 执行登记观看验证
async function toDoAuthInfo(form) {
const result = await watchCore.auth.verifyInfoAuth({
code,
});
if (result.success) {
await handleAuthVerifySuccess(result);
} else {
await handleAuthVerifyFail(result);
}
}
// 提交的表单内容
toDoAuthInfo({
phoneNumber: '18012345678',
areaCode: '+86',
smsCode: '76431',
formValues: ['18012345678', '李小明', '前端开发工程师', '18', '广州'],
});
2.3 登录登记观看
当后台设置了手机号码的表单选项后,如果观众已提交过登记表单时,可调用 loginInfoAuth 方法,传入手机号码信息进行验证,如果已存在登记信息则可直接进入观看页。
Api 方法: loginInfoAuth(params: LoginInfoAuthParams): Promise<LoginInfoAuthResult>
参数说明:
- params:调用参数,
LoginInfoAuthParams类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
phoneNumber |
手机号 | string |
是 | - |
areaCode |
手机区号 | string |
是 | - |
返回值说明: 登录结果,Promise<LoginInfoAuthResult> 类型
示例:
async function submitAuthLogin(phoneNumber, areaCode) {
const result = await watchCore.auth.loginInfoAuth({
phoneNumber: phoneNumber,
areaCode: areaCode,
});
if (result.success) {
handleAuthVerifySuccess(result);
} else {
handleAuthVerifyFail(result);
}
}
