import { _decorator, Component, Node } from ‘cc’;
const { ccclass, property } = _decorator;
import cloud from ‘./libs/faas-web-sdk/dist/index.js’;
@ccclass(‘Alipay’)
export class NewComponent extends Component {
async start() {
var self = this;
/**
my.request({
url: 'https://env-00jx3shfuxva.dev-hz.cloudbasefunction.cn/helloworld',
method: 'POST',
dataType: 'json',
success: function (res) {
self.getComponent(cc.Label).string = res.data.message
}
});
*/
const sdk = new cloud.Cloud({
//在环境概览中获取
endpoint: 'https://env-00jx49rafua2.api-hz.cloudbasefunction.cn',
//在环境概览中获取 AK
secretId: 'xxx',
//在环境概览中获取 SK
secretKey: 'xxx',
//填写自己的APPID
appId: 'xxxx',
//填写自己的环境ID
envId: 'env-00jx49rafua2',
});
try {
const res = await sdk.callFunction({
name: 'cocos',
});
console.log("---" + res.result.message);
self.getComponent(cc.Label).string = res.result.message
console.log('调用结果', res);
} catch(e) {
console.error('调用失败', e);
}
}
update(deltaTime: number) {
}
}
这里调用 支付宝云开发云函数的方式,是可以使用的 ,可以参考