@@ -2,6 +2,8 @@ import { ActionType } from './apis';
22import { CapiCredentials , RegionType , ApiServiceType } from './../interface' ;
33import { Capi } from '@tencent-sdk/capi' ;
44import APIS from './apis' ;
5+ import { getYunTiApiUrl } from '../../utils' ;
6+ import axios from 'axios' ;
57
68/** CAM (访问管理)for serverless */
79export default class Cam {
@@ -112,4 +114,54 @@ export default class Cam {
112114 async CheckSCFExcuteRole ( ) {
113115 return this . isRoleExist ( 'QCS_SCFExcuteRole' ) ;
114116 }
117+
118+ /** 查询用户AppId */
119+ async GetUserAppId ( ) : Promise < { OwnerUin : string ; AppId : string ; Uin : string } > {
120+ try {
121+ return this . request ( {
122+ Action : 'GetUserAppId' ,
123+ } ) ;
124+ } catch ( error ) {
125+ return {
126+ OwnerUin : '' ,
127+ AppId : '' ,
128+ Uin : '' ,
129+ } ;
130+ }
131+ }
132+
133+ /**
134+ * checkYunTi 检查是否是云梯账号
135+ * @returns {boolean } true: 是云梯账号; false: 非云梯账号
136+ */
137+ async checkYunTi ( ) : Promise < boolean > {
138+ let isYunTi = false ;
139+ const { OwnerUin : uin } = await this . GetUserAppId ( ) ;
140+ try {
141+ const params = JSON . stringify ( {
142+ id : '1' ,
143+ jsonrpc : '2.0' ,
144+ method : 'checkOwnUin' ,
145+ params : { ownUin : [ uin ] } ,
146+ } ) ;
147+ const apiUrl = getYunTiApiUrl ( ) ;
148+ const res = await axios . post ( apiUrl , params , {
149+ headers : { 'content-type' : 'application/json' } ,
150+ } ) ;
151+ if ( res ?. data ?. error ?. message ) {
152+ throw new Error ( res . data . error . message ) ;
153+ } else {
154+ isYunTi =
155+ res ?. data ?. result ?. data &&
156+ res . data . result . data ?. some (
157+ ( item : { ownUin : string ; appId : string } ) => item ?. ownUin === uin ,
158+ ) ;
159+ console . log ( 'check yunTi ownUin:' , isYunTi ) ;
160+ }
161+ } catch ( error ) {
162+ isYunTi = false ;
163+ console . log ( 'checkYunTiOwnUin error:' , error ) ;
164+ }
165+ return isYunTi ;
166+ }
115167}
0 commit comments