Skip to content

Commit

Permalink
Merge pull request #2696 from JeffreySu/Developer
Browse files Browse the repository at this point in the history
Developer
  • Loading branch information
JeffreySu committed Aug 8, 2022
2 parents d4e9cff + 58daa19 commit 9f337d4
Show file tree
Hide file tree
Showing 27 changed files with 1,014 additions and 495 deletions.
732 changes: 371 additions & 361 deletions Contributors.md

Large diffs are not rendered by default.

Expand Up @@ -26,6 +26,7 @@
using Senparc.CO2NET.Helpers;
using Senparc.CO2NET.Extensions;
using Senparc.Weixin.MP;
using Senparc.CO2NET.Trace;

#if NET462
using System.Web.Configuration;
Expand Down Expand Up @@ -97,7 +98,7 @@ public override async Task OnExecutedAsync(CancellationToken cancellationToken)
}
catch (Exception ex)
{
Senparc.CO2NET.Trace.SenparcTrace.SendCustomLog("小程序 OnExecutedAsync 常规跟踪(开发者请忽略)", ex.ToString());
Senparc.CO2NET.Trace.SenparcTrace.SendCustomLog("小程序 OnExecutedAsync 常规跟踪(开发者请忽略)", ex.ToString() + "\r\n" + ex.StackTrace?.ToString());
}
}

Expand Down Expand Up @@ -225,12 +226,17 @@ public override async Task<IResponseMessageBase> OnEvent_UserEnterTempSessionReq

public override async Task<IResponseMessageBase> OnMiniProgramPageRequestAsync(RequestMessageMiniProgramPage requestMessage)
{
var msg = $"您从某个小程序页面来到客服,并且发送了小程序卡片。\r\nTitle:{requestMessage.Title}\r\nAppId:{requestMessage.AppId.Substring(1,5)}...\r\nPagePath:{requestMessage.PagePath}\r\n附带照片:";
await Senparc.Weixin.WxOpen.AdvancedAPIs.CustomApi.SendTextAsync(appId, OpenId, msg);
var msg = $"您从某个小程序页面来到客服,并且发送了小程序卡片。\r\nTitle:{requestMessage.Title}\r\nAppId:{requestMessage.AppId.Substring(1, 5)}...\r\nPagePath:{requestMessage.PagePath}\r\n附带照片:";
await Senparc.Weixin.WxOpen.AdvancedAPIs.CustomApi.SendTextAsync(appId, OpenId, msg);
await Senparc.Weixin.WxOpen.AdvancedAPIs.CustomApi.SendImageAsync(appId, OpenId, requestMessage.ThumbMediaId);
return await DefaultResponseMessageAsync(requestMessage);
}

public override async Task<IResponseMessageBase> OnEvent_MediaCheckRequestAsync(RequestMessageEvent_MediaCheck requestMessage)
{
SenparcTrace.SendCustomLog("收到 OnEvent_MediaCheckRequestAsync 回调请求", requestMessage.ToJson());
return new SuccessResponseMessage();
}

