112 lines
4.9 KiB
C#
112 lines
4.9 KiB
C#
|
using MyCode.Project.Domain.Config;
|
|||
|
using MyCode.Project.Domain.Message.Act.User;
|
|||
|
using MyCode.Project.Domain.Message.Request.Activity;
|
|||
|
using MyCode.Project.Domain.Message.Request.Member;
|
|||
|
using MyCode.Project.Domain.Message.Request.User;
|
|||
|
using MyCode.Project.Domain.Message.Response.CardCover;
|
|||
|
using MyCode.Project.Domain.Message.Response.Goods;
|
|||
|
using MyCode.Project.Domain.Message.Response.LiveVideo;
|
|||
|
using MyCode.Project.Domain.Message.Response.Member;
|
|||
|
using MyCode.Project.Domain.Message.Response.Wechat;
|
|||
|
using MyCode.Project.Infrastructure.Common;
|
|||
|
using MyCode.Project.Services;
|
|||
|
using MyCode.Project.Services.CustomMessageHandler;
|
|||
|
using MyCode.Project.WebApi.App_Filter;
|
|||
|
using Senparc.NeuChar.Context;
|
|||
|
using Senparc.NeuChar.Entities;
|
|||
|
using Senparc.Weixin.MP;
|
|||
|
using Senparc.Weixin.MP.MessageHandlers;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Web.Http;
|
|||
|
using System.Xml.Linq;
|
|||
|
|
|||
|
namespace MyCode.Project.WebApi.Areas.Member.Controllers
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 微信公众号 相关接口
|
|||
|
/// </summary>
|
|||
|
public class WeChatPublicController : BaseMemberController
|
|||
|
{
|
|||
|
#region 初始化
|
|||
|
private readonly IWorkProcessService _workProcessService;
|
|||
|
public WeChatPublicController(IWorkProcessService workProcessService)
|
|||
|
{
|
|||
|
_workProcessService = workProcessService;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region WeCallBack(微信回调)
|
|||
|
/// <summary>
|
|||
|
/// 微信回调1
|
|||
|
/// </summary>
|
|||
|
[AllowAnonymous, IgnoreResultHandle, HttpGet, HttpPost, ActionName("WeCallBack")]
|
|||
|
|
|||
|
public void WeCallBack()
|
|||
|
{
|
|||
|
var context = CurrentHttpContext;
|
|||
|
string signature = context.Request["signature"];
|
|||
|
string timestamp = context.Request["timestamp"];
|
|||
|
string nonce = context.Request["nonce"];
|
|||
|
string echostr = context.Request["echostr"];
|
|||
|
|
|||
|
//get method -检验是否微信的回调,不是则不执行
|
|||
|
//if (CheckSignature.Check(signature, timestamp, nonce, SystemConfig.WeToken))
|
|||
|
//{
|
|||
|
// string postStr = @" <xml><ToUserName><![CDATA[gh_9022339a2c40]]></ToUserName>
|
|||
|
//<FromUserName><![CDATA[onGWJs5LvcR2NbYMJF2VyRhVH9XU]]></FromUserName>
|
|||
|
//<CreateTime>1576747572</CreateTime>
|
|||
|
//<MsgType><![CDATA[event]]></MsgType>
|
|||
|
//<Event><![CDATA[subscribe]]></Event>
|
|||
|
//<EventKey><![CDATA[]]></EventKey>
|
|||
|
//</xml>";
|
|||
|
Stream s = System.Web.HttpContext.Current.Request.InputStream;//此方法是对System.Web.HttpContext.Current.Request.InputStream的封装,可直接代码
|
|||
|
string postStr = "";
|
|||
|
if (s != null && s.Length > 0)
|
|||
|
{
|
|||
|
s.Position = 0; //当你读取完之后必须把stream的读取位置设为开始
|
|||
|
StreamReader reader = new StreamReader(s, System.Text.Encoding.UTF8);
|
|||
|
postStr = reader.ReadToEnd().ToString();
|
|||
|
}
|
|||
|
|
|||
|
//byte[] b = new byte[s.Length];
|
|||
|
//s.Read(b, 0, (int)s.Length);
|
|||
|
//string postStr = Encoding.UTF8.GetString(b);
|
|||
|
//LogHelper.Info(postStr);
|
|||
|
|
|||
|
var weixinContext = MessageHandler<MessageContext<IRequestMessageBase, IResponseMessageBase>>.GlobalWeixinContext.MessageQueue.FirstOrDefault();
|
|||
|
var recordCount = MessageHandler<MessageContext<IRequestMessageBase, IResponseMessageBase>>.GlobalWeixinContext.MaxRecordCount;
|
|||
|
if (string.IsNullOrEmpty(postStr))
|
|||
|
{
|
|||
|
context.Response.Output.Write(echostr);
|
|||
|
context.Response.End();
|
|||
|
return;
|
|||
|
}
|
|||
|
//var doc = XDocument.Parse(postStr);
|
|||
|
_workProcessService.Add<IWeChatPublicService>(Guid.Parse("00000000-0000-0000-0000-000000000009"), "MemberWeChatPublicCallBack","会员公众号回调", postStr,2);
|
|||
|
|
|||
|
//var maxRecordCount = 1;
|
|||
|
//var messageHandler = new CustomMessageHandler(doc, null, maxRecordCount);
|
|||
|
//messageHandler.OmitRepeatedMessage = true;
|
|||
|
//messageHandler.Execute();
|
|||
|
|
|||
|
//LogHelper.Info("RequestMessages:" + messageHandler.RequestMessage);
|
|||
|
//if (messageHandler.TextResponseMessage != null)
|
|||
|
//{
|
|||
|
// //LogHelper.Info("ResponseMessages:" + messageHandler.TextResponseMessage);
|
|||
|
// context.Response.Output.Write(messageHandler.TextResponseMessage);
|
|||
|
// context.Response.End();
|
|||
|
//}
|
|||
|
//new SuccessResponseMessage();
|
|||
|
context.Response.Output.Write(new SuccessResponseMessage());
|
|||
|
context.Response.End();
|
|||
|
//}
|
|||
|
return;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|