Skip to content

Commit ef4f1f6

Browse files
committed
feat: Add Cloud Demo
1 parent 6553f2a commit ef4f1f6

27 files changed

+17798
-16831
lines changed

Demo/API_V2/Assets/API/APISO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ MonoBehaviour:
1616
- {fileID: 11400000, guid: 587fe4b03da9d44779ac921ffdb216a7, type: 2}
1717
- {fileID: 11400000, guid: 82450cc74b3b4439da53b9f0f2298454, type: 2}
1818
- {fileID: 11400000, guid: b34629c67a7664a428561dd0b3621995, type: 2}
19+
- {fileID: 11400000, guid: 24d9eba5a9b3048b59cf7e5495bb999d, type: 2}
1920
- {fileID: 11400000, guid: 9977a581037b84833a32b508e00eb1a2, type: 2}
2021
- {fileID: 11400000, guid: 56f316e0e10ba419bbf19bd7a68bfc4c, type: 2}
2122
- {fileID: 11400000, guid: 6f0972f5fdc56c543b23c9873d760bf5, type: 2}

Demo/API_V2/Assets/API/Cloud.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/Cloud/CallContainer.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System.Collections.Generic;
2+
using LitJson;
3+
using UnityEngine;
4+
using WeChatWASM;
5+
6+
public class CallContainer : Details
7+
{
8+
// data
9+
private class CloudCallContainerData
10+
{
11+
public string action;
12+
}
13+
14+
private void Start()
15+
{
16+
GameManager.Instance.detailsController.BindExtraButtonAction(0, CloudCallContainerByInstance);
17+
}
18+
19+
protected override void TestAPI(string[] args)
20+
{
21+
this.CloudCallContainer();
22+
}
23+
24+
// 使用默认云开发操作实例调用云托管
25+
private void CloudCallContainer()
26+
{
27+
WX.cloud.Init(); // 注意初始化
28+
29+
var data = new CloudCallContainerData()
30+
{
31+
action = "inc"
32+
};
33+
34+
WX.cloud.CallContainer(new CallContainerParam()
35+
{
36+
config = new ICloudConfig()
37+
{
38+
env = "prod-xxx", // 云托管环境ID,通过创建云托管服务获取
39+
},
40+
path = "/api/count", // 服务路径
41+
header = new Dictionary<string, string>() // 设置请求的 header,header 中不能设置 Referer。content-type 默认为 application/json
42+
{
43+
{ "X-WX-SERVICE", "express-hodt" }
44+
},
45+
method = "POST", // HTTP 请求方法
46+
data = JsonMapper.ToJson(data), // 请求数据
47+
success = (res) =>
48+
{
49+
WX.ShowModal(new ShowModalOption()
50+
{
51+
content = "Cloud CallContainer Success: " + JsonMapper.ToJson(res)
52+
});
53+
},
54+
fail = (res) =>
55+
{
56+
WX.ShowModal(new ShowModalOption()
57+
{
58+
content = "Cloud CallContainer Fail: " + JsonMapper.ToJson(res)
59+
});
60+
},
61+
complete = (res) =>
62+
{
63+
WX.ShowModal(new ShowModalOption()
64+
{
65+
content = "Cloud CallContainer Complete: " + JsonMapper.ToJson(res)
66+
});
67+
}
68+
});
69+
}
70+
71+
// 新建云开发操作实例调用云托管
72+
private void CloudCallContainerByInstance()
73+
{
74+
var clo = WX.cloud.Cloud(new ICloudInstanceOptions()
75+
{
76+
resourceEnv = "cloud1-xxx", // 云开发环境ID,通过创建云开发环境获取
77+
});
78+
79+
clo.Init(); // 注意初始化
80+
81+
var data = new CloudCallContainerData()
82+
{
83+
action = "inc"
84+
};
85+
86+
clo.CallContainer(new CallContainerParam()
87+
{
88+
config = new ICloudConfig()
89+
{
90+
env = "prod-xxx", // 云托管环境ID,通过创建云托管服务获取
91+
},
92+
path = "/api/count", // 服务路径
93+
header = new Dictionary<string, string>() // 设置请求的 header,header 中不能设置 Referer。content-type 默认为 application/json
94+
{
95+
{ "X-WX-SERVICE", "express-hodt" }
96+
},
97+
method = "POST", // HTTP 请求方法
98+
data = JsonMapper.ToJson(data), // 请求数据
99+
success = (res) =>
100+
{
101+
WX.ShowModal(new ShowModalOption()
102+
{
103+
content = "Cloud CallContainer Success: " + JsonMapper.ToJson(res)
104+
});
105+
},
106+
fail = (res) =>
107+
{
108+
WX.ShowModal(new ShowModalOption()
109+
{
110+
content = "Cloud CallContainer Fail: " + JsonMapper.ToJson(res)
111+
});
112+
},
113+
complete = (res) =>
114+
{
115+
WX.ShowModal(new ShowModalOption()
116+
{
117+
content = "Cloud CallContainer Complete: " + JsonMapper.ToJson(res)
118+
});
119+
}
120+
});
121+
}
122+
}

