mini program: remove secret key
This commit is contained in:
@@ -7,19 +7,21 @@ const Credential = tencentcloud.common.Credential;
|
|||||||
const ClientProfile = tencentcloud.common.ClientProfile;
|
const ClientProfile = tencentcloud.common.ClientProfile;
|
||||||
const HttpProfile = tencentcloud.common.HttpProfile;
|
const HttpProfile = tencentcloud.common.HttpProfile;
|
||||||
|
|
||||||
let cred = new Credential("AKIDDDzjIeENdhosOg9T0LRXabO0B7pHhzQe", "f6IqCUirpeF1gLn3f0IWosjOqjOyTq2r");
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
let cred = new Credential(event.SecretId, event.SecretKey);
|
||||||
let httpProfile = new HttpProfile();
|
let httpProfile = new HttpProfile();
|
||||||
httpProfile.endpoint = "iotcloud.tencentcloudapi.com";
|
httpProfile.endpoint = "iotcloud.tencentcloudapi.com";
|
||||||
let clientProfile = new ClientProfile();
|
let clientProfile = new ClientProfile();
|
||||||
clientProfile.httpProfile = httpProfile;
|
clientProfile.httpProfile = httpProfile;
|
||||||
let client = new IotcloudClient(cred, "ap-guangzhou", clientProfile);
|
let client = new IotcloudClient(cred, "ap-guangzhou", clientProfile);
|
||||||
|
|
||||||
// 云函数入口函数
|
|
||||||
exports.main = async (event, context) => {
|
|
||||||
let req = new models.PublishMessageRequest();
|
let req = new models.PublishMessageRequest();
|
||||||
req.Topic = "U1BZWHF7F9/dev_01/data";
|
// req.Topic = "U1BZWHF7F9/dev_01/data";
|
||||||
req.DeviceName = "dev_01";
|
// req.DeviceName = "dev_01";
|
||||||
req.ProductId = "U1BZWHF7F9";
|
// req.ProductId = "U1BZWHF7F9";
|
||||||
|
req.Topic = event.Topic
|
||||||
|
req.DeviceName = event.DeviceName;
|
||||||
|
req.ProductId = event.ProductId;
|
||||||
req.Payload = event.Payload;
|
req.Payload = event.Payload;
|
||||||
|
|
||||||
return new Promise((resolve, reject)=>{
|
return new Promise((resolve, reject)=>{
|
||||||
|
@@ -7,19 +7,17 @@ const Credential = tencentcloud.common.Credential;
|
|||||||
const ClientProfile = tencentcloud.common.ClientProfile;
|
const ClientProfile = tencentcloud.common.ClientProfile;
|
||||||
const HttpProfile = tencentcloud.common.HttpProfile;
|
const HttpProfile = tencentcloud.common.HttpProfile;
|
||||||
|
|
||||||
let cred = new Credential("AKIDDDzjIeENdhosOg9T0LRXabO0B7pHhzQe", "f6IqCUirpeF1gLn3f0IWosjOqjOyTq2r");
|
exports.main = async (event, context) => {
|
||||||
|
let cred = new Credential(event.SecretId, event.SecretKey);
|
||||||
let httpProfile = new HttpProfile();
|
let httpProfile = new HttpProfile();
|
||||||
httpProfile.endpoint = "iotcloud.tencentcloudapi.com";
|
httpProfile.endpoint = "iotcloud.tencentcloudapi.com";
|
||||||
let clientProfile = new ClientProfile();
|
let clientProfile = new ClientProfile();
|
||||||
clientProfile.httpProfile = httpProfile;
|
clientProfile.httpProfile = httpProfile;
|
||||||
let client = new IotcloudClient(cred, "ap-guangzhou", clientProfile);
|
let client = new IotcloudClient(cred, "ap-guangzhou", clientProfile);
|
||||||
|
|
||||||
let req = new models.DescribeDeviceShadowRequest();
|
let req = new models.DescribeDeviceShadowRequest();
|
||||||
|
req.DeviceName = event.DeviceName;
|
||||||
|
req.ProductId = event.ProductId;
|
||||||
|
|
||||||
let params = '{"ProductId":"U1BZWHF7F9","DeviceName":"dev_01"}'
|
|
||||||
req.from_json_string(params);
|
|
||||||
|
|
||||||
exports.main = async (event, context) => {
|
|
||||||
return new Promise((resolve, reject)=>{
|
return new Promise((resolve, reject)=>{
|
||||||
client.DescribeDeviceShadow(req, function (errMsg, response) {
|
client.DescribeDeviceShadow(req, function (errMsg, response) {
|
||||||
|
|
||||||
|
@@ -4,6 +4,9 @@ App({
|
|||||||
// 腾讯云物联网通信平台中获取 产品ID和设备名称
|
// 腾讯云物联网通信平台中获取 产品ID和设备名称
|
||||||
productId: "U1BZWHF7F9", // 产品ID
|
productId: "U1BZWHF7F9", // 产品ID
|
||||||
deviceName: "dev_01", // 设备名称
|
deviceName: "dev_01", // 设备名称
|
||||||
|
// 腾讯云控制台-访问管理-访问密钥-API密钥管理中获取 SecretId, SecretKey
|
||||||
|
secretId: "xxx",
|
||||||
|
secretKey: "xxx",
|
||||||
},
|
},
|
||||||
onLaunch: function () {
|
onLaunch: function () {
|
||||||
if (!wx.cloud) {
|
if (!wx.cloud) {
|
||||||
|
@@ -30,8 +30,10 @@ Page({
|
|||||||
wx.cloud.callFunction({
|
wx.cloud.callFunction({
|
||||||
name: 'iothub-shadow-query',
|
name: 'iothub-shadow-query',
|
||||||
data: {
|
data: {
|
||||||
productId: app.globalData.productId,
|
ProductId: app.globalData.productId,
|
||||||
deviceName: app.globalData.deviceName,
|
DeviceName: app.globalData.deviceName,
|
||||||
|
SecretId: app.globalData.secretId,
|
||||||
|
SecretKey: app.globalData.secretKey,
|
||||||
},
|
},
|
||||||
success: res => {
|
success: res => {
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
@@ -67,9 +69,11 @@ Page({
|
|||||||
wx.cloud.callFunction({
|
wx.cloud.callFunction({
|
||||||
name: 'iothub-publish',
|
name: 'iothub-publish',
|
||||||
data: {
|
data: {
|
||||||
|
SecretId: app.globalData.secretId,
|
||||||
|
SecretKey: app.globalData.secretKey,
|
||||||
ProductId: app.globalData.productId,
|
ProductId: app.globalData.productId,
|
||||||
DeviceName: app.globalData.deviceName,
|
DeviceName: app.globalData.deviceName,
|
||||||
Topic: "",
|
Topic: app.globalData.productId + "/" + app.globalData.deviceName + "/data",
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
},
|
},
|
||||||
success: res => {
|
success: res => {
|
||||||
|
Reference in New Issue
Block a user