添加微信云开发环境
This commit is contained in:
84
assets/script/game/wx_clound_client_api/WxCloudApi.ts
Normal file
84
assets/script/game/wx_clound_client_api/WxCloudApi.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
export type CloudReturnType<T = any> = {
|
||||
code: number,// 200成功
|
||||
msg?:string,
|
||||
data?:T
|
||||
}
|
||||
|
||||
export class WxCloudApi{
|
||||
/**
|
||||
* @en init the cloud
|
||||
* @zh 初始化云客户端(只调用一次即可)
|
||||
* @param {string} env 云环境名称
|
||||
*/
|
||||
public static init(env:string){
|
||||
wx?.cloud.init({
|
||||
env: env
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Login to the cloud
|
||||
* @zh 登录云
|
||||
* @return 返回结果
|
||||
* 参考:
|
||||
* result.result = {
|
||||
* code: number, // 200成功,其他都是失败
|
||||
* msg: string, // 如果失败,这里是失败原因等信息
|
||||
* data: { // 成功才有
|
||||
* openid: string, // 用户微信平台openid
|
||||
* regist_time: number, // 时间戳,用户注册时间
|
||||
* game_data: object, // 开发者自己保存的数据
|
||||
* }
|
||||
* }
|
||||
* 如果这个泛型令你报错(一般是因为你删了wx.api.d.ts导致),请使用以下签名:
|
||||
* login():Promise<{result: CloudReturnType<{openid: string, regist_time: number, game_data: object}>}>
|
||||
* 或者你是个“不拘小节”的老哥,可以用以下简洁版签名(参考上方的数据结构例子使用即可)
|
||||
* login():Promise<any>
|
||||
*/
|
||||
public static async login(): Promise<CloudCallFunctionResult<CloudReturnType<{
|
||||
openid:string,
|
||||
regist_time:number,
|
||||
game_data:any
|
||||
}>>>{
|
||||
return await wx?.cloud.callFunction({
|
||||
name: 'cocos_cloud',
|
||||
data: {
|
||||
cmd: "login"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Save game data to the cloud
|
||||
* @zh 把客户端数据写入云,此为全覆盖写入,请自行管理完整数据
|
||||
* @return 返回结果
|
||||
* 参考:
|
||||
* result.result = {
|
||||
* code: number, // 200成功,其他都是失败
|
||||
* msg: string, // 如果失败,这里是失败原因等信息
|
||||
* data: {
|
||||
* errMsg: "document.update:ok", // 数据库返回结果
|
||||
* stats: {
|
||||
* updated: number, // 更新了几条数据(正常是1)
|
||||
* }
|
||||
* }
|
||||
* 如果这个泛型令你报错(一般是因为你删了wx.api.d.ts导致),请使用以下签名:
|
||||
* save(gameData: any): Promise<{resoult:CloudReturnType}>
|
||||
* 或者你是个“不拘小节”的老哥,可以用以下简洁版签名(参考上方的数据结构例子使用即可)
|
||||
* login():Promise<any>
|
||||
*/
|
||||
public static async save(gameData: any): Promise<CloudCallFunctionResult<CloudReturnType<{
|
||||
errMsg: string,
|
||||
status:{
|
||||
updated: number
|
||||
}
|
||||
}>>> {
|
||||
return await wx?.cloud.callFunction({
|
||||
name: 'cocos_cloud',
|
||||
data: {
|
||||
cmd: 'save',
|
||||
data: gameData
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0b5acaf6-aa85-428d-a38c-97bf645cc1db",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
29
assets/script/game/wx_clound_client_api/wx.aip.d.ts
vendored
Normal file
29
assets/script/game/wx_clound_client_api/wx.aip.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// 注意:此文件是为了引入微信接口
|
||||
// !!如果这个文件,与你的wx.d.ts因为定义重复报错,你可以删除本文件!!
|
||||
|
||||
// @ts-ignore
|
||||
declare class wx {
|
||||
public static cloud: Cloud;
|
||||
}
|
||||
// @ts-ignore
|
||||
declare class Cloud {
|
||||
public init(options: {
|
||||
env?: string | {
|
||||
database?: string
|
||||
storage?: string
|
||||
functions?: string
|
||||
},
|
||||
traceUser?: boolean//default true
|
||||
});
|
||||
public callFunction(obj: {
|
||||
name: string,
|
||||
data?: any,
|
||||
config?: { env: string },
|
||||
}): Promise<CloudCallFunctionResult>;
|
||||
}
|
||||
// @ts-ignore
|
||||
declare type CloudCallFunctionResult<T = any> = {
|
||||
result: T,
|
||||
errMsg: string,
|
||||
requestID: string
|
||||
}
|
||||
9
assets/script/game/wx_clound_client_api/wx.aip.d.ts.meta
Normal file
9
assets/script/game/wx_clound_client_api/wx.aip.d.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "845c60fa-24b5-49c9-85d3-ef55ed459817",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user