码迷,mamicode.com
首页 > 微信 > 详细

c# 微信开发 《主动发送内容》

时间:2018-02-07 16:58:47      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:gty   ccs   media   token   csharp   公众   access   ram   post   

需要用户和公众号,在48小时内有过互动,不然发不出去。

 

  public const string customUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}";

/// <summary> /// 主动推送微信消息 /// </summary> public static void PushWeiXinMessage(string PostData) { try { string Accsss_token = WeiXinCommom.GetAccsss_token(); string PostUrl = string.Format(WeiXinCommom.customUrl, Accsss_token); WeiXinCommom.PostData(PostUrl, PostData); }catch(Exception ex){ LogHelper.WriteFileLog("PushWeiXinMessageError", string.Format("{0}", ex.Message)); return; } } /// <summary> /// 返回要推送的文本信息 /// </summary> /// <param name="WeixinOpendID"></param> /// <param name="Content"></param> /// <returns></returns> public static string ReturnTextMessage(string WeixinOpendID, string Content) { string responeJsonStr = "{"; responeJsonStr += "\"touser\": \"" + WeixinOpendID + "\","; responeJsonStr += "\"msgtype\": \"text\","; responeJsonStr += "\"text\": {"; responeJsonStr += " \"content\": \"" + Content + "\""; responeJsonStr += "},"; responeJsonStr += "\"safe\":\"0\""; responeJsonStr += "}"; return responeJsonStr; } /// <summary> /// 返回要推送的图片信息 /// </summary> /// <param name="WeixinOpendID"></param> /// <param name="Content"></param> /// <returns></returns> public static string ReturnImgMessage(string WeixinOpendID, string MEDIA_ID) { string responeJsonStr = "{"; responeJsonStr += "\"touser\": \"" + WeixinOpendID + "\","; responeJsonStr += "\"msgtype\": \"image\","; responeJsonStr += "\"image\": {"; responeJsonStr += " \"media_id\": \"" + MEDIA_ID + "\""; responeJsonStr += "},"; responeJsonStr += "\"safe\":\"0\""; responeJsonStr += "}"; return responeJsonStr; }

  

c# 微信开发 《主动发送内容》

标签:gty   ccs   media   token   csharp   公众   access   ram   post   

原文地址:https://www.cnblogs.com/yyyuguo/p/8426792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!