-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
feat: Add Cloud Demo
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System.Collections.Generic; | ||
using LitJson; | ||
using UnityEngine; | ||
using WeChatWASM; | ||
|
||
public class CallContainer : Details | ||
{ | ||
// data | ||
private class CloudCallContainerData | ||
{ | ||
public string action; | ||
} | ||
|
||
private void Start() | ||
{ | ||
GameManager.Instance.detailsController.BindExtraButtonAction(0, CloudCallContainerByInstance); | ||
} | ||
|
||
protected override void TestAPI(string[] args) | ||
{ | ||
this.CloudCallContainer(); | ||
} | ||
|
||
// 使用默认云开发操作实例调用云托管 | ||
private void CloudCallContainer() | ||
{ | ||
WX.cloud.Init(); // 注意初始化 | ||
|
||
var data = new CloudCallContainerData() | ||
{ | ||
action = "inc" | ||
}; | ||
|
||
WX.cloud.CallContainer(new CallContainerParam() | ||
{ | ||
config = new ICloudConfig() | ||
{ | ||
env = "prod-xxx", // 云托管环境ID,通过创建云托管服务获取 | ||
}, | ||
path = "/api/count", // 服务路径 | ||
header = new Dictionary<string, string>() // 设置请求的 header,header 中不能设置 Referer。content-type 默认为 application/json | ||
{ | ||
{ "X-WX-SERVICE", "express-hodt" } | ||
}, | ||
method = "POST", // HTTP 请求方法 | ||
data = JsonMapper.ToJson(data), // 请求数据 | ||
success = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallContainer Success: " + JsonMapper.ToJson(res) | ||
}); | ||
}, | ||
fail = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallContainer Fail: " + JsonMapper.ToJson(res) | ||
}); | ||
}, | ||
complete = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallContainer Complete: " + JsonMapper.ToJson(res) | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
// 新建云开发操作实例调用云托管 | ||
private void CloudCallContainerByInstance() | ||
{ | ||
var clo = WX.cloud.Cloud(new ICloudInstanceOptions() | ||
{ | ||
resourceEnv = "cloud1-xxx", // 云开发环境ID,通过创建云开发环境获取 | ||
}); | ||
|
||
clo.Init(); // 注意初始化 | ||
|
||
var data = new CloudCallContainerData() | ||
{ | ||
action = "inc" | ||
}; | ||
|
||
clo.CallContainer(new CallContainerParam() | ||
{ | ||
config = new ICloudConfig() | ||
{ | ||
env = "prod-xxx", // 云托管环境ID,通过创建云托管服务获取 | ||
}, | ||
path = "/api/count", // 服务路径 | ||
header = new Dictionary<string, string>() // 设置请求的 header,header 中不能设置 Referer。content-type 默认为 application/json | ||
{ | ||
{ "X-WX-SERVICE", "express-hodt" } | ||
}, | ||
method = "POST", // HTTP 请求方法 | ||
data = JsonMapper.ToJson(data), // 请求数据 | ||
success = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallContainer Success: " + JsonMapper.ToJson(res) | ||
}); | ||
}, | ||
fail = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallContainer Fail: " + JsonMapper.ToJson(res) | ||
}); | ||
}, | ||
complete = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallContainer Complete: " + JsonMapper.ToJson(res) | ||
}); | ||
} | ||
}); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!114 &11400000 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3} | ||
m_Name: CallContainerSO | ||
m_EditorClassIdentifier: | ||
entryScriptTypeName: CallContainer | ||
entryName: "\u4E91\u6258\u7BA1" | ||
entryAPI: WX.cloud.CallContainer | ||
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/" | ||
optionList: [] | ||
initialButtonText: "\u4F7F\u7528\u9ED8\u8BA4\u4E91\u5F00\u53D1\u64CD\u4F5C\u5B9E\u4F8B\u8C03\u7528\u4E91\u6258\u7BA1" | ||
extraButtonList: | ||
- buttonText: "\u65B0\u5EFA\u4E91\u5F00\u53D1\u64CD\u4F5C\u5B9E\u4F8B\u8C03\u7528\u4E91\u6258\u7BA1" | ||
initialResultList: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
using System.Collections.Generic; | ||
using LitJson; | ||
using UnityEngine; | ||
using WeChatWASM; | ||
|
||
public class CallFunction : Details | ||
{ | ||
// data | ||
private class CloudCallFunctionData | ||
{ | ||
public int NormalData; | ||
public string WeRunData; | ||
public string BigData1; | ||
public string BigData2; | ||
public CloudCallFunctionDataObj Obj; | ||
} | ||
private class CloudCallFunctionDataObj | ||
{ | ||
public string BigData3; | ||
public string ShareInfo; | ||
} | ||
|
||
private string CloudID; // 通过其他接口获取的CloudID | ||
|
||
private void Start() | ||
{ | ||
GameManager.Instance.detailsController.BindExtraButtonAction(0, CloudCallFunctionByInstance); | ||
|
||
WX.GetUserInfo(new GetUserInfoOption() // 获取敏感数据对应的CloudID | ||
{ | ||
success = (res) => | ||
{ | ||
CloudID = res.cloudID; | ||
} | ||
}); | ||
} | ||
|
||
protected override void TestAPI(string[] args) | ||
{ | ||
this.CloudCallFunction(); | ||
} | ||
|
||
// 使用默认云开发操作实例调用云函数 | ||
private void CloudCallFunction() | ||
{ | ||
WX.cloud.Init(); // 注意初始化 | ||
|
||
var obj = new CloudCallFunctionDataObj() | ||
{ | ||
BigData3 = WX.cloud.CDN(new ICDNFilePathSpec() | ||
{ | ||
type = "filePath", // 此项必填filePath | ||
filePath = "/7865-xxx-xxx-xxx/xxx.png", // 替换为实际的文件路径 | ||
}), // 参数为文件路径定义对象 | ||
ShareInfo = WX.cloud.CloudID(CloudID), // 通过其他接口获取的CloudID | ||
}; | ||
var data = new CloudCallFunctionData() | ||
{ | ||
NormalData = 111, | ||
WeRunData = WX.cloud.CloudID(CloudID), // 通过其他接口获取的CloudID | ||
BigData1 = WX.cloud.CDN("some large string"), // 参数为字符串 | ||
BigData2 = WX.cloud.CDN(new byte[] { 1, 2, 3, 4 }), // 参数为byte[] | ||
Obj = obj, | ||
}; | ||
|
||
WX.cloud.CallFunction(new CallFunctionParam() | ||
{ | ||
name = "myFunction", // 须在云函数侧创建对应函数 | ||
data = data, | ||
success = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallFunction Success: " + JsonMapper.ToJson(res) | ||
}); | ||
}, | ||
fail = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallFunction Fail: " + JsonMapper.ToJson(res) | ||
}); | ||
}, | ||
complete = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallFunction Complete: " + JsonMapper.ToJson(res) | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
// 新建云开发操作实例调用云函数 | ||
private void CloudCallFunctionByInstance() | ||
{ | ||
var clo = WX.cloud.Cloud(new ICloudInstanceOptions() | ||
{ | ||
resourceEnv = "cloud1-xxx", // 云开发环境ID,通过创建云开发环境获取 | ||
}); | ||
|
||
clo.Init(); // 注意初始化 | ||
|
||
var obj = new CloudCallFunctionDataObj() | ||
{ | ||
BigData3 = clo.CDN(new ICDNFilePathSpec() | ||
{ | ||
type = "filePath", // 此项必填filePath | ||
filePath = "/7865-xxx-xxx-xxx/xxx.png", // 替换为实际的文件路径 | ||
}), // 参数为文件路径定义对象 | ||
ShareInfo = clo.CloudID(CloudID), // 通过其他接口获取的CloudID | ||
}; | ||
var data = new CloudCallFunctionData() | ||
{ | ||
NormalData = 111, | ||
WeRunData = clo.CloudID(CloudID), // 通过其他接口获取的CloudID | ||
BigData1 = clo.CDN("some large string"), // 参数为字符串 | ||
BigData2 = clo.CDN(new byte[] { 1, 2, 3, 4 }), // 参数为byte[] | ||
Obj = obj, | ||
}; | ||
|
||
clo.CallFunction(new CallFunctionParam() | ||
{ | ||
name = "myFunction", // 须在云函数侧创建对应函数 | ||
data = data, | ||
success = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallFunction Success: " + JsonMapper.ToJson(res) | ||
}); | ||
}, | ||
fail = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallFunction Fail: " + JsonMapper.ToJson(res) | ||
}); | ||
}, | ||
complete = (res) => | ||
{ | ||
WX.ShowModal(new ShowModalOption() | ||
{ | ||
content = "Cloud CallFunction Complete: " + JsonMapper.ToJson(res) | ||
}); | ||
} | ||
}); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!114 &11400000 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3} | ||
m_Name: CallFunctionSO | ||
m_EditorClassIdentifier: | ||
entryScriptTypeName: CallFunction | ||
entryName: "\u4E91\u51FD\u6570" | ||
entryAPI: WX.cloud.CallFunction | ||
entryDescription: "<color=red>\u8BF7\u5C06\u53C2\u6570\u6309\u5B9E\u9645\u60C5\u51B5\u8FDB\u884C\u66FF\u6362</color>\n\u5982\u679C | ||
data \u4E2D\u5305\u542B\u5927\u6570\u636E\u5B57\u6BB5\uFF08\u5EFA\u8BAE\u4E34\u754C\u503C | ||
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" | ||
optionList: [] | ||
initialButtonText: "\u4F7F\u7528\u9ED8\u8BA4\u4E91\u5F00\u53D1\u64CD\u4F5C\u5B9E\u4F8B\u8C03\u7528\u4E91\u51FD\u6570" | ||
extraButtonList: | ||
- buttonText: "\u65B0\u5EFA\u4E91\u5F00\u53D1\u64CD\u4F5C\u5B9E\u4F8B\u8C03\u7528\u4E91\u51FD\u6570" | ||
initialResultList: [] |