• 微信公众号之获取公众平台回复模板,根据关键字动态回复消息 ^


    /// <summary>
    /// 获取回复模板配置
    /// </summary>
    /// <param name="token">微信token</param>
    /// <returns></returns>
    private WeiXinReplyContent GetReplyContent(string token)
    {
    string _baseUrl = "https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info?access_token=" + token;
    var baseResults = WebServiceApi.GetService(_baseUrl);
    var wxUserInfo = JsonConvert.DeserializeObject<WeiXinReplyContent>(baseResults);
    if (wxUserInfo != null)
    {
    var weiXinToken = CachrProfix.WeiXinTemplate;
    var key = new CacheKey(weiXinToken, ApolloToConfigure.Get().WeiXinChatSetting.AppId);
    key.CacheTime = 1440;
    _cacheManager.SetAsync(key, wxUserInfo);
    return wxUserInfo;
    }
    return null;
    }

    /// <summary>
    /// 微信回复内容实体
    /// </summary>
    [DataContract]
    public class WeiXinReplyContent
    {
    [DataMember]
    public int is_add_friend_reply_open { get; set; }

    [DataMember]
    public int is_autoreply_open { get; set; }

    [DataMember]
    public WeiXinReplyInfo add_friend_autoreply_info { get; set; }

    [DataMember]

    public WeiXinAutoreplyList keyword_autoreply_info { get; set; }

    }

    //发送消息对象
    var textMessage = new CusTextMessage
    {
    touser = fromUserName,
    msgtype = "text",
    text = new Content { content = listinfo.content }
    };

    //调用发送客服消息
    SendCusMsg(_access_token, JsonConvert.SerializeObject(textMessage));

    /// <summary>
    /// 发送客服消息
    /// </summary>
    /// <param name="token">微信token</param>
    /// <param name="content">消息内容</param>
    /// <returns></returns>
    private ResultMsg SendCusMsg(string token,string content)
    {
    string _baseUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + token;
    var baseResults = WebServiceApi.PostServer(_baseUrl, content);
    var wxUserInfo = JsonConvert.DeserializeObject<ResultMsg>(baseResults);
    return wxUserInfo;
    }


    注释:返回给微信的文字消息必须是Response.WriteAsync(item);

  • 相关阅读:
    Oracle Vm VirtualBox 搭建 yum 环境
    Vmware Workstation _linux yum 仓库搭建
    redhat5 设置静态ip
    管理表空间和数据文件
    表空间详解
    ocp linux 基础要点
    事务
    Hash哈希类型
    SortedSet有序集合类型
    set集合类型
  • 原文地址:https://www.cnblogs.com/wang150601/p/16300277.html
Copyright © 2020-2023  润新知