Demo/API_V2/Assets/API/Cloud/CallContainer/CallContainer.cs.meta

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: CallContainerSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: CallContainer
16+
entryName: "\u4E91\u6258\u7BA1"
17+
entryAPI: WX.cloud.CallContainer
18+
entryDescription: "<color=red>\u8BF7\u5C06\u53C2\u6570\u6309\u5B9E\u9645\u60C5\u51B5\u8FDB\u884C\u66FF\u6362</color>\n\u6709\u5173\u5FEB\u901F\u90E8\u7F72\u4E91\u6258\u7BA1\u8BE6\u89C1https://developers.weixin.qq.com/miniprogram/dev/wxcloudrun/src/quickstart/template/"
19+
optionList: []
20+
initialButtonText: "\u4F7F\u7528\u9ED8\u8BA4\u4E91\u5F00\u53D1\u64CD\u4F5C\u5B9E\u4F8B\u8C03\u7528\u4E91\u6258\u7BA1"
21+
extraButtonList:
22+
- buttonText: "\u65B0\u5EFA\u4E91\u5F00\u53D1\u64CD\u4F5C\u5B9E\u4F8B\u8C03\u7528\u4E91\u6258\u7BA1"
23+
initialResultList: []

Demo/API_V2/Assets/API/Cloud/CallContainer/CallContainerSO.asset.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/Cloud/CallFunction.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
using System.Collections.Generic;
2+
using LitJson;
3+
using UnityEngine;
4+
using WeChatWASM;
5+
6+
public class CallFunction : Details
7+
{
8+
// data
9+
private class CloudCallFunctionData
10+
{
11+
public int NormalData;
12+
public string WeRunData;
13+
public string BigData1;
14+
public string BigData2;
15+
public CloudCallFunctionDataObj Obj;
16+
}
17+
private class CloudCallFunctionDataObj
18+
{
19+
public string BigData3;
20+
public string ShareInfo;
21+
}
22+
23+
private string CloudID; // 通过其他接口获取的CloudID
24+
25+
private void Start()
26+
{
27+
GameManager.Instance.detailsController.BindExtraButtonAction(0, CloudCallFunctionByInstance);
28+
29+
WX.GetUserInfo(new GetUserInfoOption() // 获取敏感数据对应的CloudID
30+
{
31+
success = (res) =>
32+
{
33+
CloudID = res.cloudID;
34+
}
35+
});
36+
}
37+
38+
protected override void TestAPI(string[] args)
39+
{
40+
this.CloudCallFunction();
41+
}
42+
43+
// 使用默认云开发操作实例调用云函数
44+
private void CloudCallFunction()
45+
{
46+
WX.cloud.Init(); // 注意初始化
47+
48+
var obj = new CloudCallFunctionDataObj()
49+
{
50+
BigData3 = WX.cloud.CDN(new ICDNFilePathSpec()
51+
{
52+
type = "filePath", // 此项必填filePath
53+
filePath = "/7865-xxx-xxx-xxx/xxx.png", // 替换为实际的文件路径
54+
}), // 参数为文件路径定义对象
55+
ShareInfo = WX.cloud.CloudID(CloudID), // 通过其他接口获取的CloudID
56+
};
57+
var data = new CloudCallFunctionData()
58+
{
59+
NormalData = 111,
60+
WeRunData = WX.cloud.CloudID(CloudID), // 通过其他接口获取的CloudID
61+
BigData1 = WX.cloud.CDN("some large string"), // 参数为字符串
62+
BigData2 = WX.cloud.CDN(new byte[] { 1, 2, 3, 4 }), // 参数为byte[]
63+
Obj = obj,
64+
};
65+
66+
WX.cloud.CallFunction(new CallFunctionParam()
67+
{
68+
name = "myFunction", // 须在云函数侧创建对应函数
69+
data = data,
70+
success = (res) =>
71+
{
72+
WX.ShowModal(new ShowModalOption()
73+
{
74+
content = "Cloud CallFunction Success: " + JsonMapper.ToJson(res)
75+
});
76+
},
77+
fail = (res) =>
78+
{
79+
WX.ShowModal(new ShowModalOption()
80+
{
81+
content = "Cloud CallFunction Fail: " + JsonMapper.ToJson(res)
82+
});
83+
},
84+
complete = (res) =>
85+
{
86+
WX.ShowModal(new ShowModalOption()
87+
{
88+
content = "Cloud CallFunction Complete: " + JsonMapper.ToJson(res)
89+
});
90+
}
91+
});
92+
}
93+
94+
// 新建云开发操作实例调用云函数
95+
private void CloudCallFunctionByInstance()
96+
{
97+
var clo = WX.cloud.Cloud(new ICloudInstanceOptions()
98+
{
99+
resourceEnv = "cloud1-xxx", // 云开发环境ID,通过创建云开发环境获取
100+
});
101+
102+
clo.Init(); // 注意初始化
103+
104+
var obj = new CloudCallFunctionDataObj()
105+
{
106+
BigData3 = clo.CDN(new ICDNFilePathSpec()
107+
{
108+
type = "filePath", // 此项必填filePath
109+
filePath = "/7865-xxx-xxx-xxx/xxx.png", // 替换为实际的文件路径
110+
}), // 参数为文件路径定义对象
111+
ShareInfo = clo.CloudID(CloudID), // 通过其他接口获取的CloudID
112+
};
113+
var data = new CloudCallFunctionData()
114+
{
115+
NormalData = 111,
116+
WeRunData = clo.CloudID(CloudID), // 通过其他接口获取的CloudID
117+
BigData1 = clo.CDN("some large string"), // 参数为字符串
118+
BigData2 = clo.CDN(new byte[] { 1, 2, 3, 4 }), // 参数为byte[]
119+
Obj = obj,
120+
};
121+
122+
clo.CallFunction(new CallFunctionParam()
123+
{
124+
name = "myFunction", // 须在云函数侧创建对应函数
125+
data = data,
126+
success = (res) =>
127+
{
128+
WX.ShowModal(new ShowModalOption()
129+
{
130+
content = "Cloud CallFunction Success: " + JsonMapper.ToJson(res)
131+
});
132+
},
133+
fail = (res) =>
134+
{
135+
WX.ShowModal(new ShowModalOption()
136+
{
137+
content = "Cloud CallFunction Fail: " + JsonMapper.ToJson(res)
138+
});
139+
},
140+
complete = (res) =>
141+
{
142+
WX.ShowModal(new ShowModalOption()
143+
{
144+
content = "Cloud CallFunction Complete: " + JsonMapper.ToJson(res)
145+
});
146+
}
147+
});
148+
}
149+
}

