|
|
|
|
|
|
|
const cloud = require('wx-server-sdk')
|
|
|
|
|
|
|
|
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV})
|
|
|
|
|
|
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
|
|
let {name, data} = event;
|
|
|
|
switch (event.name||event.action) {
|
|
|
|
case "wxacode.getUnlimited":
|
|
|
|
case "getWXACodeUnlimited":{
|
|
|
|
return getWXACodeUnlimited(data)
|
|
|
|
}
|
|
|
|
case "wxacode.get":
|
|
|
|
case 'getWXACode': {
|
|
|
|
return getWXACode(data)
|
|
|
|
}
|
|
|
|
case "security.msgSecCheck":{
|
|
|
|
try{
|
|
|
|
var res = await cloud.openapi.security.msgSecCheck(data);
|
|
|
|
return res;
|
|
|
|
}catch(e){
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "security.imgSecCheck":{
|
|
|
|
try{
|
|
|
|
console.log(data);
|
|
|
|
var res = await cloud.openapi.security.imgSecCheck({
|
|
|
|
media:{
|
|
|
|
contentType:"image/jpg",
|
|
|
|
value:Buffer.from(data.media)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return res;
|
|
|
|
}catch(e){
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 'getOpenData': {
|
|
|
|
return getOpenData(event)
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getWXACodeUnlimited(data){
|
|
|
|
let {scene, page} = data;
|
|
|
|
const wxacodeResult = await cloud.openapi.wxacode.getUnlimited({
|
|
|
|
scene, page
|
|
|
|
})
|
|
|
|
const fileExtensionMatches = wxacodeResult.contentType.match(/\/([^\/]+)/)
|
|
|
|
const fileExtension = (fileExtensionMatches && fileExtensionMatches[1]) || 'jpg'
|
|
|
|
|
|
|
|
return cloud.uploadFile({
|
|
|
|
cloudPath: `images/wxacode/${(page+"?"+scene).replace(/[\/?&]/g, "_")}.${fileExtension}`,
|
|
|
|
fileContent: wxacodeResult.buffer,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getWXACode(data) {
|
|
|
|
let {path} = data;
|
|
|
|
const wxacodeResult = await cloud.openapi.wxacode.get({
|
|
|
|
path
|
|
|
|
})
|
|
|
|
|
|
|
|
const fileExtensionMatches = wxacodeResult.contentType.match(/\/([^\/]+)/)
|
|
|
|
const fileExtension = (fileExtensionMatches && fileExtensionMatches[1]) || 'jpg'
|
|
|
|
|
|
|
|
return cloud.uploadFile({
|
|
|
|
cloudPath: `images/wxacode/${path.replace(/[\/?&]/g,"_")}.${fileExtension}`,
|
|
|
|
fileContent: wxacodeResult.buffer,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getOpenData(event) {
|
|
|
|
return cloud.getOpenData({
|
|
|
|
list: event.openData.list,
|
|
|
|
})
|
|
|
|
}
|