You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
3.4 KiB
78 lines
3.4 KiB
using Senparc.NeuChar.Entities;
|
|
using Senparc.NeuChar.Helpers;
|
|
using Senparc.Weixin.MP.AdvancedAPIs;
|
|
using Senparc.Weixin.MP.Entities;
|
|
using Senparc.Weixin.MP.Entities.Request;
|
|
using Senparc.Weixin.MP.MessageHandlers;
|
|
using Senparc.Weixin.Open.ComponentAPIs;
|
|
using System.IO;
|
|
using Znyc.Recruitment.Admin.WeChat.CommonService.CustomMessageHandler;
|
|
using Znyc.Recruitment.Admin.WeChat.CommonService.OpenTicket;
|
|
|
|
namespace Znyc.Recruitment.Admin.WeChat.CommonService.OpenMessageHandler
|
|
{
|
|
/// <summary>
|
|
/// 开放平台全网发布之前需要做的验证
|
|
/// </summary>
|
|
public class OpenCheckMessageHandler : MessageHandler<CustomMessageContext>
|
|
{
|
|
/*
|
|
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318611&lang=zh_CN
|
|
自动化测试的专用测试公众号的信息如下:
|
|
(1)appid: wx570bc396a51b8ff8
|
|
(2)Username: gh_3c884a361561
|
|
*/
|
|
|
|
//private string testAppId = "wx570bc396a51b8ff8";
|
|
|
|
private readonly string componentAppId = "ComponentAppId";
|
|
private readonly string componentSecret = "Component_Secret";
|
|
|
|
public OpenCheckMessageHandler(Stream inputStream, PostModel postModel, int maxRecordCount = 0)
|
|
: base(inputStream, postModel, maxRecordCount)
|
|
{
|
|
}
|
|
|
|
public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
|
|
{
|
|
if (requestMessage.Content == "TESTCOMPONENT_MSG_TYPE_TEXT")
|
|
{
|
|
ResponseMessageText responseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
|
|
responseMessage.Content =
|
|
requestMessage.Content + "_callback"; //固定为TESTCOMPONENT_MSG_TYPE_TEXT_callback
|
|
return responseMessage;
|
|
}
|
|
|
|
if (requestMessage.Content.StartsWith("QUERY_AUTH_CODE:"))
|
|
{
|
|
string openTicket = OpenTicketHelper.GetOpenTicket(componentAppId);
|
|
string query_auth_code = requestMessage.Content.Replace("QUERY_AUTH_CODE:", "");
|
|
string component_access_token = ComponentApi
|
|
.GetComponentAccessToken(componentAppId, componentSecret, openTicket).component_access_token;
|
|
QueryAuthResult oauthResult = ComponentApi.QueryAuth(component_access_token, componentAppId, query_auth_code);
|
|
|
|
//调用客服接口
|
|
string content = query_auth_code + "_from_api";
|
|
Senparc.Weixin.Entities.WxJsonResult sendResult = CustomApi.SendText(
|
|
oauthResult.authorization_info.authorizer_access_token,
|
|
requestMessage.FromUserName, content);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public override IResponseMessageBase OnEventRequest(IRequestMessageEventBase requestMessage)
|
|
{
|
|
ResponseMessageText responseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
|
|
responseMessage.Content = requestMessage.Event + "from_callback";
|
|
return responseMessage;
|
|
}
|
|
|
|
public override IResponseMessageBase DefaultResponseMessage(IRequestMessageBase requestMessage)
|
|
{
|
|
ResponseMessageText responseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
|
|
responseMessage.Content = "默认消息";
|
|
return responseMessage;
|
|
}
|
|
}
|
|
}
|