Skip to content
Permalink
Browse files

added mini program forward code, needs testing

  • Loading branch information...
lhr0909 committed Mar 23, 2019
1 parent ddb3b40 commit 057927caf64f4b811b7269adfc18c7c8dec86efd
@@ -75,7 +75,7 @@ import {

videoPayloadParser,
voicePayloadParser,
generateLocationMessage,
// generateLocationMessage,
} from './pure-function-helpers'

import {
@@ -112,7 +112,7 @@ import {

import { WechatGateway } from './gateway/wechat-gateway'
import { CDNManager } from './manager/cdn-manager'
import { locationPayloadParser } from './pure-function-helpers/message-location-payload-parser';
// import { locationPayloadParser } from './pure-function-helpers/message-location-payload-parser';

let PADPRO_COUNTER = 0 // PuppetPadpro Instance Counter

@@ -1216,7 +1216,8 @@ export class PuppetPadpro extends Puppet {
// await this.forwardLocation(receiver, messageId)
} else if (
payload.type === MessageType.Attachment ||
payload.type === MessageType.ChatHistory
payload.type === MessageType.ChatHistory ||
payload.type === MessageType.MiniProgram
) {
await this.forwardAttachment(receiver, messageId)
} else {
@@ -30,7 +30,7 @@ export const generateAppXMLMessage = ({ title, description, url, thumbnailUrl }:

export const generateAttachmentXMLMessageFromRaw = (payload: PadproAppMessagePayload): string => {
return `
<appmsg appid="" sdkver="0">
<appmsg appid="${payload.$appid}" sdkver="0">
<title>${payload.title}</title>
<des></des>
<username />
@@ -59,6 +59,11 @@ export const generateAttachmentXMLMessageFromRaw = (payload: PadproAppMessagePay
<appattach>
<attachid>${payload.appattach && payload.appattach.attachid}</attachid>
<cdnattachurl>${payload.appattach && payload.appattach.cdnattachurl}</cdnattachurl>
<cdnthumburl>${payload.appattach && payload.appattach.cdnthumburl}</cdnthumburl>
<cdnthumblength>${payload.appattach && payload.appattach.cdnthumblength}</cdnthumblength>
<cdnthumbwidth>${payload.appattach && payload.appattach.cdnthumbwidth}</cdnthumbwidth>
<cdnthumbheight>${payload.appattach && payload.appattach.cdnthumbheight}</cdnthumbheight>
<cdnthumbaeskey>${payload.appattach && payload.appattach.cdnthumbaeskey}</cdnthumbaeskey>
<totallen>${payload.appattach && payload.appattach.totallen}</totallen>
<aeskey>${payload.appattach && payload.appattach.aeskey}</aeskey>
<encryver>${payload.appattach && payload.appattach.encryver}</encryver>
@@ -100,9 +105,16 @@ export const generateAttachmentXMLMessageFromRaw = (payload: PadproAppMessagePay
<template_id />
<md5>${payload.md5 || ''}</md5>
<weappinfo>
<username />
<appid />
<username><![CDATA[${payload.weappinfo && payload.weappinfo.username}]]</username>
<appid><![CDATA[${payload.weappinfo && payload.weappinfo.appid}]]</appid>
<pagepath><![CDATA[${payload.weappinfo && payload.weappinfo.pagepath}]]</pagepath>
<version>${payload.weappinfo && payload.weappinfo.version}</version>
<weappiconurl><![CDATA[${payload.weappinfo && payload.weappinfo.weappiconurl}]]</weappiconurl>
<appservicetype>0</appservicetype>
<pkginfo>
<type>${payload.weappinfo && payload.weappinfo.pkginfo && payload.weappinfo.pkginfo.type}</type>
<md5><![CDATA[${payload.weappinfo && payload.weappinfo.pkginfo && payload.weappinfo.pkginfo.md5}]]></md5>
</pkginfo>
<videopageinfo>
<thumbwidth>0</thumbwidth>
<thumbheight>0</thumbheight>
@@ -119,8 +131,8 @@ export const generateAttachmentXMLMessageFromRaw = (payload: PadproAppMessagePay
<fromusername>${payload.fromusername}</fromusername>
<scene>0</scene>
<appinfo>
<version>1</version>
<appname></appname>
<version>${payload.appinfo && payload.appinfo.version || '1'}</version>
<appname>${payload.appinfo && payload.appinfo.appname}</appname>
</appinfo>
<commenturl></commenturl>`
}
@@ -20,6 +20,10 @@ export async function appMessageParser (rawPayload: PadproMessagePayload): Promi
interface XmlSchema {
msg: {
appmsg: {
$: {
appid: string,
sdkver: string,
},
title: string,
des: string,
type: string,
@@ -30,18 +34,37 @@ export async function appMessageParser (rawPayload: PadproMessagePayload): Promi
emoticonmd5: string,
fileext: string,
cdnattachurl: string,
cdnthumburl: string,
cdnthumbmd5: string,
cdnthumblength: string,
cdnthumbwidth: string,
cdnthumbheight: string,
cdnthumbaeskey: string,
aeskey: string,
encryver: string,
islargefilemsg: string,
// filekey: string,
},
statextstr: string,
thumburl: string,
md5: any,
recorditem?: string
recorditem?: string,
weappinfo?: {
username: string,
appid: string,
pagepath: string,
version: string,
weappiconurl: string,
pkginfo?: {
type: string,
md5: string,
},
},
},
fromusername: string,
appinfo: {
appname: any
appname: string,
version: string,
}
}
}
@@ -51,14 +74,20 @@ export async function appMessageParser (rawPayload: PadproMessagePayload): Promi
try {
const jsonPayload: XmlSchema = await xmlToJson(tryXmlText)

const { title, des, url, thumburl, type, md5, recorditem } = jsonPayload.msg.appmsg
const { appinfo } = jsonPayload.msg;
const { title, des, url, thumburl, type, md5, recorditem, weappinfo } = jsonPayload.msg.appmsg
let appattach: PadproAppAttachPayload | undefined
const tmp = jsonPayload.msg.appmsg.appattach
if (tmp) {
appattach = {
aeskey : tmp.aeskey,
attachid : tmp.attachid,
cdnattachurl : tmp.cdnattachurl,
cdnthumburl : tmp.cdnthumburl,
cdnthumbmd5 : tmp.cdnthumbmd5,
cdnthumblength: tmp.cdnthumblength,
cdnthumbwidth : tmp.cdnthumbwidth,
cdnthumbheight: tmp.cdnthumbheight,
cdnthumbaeskey: tmp.cdnthumbaeskey,
emoticonmd5 : tmp.emoticonmd5,
encryver : parseInt(tmp.encryver, 10),
@@ -67,7 +96,19 @@ export async function appMessageParser (rawPayload: PadproMessagePayload): Promi
islargefilemsg: parseInt(tmp.islargefilemsg, 10),
}
}
return { title, des, url, thumburl, md5, type: parseInt(type, 10), appattach, recorditem }
return {
$appid: jsonPayload.msg.appmsg.$.appid,
title,
des,
url,
thumburl,
md5,
type: parseInt(type, 10),
appattach,
recorditem,
weappinfo,
appinfo,
}
} catch (e) {
log.verbose(e.stack)
return null
@@ -228,6 +228,7 @@ export async function messageRawPayloadParser (
payload.type = MessageType.ChatHistory
break
case WechatAppMessageType.MiniProgram:
case WechatAppMessageType.MiniProgramApp:
payload.type = MessageType.MiniProgram
break
case WechatAppMessageType.RedEnvelopes:
@@ -100,6 +100,7 @@ export enum WechatAppMessageType {
RealtimeShareLocation = 17,
ChatHistory = 19,
MiniProgram = 33,
MiniProgramApp = 36, // this is forwardable mini program
Transfers = 2000,
RedEnvelopes = 2001,
ReaderType = 100001,
@@ -164,6 +164,7 @@ export interface PadproRoomInvitationPayload {
}

export interface PadproAppMessagePayload {
$appid? : string,
des? : string,
thumburl? : string,
title : string,
@@ -173,18 +174,42 @@ export interface PadproAppMessagePayload {
md5? : string,
fromusername? : string,
recorditem? : string,
weappinfo? : PadproWeAppInfoPayload,
appinfo? : PadproAppInfoPayload,
}

export interface PadproAppInfoPayload {
version: string,
appname: string,
}

export interface PadproAppAttachPayload {
totallen? : number,
attachid? : string,
emoticonmd5? : string,
fileext? : string,
cdnattachurl? : string,
aeskey? : string,
cdnattachurl? : string,
cdnthumburl? : string,
cdnthumbmd5? : string,
cdnthumblength?: string,
cdnthumbwidth? : string,
cdnthumbheight?: string,
cdnthumbaeskey?: string,
encryver? : number,
islargefilemsg : number,
islargefilemsg?: number,
}

export interface PadproWeAppInfoPayload {
username: string,
appid: string,
pagepath: string,
version: string,
weappiconurl: string,
pkginfo?: {
type: string,
md5: string,
},
}

export interface PadproEmojiMessagePayload {

0 comments on commit 057927c

Please sign in to comment.
You can’t perform that action at this time.