微信快速開發框架(七)--發送客服信息,版本更新至V2.2 代碼已更新至github


在V2版本發布的博文中,已經介紹了大多數Api的用法,同時也收到了很多意見,其中發布了幾個修正版本,修改了幾個bug,在此感謝大家的使用,有了大家的支持,相信快速開發框架會越來越好,也會越來越完善的。

如果您是第一次看到此框架,可以先從以下鏈接了解下:

一、對微信公眾平台開發的消息處理
   二、快速開發微信公眾平台框架---簡介
   三、建立微信公眾平台測試賬號
   四、體驗微信公眾平台快速開發框架
   五、利用快速開發框架,快速搭建微信瀏覽博客園首頁文章
   六、微信快速開發框架(WXPP QuickFramework)V2.0版本上線--源碼已更新至github

版本說明

此版本關鍵是增加了“發送客服消息”接口,之前大意了,忘記寫了,幸虧@我想我是風的提醒。

目前此項目屬於開源項目,所有代碼都在github中,您也可以通過NuGet獲取

PM> Install-Package JCSoft.WX.Framework

微信文檔中,對於“發送客服消息”有一定限制,必須關注者發送過來消息,包括關注、自定義菜單等事件,我們可以在48小時內通過Post一個Json數據包,發送6種形式的消息。

我用以下名稱,對應這6種消息方式:

1、文本消息:MessageCustomSendTextRequest

2、圖片消息:MessageCustomSendImageRequest

3、語音消息:MessageCustomSendVoiceRequest

4、視頻消息:MessageCustomSendVideoRequest

5、音樂消息:MessageCustomSendMusicRequest

6、圖文消息:MessageCustomSendNewsRequest

以上幾個Request繼承自MessageCustomSendRequest,對應了統一MessageCustomSendResponse。

使用方法

看過之前系列的,應該知道如何使用此Api,這里簡單說下幾個消息類型的構建:

文本消息:

var textRequest = new MessageCustomSendTextRequest
            {
                ToUser = "james",
                Text = new WX.Model.TextMessage
                {
                    Content = "test content"
                }
            };

圖片消息:

        var imageRequest = new MessageCustomSendImageRequest
            {
                ToUser = "james",
                Image = new ImageMessage
                {
                    MediaId = "image_media_id"
                }
            };

語音消息:

        var voiceRequest = new MessageCustomSendVoiceRequest
            {
                ToUser = "james",
                Voice = new VoiceMessage
                {
                    MediaId = "voice_media_id"
                }
            };

視頻消息:

        var videoRequest = new MessageCustomSendVideoRequest
            {
                ToUser = "james",
                Video = new VideoMessage
                {
                    MediaId = "video_media_id",
                    Title = "video test title"
                }
            };

音樂消息:

var musicRequest = new MessageCustomSendMusicRequest
            {
                ToUser = "james",
                Music = new MusicMessage
                {
                    Title = "test music title",
                    HQMusicUrl = "hqmusicurl",
                    MusicURL = "musicurl",
                    ThumbMediaId = "media_id"
                }
            };

圖文消息:

        var newsRequest = new MessageCustomSendNewsRequest
            {
                ToUser = "james",
                News = new NewsMessage
                {
                    Articles = new List<NewsArticleMessage>
                    {
                        new NewsArticleMessage{
                            Title = "Happy Day",
                            Description = "Is Really A Happy Day",
                            Url = "url1",
                            PicUrl = "picurl1"
                        },
                        new NewsArticleMessage {
                            Title = "Happy Day",
                            Description = "Is Really A Happy Day",
                            Url = "url2",
                            PicUrl = "picurl2"
                        }
                    }
                }
            };

以上實例中,ToUser為用戶的OpenId

構建了Request后,只要使用IApiClient.Execute(request)即可得到微信服務端給我們的反饋。

實戰測試

測試中,我只測試了文本消息和圖文消息,通過執行后,結果如下圖所示:

image

其余幾個至測試了輸出的json數據包,並未實戰測試,大家也可以幫我測試下。

寫在最后

這次非常感謝幾位朋友的測試,對我完善框架提供了很大的幫助,因為精力有限,有時候難免會出現這樣或者那樣的錯誤。現在體會到開源的好處,不僅可以完善自己的項目,還能提高自己的水平,也希望大家也進入開源的大軍來。

這1個月,在萬網購買了主機和域名,現在大家可以通過瀏覽以下網址了解微信快速開發框架:

http://www.wxquickframework.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM