Пример #1
0
 /// <summary>
 /// 发送图文客服消息
 /// </summary>
 /// <param name="accessToken">调用凭据</param>
 /// <param name="msg">消息</param>
 /// <returns></returns>
 public static SendCustomMessageResponse SendNewsCustomMessage(string accessToken, NewsCustomMessage msg)
 {
     msg.AccessToken = accessToken;
     return(SendCustomMessage(accessToken, msg));
 }
Пример #2
0
        /// <summary>
        /// 发送图文客服信息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="msg"></param>
        public static void SendNewsCustomMessageTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }


            List <NewsCustomMessageItem> items = new List <NewsCustomMessageItem>();
            NewsCustomMessageItem        itm;

            itm = new NewsCustomMessageItem()
            {
                Description = "汽车描述1-客服信息",
                Url         = "http://www.60px.com",
                PicUrl      = "http://t10.baidu.com/it/u=3676282639,2721194652&fm=23&gp=0.jpg",
                Title       = "汽车标题1"
            };
            items.Add(itm);

            itm = new NewsCustomMessageItem()
            {
                Description = "汽车描述2",
                Url         = "http://www.011011.com",
                PicUrl      = "http://t2.baidu.com/it/u=308326304,3930874379&fm=21&gp=0.jpg",
                Title       = "汽车标题2"
            };
            items.Add(itm);

            itm = new NewsCustomMessageItem()
            {
                Description = "汽车描述3",
                Url         = "http://www.gd-fzc.com",
                PicUrl      = "http://t2.baidu.com/it/u=2618819304,4153638089&fm=21&gp=0.jpg",
                Title       = "汽车标题3"
            };
            items.Add(itm);


            NewsCustomMessage msg = new NewsCustomMessage()
            {
                Articles    = items,
                AccessToken = response.AccessToken.AccessToken,
                MsgType     = "news",
                ToUser      = "******"
            };
            var response2 = MessageHandler.SendNewsCustomMessage(response.AccessToken.AccessToken, msg);

            msg.ToUser = "******";
            response2  = MessageHandler.SendNewsCustomMessage(response.AccessToken.AccessToken, msg);

            if (response2.IsError)
            {
                Console.WriteLine("发送失败");
            }
            else
            {
                Console.WriteLine("发送成功");
            }
            //string accessToken,NewsCustomMessage msg
        }