Demo/API_V2/Assets/API/Cloud/CallFunction/CallFunction.cs.meta

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: CallFunctionSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: CallFunction
16+
entryName: "\u4E91\u51FD\u6570"
17+
entryAPI: WX.cloud.CallFunction
18+
entryDescription: "<color=red>\u8BF7\u5C06\u53C2\u6570\u6309\u5B9E\u9645\u60C5\u51B5\u8FDB\u884C\u66FF\u6362</color>\n\u5982\u679C
19+
data \u4E2D\u5305\u542B\u5927\u6570\u636E\u5B57\u6BB5\uFF08\u5EFA\u8BAE\u4E34\u754C\u503C
20+
100KB\uFF09\uFF0C\u5EFA\u8BAE\u4F7F\u7528 WX.cloud.CDN \u6807\u8BB0\u5927\u6570\u636E\u5B57\u6BB5\u3002\n\u5BF9\u4E8E\u654F\u611F\u6570\u636E\uFF0C\u53EF\u4EE5\u901A\u8FC7\u5728data\u4E2D\u4F7F\u7528WX.cloud.CloudID\u6765\u83B7\u53D6\u3002\u8BE6\u89C1https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html\n\u6709\u5173\u4E91\u51FD\u6570\u7684\u521B\u5EFA\uFF0C\u8BF7\u53C2\u8003https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/functions/getting-started.html"
21+
optionList: []
22+
initialButtonText: "\u4F7F\u7528\u9ED8\u8BA4\u4E91\u5F00\u53D1\u64CD\u4F5C\u5B9E\u4F8B\u8C03\u7528\u4E91\u51FD\u6570"
23+
extraButtonList:
24+
- buttonText: "\u65B0\u5EFA\u4E91\u5F00\u53D1\u64CD\u4F5C\u5B9E\u4F8B\u8C03\u7528\u4E91\u51FD\u6570"
25+
initialResultList: []

0 commit comments

Comments
 (0)