You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
6.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const cloud = require('wx-server-sdk')
const sceneDescMap = {
[void 0]: "未知",
1000: "其他",
1001: "发现栏小程序主入口「最近使用」列表基础库2.2.4版本起包含「我的小程序」列表)",
1005: "微信首页顶部搜索框的搜索结果页",
1006: "发现栏小程序主入口搜索框的搜索结果页",
1007: "单人聊天会话中的小程序消息卡片",
1008: "群聊会话中的小程序消息卡片",
1011: "扫描二维码",
1012: "长按图片识别二维码",
1013: "扫描手机相册中选取的二维码",
1014: "小程序模板消息",
1017: "前往小程序体验版的入口页",
1019: "微信钱包微信客户端7.0.0版本改为支付入口)",
1020: "公众号profile 页相关小程序列表(已废弃)",
1022: "聊天顶部置顶小程序入口微信客户端6.6.1版本起废弃)",
1023: "安卓系统桌面图标",
1024: "小程序profile页",
1025: "扫描一维码",
1026: "发现栏小程序主入口,「附近的小程序」列表",
1027: "微信首页顶部搜索框搜索结果页「使用过的小程序」列表",
1028: "我的卡包",
1029: "小程序中的卡券详情页",
1030: "自动化测试下打开小程序",
1031: "长按图片识别一维码",
1032: "扫描手机相册中选取的一维码",
1034: "微信支付完成页",
1035: "公众号自定义菜单",
1036: "App分享消息卡片",
1037: "小程序打开小程序",
1038: "从另一个小程序返回",
1039: "摇电视",
1042: "添加好友搜索框的搜索结果页",
1043: "公众号模板消息",
1044: "带shareTicket的小程序消息卡片",
1045: "朋友圈广告",
1046: "朋友圈广告详情页",
1047: "扫描小程序码",
1048: "长按图片识别小程序码",
1049: "扫描手机相册中选取的小程序码",
1052: "卡券的适用门店列表",
1053: "搜一搜的结果页",
1054: "顶部搜索框小程序快捷入口微信客户端版本6.7.4起废弃)",
1056: "聊天顶部音乐播放器右上角菜单",
1057: "钱包中的银行卡详情页",
1058: "公众号文章",
1059: "体验版小程序绑定邀请页",
1064: "微信首页连Wi-Fi状态栏",
1067: "公众号文章广告",
1068: "附近小程序列表广告(已废弃)",
1069: "移动应用",
1071: "钱包中的银行卡列表页",
1072: "二维码收款页面",
1073: "客服消息列表下发的小程序消息卡片",
1074: "公众号会话下发的小程序消息卡片",
1077: "摇周边",
1078: "微信连Wi-Fi成功提示页",
1079: "微信游戏中心",
1081: "客服消息下发的文字链",
1082: "公众号会话下发的文字链",
1084: "朋友圈广告原生页",
1088: "会话中系统消息,打开小程序",
1089: "微信聊天主界面下拉「最近使用」栏基础库2.2.4版本起包含「我的小程序」栏)",
1090: "长按小程序右上角菜单唤出最近使用历史",
1091: "公众号文章商品卡片",
1092: "城市服务入口",
1095: "小程序广告组件",
1096: "聊天记录,打开小程序",
1097: "微信支付签约原生页,打开小程序",
1099: "页面内嵌插件",
1102: "公众号profile 页服务预览",
1103: "发现栏小程序主入口「我的小程序」列表基础库2.2.4版本起废弃)",
1104: "微信聊天主界面下拉「我的小程序」栏基础库2.2.4版本起废弃)",
1106: "聊天主界面下拉,从顶部搜索结果页,打开小程序",
1107: "订阅消息,打开小程序",
1113: "安卓手机负一屏,打开小程序(三星)",
1114: "安卓手机侧边栏,打开小程序(三星)",
1124: "扫“一物一码”打开小程序",
1125: "长按图片识别“一物一码”",
1126: "扫描手机相册中选取的“一物一码”",
1129: "微信爬虫访问",
1131: "浮窗打开小程序",
1135: "小程序资料页打开小程序",
1146: "地理位置信息打开出行类小程序",
1148: "卡包-交通卡,打开小程序",
1150: "扫一扫商品条码结果页打开小程序",
1153: '“识物”结果页打开小程序',
1154:'朋友圈内打开“单页模式”',
1155:'“单页模式”打开小程序',
1169:'发现栏小程序主入口,各个生活服务入口(例如快递服务、出行服务等)'
}
function getFormatTime(date){
date = date || new Date();
let hour = date.getHours();
let minu = date.getMinutes();
let sec = date.getSeconds();
if (hour < 10) hour = "0" + hour;
if (minu < 10) minu = "0" + minu;
if (sec < 10) sec = "0" + sec;
return hour + ":" + minu + ":" + sec;
}
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
const pageHistoryCollection = db.collection("pageHistory");
exports.main = async (event, context) => {
let {name, data} = event;
console.log(event);
const wxContext = cloud.getWXContext();
switch (name) {
case 'getOpenData': {
return cloud.getOpenData(data);
}
case "login":{
return {
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
env: wxContext.ENV,
}
}
case "reportPageHistory":{
console.log("reportPageHistory");
var now = new Date();
let res = await pageHistoryCollection.add({
data:{
...data,
isCrawl: data.scene==1129,
sceneDesc: sceneDescMap[data.scene],
time: now,
timestamp: Date.now(),
openid: wxContext.OPENID
}
});
try{
console.log(sceneDescMap[data.scene].slice(0,31),now.toLocaleTimeString());
let result = await cloud.openapi.subscribeMessage.send({
touser: 'oqugK431bepFwW6TGrHpQTerPkI0',
page: 'admin/pages/page_history/page_history',
lang: 'zh_CN',
templateId: 'atZ4ZFfGIPxTiFGTCtkwvnfqjBA-fM7o1p5OiJQA_0Y',
miniprogramState: 'trial',
data: {
character_string1:{
value:"pageHistory" //服务器
},
character_string2:{
value: (data.route||data.page).match(/\/([^\/]*$)/)[1] //数据类型
},
thing4:{
value:sceneDescMap[data.scene].slice(0,20) //添加内容
},
date3:{
value:getFormatTime(now)
}
}
})
console.log(result);
}catch(e){
console.error(e);
}
return res;
}
case "clearPageHistory":{
return pageHistoryCollection.where(data).remove();
}
default: {
return
}
}
}