For the complete documentation index, see llms.txt. This page is also available as Markdown.

User.getConsentedData

函数式 API getConsentedUserData也可以通过它使用相同的功能。

功能说明

请求基于用户同意的数据。如果需要同意,则会打开条款 WebView;同意完成后,返回从服务器查询到的数据。

Toss App 5.264.0 可在以上版本中使用。调用前 User.getConsentedData.isSupported()可通过它确认是否支持。函数式 API getConsentedUserData在不支持的版本中 undefined会返回,并且 User.getConsentedDataUNSUPPORTED_APP_VERSION 会抛出错误。

类型

User.getConsentedData(options: GetConsentedUserDataOptions): Promise<ConsentedUserData>;

Params

interface GetConsentedUserDataOptions {
  /** 服务器用于查找用户数据提供同意书和数据包的 key。例如:`cud_delivery` */
  consentedUserDataKey: string;
  /** 即使在 `USER_DECLINED` 状态下,是否再次打开条款 WebView。默认值为 `false`。 */
  shouldRequestAgreementWhenUserDeclined?: boolean;
}

Response

type ConsentedUserDataKey =
  | "USER_NAME"
  | "USER_GENDER"
  | "USER_NATIONALITY"
  | "USER_BIRTHDAY"
  | "USER_PHONE"
  | "USER_ADDRESS"
  | "USER_EMAIL"
  | "USER_CONSUMPTION_HISTORY";

type ConsentedUserData = Partial<Record<ConsentedUserDataKey, string>>;

只能包含与所请求项目对应的 key。

错误

错误代码是 catch 到的错误的 error.code 值。

代码
说明

UNSUPPORTED_APP_VERSION

如果当前运行的 Toss App 版本不支持此功能,调用后会立即发生。 User.getConsentedData.isSupported()可通过它提前确认,发生时 error.message请向用户显示(更新提示文案)。

USER_DECLINED

用户明确拒绝,且没有重新请求选项,或者在条款 WebView 中拒绝了同意。

UNAVAILABLE

服务器无法判断用户是否同意的情况。

TERMS_NOT_SET

迷你应用中未设置用户数据提供同意文的情况。

INVALID_REQUEST

consentedUserDataKey为空,或 termsUrl不存在,或者不是 HTTPS 公司域名的情况。

CANCELED

条款 WebView 在发送结果前被关闭的情况。

CONSENTED_USER_DATA_AGREEMENT_FAILED

处理条款 WebView 时发生错误的情况。

CONSENTED_USER_DATA_INVALID_DATA

PROVIDED数据没有,或者同意成功后重新查询的结果 PROVIDED不是该值的情况。

示例代码

这有帮助吗?