public override IResponseMessageBase DefaultResponseMessage(IRequestMessageBase requestMessage)
{
Expand Down
Expand Up @@ -35,6 +35,7 @@
using Senparc.Weixin.Work.Helpers;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace Senparc.Weixin.Sample.Net6.Controllers
Expand Down Expand Up @@ -77,15 +78,14 @@ public ActionResult Get(string msg_signature = "", string timestamp = "", string
/// </summary>
[HttpPost]
[ActionName("Index")]
public ActionResult Post(PostModel postModel)
public async Task<ActionResult> Post(PostModel postModel)
{
var maxRecordCount = 10;

postModel.Token = Token;
postModel.EncodingAESKey = EncodingAESKey;
postModel.CorpId = CorpId;


#region 用于生产环境测试原始数据
//var ms = new MemoryStream();
//Request.InputStream.CopyTo(ms);
Expand All @@ -99,7 +99,8 @@ public ActionResult Post(PostModel postModel)
#endregion

//自定义MessageHandler,对微信请求的详细判断操作都在这里面。
var messageHandler = new WorkCustomMessageHandler(Request.GetRequestMemoryStream(), postModel, maxRecordCount);
var requestStream = Request.GetRequestMemoryStream();
var messageHandler = new WorkCustomMessageHandler(requestStream, postModel, maxRecordCount);

if (messageHandler.RequestMessage == null)
{
Expand All @@ -108,12 +109,19 @@ public ActionResult Post(PostModel postModel)

try
{
Senparc.Weixin.WeixinTrace.SendApiLog("企业微信收到消息", messageHandler.RequestDocument.ToString());
if (messageHandler.RequestDocument != null)
{
Senparc.Weixin.WeixinTrace.SendApiLog("企业微信收到消息", messageHandler.RequestDocument.ToString());
}
else
{
Senparc.Weixin.WeixinTrace.SendApiLog("企业微信收到消息-XML为空", requestStream);
}

//测试时可开启此记录,帮助跟踪数据,使用前请确保App_Data文件夹存在,且有读写权限。
messageHandler.SaveRequestMessageLog();//记录 Request 日志(可选)

messageHandler.Execute();//执行微信处理过程(关键)
await messageHandler.ExecuteAsync(new CancellationToken());//执行微信处理过程(关键)

messageHandler.SaveResponseMessageLog();//记录 Response 日志(可选)

Expand All @@ -124,16 +132,16 @@ public ActionResult Post(PostModel postModel)
{
using (TextWriter tw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Work_Error_" + SystemTime.Now.Ticks + ".txt")))
{
tw.WriteLine("ExecptionMessage:" + ex.Message);
tw.WriteLine(ex.Source);
tw.WriteLine(ex.StackTrace);
await tw.WriteLineAsync("ExecptionMessage:" + ex.Message);
await tw.WriteLineAsync(ex.Source);
await tw.WriteLineAsync(ex.StackTrace);
//tw.WriteLine("InnerExecptionMessage:" + ex.InnerException.Message);

if (messageHandler.FinalResponseDocument != null && messageHandler.FinalResponseDocument.Root != null)
{
tw.WriteLine(messageHandler.FinalResponseDocument.ToString());
await tw.WriteLineAsync(messageHandler.FinalResponseDocument.ToString());
}
tw.Flush();
await tw.FlushAsync();
tw.Close();
}
return Content("");
Expand Down
Expand Up @@ -94,16 +94,9 @@ public async Task<ActionResult> Post(PostModel postModel)
//v4.2.2之后的版本,可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制
var maxRecordCount = 10;

var logPath = ServerUtility.ContentRootMapPath(string.Format("~/App_Data/WxOpen/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}

//自定义MessageHandler,对微信请求的详细判断操作都在这里面。
var messageHandler = new CustomWxOpenMessageHandler(await Request.GetRequestMemoryStreamAsync(), postModel, maxRecordCount);


try
{
/* 如果需要添加消息去重功能,只需打开OmitRepeatedMessage功能,SDK会自动处理。
Expand Down
2 changes: 1 addition & 1 deletion Samples/All/net6-mvc/Senparc.Weixin.Sample.Net6/Startup.cs
Expand Up @@ -273,7 +273,7 @@ public void ConfigureServices(IServiceCollection services)
* 添加对应证书。
*/
.RegisterTenpayApiV3(senparcWeixinSetting.Value, "【盛派网络小助手】公众号-RealV3")//注册最新的 TenPay V3
.RegisterTenpayApiV3(senparcWeixinSetting.Value, "【盛派网络小助手】公众号-ApiV3")//注册最新的 TenPay V3
#endregion // DPBMARK_END
Expand Down
Expand Up @@ -111,7 +111,7 @@
<th>Nuget 版本</th>
@*<th>Nuget 下载量</th>*@
<th>当前站点运行版本</th>
<th>.NET 4.5.1</th>
<th>.NET 4.6.2</th>
@*<th>.NET Standard<br />2.0 / 2.1</th>*@
<th>.NET Core<br />2.x / 3.x</th>
<th>.NET<br />5.0 / 6.0</th>
Expand Down Expand Up @@ -146,7 +146,7 @@
<text>v@(value.Version)</text>
}
</td>
<td><img title=".NET 4.5.1" alt=".NET 4.5.1" src="https://img.shields.io/badge/4.5.1-@(YesOrNo(value.SupportNet45)).svg" /></td>
<td><img title=".NET 4.6.2" alt=".NET 4.6.2" src="https://img.shields.io/badge/4.6.2-@(YesOrNo(value.SupportNet45)).svg" /></td>
@*<td><img title=".NET Standard 2.0 / 2.1" alt=".NET Standard 2.0 / 2.1" src="https://img.shields.io/badge/standard2.1-@(YesOrNo(value.SupportStandard21)).svg" /></td>*@
<td><img title=".NET Core 2.x / 3.x" alt=".NET Core 2.x / 3.x" src="https://img.shields.io/badge/netcore3.1-@(YesOrNo(value.SupportNetCore31)).svg" /></td>
<td><img title=".NET 5.0 / 6.0" alt=".NET 5.0 / 6.0" src="https://img.shields.io/badge/net6.0-@(YesOrNo(value.SupportNet6)).svg" /></td>
Expand Down
Expand Up @@ -83,12 +83,6 @@ public ActionResult Post(PostModel postModel)
//v4.2.2之后的版本,可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制
var maxRecordCount = 10;

var logPath = ServerUtility.ContentRootMapPath(string.Format("~/App_Data/WxOpen/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}

//自定义MessageHandler,对微信请求的详细判断操作都在这里面。
var messageHandler = new CustomWxOpenMessageHandler(Request.GetRequestMemoryStream(), postModel, maxRecordCount);

Expand Down
@@ -1,21 +1,21 @@
{
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:17967",
"sslPort": 44367
"applicationUrl": "http://localhost:59721/",
"sslPort": 44309
}
},
"profiles": {
"Senparc.Weixin.Sample.WxOpen": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7067;http://localhost:5067",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "https://localhost:7067;http://localhost:5067",
"dotnetRunMessages": true
},
"IIS Express": {
"commandName": "IISExpress",
Expand All @@ -25,4 +25,4 @@
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/Senparc.Weixin.MP/Senparc.Weixin.MP/Enums.cs
Expand Up @@ -335,6 +335,7 @@ public enum Event
/// 点击菜单跳转小程序的事件推送
/// </summary>
view_miniprogram,

#region 微信认证事件推送
/// <summary>
/// 资质认证成功(此时立即获得接口权限)
Expand Down Expand Up @@ -407,6 +408,7 @@ public enum Event
/// </summary>
submit_invoice_title,
#endregion

#region 订阅通知
/// <summary>
/// 用户操作订阅通知弹窗 场景:用户在图文等场景内订阅通知的操作
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1</TargetFrameworks>
<Version>4.14.7</Version>
<Version>4.14.8</Version>
<AssemblyName>Senparc.Weixin.Open</AssemblyName>
<RootNamespace>Senparc.Weixin.Open</RootNamespace>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
Expand Down Expand Up @@ -193,7 +193,8 @@
v4.14.3 补充小程序/公众号获取基本信息字段
v4.14.4 添加半屏小程序管理接口
v4.14.6 添加“查询小程序版本信息”接口
</PackageReleaseNotes>
v4.14.8 增加搜索状态接口
</PackageReleaseNotes>
<RepositoryUrl>https://github.com/JeffreySu/WeiXinMPSDK</RepositoryUrl>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
@@ -0,0 +1,108 @@
#region Apache License Version 2.0
/*----------------------------------------------------------------
Copyright 2022 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
----------------------------------------------------------------*/
#endregion Apache License Version 2.0

/*----------------------------------------------------------------
Copyright (C) 2022 Senparc
文件名:SearchStatusApi.cs
文件功能描述:搜索状态接口
创建标识:Yaofeng - 20220805
----------------------------------------------------------------*/

//文档:https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/basic-info-management/getSearchStatus.html

using Senparc.CO2NET.Extensions;
using Senparc.NeuChar;
using Senparc.Weixin.CommonAPIs;
using Senparc.Weixin.Entities;
using Senparc.Weixin.Open.WxaAPIs.ModifyDomain;
using Senparc.Weixin.Open.WxaAPIs.SearchStatus;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Senparc.Weixin.Open.WxaAPIs
{
[NcApiBind(NeuChar.PlatformType.WeChat_Open, true)]
public class SearchStatusApi
{
#region 同步方法
/// <summary>
/// 获取搜索状态
/// </summary>
/// <param name="accessToken"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static GetWxaSearchStatusResultJson GetWxaSearchStatus(string accessToken, int timeOut = Config.TIME_OUT)
{
var url = string.Format(Config.ApiMpHost + "/wxa/getwxasearchstatus?access_token={0}", accessToken.AsUrlData());
return CommonJsonSend.Send<GetWxaSearchStatusResultJson>(null, url, null, CommonJsonSendType.GET, timeOut);
}

/// <summary>
/// 设置搜索状态
/// </summary>
/// <param name="accessToken"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static WxJsonResult ChangeWxaSearchStatus(string accessToken, int status, int timeOut = Config.TIME_OUT)
{
var url = string.Format(Config.ApiMpHost + "/wxa/changewxasearchstatus?access_token={0}", accessToken.AsUrlData());
object data = new
{
status = status
};
return CommonJsonSend.Send<WxJsonResult>(null, url, data, CommonJsonSendType.POST, timeOut);
}
#endregion

#region 异步方法
/// <summary>
/// 获取搜索状态
/// </summary>
/// <param name="accessToken"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static async Task<GetWxaSearchStatusResultJson> GetWxaSearchStatusAsync(string accessToken, int timeOut = Config.TIME_OUT)
{
var url = string.Format(Config.ApiMpHost + "/wxa/getwxasearchstatus?access_token={0}", accessToken.AsUrlData());
return await CommonJsonSend.SendAsync<GetWxaSearchStatusResultJson>(null, url, null, CommonJsonSendType.GET, timeOut);
}

/// <summary>
/// 设置搜索状态
/// </summary>
/// <param name="accessToken"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static async Task<WxJsonResult> ChangeWxaSearchStatusAsync(string accessToken, int status, int timeOut = Config.TIME_OUT)
{
var url = string.Format(Config.ApiMpHost + "/wxa/changewxasearchstatus?access_token={0}", accessToken.AsUrlData());
object data = new
{
status = status
};
return await CommonJsonSend.SendAsync<WxJsonResult>(null, url, data, CommonJsonSendType.POST, timeOut);
}
#endregion
}
}
@@ -0,0 +1,46 @@
#region Apache License Version 2.0
/*----------------------------------------------------------------
Copyright 2022 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
----------------------------------------------------------------*/
#endregion Apache License Version 2.0

/*----------------------------------------------------------------
Copyright (C) 2022 Senparc
文件名:GetWxaSearchStatusJson.cs
文件功能描述:获取搜索状态返回类型
创建标识:Yaofeng - 20220805
----------------------------------------------------------------*/

using Senparc.Weixin.Entities;

namespace Senparc.Weixin.Open.WxaAPIs.SearchStatus
{
/// <summary>
/// 获取搜索状态返回类型
/// </summary>
public class GetWxaSearchStatusResultJson : WxJsonResult
{
/// <summary>
/// 1 表示不可搜索,0 表示可搜索
/// </summary>
public int status { get; set; }
}
}

0 comments on commit 9f337d4

Please sign in to comment.