/// import { AuthenticationTokenProvider } from './AuthenticationTokenProvider'; import { AuthenticationClientOptions, QRCodeGenarateResult, QRCodeStatus, QRCodeUserInfo } from './types'; import { User } from '../../types/graphql.v2'; import { HttpClient } from '../common/HttpClient'; import { BaseAuthenticationClient } from './BaseAuthenticationClient'; /** * @class QrCodeAuthenticationClient QrCode Authentication Client * @description This client is used for Qrcode login, which is divided into two types of small program scanning code login (wxqrcode) and APP scanning code login (qrcode). The API of the two scan code login methods is exactly the same. * * Use the mini program to scan the code to log in: * * \`\`\`javascript * import { AuthenticationClient } from "approw-js-sdk" * const authenticationClient = new AuthenticationClient({ * appId: "YOUR_APP_ID", * }) * authenticationClient.wxqrcode.startScanning() # Scan code to log in * \`\`\` * * Use APP to scan code to log in * * \`\`\`javascript * import { AuthenticationClient } from "approw-js-sdk" * const authenticationClient = new AuthenticationClient({ * appId: "YOUR_APP_ID", * }) * authenticationClient.qrcode.startScanning() # Scan code to log in * \`\`\` * * @name QrCodeAuthenticationClient */ export declare class QrCodeAuthenticationClient { options: AuthenticationClientOptions; tokenProvider: AuthenticationTokenProvider; scene: string; httpClient: HttpClient; baseClient: BaseAuthenticationClient; constructor(options: AuthenticationClientOptions, tokenProvider: AuthenticationTokenProvider, httpClient: HttpClient, scene: 'WXAPP_AUTH' | 'APP_AUTH'); /** * @name startScanning * @name_zh start scanning * @description start scanning * * @param {string} domId The ID of the DOM element. * @param {Object} options * @param {boolean} options.autoExchangeUserInfo Whether to customize the use of ticket in exchange for user information * @param {number} options.interval Interval time, in milliseconds, the default is 800 milliseconds * @param {Function} options.onStart The event callback function to start polling, the first parameter is the timer returned by setInterval, you can use clearInterval to cancel this timer * @param {Function} options.onResult Get the latest status event callback function of the QR code. The type of the first parameter is QRCodeStatus. * @param {Function} options.onScanned The callback function of the user's first scan code event. At this time, the user has not been authorized, and the callback user information only contains the nickname and avatar for display purposes. * For security reasons, by default, userInfo will only contain two fields, nickname and photo. Developers can also configure it in the background to return complete user information. * @param {Function} options.onSuccess The user agrees to the authorization event callback function. This function will only call back once, after which the polling ends. The first parameter is userInfo user information, and the second parameter is ticket, which is used in exchange for user details. * Details: https://docs.approw.com/scan-qrcode/app-qrcode/customize.html。 * ticket Can be used to exchange for complete user information, see the related interface: https://docs.approw.com/scan-qrcode/app-qrcode/full-api-list.html。 * @param {Function} options.onCancel User cancellation event callback function. This event will only be called back once, after which the polling ends. * @param {Function} options.onError The callback function for the failure to get the QR code status. The common cause is network failure, etc. It will call back every time the query fails. Examples of callback parameter data such as {"code": 2241,"message": "QR code does not exist"} * @param {Function} options.onExpired When the QR code fails, it will be called back only once, after which the polling ends. * @param {Function} options.onCodeShow The event where the QR code is successfully displayed for the first time. * @param {Function} options.onCodeLoaded The first successful load event of the QR code. * @param {Function} options.onCodeLoadFailed The event that the QR code failed to load. * @param {Function} options.onCodeDestroyed The event that the QR code is destroyed. * @param {Object} options.size The size of the QR code image, the default is 240 * 240, and the unit is px. * @param {number} options.size.height height * @param {number} options.size.width width * @param {Object} options.containerSize The size of the DOM container, the default is 300 * 300, and the unit is px. * @param {number} options.containerSize.height height * @param {number} options.containerSize.width width * @param {Object} options.tips Custom prompt message * @param {number} options.tips.title * @param {number} options.tips.scanned * @param {Object} options.tips.succeed * @param {number} options.tips.canceled * @param {number} options.tips.expired * @param {number} options.tips.retry * @param {number} options.tips.failed * * @example * * authenticationClient.wxqrcode.startScanning("qrcode", { * onSuccess: (userInfo, ticket) => { * console.log(userInfo, ticket) * }, * onError: (message) => onFail && onFail(`${message}`), * }); * * @returns {null} * @memberof QrCodeAuthenticationClient * */ startScanning(domId: string, options?: { autoExchangeUserInfo?: boolean; size?: { height: number; width: number; }; containerSize?: { height: number; width: number; }; interval?: number; onStart?: (timer: any) => any; onResult?: (data: QRCodeStatus) => any; onScanned?: (userInfo: QRCodeUserInfo) => any; onSuccess?: (userInfo: QRCodeUserInfo, ticket: string) => any; onCancel?: () => any; onError?: (message: string) => any; onExpired?: () => any; onCodeShow?: (random: string, url: string) => any; onCodeLoaded?: (random: string, url: string) => any; onCodeLoadFailed?: (message: string) => any; onCodeDestroyed?: (random: string) => any; tips?: { title?: string; scanned?: string; succeed?: string; canceled?: string; expired?: string; retry?: string; failed?: string; }; /** * @description User-defined fields that will be written to the configuration */ customData?: { [x: string]: any; }; /** * @description The request context will be passed to the pipeline */ context?: { [x: string]: any; }; }): Promise; /** * @name geneCode * @name_zh Generate QR code * @description Generate QR code * * @example * const authenticationClient = new AuthenticationClient({ * appId: "YOUR_APP_ID", * }) * const { url, random } = await authenticationClient.wxqrcode.geneCode() * * # random QR code unique ID * # url QR code link * * @returns {Promise} * @memberof QrCodeAuthenticationClient */ geneCode(options?: { context?: { [x: string]: any; }; customData?: { [x: string]: any; }; }): Promise; /** * @name checkStatus * @name_zh Check scan code status * @description Check scan code status * * @param {string} random * * @example * * const authenticationClient = new AuthenticationClient({ * appId: "YOUR_APP_ID", * }) * const { random, status, ticket, userInfo } = await authenticationClient.wxqrcode.checkStatus('RANDOM') * # status: QR code status: 0-not used, 1-scanned, 2-authorized, 3-canceled authorization, -1-expired * # ticket: A random string used in exchange for user information * # userInfo: User Info * * @returns {Promise} * @memberof QrCodeAuthenticationClient */ checkStatus(random: string): Promise; /** * @name exchangeUserInfo * @name_zh Use ticket to exchange user information * @description Use ticket to exchange user information * * @example * * const authenticationClient = new AuthenticationClient({ * appId: "YOUR_APP_ID", * }) * const user = await authenticationClient.wxqrcode.exchangeUserInfo('TICKET') * # user: Complete user information, where user.token is the user's login credentials. * * @param {string} ticket ticket * @returns {Promise>} * @memberof QrCodeAuthenticationClient */ exchangeUserInfo(ticket: string): Promise>; /** * @name startPolling * @name_zh Start to poll the QR code status * @description Start to poll the QR code status * * @param {string} random QR code unique ID * @param {Object} options * @param {number} options.interval Interval time, in milliseconds, the default is 800 milliseconds * @param {Function} options.onStart The event callback function to start polling, the first parameter is the timer returned by setInterval, you can use clearInterval to cancel this timer * @param {Function} options.onResult Get the latest status event callback function of the QR code. The type of the first parameter is QRCodeStatus. * @param {Function} options.onScanned The callback function of the user's first scan code event. At this time, the user has not been authorized, and the callback user information only contains the nickname and avatar for display purposes. * For security reasons, by default, userInfo will only contain two fields, nickname and photo. Developers can also configure it in the background to return complete user information. * @param {Function} options.onSuccess The user agrees to the authorization event callback function. This function will only call back once, after which the polling ends. The first parameter is userInfo user information, and the second parameter is ticket, which is used in exchange for user details. * Details: https://docs.approw.com/scan-qrcode/app-qrcode/customize.html。 * ticket Can be used to exchange for complete user information, see the related interface: https://docs.approw.com/scan-qrcode/app-qrcode/full-api-list.html。 * @param {Function} options.onCancel User cancellation event callback function. This event will only be called back once, after which the polling ends. * @param {Function} options.onError The callback function for the failure to get the QR code status. The common cause is network failure, etc. It will call back every time the query fails. Examples of callback parameter data such as {"code": 2241,"message": "QR code does not exist"} * @param {Function} options.onExpired When the QR code fails, it will be called back only once, after which the polling ends. * * @returns {null} * @memberof QrCodeAuthenticationClient */ startPolling(random: string, options?: { interval?: number; onStart?: (timer: any) => any; onResult?: (data: QRCodeStatus) => any; onScanned?: (userInfo: QRCodeUserInfo) => any; onSuccess?: (userInfo: QRCodeUserInfo, ticket: string) => any; onCancel?: () => any; onError?: (message: string) => any; onExpired?: () => any; }): Promise; stopPolling(timer: any): Promise; }