Beispiel #1
0
        //发送图文消息
        public string SendImageText(out string msg, HttpContext context = null)
        {
            msg = "";
            //消息上传
            method = "POST";
            //for (int i = 0; i < articles.Length; i++)
            //{
            //    articles[i].content = System.Web.HttpUtility.HtmlDecode(articles[i].content);
            //}
            Url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=" + Token;

            string wxstring = WXRequestString(out msg);

            if (msg != "")
            {
                msg = "图文消息创建失败";
                return(msg);
            }


            WX_Message test = JsonConvert.DeserializeObject <WX_Message>(wxstring);

            //消息发送
            test.filter           = new FILTER();
            test.filter.is_to_all = this.filter.is_to_all;
            test.filter.group_id  = filter.group_id;
            test.mpnews           = new MEDIA();
            test.mpnews.media_id  = test.media_id;
            test.msgtype          = "mpnews";
            test.dir = this.dir;
            //filename = test.DownData(out msg, "thumb");
            if (msg != "")
            {
                return("");
            }

            if (preview == false)
            {
                Url      = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=" + Token;
                wxstring = WXRequestString(out msg, null, JsonConvert.SerializeObject(test));
                return(wxstring);
            }
            WX_MessagePreview msgpreview = new WX_MessagePreview();

            msgpreview.touser  = previewuser;
            msgpreview.mpnews  = test.mpnews;
            msgpreview.msgtype = msgtype;
            Url      = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=" + Token;
            wxstring = WXRequestString(out msg, context, JsonConvert.SerializeObject(msgpreview));
            return(wxstring);
        }
Beispiel #2
0
        //发送语音消息
        public string SendVoice(out string msg, HttpContext context = null)
        {
            msgtype = "voice";
            method  = "POST";
            string wxstring = "";

            if (preview == false)
            {
                Url      = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=" + Token;
                wxstring = WXRequestString(out msg);
                return(wxstring);
            }
            //预览,待修改成静态函数,直接调用
            WX_MessagePreview msgpreview = new WX_MessagePreview();

            msgpreview.touser  = previewuser;
            msgpreview.voice   = voice;
            msgpreview.msgtype = msgtype;
            Url      = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=" + Token;
            wxstring = WXRequestString(out msg, context, JsonConvert.SerializeObject(msgpreview));
            return(wxstring);
        }
Beispiel #3
0
        //发送视频消息
        public string SendVideo(out string msg, HttpContext context = null)
        {
            Url    = "https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token=" + Token;
            method = "POST";

            string wxstring = UploadVideo(out msg);//二次上传

            if (msg == "")
            {
                WX_Message videomsg = JsonConvert.DeserializeObject <WX_Message>(wxstring);
                videomsg.filter           = new FILTER();
                videomsg.filter.is_to_all = this.filter.is_to_all;
                videomsg.filter.group_id  = filter.group_id;
                videomsg.Url              = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=" + Token;
                Url                       = videomsg.Url;
                videomsg.mpvideo          = new MEDIA();
                videomsg.mpvideo.media_id = videomsg.media_id;
                videomsg.msgtype          = "mpvideo";
                videomsg.method           = "POST";
                if (preview == false)
                {
                    wxstring = videomsg.WXRequestString(out msg, null, JsonConvert.SerializeObject(videomsg));
                    return(wxstring);
                }
                //预览
                WX_MessagePreview msgpreview = new WX_MessagePreview();
                msgpreview.touser  = previewuser;
                msgpreview.mpvideo = videomsg.mpvideo;
                msgpreview.msgtype = videomsg.msgtype;
                Url      = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=" + Token;
                wxstring = WXRequestString(out msg, context, JsonConvert.SerializeObject(msgpreview));
                return(wxstring);
            }

            return(wxstring);
        }