Ejemplo n.º 1
0
        /// <summary>
        /// 构建根据OpenID群发消息的Json内容
        /// </summary>
        /// <param name="message"></param>
        /// <param name="openIdList"></param>
        /// <returns></returns>
        public static string BuildPushJsonByOpenID(PushMessage.Base message, List <string> openIdList)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("touser", openIdList);
            dic.Add(message.MsgType, message.GetData());
            dic.Add("msgtype", message.MsgType);

            return(JsonConvert.SerializeObject(dic));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 构建根据群组ID群发消息的Json内容
        /// </summary>
        /// <param name="message"></param>
        /// <param name="groupId"></param>
        /// <param name="isToAll"></param>
        /// <returns></returns>
        public static string BuildPushJsonByGroupID(PushMessage.Base message, string groupId, bool isToAll)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("filter", new { is_to_all = isToAll, group_id = groupId });
            dic.Add(message.MsgType, message.GetData());
            dic.Add("msgtype", message.MsgType);

            return(JsonConvert.SerializeObject(dic));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 构建预览消息的Json内容
        /// </summary>
        /// <param name="message"></param>
        /// <param name="toOpenId">接收消息用户对应该公众号的openid,也可以使用toWxName,以实现对微信号的预览</param>
        /// <param name="toWxName">接收消息用户的微信号</param>
        /// <returns></returns>
        public static string BuildPreviewJson(PushMessage.Base message, string toOpenId, string toWxName)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            if (!string.IsNullOrWhiteSpace(toWxName))
            {
                dic.Add("towxname", toWxName);
            }
            string msgType = message.MsgType == "video" ? "mpvideo" : message.MsgType;

            dic.Add("touser", toOpenId);
            dic.Add(msgType, message.GetData());
            dic.Add("msgtype", msgType);

            return(JsonConvert.SerializeObject(dic));
        }