/// <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);